Search in sources :

Example 1 with ConfiguredTargetKey

use of com.google.devtools.build.lib.skyframe.ConfiguredTargetKey in project bazel by bazelbuild.

the class BuildView method getRuleContextForTesting.

/**
   * Returns a RuleContext which is the same as the original RuleContext of the target parameter.
   */
@VisibleForTesting
public RuleContext getRuleContextForTesting(ConfiguredTarget target, StoredEventHandler eventHandler, BuildConfigurationCollection configurations) throws EvalException, InvalidConfigurationException, InterruptedException, InconsistentAspectOrderException {
    BuildConfiguration targetConfig = target.getConfiguration();
    CachingAnalysisEnvironment env = new CachingAnalysisEnvironment(getArtifactFactory(), new ConfiguredTargetKey(target.getLabel(), targetConfig), /*isSystemEnv=*/
    false, targetConfig.extendedSanityChecks(), eventHandler, /*skyframeEnv=*/
    null, targetConfig.isActionsEnabled());
    return getRuleContextForTesting(eventHandler, target, env, configurations);
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) ConfiguredTargetKey(com.google.devtools.build.lib.skyframe.ConfiguredTargetKey) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ConfiguredTargetKey

use of com.google.devtools.build.lib.skyframe.ConfiguredTargetKey in project bazel by bazelbuild.

the class ConfiguredTargetFactory method createConfiguredTarget.

/**
   * Invokes the appropriate constructor to create a {@link ConfiguredTarget} instance.
   * <p>For use in {@code ConfiguredTargetFunction}.
   *
   * <p>Returns null if Skyframe deps are missing or upon certain errors.
   */
@Nullable
public final ConfiguredTarget createConfiguredTarget(AnalysisEnvironment analysisEnvironment, ArtifactFactory artifactFactory, Target target, BuildConfiguration config, BuildConfiguration hostConfig, OrderedSetMultimap<Attribute, ConfiguredTarget> prerequisiteMap, ImmutableMap<Label, ConfigMatchingProvider> configConditions) throws InterruptedException {
    if (target instanceof Rule) {
        return createRule(analysisEnvironment, (Rule) target, config, hostConfig, prerequisiteMap, configConditions);
    }
    // Visibility, like all package groups, doesn't have a configuration
    NestedSet<PackageSpecification> visibility = convertVisibility(prerequisiteMap, analysisEnvironment.getEventHandler(), target, null);
    TargetContext targetContext = new TargetContext(analysisEnvironment, target, config, prerequisiteMap.get(null), visibility);
    if (target instanceof OutputFile) {
        OutputFile outputFile = (OutputFile) target;
        boolean isFileset = outputFile.getGeneratingRule().getRuleClass().equals("Fileset");
        Artifact artifact = getOutputArtifact(outputFile, config, isFileset, artifactFactory);
        TransitiveInfoCollection rule = targetContext.findDirectPrerequisite(outputFile.getGeneratingRule().getLabel(), config);
        if (isFileset) {
            return new FilesetOutputConfiguredTarget(targetContext, outputFile, rule, artifact, rule.getProvider(FilesetProvider.class).getTraversals());
        } else {
            return new OutputFileConfiguredTarget(targetContext, outputFile, rule, artifact);
        }
    } else if (target instanceof InputFile) {
        InputFile inputFile = (InputFile) target;
        Artifact artifact = artifactFactory.getSourceArtifact(inputFile.getExecPath(), Root.asSourceRoot(inputFile.getPackage().getSourceRoot(), inputFile.getPackage().getPackageIdentifier().getRepository().isMain()), new ConfiguredTargetKey(target.getLabel(), config));
        return new InputFileConfiguredTarget(targetContext, inputFile, artifact);
    } else if (target instanceof PackageGroup) {
        PackageGroup packageGroup = (PackageGroup) target;
        return new PackageGroupConfiguredTarget(targetContext, packageGroup);
    } else if (target instanceof EnvironmentGroup) {
        return new EnvironmentGroupConfiguredTarget(targetContext, (EnvironmentGroup) target);
    } else {
        throw new AssertionError("Unexpected target class: " + target.getClass().getName());
    }
}
Also used : OutputFile(com.google.devtools.build.lib.packages.OutputFile) Artifact(com.google.devtools.build.lib.actions.Artifact) PackageGroup(com.google.devtools.build.lib.packages.PackageGroup) InputFile(com.google.devtools.build.lib.packages.InputFile) EnvironmentGroup(com.google.devtools.build.lib.packages.EnvironmentGroup) Rule(com.google.devtools.build.lib.packages.Rule) ConfiguredTargetKey(com.google.devtools.build.lib.skyframe.ConfiguredTargetKey) PackageSpecification(com.google.devtools.build.lib.packages.PackageSpecification) Nullable(javax.annotation.Nullable)

Example 3 with ConfiguredTargetKey

use of com.google.devtools.build.lib.skyframe.ConfiguredTargetKey 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;
}
Also used : SkylarkImportSyntaxException(com.google.devtools.build.lib.syntax.SkylarkImports.SkylarkImportSyntaxException) SkyframeAnalysisResult(com.google.devtools.build.lib.skyframe.SkyframeAnalysisResult) ArrayList(java.util.ArrayList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SkyframeAnalysisResult(com.google.devtools.build.lib.skyframe.SkyframeAnalysisResult) SkylarkImport(com.google.devtools.build.lib.syntax.SkylarkImport) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) Target(com.google.devtools.build.lib.packages.Target) AspectValueKey(com.google.devtools.build.lib.skyframe.AspectValue.AspectValueKey) NativeAspectClass(com.google.devtools.build.lib.packages.NativeAspectClass) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) Rule(com.google.devtools.build.lib.packages.Rule) ConfiguredTargetKey(com.google.devtools.build.lib.skyframe.ConfiguredTargetKey) ThreadCompatible(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible)

Example 4 with ConfiguredTargetKey

use of com.google.devtools.build.lib.skyframe.ConfiguredTargetKey in project bazel by bazelbuild.

the class ConfiguredTargetFactory method getOutputArtifact.

private Artifact getOutputArtifact(OutputFile outputFile, BuildConfiguration configuration, boolean isFileset, ArtifactFactory artifactFactory) {
    Rule rule = outputFile.getAssociatedRule();
    Root root = rule.hasBinaryOutput() ? configuration.getBinDirectory(rule.getRepository()) : configuration.getGenfilesDirectory(rule.getRepository());
    ArtifactOwner owner = new ConfiguredTargetKey(rule.getLabel(), configuration.getArtifactOwnerConfiguration());
    PathFragment rootRelativePath = outputFile.getLabel().getPackageIdentifier().getSourceRoot().getRelative(outputFile.getLabel().getName());
    Artifact result = isFileset ? artifactFactory.getFilesetArtifact(rootRelativePath, root, owner) : artifactFactory.getDerivedArtifact(rootRelativePath, root, owner);
    // The associated rule should have created the artifact.
    Preconditions.checkNotNull(result, "no artifact for %s", rootRelativePath);
    return result;
}
Also used : ArtifactOwner(com.google.devtools.build.lib.actions.ArtifactOwner) Root(com.google.devtools.build.lib.actions.Root) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Rule(com.google.devtools.build.lib.packages.Rule) ConfiguredTargetKey(com.google.devtools.build.lib.skyframe.ConfiguredTargetKey) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 5 with ConfiguredTargetKey

use of com.google.devtools.build.lib.skyframe.ConfiguredTargetKey in project bazel by bazelbuild.

the class BuildViewTestCase method getImplicitOutputArtifact.

protected Artifact getImplicitOutputArtifact(ConfiguredTarget target, SafeImplicitOutputsFunction outputFunction) {
    Rule associatedRule = target.getTarget().getAssociatedRule();
    RepositoryName repository = associatedRule.getRepository();
    BuildConfiguration configuration = target.getConfiguration();
    Root root;
    if (associatedRule.hasBinaryOutput()) {
        root = configuration.getBinDirectory(repository);
    } else {
        root = configuration.getGenfilesDirectory(repository);
    }
    ArtifactOwner owner = new ConfiguredTargetKey(target.getTarget().getLabel(), target.getConfiguration());
    RawAttributeMapper attr = RawAttributeMapper.of(associatedRule);
    String path = Iterables.getOnlyElement(outputFunction.getImplicitOutputs(attr));
    return view.getArtifactFactory().getDerivedArtifact(target.getTarget().getLabel().getPackageFragment().getRelative(path), root, owner);
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) RawAttributeMapper(com.google.devtools.build.lib.packages.RawAttributeMapper) ArtifactOwner(com.google.devtools.build.lib.actions.ArtifactOwner) Root(com.google.devtools.build.lib.actions.Root) RepositoryName(com.google.devtools.build.lib.cmdline.RepositoryName) Rule(com.google.devtools.build.lib.packages.Rule) ConfiguredTargetKey(com.google.devtools.build.lib.skyframe.ConfiguredTargetKey)

Aggregations

ConfiguredTargetKey (com.google.devtools.build.lib.skyframe.ConfiguredTargetKey)5 Rule (com.google.devtools.build.lib.packages.Rule)4 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)3 Artifact (com.google.devtools.build.lib.actions.Artifact)2 ArtifactOwner (com.google.devtools.build.lib.actions.ArtifactOwner)2 Root (com.google.devtools.build.lib.actions.Root)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 RepositoryName (com.google.devtools.build.lib.cmdline.RepositoryName)1 ThreadCompatible (com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible)1 AspectDescriptor (com.google.devtools.build.lib.packages.AspectDescriptor)1 EnvironmentGroup (com.google.devtools.build.lib.packages.EnvironmentGroup)1 InputFile (com.google.devtools.build.lib.packages.InputFile)1 NativeAspectClass (com.google.devtools.build.lib.packages.NativeAspectClass)1 OutputFile (com.google.devtools.build.lib.packages.OutputFile)1 PackageGroup (com.google.devtools.build.lib.packages.PackageGroup)1 PackageSpecification (com.google.devtools.build.lib.packages.PackageSpecification)1 RawAttributeMapper (com.google.devtools.build.lib.packages.RawAttributeMapper)1 Target (com.google.devtools.build.lib.packages.Target)1 AspectValueKey (com.google.devtools.build.lib.skyframe.AspectValue.AspectValueKey)1