Search in sources :

Example 41 with SkyValue

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

the class TestSuiteExpansionFunction method compute.

@Override
public SkyValue compute(SkyKey key, Environment env) throws InterruptedException {
    TestSuiteExpansion expansion = (TestSuiteExpansion) key.argument();
    ResolvedTargets<Target> targets = labelsToTargets(env, expansion.getTargets(), false);
    List<SkyKey> testsInSuitesKeys = new ArrayList<>();
    for (Target target : targets.getTargets()) {
        if (TargetUtils.isTestSuiteRule(target)) {
            testsInSuitesKeys.add(TestsInSuiteValue.key(target, true));
        }
    }
    Map<SkyKey, SkyValue> testsInSuites = env.getValues(testsInSuitesKeys);
    if (env.valuesMissing()) {
        return null;
    }
    Set<Target> result = new LinkedHashSet<>();
    boolean hasError = targets.hasError();
    for (Target target : targets.getTargets()) {
        if (TargetUtils.isTestRule(target)) {
            result.add(target);
        } else if (TargetUtils.isTestSuiteRule(target)) {
            TestsInSuiteValue value = (TestsInSuiteValue) testsInSuites.get(TestsInSuiteValue.key(target, true));
            if (value != null) {
                result.addAll(value.getTargets().getTargets());
                hasError |= value.getTargets().hasError();
            }
        } else {
            result.add(target);
        }
    }
    if (env.valuesMissing()) {
        return null;
    }
    // any filtered targets.
    return new TestSuiteExpansionValue(new ResolvedTargets<Target>(result, hasError));
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) LinkedHashSet(java.util.LinkedHashSet) TestSuiteExpansion(com.google.devtools.build.lib.skyframe.TestSuiteExpansionValue.TestSuiteExpansion) ArrayList(java.util.ArrayList) SkyValue(com.google.devtools.build.skyframe.SkyValue) Target(com.google.devtools.build.lib.packages.Target)

Example 42 with SkyValue

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

the class TimestampBuilderTestCase method createBuilder.

protected Builder createBuilder(final ActionCache actionCache, final int threadCount, final boolean keepGoing, @Nullable EvaluationProgressReceiver evaluationProgressReceiver) throws Exception {
    AtomicReference<PathPackageLocator> pkgLocator = new AtomicReference<>(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)));
    AtomicReference<TimestampGranularityMonitor> tsgmRef = new AtomicReference<>(tsgm);
    BlazeDirectories directories = new BlazeDirectories(rootDirectory, outputBase, rootDirectory, TestConstants.PRODUCT_NAME);
    ExternalFilesHelper externalFilesHelper = new ExternalFilesHelper(pkgLocator, ExternalFileAction.DEPEND_ON_EXTERNAL_PKG_FOR_EXTERNAL_REPO_PATHS, directories);
    differencer = new RecordingDifferencer();
    ActionExecutionStatusReporter statusReporter = ActionExecutionStatusReporter.create(new StoredEventHandler());
    final SkyframeActionExecutor skyframeActionExecutor = new SkyframeActionExecutor(eventBusRef, new AtomicReference<>(statusReporter));
    Path actionOutputBase = scratch.dir("/usr/local/google/_blaze_jrluser/FAKEMD5/action_out/");
    skyframeActionExecutor.setActionLogBufferPathGenerator(new ActionLogBufferPathGenerator(actionOutputBase));
    ActionInputFileCache cache = new SingleBuildFileCache(rootDirectory.getPathString(), scratch.getFileSystem());
    skyframeActionExecutor.setFileCache(cache);
    final InMemoryMemoizingEvaluator evaluator = new InMemoryMemoizingEvaluator(ImmutableMap.<SkyFunctionName, SkyFunction>builder().put(SkyFunctions.FILE_STATE, new FileStateFunction(tsgmRef, externalFilesHelper)).put(SkyFunctions.FILE, new FileFunction(pkgLocator)).put(SkyFunctions.ARTIFACT, new ArtifactFunction(Predicates.<PathFragment>alwaysFalse())).put(SkyFunctions.ACTION_EXECUTION, new ActionExecutionFunction(skyframeActionExecutor, tsgmRef)).put(SkyFunctions.PACKAGE, new PackageFunction(null, null, null, null, null, null, null)).put(SkyFunctions.PACKAGE_LOOKUP, new PackageLookupFunction(null, CrossRepositoryLabelViolationStrategy.ERROR, ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD))).put(SkyFunctions.WORKSPACE_AST, new WorkspaceASTFunction(TestRuleClassProvider.getRuleClassProvider())).put(SkyFunctions.WORKSPACE_FILE, new WorkspaceFileFunction(TestRuleClassProvider.getRuleClassProvider(), TestConstants.PACKAGE_FACTORY_FACTORY_FOR_TESTING.create(TestRuleClassProvider.getRuleClassProvider(), scratch.getFileSystem()), directories)).put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction()).put(SkyFunctions.ACTION_TEMPLATE_EXPANSION, new DelegatingActionTemplateExpansionFunction()).build(), differencer, evaluationProgressReceiver);
    final SequentialBuildDriver driver = new SequentialBuildDriver(evaluator);
    PrecomputedValue.BUILD_ID.set(differencer, UUID.randomUUID());
    PrecomputedValue.ACTION_ENV.set(differencer, ImmutableMap.<String, String>of());
    PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get());
    return new Builder() {

        private void setGeneratingActions() {
            if (evaluator.getExistingValueForTesting(OWNER_KEY) == null) {
                differencer.inject(ImmutableMap.of(OWNER_KEY, new ActionLookupValue(ImmutableList.copyOf(actions))));
            }
        }

        @Override
        public void buildArtifacts(Reporter reporter, Set<Artifact> artifacts, Set<ConfiguredTarget> parallelTests, Set<ConfiguredTarget> exclusiveTests, Collection<ConfiguredTarget> targetsToBuild, Collection<AspectValue> aspects, Executor executor, Set<ConfiguredTarget> builtTargets, boolean explain, Range<Long> lastExecutionTimeRange, TopLevelArtifactContext topLevelArtifactContext) throws BuildFailedException, AbruptExitException, InterruptedException, TestExecException {
            skyframeActionExecutor.prepareForExecution(reporter, executor, keepGoing, /*explain=*/
            false, new ActionCacheChecker(actionCache, null, ALWAYS_EXECUTE_FILTER, null), null);
            List<SkyKey> keys = new ArrayList<>();
            for (Artifact artifact : artifacts) {
                keys.add(ArtifactSkyKey.key(artifact, true));
            }
            setGeneratingActions();
            EvaluationResult<SkyValue> result = driver.evaluate(keys, keepGoing, threadCount, reporter);
            if (result.hasError()) {
                boolean hasCycles = false;
                for (Map.Entry<SkyKey, ErrorInfo> entry : result.errorMap().entrySet()) {
                    Iterable<CycleInfo> cycles = entry.getValue().getCycleInfo();
                    hasCycles |= !Iterables.isEmpty(cycles);
                }
                if (hasCycles) {
                    throw new BuildFailedException(CYCLE_MSG);
                } else if (result.errorMap().isEmpty() || keepGoing) {
                    throw new BuildFailedException();
                } else {
                    SkyframeBuilder.rethrow(Preconditions.checkNotNull(result.getError().getException()));
                }
            }
        }
    };
}
Also used : SkyframeBuilder(com.google.devtools.build.lib.buildtool.SkyframeBuilder) ArrayList(java.util.ArrayList) PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) SequentialBuildDriver(com.google.devtools.build.skyframe.SequentialBuildDriver) StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) SkyKey(com.google.devtools.build.skyframe.SkyKey) InMemoryMemoizingEvaluator(com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator) SkyFunction(com.google.devtools.build.skyframe.SkyFunction) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) Range(com.google.common.collect.Range) ActionLogBufferPathGenerator(com.google.devtools.build.lib.actions.ActionLogBufferPathGenerator) ActionCacheChecker(com.google.devtools.build.lib.actions.ActionCacheChecker) Collection(java.util.Collection) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) RecordingDifferencer(com.google.devtools.build.skyframe.RecordingDifferencer) ResourceSet(com.google.devtools.build.lib.actions.ResourceSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) CycleInfo(com.google.devtools.build.skyframe.CycleInfo) SkyValue(com.google.devtools.build.skyframe.SkyValue) SkyFunctionName(com.google.devtools.build.skyframe.SkyFunctionName) Executor(com.google.devtools.build.lib.actions.Executor) DummyExecutor(com.google.devtools.build.lib.actions.util.DummyExecutor) ActionExecutionStatusReporter(com.google.devtools.build.lib.actions.ActionExecutionStatusReporter) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor) SingleBuildFileCache(com.google.devtools.build.lib.exec.SingleBuildFileCache) Path(com.google.devtools.build.lib.vfs.Path) Reporter(com.google.devtools.build.lib.events.Reporter) ActionExecutionStatusReporter(com.google.devtools.build.lib.actions.ActionExecutionStatusReporter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Artifact(com.google.devtools.build.lib.actions.Artifact) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) ActionInputFileCache(com.google.devtools.build.lib.actions.ActionInputFileCache) TopLevelArtifactContext(com.google.devtools.build.lib.analysis.TopLevelArtifactContext)

Example 43 with SkyValue

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

the class SkyQueryEnvironment method getSkyKeysForFileFragments.

/**
   * Returns FileValue keys for which there may be relevant (from the perspective of {@link
   * #getRBuildFiles}) FileValues in the graph corresponding to the given {@code pathFragments},
   * which are assumed to be file paths.
   *
   * <p>To do this, we emulate the {@link ContainingPackageLookupFunction} logic: for each given
   * file path, we look for the nearest ancestor directory (starting with its parent directory), if
   * any, that has a package. The {@link PackageLookupValue} for this package tells us the package
   * root that we should use for the {@link RootedPath} for the {@link FileValue} key.
   *
   * <p>Note that there may not be nodes in the graph corresponding to the returned SkyKeys.
   */
Collection<SkyKey> getSkyKeysForFileFragments(Iterable<PathFragment> pathFragments) throws InterruptedException {
    Set<SkyKey> result = new HashSet<>();
    Multimap<PathFragment, PathFragment> currentToOriginal = ArrayListMultimap.create();
    for (PathFragment pathFragment : pathFragments) {
        currentToOriginal.put(pathFragment, pathFragment);
    }
    while (!currentToOriginal.isEmpty()) {
        Multimap<SkyKey, PathFragment> packageLookupKeysToOriginal = ArrayListMultimap.create();
        Multimap<SkyKey, PathFragment> packageLookupKeysToCurrent = ArrayListMultimap.create();
        for (Entry<PathFragment, PathFragment> entry : currentToOriginal.entries()) {
            PathFragment current = entry.getKey();
            PathFragment original = entry.getValue();
            for (SkyKey packageLookupKey : getPkgLookupKeysForFile(original, current)) {
                packageLookupKeysToOriginal.put(packageLookupKey, original);
                packageLookupKeysToCurrent.put(packageLookupKey, current);
            }
        }
        Map<SkyKey, SkyValue> lookupValues = graph.getSuccessfulValues(packageLookupKeysToOriginal.keySet());
        for (Map.Entry<SkyKey, SkyValue> entry : lookupValues.entrySet()) {
            SkyKey packageLookupKey = entry.getKey();
            PackageLookupValue packageLookupValue = (PackageLookupValue) entry.getValue();
            if (packageLookupValue.packageExists()) {
                Collection<PathFragment> originalFiles = packageLookupKeysToOriginal.get(packageLookupKey);
                Preconditions.checkState(!originalFiles.isEmpty(), entry);
                for (PathFragment fileName : originalFiles) {
                    result.add(FileValue.key(RootedPath.toRootedPath(packageLookupValue.getRoot(), fileName)));
                }
                for (PathFragment current : packageLookupKeysToCurrent.get(packageLookupKey)) {
                    currentToOriginal.removeAll(current);
                }
            }
        }
        Multimap<PathFragment, PathFragment> newCurrentToOriginal = ArrayListMultimap.create();
        for (PathFragment pathFragment : currentToOriginal.keySet()) {
            PathFragment parent = pathFragment.getParentDirectory();
            if (parent != null) {
                newCurrentToOriginal.putAll(parent, currentToOriginal.get(pathFragment));
            }
        }
        currentToOriginal = newCurrentToOriginal;
    }
    return result;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) PackageLookupValue(com.google.devtools.build.lib.skyframe.PackageLookupValue) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SkyValue(com.google.devtools.build.skyframe.SkyValue) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashSet(java.util.LinkedHashSet) CompactHashSet(com.google.devtools.build.lib.collect.CompactHashSet) HashSet(java.util.HashSet)

Example 44 with SkyValue

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

the class SkyQueryEnvironment method makeTargetsFromPackageKeyToTargetKeyMap.

@ThreadSafe
public Map<SkyKey, Target> makeTargetsFromPackageKeyToTargetKeyMap(Multimap<SkyKey, SkyKey> packageKeyToTargetKeyMap) throws InterruptedException {
    ImmutableMap.Builder<SkyKey, Target> result = ImmutableMap.builder();
    Set<SkyKey> processedTargets = new HashSet<>();
    Map<SkyKey, SkyValue> packageMap = graph.getSuccessfulValues(packageKeyToTargetKeyMap.keySet());
    for (Map.Entry<SkyKey, SkyValue> entry : packageMap.entrySet()) {
        for (SkyKey targetKey : packageKeyToTargetKeyMap.get(entry.getKey())) {
            if (processedTargets.add(targetKey)) {
                try {
                    result.put(targetKey, ((PackageValue) entry.getValue()).getPackage().getTarget((SKYKEY_TO_LABEL.apply(targetKey)).getName()));
                } catch (NoSuchTargetException e) {
                // Skip missing target.
                }
            }
        }
    }
    return result.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) SkyValue(com.google.devtools.build.skyframe.SkyValue) Target(com.google.devtools.build.lib.packages.Target) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) PackageValue(com.google.devtools.build.lib.skyframe.PackageValue) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashSet(java.util.LinkedHashSet) CompactHashSet(com.google.devtools.build.lib.collect.CompactHashSet) HashSet(java.util.HashSet) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)

Example 45 with SkyValue

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

the class PostConfiguredTargetFunction method getConfigurableAttributeConditions.

/**
   * Returns the configurable attribute conditions necessary to evaluate the given configured
   * target, or null if not all dependencies have yet been SkyFrame-evaluated.
   */
@Nullable
private static ImmutableMap<Label, ConfigMatchingProvider> getConfigurableAttributeConditions(TargetAndConfiguration ctg, Environment env) throws InterruptedException {
    if (!(ctg.getTarget() instanceof Rule)) {
        return ImmutableMap.of();
    }
    Rule rule = (Rule) ctg.getTarget();
    RawAttributeMapper mapper = RawAttributeMapper.of(rule);
    Set<SkyKey> depKeys = new LinkedHashSet<>();
    for (Attribute attribute : rule.getAttributes()) {
        for (Label label : mapper.getConfigurabilityKeys(attribute.getName(), attribute.getType())) {
            if (!BuildType.Selector.isReservedLabel(label)) {
                depKeys.add(ConfiguredTargetValue.key(label, ctg.getConfiguration()));
            }
        }
    }
    Map<SkyKey, SkyValue> cts = env.getValues(depKeys);
    if (env.valuesMissing()) {
        return null;
    }
    Map<Label, ConfigMatchingProvider> conditions = new LinkedHashMap<>();
    for (Map.Entry<SkyKey, SkyValue> entry : cts.entrySet()) {
        Label label = ((ConfiguredTargetKey) entry.getKey().argument()).getLabel();
        ConfiguredTarget ct = ((ConfiguredTargetValue) entry.getValue()).getConfiguredTarget();
        conditions.put(label, Preconditions.checkNotNull(ct.getProvider(ConfigMatchingProvider.class)));
    }
    return ImmutableMap.copyOf(conditions);
}
Also used : RawAttributeMapper(com.google.devtools.build.lib.packages.RawAttributeMapper) LinkedHashSet(java.util.LinkedHashSet) SkyKey(com.google.devtools.build.skyframe.SkyKey) Attribute(com.google.devtools.build.lib.packages.Attribute) Label(com.google.devtools.build.lib.cmdline.Label) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) LinkedHashMap(java.util.LinkedHashMap) SkyValue(com.google.devtools.build.skyframe.SkyValue) ConfigMatchingProvider(com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider) Rule(com.google.devtools.build.lib.packages.Rule) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Nullable(javax.annotation.Nullable)

Aggregations

SkyValue (com.google.devtools.build.skyframe.SkyValue)66 SkyKey (com.google.devtools.build.skyframe.SkyKey)63 Map (java.util.Map)20 ImmutableMap (com.google.common.collect.ImmutableMap)18 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)17 Test (org.junit.Test)16 Artifact (com.google.devtools.build.lib.actions.Artifact)15 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)15 HashMap (java.util.HashMap)14 ImmutableList (com.google.common.collect.ImmutableList)10 SequentialBuildDriver (com.google.devtools.build.skyframe.SequentialBuildDriver)10 Path (com.google.devtools.build.lib.vfs.Path)9 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)8 LinkedHashMap (java.util.LinkedHashMap)8 Label (com.google.devtools.build.lib.cmdline.Label)7 HashSet (java.util.HashSet)7 Target (com.google.devtools.build.lib.packages.Target)6 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)5 IOException (java.io.IOException)5 ImmutableSet (com.google.common.collect.ImmutableSet)4