use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class BuildView method update.
@ThreadCompatible
public AnalysisResult update(LoadingResult loadingResult, BuildConfigurationCollection configurations, List<String> aspects, Options viewOptions, TopLevelArtifactContext topLevelOptions, ExtendedEventHandler eventHandler, EventBus eventBus) throws ViewCreationFailedException, InterruptedException {
LOG.info("Starting analysis");
pollInterruptedStatus();
skyframeBuildView.resetEvaluatedConfiguredTargetKeysSet();
Collection<Target> targets = loadingResult.getTargets();
eventBus.post(new AnalysisPhaseStartedEvent(targets));
skyframeBuildView.setConfigurations(configurations);
// Determine the configurations.
List<TargetAndConfiguration> topLevelTargetsWithConfigs = nodesForTopLevelTargets(configurations, targets, eventHandler);
List<ConfiguredTargetKey> topLevelCtKeys = Lists.transform(topLevelTargetsWithConfigs, new Function<TargetAndConfiguration, ConfiguredTargetKey>() {
@Override
public ConfiguredTargetKey apply(TargetAndConfiguration node) {
return new ConfiguredTargetKey(node.getLabel(), node.getConfiguration());
}
});
List<AspectValueKey> aspectKeys = new ArrayList<>();
for (String aspect : aspects) {
// Syntax: label%aspect
int delimiterPosition = aspect.indexOf('%');
if (delimiterPosition >= 0) {
// TODO(jfield): For consistency with Skylark loads, the aspect should be specified
// as an absolute path. Also, we probably need to do at least basic validation of
// path well-formedness here.
String bzlFileLoadLikeString = aspect.substring(0, delimiterPosition);
if (!bzlFileLoadLikeString.startsWith("//") && !bzlFileLoadLikeString.startsWith("@")) {
// "Legacy" behavior of '--aspects' parameter.
bzlFileLoadLikeString = new PathFragment("/" + bzlFileLoadLikeString).toString();
if (bzlFileLoadLikeString.endsWith(".bzl")) {
bzlFileLoadLikeString = bzlFileLoadLikeString.substring(0, bzlFileLoadLikeString.length() - ".bzl".length());
}
}
SkylarkImport skylarkImport;
try {
skylarkImport = SkylarkImports.create(bzlFileLoadLikeString);
} catch (SkylarkImportSyntaxException e) {
throw new ViewCreationFailedException(String.format("Invalid aspect '%s': %s", aspect, e.getMessage()), e);
}
String skylarkFunctionName = aspect.substring(delimiterPosition + 1);
for (TargetAndConfiguration targetSpec : topLevelTargetsWithConfigs) {
if (!(targetSpec.getTarget() instanceof Rule)) {
continue;
}
aspectKeys.add(AspectValue.createSkylarkAspectKey(targetSpec.getLabel(), // aspect and the base target while the top-level configuration is untrimmed.
targetSpec.getConfiguration(), targetSpec.getConfiguration(), skylarkImport, skylarkFunctionName));
}
} else {
final NativeAspectClass aspectFactoryClass = ruleClassProvider.getNativeAspectClassMap().get(aspect);
if (aspectFactoryClass != null) {
for (TargetAndConfiguration targetSpec : topLevelTargetsWithConfigs) {
if (!(targetSpec.getTarget() instanceof Rule)) {
continue;
}
// For invoking top-level aspects, use the top-level configuration for both the
// aspect and the base target while the top-level configuration is untrimmed.
BuildConfiguration configuration = targetSpec.getConfiguration();
aspectKeys.add(AspectValue.createAspectKey(targetSpec.getLabel(), configuration, new AspectDescriptor(aspectFactoryClass, AspectParameters.EMPTY), configuration));
}
} else {
throw new ViewCreationFailedException("Aspect '" + aspect + "' is unknown");
}
}
}
skyframeExecutor.injectWorkspaceStatusData(loadingResult.getWorkspaceName());
SkyframeAnalysisResult skyframeAnalysisResult;
try {
skyframeAnalysisResult = skyframeBuildView.configureTargets(eventHandler, topLevelCtKeys, aspectKeys, eventBus, viewOptions.keepGoing, viewOptions.loadingPhaseThreads);
setArtifactRoots(skyframeAnalysisResult.getPackageRoots());
} finally {
skyframeBuildView.clearInvalidatedConfiguredTargets();
}
int numTargetsToAnalyze = topLevelTargetsWithConfigs.size();
int numSuccessful = skyframeAnalysisResult.getConfiguredTargets().size();
if (0 < numSuccessful && numSuccessful < numTargetsToAnalyze) {
String msg = String.format("Analysis succeeded for only %d of %d top-level targets", numSuccessful, numTargetsToAnalyze);
eventHandler.handle(Event.info(msg));
LOG.info(msg);
}
AnalysisResult result = createResult(eventHandler, loadingResult, topLevelOptions, viewOptions, skyframeAnalysisResult);
LOG.info("Finished analysis");
return result;
}
use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class DependencyResolver method dependentNodeMap.
/**
* Returns ids for dependent nodes of a given node, sorted by attribute. Note that some
* dependencies do not have a corresponding attribute here, and we use the null attribute to
* represent those edges.
*
* <p>If {@code aspects} is empty, returns the dependent nodes of the configured target node
* representing the given target and configuration.
*
* Otherwise {@code aspects} represents an aspect path. The function returns dependent nodes
* of the entire path applied to given target and configuration. These are the depenent nodes
* of the last aspect in the path.
*
* <p>This also implements the first step of applying
* configuration transitions, namely, split transitions. This needs to be done before the labels
* are resolved because late bound attributes depend on the configuration. A good example for this
* is @{code :cc_toolchain}.
*
* <p>The long-term goal is that most configuration transitions be applied here. However, in order
* to do that, we first have to eliminate transitions that depend on the rule class of the
* dependency.
*
* @param node the target/configuration being evaluated
* @param hostConfig the configuration this target would use if it was evaluated as a host tool.
* This is needed to support {@link LateBoundDefault#useHostConfiguration()}.
* @param aspects the aspects applied to this target (if any)
* @param configConditions resolver for config_setting labels
* @param rootCauses collector for dep labels that can't be (loading phase) loaded
* @return a mapping of each attribute in this rule or aspects to its dependent nodes
*/
public final OrderedSetMultimap<Attribute, Dependency> dependentNodeMap(TargetAndConfiguration node, BuildConfiguration hostConfig, Iterable<Aspect> aspects, ImmutableMap<Label, ConfigMatchingProvider> configConditions, NestedSetBuilder<Label> rootCauses) throws EvalException, InvalidConfigurationException, InterruptedException, InconsistentAspectOrderException {
Target target = node.getTarget();
BuildConfiguration config = node.getConfiguration();
OrderedSetMultimap<Attribute, Dependency> outgoingEdges = OrderedSetMultimap.create();
if (target instanceof OutputFile) {
Preconditions.checkNotNull(config);
visitTargetVisibility(node, rootCauses, outgoingEdges.get(null));
Rule rule = ((OutputFile) target).getGeneratingRule();
outgoingEdges.put(null, Dependency.withConfiguration(rule.getLabel(), config));
} else if (target instanceof InputFile) {
visitTargetVisibility(node, rootCauses, outgoingEdges.get(null));
} else if (target instanceof EnvironmentGroup) {
visitTargetVisibility(node, rootCauses, outgoingEdges.get(null));
} else if (target instanceof Rule) {
visitRule(node, hostConfig, aspects, configConditions, rootCauses, outgoingEdges);
} else if (target instanceof PackageGroup) {
visitPackageGroup(node, (PackageGroup) target, rootCauses, outgoingEdges.get(null));
} else {
throw new IllegalStateException(target.getLabel().toString());
}
return outgoingEdges;
}
use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class ExtraActionUtils method createExtraActionProvider.
/**
* Scans {@code action_listeners} associated with this build to see if any
* {@code extra_actions} should be added to this configured target. If any
* action_listeners are present, a partial visit of the artifact/action graph
* is performed (for as long as actions found are owned by this {@link
* ConfiguredTarget}). Any actions that match the {@code action_listener}
* get an {@code extra_action} associated. The output artifacts of the
* extra_action are reported to the {@link AnalysisEnvironment} for
* bookkeeping.
*/
static ExtraActionArtifactsProvider createExtraActionProvider(Set<ActionAnalysisMetadata> actionsWithoutExtraAction, RuleContext ruleContext) {
BuildConfiguration configuration = ruleContext.getConfiguration();
if (configuration.isHostConfiguration()) {
return ExtraActionArtifactsProvider.EMPTY;
}
ImmutableList<Artifact> extraActionArtifacts = ImmutableList.of();
NestedSetBuilder<Artifact> builder = NestedSetBuilder.stableOrder();
List<Label> actionListenerLabels = configuration.getActionListeners();
if (!actionListenerLabels.isEmpty() && ruleContext.attributes().getAttributeDefinition(":action_listener") != null) {
ExtraActionsVisitor visitor = new ExtraActionsVisitor(ruleContext, computeMnemonicsToExtraActionMap(ruleContext));
// thus the copy
for (ActionAnalysisMetadata action : ImmutableList.copyOf(ruleContext.getAnalysisEnvironment().getRegisteredActions())) {
if (!actionsWithoutExtraAction.contains(action)) {
visitor.maybeAddExtraAction(action);
}
}
extraActionArtifacts = visitor.getAndResetExtraArtifacts();
if (!extraActionArtifacts.isEmpty()) {
builder.addAll(extraActionArtifacts);
}
}
// Add extra action artifacts from dependencies
for (ExtraActionArtifactsProvider provider : AnalysisUtils.getProviders(ruleContext.getConfiguredTargetMap().values(), ExtraActionArtifactsProvider.class)) {
builder.addTransitive(provider.getTransitiveExtraActionArtifacts());
}
return ExtraActionArtifactsProvider.create(NestedSetBuilder.<Artifact>stableOrder().addAll(extraActionArtifacts).build(), builder.build());
}
use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class RunfilesSupport method createRunfilesAction.
/**
* Creates a runfiles action for all of the specified files, and returns the
* output artifact (the artifact for the MANIFEST file).
*
* <p>The "runfiles" action creates a symlink farm that links all the runfiles
* (which may come from different places, e.g. different package paths,
* generated files, etc.) into a single tree, so that programs can access them
* using the workspace-relative name.
*/
private Artifact createRunfilesAction(ActionConstructionContext context, Runfiles runfiles, Artifact artifactsMiddleman) {
// Compute the names of the runfiles directory and its MANIFEST file.
Artifact inputManifest = getRunfilesInputManifest();
context.getAnalysisEnvironment().registerAction(SourceManifestAction.forRunfiles(ManifestType.SOURCE_SYMLINKS, context.getActionOwner(), inputManifest, runfiles));
if (!createSymlinks) {
// Just return the manifest if that's all the build calls for.
return inputManifest;
}
PathFragment runfilesDir = FileSystemUtils.replaceExtension(inputManifest.getRootRelativePath(), RUNFILES_DIR_EXT);
PathFragment outputManifestPath = runfilesDir.getRelative("MANIFEST");
BuildConfiguration config = context.getConfiguration();
Artifact outputManifest = context.getDerivedArtifact(outputManifestPath, config.getBinDirectory(context.getRule().getRepository()));
context.getAnalysisEnvironment().registerAction(new SymlinkTreeAction(context.getActionOwner(), inputManifest, artifactsMiddleman, outputManifest, /*filesetTree=*/
false, config.getLocalShellEnvironment(), config.runfilesEnabled()));
return outputManifest;
}
use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class DependencyTest method equalsPassesEqualsTester.
@Test
public void equalsPassesEqualsTester() throws Exception {
update();
Label a = Label.parseAbsolute("//a");
Label aExplicit = Label.parseAbsolute("//a:a");
Label b = Label.parseAbsolute("//b");
BuildConfiguration host = getHostConfiguration();
BuildConfiguration target = getTargetConfiguration();
AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT);
AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT);
AspectDescriptor errorAspect = new AspectDescriptor(TestAspects.ERROR_ASPECT);
AspectCollection twoAspects = AspectCollection.createForTests(simpleAspect, attributeAspect);
AspectCollection inverseAspects = AspectCollection.createForTests(attributeAspect, simpleAspect);
AspectCollection differentAspects = AspectCollection.createForTests(attributeAspect, errorAspect);
AspectCollection noAspects = AspectCollection.EMPTY;
ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectsHostMap = ImmutableMap.of(simpleAspect, host, attributeAspect, host);
ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectsTargetMap = ImmutableMap.of(simpleAspect, target, attributeAspect, target);
ImmutableMap<AspectDescriptor, BuildConfiguration> differentAspectsHostMap = ImmutableMap.of(attributeAspect, host, errorAspect, host);
ImmutableMap<AspectDescriptor, BuildConfiguration> differentAspectsTargetMap = ImmutableMap.of(attributeAspect, target, errorAspect, target);
ImmutableMap<AspectDescriptor, BuildConfiguration> noAspectsMap = ImmutableMap.<AspectDescriptor, BuildConfiguration>of();
new EqualsTester().addEqualityGroup(// base set: //a, host configuration, normal aspect set
Dependency.withConfigurationAndAspects(a, host, twoAspects), Dependency.withConfigurationAndAspects(aExplicit, host, twoAspects), Dependency.withConfigurationAndAspects(a, host, inverseAspects), Dependency.withConfigurationAndAspects(aExplicit, host, inverseAspects), Dependency.withConfiguredAspects(a, host, twoAspects, twoAspectsHostMap), Dependency.withConfiguredAspects(aExplicit, host, twoAspects, twoAspectsHostMap)).addEqualityGroup(// base set but with label //b
Dependency.withConfigurationAndAspects(b, host, twoAspects), Dependency.withConfigurationAndAspects(b, host, inverseAspects), Dependency.withConfiguredAspects(b, host, twoAspects, twoAspectsHostMap)).addEqualityGroup(// base set but with target configuration
Dependency.withConfigurationAndAspects(a, target, twoAspects), Dependency.withConfigurationAndAspects(aExplicit, target, twoAspects), Dependency.withConfigurationAndAspects(a, target, inverseAspects), Dependency.withConfigurationAndAspects(aExplicit, target, inverseAspects), Dependency.withConfiguredAspects(a, target, twoAspects, twoAspectsTargetMap), Dependency.withConfiguredAspects(aExplicit, target, twoAspects, twoAspectsTargetMap)).addEqualityGroup(// base set but with null configuration
Dependency.withNullConfiguration(a), Dependency.withNullConfiguration(aExplicit)).addEqualityGroup(// base set but with different aspects
Dependency.withConfigurationAndAspects(a, host, differentAspects), Dependency.withConfigurationAndAspects(aExplicit, host, differentAspects), Dependency.withConfiguredAspects(a, host, differentAspects, differentAspectsHostMap), Dependency.withConfiguredAspects(aExplicit, host, differentAspects, differentAspectsHostMap)).addEqualityGroup(// base set but with label //b and target configuration
Dependency.withConfigurationAndAspects(b, target, twoAspects), Dependency.withConfigurationAndAspects(b, target, inverseAspects), Dependency.withConfiguredAspects(b, target, twoAspects, twoAspectsTargetMap)).addEqualityGroup(// base set but with label //b and null configuration
Dependency.withNullConfiguration(b)).addEqualityGroup(// base set but with label //b and different aspects
Dependency.withConfigurationAndAspects(b, host, differentAspects), Dependency.withConfiguredAspects(b, host, differentAspects, differentAspectsHostMap)).addEqualityGroup(// base set but with target configuration and different aspects
Dependency.withConfigurationAndAspects(a, target, differentAspects), Dependency.withConfigurationAndAspects(aExplicit, target, differentAspects), Dependency.withConfiguredAspects(a, target, differentAspects, differentAspectsTargetMap), Dependency.withConfiguredAspects(aExplicit, target, differentAspects, differentAspectsTargetMap)).addEqualityGroup(// inverse of base set: //b, target configuration, different aspects
Dependency.withConfigurationAndAspects(b, target, differentAspects), Dependency.withConfiguredAspects(b, target, differentAspects, differentAspectsTargetMap)).addEqualityGroup(// base set but with no aspects
Dependency.withConfiguration(a, host), Dependency.withConfiguration(aExplicit, host), Dependency.withConfigurationAndAspects(a, host, noAspects), Dependency.withConfigurationAndAspects(aExplicit, host, noAspects), Dependency.withConfiguredAspects(a, host, noAspects, noAspectsMap), Dependency.withConfiguredAspects(aExplicit, host, noAspects, noAspectsMap)).addEqualityGroup(// base set but with label //b and no aspects
Dependency.withConfiguration(b, host), Dependency.withConfigurationAndAspects(b, host, noAspects), Dependency.withConfiguredAspects(b, host, noAspects, noAspectsMap)).addEqualityGroup(// base set but with target configuration and no aspects
Dependency.withConfiguration(a, target), Dependency.withConfiguration(aExplicit, target), Dependency.withConfigurationAndAspects(a, target, noAspects), Dependency.withConfigurationAndAspects(aExplicit, target, noAspects), Dependency.withConfiguredAspects(a, target, noAspects, noAspectsMap), Dependency.withConfiguredAspects(aExplicit, target, noAspects, noAspectsMap)).addEqualityGroup(// inverse of base set: //b, target configuration, no aspects
Dependency.withConfiguration(b, target), Dependency.withConfigurationAndAspects(b, target, noAspects), Dependency.withConfiguredAspects(b, target, noAspects, noAspectsMap)).addEqualityGroup(// base set but with transition HOST
Dependency.withTransitionAndAspects(a, ConfigurationTransition.HOST, twoAspects), Dependency.withTransitionAndAspects(aExplicit, ConfigurationTransition.HOST, twoAspects), Dependency.withTransitionAndAspects(a, ConfigurationTransition.HOST, inverseAspects), Dependency.withTransitionAndAspects(aExplicit, ConfigurationTransition.HOST, inverseAspects)).addEqualityGroup(// base set but with transition HOST and different aspects
Dependency.withTransitionAndAspects(a, ConfigurationTransition.HOST, differentAspects), Dependency.withTransitionAndAspects(aExplicit, ConfigurationTransition.HOST, differentAspects)).addEqualityGroup(// base set but with transition HOST and label //b
Dependency.withTransitionAndAspects(b, ConfigurationTransition.HOST, twoAspects), Dependency.withTransitionAndAspects(b, ConfigurationTransition.HOST, inverseAspects)).addEqualityGroup(// inverse of base set: transition HOST, label //b, different aspects
Dependency.withTransitionAndAspects(b, ConfigurationTransition.HOST, differentAspects), Dependency.withTransitionAndAspects(b, ConfigurationTransition.HOST, differentAspects)).addEqualityGroup(// base set but with transition NONE
Dependency.withTransitionAndAspects(a, ConfigurationTransition.NONE, twoAspects), Dependency.withTransitionAndAspects(aExplicit, ConfigurationTransition.NONE, twoAspects), Dependency.withTransitionAndAspects(a, ConfigurationTransition.NONE, inverseAspects), Dependency.withTransitionAndAspects(aExplicit, ConfigurationTransition.NONE, inverseAspects)).addEqualityGroup(// base set but with transition NONE and different aspects
Dependency.withTransitionAndAspects(a, ConfigurationTransition.NONE, differentAspects), Dependency.withTransitionAndAspects(aExplicit, ConfigurationTransition.NONE, differentAspects)).addEqualityGroup(// base set but with transition NONE and label //b
Dependency.withTransitionAndAspects(b, ConfigurationTransition.NONE, twoAspects), Dependency.withTransitionAndAspects(b, ConfigurationTransition.NONE, inverseAspects)).addEqualityGroup(// inverse of base set: transition NONE, label //b, different aspects
Dependency.withTransitionAndAspects(b, ConfigurationTransition.NONE, differentAspects), Dependency.withTransitionAndAspects(b, ConfigurationTransition.NONE, differentAspects)).testEquals();
}
Aggregations