-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
ArgChunk
, a layer of indirection in CommandLine
expansi…
…on that allows lazy command lines to provide an efficient way to obtain the total argument length without materializing the arguments. An `AbstractCommandLine` class is split out to provide simple implementations of the modified interface. Currently, all implementations use `AbstractCommandLine`, but soon `StarlarkCustomCommandLine` won't. At that point, it will use a lazy `Iterable` and an efficient custom implementation of `ArgChunk#totalArgLength`. PiperOrigin-RevId: 610413772 Change-Id: Id6216cdea28345ddd17d7fa15f1cd3857bc92715
- Loading branch information
1 parent
81fa509
commit b82dcdc
Showing
10 changed files
with
180 additions
and
75 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/main/java/com/google/devtools/build/lib/actions/AbstractCommandLine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2014 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.actions; | ||
|
||
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander; | ||
import com.google.devtools.build.lib.util.Fingerprint; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Partial implementation of a {@link CommandLine} suitable for when expansion eagerly materializes | ||
* strings. | ||
*/ | ||
public abstract class AbstractCommandLine extends CommandLine { | ||
|
||
@Override | ||
public final ArgChunk expand() throws CommandLineExpansionException, InterruptedException { | ||
return new SimpleArgChunk(arguments()); | ||
} | ||
|
||
@Override | ||
public final ArgChunk expand(ArtifactExpander artifactExpander, PathMapper pathMapper) | ||
throws CommandLineExpansionException, InterruptedException { | ||
return new SimpleArgChunk(arguments(artifactExpander, pathMapper)); | ||
} | ||
|
||
/** | ||
* Returns the expanded command line with enclosed artifacts expanded by {@code artifactExpander} | ||
* at execution time. | ||
* | ||
* <p>By default, this method just delegates to {@link #arguments()}, without performing any | ||
* artifact expansion. Subclasses should override this method if they contain tree artifacts and | ||
* need to expand them for proper argument evaluation. | ||
*/ | ||
@Override | ||
public Iterable<String> arguments(ArtifactExpander artifactExpander, PathMapper pathMapper) | ||
throws CommandLineExpansionException, InterruptedException { | ||
return arguments(); | ||
} | ||
|
||
@Override | ||
public void addToFingerprint( | ||
ActionKeyContext actionKeyContext, | ||
@Nullable ArtifactExpander artifactExpander, | ||
Fingerprint fingerprint) | ||
throws CommandLineExpansionException, InterruptedException { | ||
for (String s : arguments()) { | ||
fingerprint.addString(s); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.