diff options
author | 2017-02-10 17:24:03 +0000 | |
---|---|---|
committer | 2017-02-10 18:19:31 +0000 | |
commit | 5490757be5e527df82eee5094a0f59c86a5de766 (patch) | |
tree | 6d75800e0348de7e3472dd37de75d467a65fb468 /src/main/java/com/google/devtools/build/lib/analysis | |
parent | 762576e5e7a3ee0da39dbb24134cb8530cbb911e (diff) |
Introduce CppCompileActionTemplate, which expands into a list of CppCompileActions that to be executed at execution time.
--
PiperOrigin-RevId: 147163077
MOS_MIGRATED_REVID=147163077
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/actions/ActionTemplate.java | 75 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTemplate.java | 85 |
2 files changed, 84 insertions, 76 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/ActionTemplate.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/ActionTemplate.java new file mode 100644 index 0000000000..afad7b736d --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/ActionTemplate.java @@ -0,0 +1,75 @@ +// Copyright 2017 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.analysis.actions; + +import com.google.devtools.build.lib.actions.Action; +import com.google.devtools.build.lib.actions.ActionAnalysisMetadata; +import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact; +import com.google.devtools.build.lib.actions.ArtifactOwner; + +/** + * A placeholder action that, at execution time, expands into a list of {@link Action}s to be + * executed. + * + * <p>ActionTemplate is for users who want to dynamically register Actions operating on + * individual {@link TreeFileArtifact} inside input and output TreeArtifacts at execution time. + * + * <p>It takes in one TreeArtifact and generates one TreeArtifact. The following happens at + * execution time for ActionTemplate: + * <ol> + * <li>Input TreeArtifact is resolved. + * <li>For each individual {@link TreeFileArtifact} inside input TreeArtifact, generate an output + * {@link TreeFileArtifact} inside output TreeArtifact. + * <li>For each pair of input and output {@link TreeFileArtifact}s, generate an associated + * {@link Action}. + * <li>All expanded {@link Action}s are executed and their output {@link TreeFileArtifact}s + * collected. + * <li>Output TreeArtifact is resolved. + * </ol> + * + * <p>Implementations of ActionTemplate must follow the contract of this interface and also make + * sure: + * <ol> + * <li>ActionTemplate instances should be immutable and side-effect free. + * <li>ActionTemplate inputs and outputs are supersets of the inputs and outputs of expanded + * actions, excluding inputs discovered at execution time. This ensures the ActionTemplate + * can properly represent the expanded actions at analysis time, and the action graph + * at analysis time is correct. This is important because the action graph is walked in a lot + * of places for correctness checks and build analysis. + * <li>The outputs of expanded actions must be under the output TreeArtifact and must not have + * artifact or artifact path prefix conflicts. + * </ol> + */ +public interface ActionTemplate<T extends Action> extends ActionAnalysisMetadata { + /** + * Given a list of input TreeFileArtifacts resolved at execution time, returns a list of expanded + * SpawnActions to be executed. + * + * @param inputTreeFileArtifacts the list of {@link TreeFileArtifact}s inside input TreeArtifact + * resolved at execution time + * @param artifactOwner the {@link ArtifactOwner} of the generated output + * {@link TreeFileArtifact}s + * @return a list of expanded {@link Action}s to execute, one for each input + * {@link TreeFileArtifact} + */ + Iterable<T> generateActionForInputArtifacts( + Iterable<TreeFileArtifact> inputTreeFileArtifacts, ArtifactOwner artifactOwner); + + /** Returns the input TreeArtifact. */ + Artifact getInputTreeArtifact(); + + /** Returns the output TreeArtifact. */ + Artifact getOutputTreeArtifact(); +} diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTemplate.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTemplate.java index 4587e4a133..6394c0cbf1 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTemplate.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTemplate.java @@ -18,12 +18,9 @@ import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.actions.ActionAnalysisMetadata; import com.google.devtools.build.lib.actions.ActionInputHelper; import com.google.devtools.build.lib.actions.ActionOwner; -import com.google.devtools.build.lib.actions.Actions; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact; import com.google.devtools.build.lib.actions.ArtifactOwner; -import com.google.devtools.build.lib.actions.ArtifactPrefixConflictException; -import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; import com.google.devtools.build.lib.analysis.FilesToRunProvider; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; @@ -32,27 +29,9 @@ import com.google.devtools.build.lib.vfs.PathFragment; import java.util.Map; /** - * A placeholder action that, at execution time, expands into a list of {@link SpawnAction}s that - * will be executed. - * - * <p>SpawnActionTemplate is for users who want to dynamically register SpawnActions operating on - * individual {@link TreeFileArtifact} inside input and output TreeArtifacts at execution time. - * - * <p>It takes in one TreeArtifact and generates one TreeArtifact. The following happens at - * execution time for SpawnActionTemplate: - * <ol> - * <li>Input TreeArtifact is resolved. - * <li>For each individual {@link TreeFileArtifact} inside input TreeArtifact, generate an output - * {@link TreeFileArtifact} inside output TreeArtifact at the parent-relative path provided by - * {@link OutputPathMapper}. - * <li>For each pair of input and output {@link TreeFileArtifact}s, generate an associated - * {@link SpawnAction}. - * <li>All expanded {@link SpawnAction}s are executed and their output {@link TreeFileArtifact}s - * collected. - * <li>Output TreeArtifact is resolved. - * </ol> + * An {@link ActionTemplate} that expands into {@link SpawnAction}s at execution time. */ -public final class SpawnActionTemplate implements ActionAnalysisMetadata { +public final class SpawnActionTemplate implements ActionTemplate<SpawnAction> { private final Artifact inputTreeArtifact; private final Artifact outputTreeArtifact; private final NestedSet<Artifact> commonInputs; @@ -110,39 +89,23 @@ public final class SpawnActionTemplate implements ActionAnalysisMetadata { this.commandLineTemplate = commandLineTemplate; } - /** - * Given a list of input TreeFileArtifacts resolved at execution time, returns a list of expanded - * SpawnActions to be executed. - * - * @param inputTreeFileArtifacts the list of {@link TreeFileArtifact}s inside input TreeArtifact - * resolved at execution time - * @param artifactOwner the {@link ArtifactOwner} of the generated output - * {@link TreeFileArtifact}s - * @return a list of expanded {@link SpawnAction}s to execute, one for each input - * {@link TreeFileArtifact} - * @throws ActionConflictException if the expanded actions have duplicated outputs - * @throws ArtifactPrefixConflictException if there is prefix conflict among the outputs of - * expanded actions - */ + @Override public Iterable<SpawnAction> generateActionForInputArtifacts( - Iterable<TreeFileArtifact> inputTreeFileArtifacts, ArtifactOwner artifactOwner) - throws ActionConflictException, ArtifactPrefixConflictException { + Iterable<TreeFileArtifact> inputTreeFileArtifacts, ArtifactOwner artifactOwner) { ImmutableList.Builder<SpawnAction> expandedActions = new ImmutableList.Builder<>(); for (TreeFileArtifact inputTreeFileArtifact : inputTreeFileArtifacts) { PathFragment parentRelativeOutputPath = outputPathMapper.parentRelativeOutputPath(inputTreeFileArtifact); - TreeFileArtifact outputTreeFileArtifact = createTreeFileArtifact( + TreeFileArtifact outputTreeFileArtifact = ActionInputHelper.treeFileArtifact( outputTreeArtifact, - checkOutputParentRelativePath(parentRelativeOutputPath), + parentRelativeOutputPath, artifactOwner); expandedActions.add(createAction(inputTreeFileArtifact, outputTreeFileArtifact)); } - Iterable<SpawnAction> actions = expandedActions.build(); - checkActionAndArtifactConflicts(ImmutableList.<ActionAnalysisMetadata>copyOf(actions)); - return actions; + return expandedActions.build(); } /** @@ -171,37 +134,6 @@ public final class SpawnActionTemplate implements ActionAnalysisMetadata { /*paramFileWriteAction=*/ null); } - private static void checkActionAndArtifactConflicts(Iterable<ActionAnalysisMetadata> actions) - throws ActionConflictException, ArtifactPrefixConflictException { - Map<Artifact, ActionAnalysisMetadata> generatingActions = - Actions.findAndThrowActionConflict(actions); - Map<ActionAnalysisMetadata, ArtifactPrefixConflictException> artifactPrefixConflictMap = - Actions.findArtifactPrefixConflicts(generatingActions); - - if (!artifactPrefixConflictMap.isEmpty()) { - throw artifactPrefixConflictMap.values().iterator().next(); - } - - return; - } - - private static PathFragment checkOutputParentRelativePath(PathFragment parentRelativeOutputPath) { - Preconditions.checkArgument( - parentRelativeOutputPath.isNormalized() && !parentRelativeOutputPath.isAbsolute(), - "%s is not a proper relative path", - parentRelativeOutputPath); - return parentRelativeOutputPath; - } - - private static TreeFileArtifact createTreeFileArtifact(Artifact parentTreeArtifact, - PathFragment parentRelativeOutputPath, ArtifactOwner artifactOwner) { - return ActionInputHelper.treeFileArtifact( - parentTreeArtifact, - parentRelativeOutputPath, - artifactOwner); - } - - /** * Returns the input TreeArtifact. * @@ -209,11 +141,13 @@ public final class SpawnActionTemplate implements ActionAnalysisMetadata { * TreeFileArtifacts. Skyframe then expands this SpawnActionTemplate with the TreeFileArtifacts * through {@link #generateActionForInputArtifacts}. */ + @Override public Artifact getInputTreeArtifact() { return inputTreeArtifact; } /** Returns the output TreeArtifact. */ + @Override public Artifact getOutputTreeArtifact() { return outputTreeArtifact; } @@ -223,7 +157,6 @@ public final class SpawnActionTemplate implements ActionAnalysisMetadata { return actionOwner; } - @Override public final String getMnemonic() { return mnemonic; |