blob: 1e13cbec967b517bb0ec1e8823c587bd6eeaaba6 [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.actions;
15
16import com.google.common.collect.ImmutableSet;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010017
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010018/**
Rumou Duan33bab462016-04-25 17:55:12 +000019 * An Analysis phase interface for an {@link Action} or Action-like object, containing only
20 * side-effect-free query methods for information needed during action analysis.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010021 */
Rumou Duan33bab462016-04-25 17:55:12 +000022public interface ActionAnalysisMetadata {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010023 /**
24 * Returns the owner of this executable if this executable can supply verbose information. This is
25 * typically the rule that constructed it; see ActionOwner class comment for details. Returns
26 * {@code null} if no owner can be determined.
27 *
28 * <p>If this executable does not supply verbose information, this function may throw an
29 * IllegalStateException.
30 */
Philipp Wollermannb1b97202015-11-02 10:31:49 +000031 ActionOwner getOwner();
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010032
33 /**
34 * Returns a mnemonic (string constant) for this kind of action; written into
35 * the master log so that the appropriate parser can be invoked for the output
36 * of the action. Effectively a public method as the value is used by the
37 * extra_action feature to match actions.
38 */
39 String getMnemonic();
40
41 /**
42 * Returns a pretty string representation of this action, suitable for use in
43 * progress messages or error messages.
44 */
45 String prettyPrint();
46
47 /**
Philipp Wollermannaf33c672015-11-04 17:52:32 +000048 * Returns the tool Artifacts that this Action depends upon. May be empty. This is a subset of
49 * getInputs().
50 *
51 * <p>This may be used by spawn strategies to determine whether an external tool has not changed
52 * since the last time it was used and could thus be reused, or whether it has to be restarted.
53 *
54 * <p>See {@link AbstractAction#getTools()} for an explanation of why it's important that this
55 * set contains exactly the right set of artifacts in order for the build to stay correct and the
56 * worker strategy to work.
57 */
58 Iterable<Artifact> getTools();
59
60 /**
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010061 * Returns the input Artifacts that this Action depends upon. May be empty.
62 *
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010063 * <p>During execution, the {@link Iterable} returned by {@code getInputs} <em>must not</em> be
64 * concurrently modified before the value is fully read in {@code JavaDistributorDriver#exec} (via
65 * the {@code Iterable<ActionInput>} argument there). Violating this would require somewhat
66 * pathological behavior by the {@link Action}, since it would have to modify its inputs, as a
67 * list, say, without reassigning them. This should never happen with any Action subclassing
68 * AbstractAction, since AbstractAction's implementation of getInputs() returns an immutable
69 * iterable.
70 */
71 Iterable<Artifact> getInputs();
72
73 /**
Klaus Aehlig833fa072016-08-24 09:22:45 +000074 * Returns the environment variables from the client environment that this action depends on. May
75 * be empty.
Klaus Aehlig6f33a1c2016-09-13 16:46:10 +000076 *
77 * <p>Warning: For optimization reasons, the available environment variables are restricted to
78 * those white-listed on the command line. If actions want to specify additional client
79 * environment variables to depend on, that restriction must be lifted in
80 * {@link com.google.devtools.build.lib.runtime.CommandEnvironment}.
Klaus Aehlig833fa072016-08-24 09:22:45 +000081 */
82 Iterable<String> getClientEnvironmentVariables();
83
84 /**
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010085 * Returns the (unordered, immutable) set of output Artifacts that
86 * this action generates. (It would not make sense for this to be empty.)
87 */
88 ImmutableSet<Artifact> getOutputs();
89
90 /**
Lukacs Berki95a4dd02017-03-14 11:24:01 +000091 * Returns input files that need to be present to allow extra_action rules to shadow this action
92 * correctly when run remotely. This is at least the normal inputs of the action, but may include
93 * other files as well. For example C(++) compilation may perform include file header scanning.
94 * This needs to be mirrored by the extra_action rule. Called by
ulfjack9220eec2017-08-10 12:29:25 +020095 * {@link com.google.devtools.build.lib.analysis.extra.ExtraAction} at execution time for actions
Lukacs Berki95a4dd02017-03-14 11:24:01 +000096 * that return true for {link #discoversInputs()}.
97 *
98 * @param actionExecutionContext Services in the scope of the action, like the Out/Err streams.
99 * @throws ActionExecutionException only when code called from this method
100 * throws that exception.
101 * @throws InterruptedException if interrupted
102 */
103 Iterable<Artifact> getInputFilesForExtraAction(ActionExecutionContext actionExecutionContext)
104 throws ActionExecutionException, InterruptedException;
105
106 /**
Michajlo Matijkiw13459b42015-03-12 19:43:20 +0000107 * Returns the set of output Artifacts that are required to be saved. This is
108 * used to identify items that would otherwise be potentially identified as
109 * orphaned (not consumed by any downstream {@link Action}s and potentially
110 * discarded during the build process.
111 */
Philipp Wollermannb1b97202015-11-02 10:31:49 +0000112 ImmutableSet<Artifact> getMandatoryOutputs();
Michajlo Matijkiw13459b42015-03-12 19:43:20 +0000113
114 /**
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100115 * Returns the "primary" input of this action, if applicable.
116 *
117 * <p>For example, a C++ compile action would return the .cc file which is being compiled,
118 * irrespective of the other inputs.
119 *
120 * <p>May return null.
121 */
122 Artifact getPrimaryInput();
123
124 /**
125 * Returns the "primary" output of this action.
126 *
127 * <p>For example, the linked library would be the primary output of a LinkAction.
128 *
129 * <p>Never returns null.
130 */
131 Artifact getPrimaryOutput();
132
133 /**
134 * Returns an iterable of input Artifacts that MUST exist prior to executing an action. In other
135 * words, in case when action is scheduled for execution, builder will ensure that all artifacts
136 * returned by this method are present in the filesystem (artifact.getPath().exists() is true) or
137 * action execution will be aborted with an error that input file does not exist. While in
138 * majority of cases this method will return all action inputs, for some actions (e.g.
139 * CppCompileAction) it can return a subset of inputs because that not all action inputs might be
140 * mandatory for action execution to succeed (e.g. header files retrieved from *.d file from the
141 * previous build).
142 */
143 Iterable<Artifact> getMandatoryInputs();
144
145 /**
Rumou Duan33bab462016-04-25 17:55:12 +0000146 * @return true iff path prefix conflict (conflict where two actions generate
147 * two output artifacts with one of the artifact's path being the
148 * prefix for another) between this action and another action should
149 * be reported.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100150 */
Rumou Duan33bab462016-04-25 17:55:12 +0000151 boolean shouldReportPathPrefixConflict(ActionAnalysisMetadata action);
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100152
Rumou Duan33bab462016-04-25 17:55:12 +0000153 /** Returns the action type. Must not be {@code null}. */
154 MiddlemanType getActionType();
155
156 /** The action type. */
157 public enum MiddlemanType {
158
159 /** A normal action. */
160 NORMAL,
161
162 /** A normal middleman, which just encapsulates a list of artifacts. */
163 AGGREGATING_MIDDLEMAN,
164
165 /**
166 * A middleman that enforces action ordering, is not validated by the dependency checker, but
167 * allows errors to be propagated.
168 */
169 ERROR_PROPAGATING_MIDDLEMAN,
170
171 /**
172 * A runfiles middleman, which is validated by the dependency checker, but is not expanded
173 * in blaze. Instead, the runfiles manifest is sent to remote execution client, which
174 * performs the expansion.
175 */
176 RUNFILES_MIDDLEMAN;
177
178 public boolean isMiddleman() {
179 return this != NORMAL;
180 }
181 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100182}