Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | // |
| 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. |
| 14 | package com.google.devtools.build.lib.actions; |
| 15 | |
| 16 | import com.google.common.collect.ImmutableSet; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 17 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 18 | /** |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 19 | * 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 21 | */ |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 22 | public interface ActionAnalysisMetadata { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 23 | /** |
| 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 Wollermann | b1b9720 | 2015-11-02 10:31:49 +0000 | [diff] [blame] | 31 | ActionOwner getOwner(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 32 | |
| 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 Wollermann | af33c67 | 2015-11-04 17:52:32 +0000 | [diff] [blame] | 48 | * 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 61 | * Returns the input Artifacts that this Action depends upon. May be empty. |
| 62 | * |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 63 | * <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 Aehlig | 833fa07 | 2016-08-24 09:22:45 +0000 | [diff] [blame] | 74 | * Returns the environment variables from the client environment that this action depends on. May |
| 75 | * be empty. |
Klaus Aehlig | 6f33a1c | 2016-09-13 16:46:10 +0000 | [diff] [blame] | 76 | * |
| 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 Aehlig | 833fa07 | 2016-08-24 09:22:45 +0000 | [diff] [blame] | 81 | */ |
| 82 | Iterable<String> getClientEnvironmentVariables(); |
| 83 | |
| 84 | /** |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 85 | * 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 Berki | 95a4dd0 | 2017-03-14 11:24:01 +0000 | [diff] [blame] | 91 | * 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 |
ulfjack | 9220eec | 2017-08-10 12:29:25 +0200 | [diff] [blame] | 95 | * {@link com.google.devtools.build.lib.analysis.extra.ExtraAction} at execution time for actions |
Lukacs Berki | 95a4dd0 | 2017-03-14 11:24:01 +0000 | [diff] [blame] | 96 | * 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 Matijkiw | 13459b4 | 2015-03-12 19:43:20 +0000 | [diff] [blame] | 107 | * 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 Wollermann | b1b9720 | 2015-11-02 10:31:49 +0000 | [diff] [blame] | 112 | ImmutableSet<Artifact> getMandatoryOutputs(); |
Michajlo Matijkiw | 13459b4 | 2015-03-12 19:43:20 +0000 | [diff] [blame] | 113 | |
| 114 | /** |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 115 | * 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 Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 146 | * @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 150 | */ |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 151 | boolean shouldReportPathPrefixConflict(ActionAnalysisMetadata action); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 152 | |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 153 | /** 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 182 | } |