Search in sources :

Example 1 with ValueOrException

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

the class SkyframeDependencyResolver method getConfigurations.

@Nullable
@Override
protected List<BuildConfiguration> getConfigurations(Set<Class<? extends BuildConfiguration.Fragment>> fragments, Iterable<BuildOptions> buildOptions) throws InvalidConfigurationException, InterruptedException {
    List<SkyKey> keys = new ArrayList<>();
    for (BuildOptions options : buildOptions) {
        keys.add(BuildConfigurationValue.key(fragments, options));
    }
    Map<SkyKey, ValueOrException<InvalidConfigurationException>> configValues = env.getValuesOrThrow(keys, InvalidConfigurationException.class);
    if (env.valuesMissing()) {
        return null;
    }
    ImmutableList.Builder<BuildConfiguration> result = ImmutableList.builder();
    for (SkyKey key : keys) {
        result.add(((BuildConfigurationValue) configValues.get(key).get()).getConfiguration());
    }
    return result.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) ValueOrException(com.google.devtools.build.skyframe.ValueOrException) Nullable(javax.annotation.Nullable)

Example 2 with ValueOrException

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

the class TestsInSuiteFunction method getPrerequisites.

/**
   * Adds the set of targets found in the attribute named {@code attrName}, which must be of label
   * list type, of the {@code test_suite} rule named {@code testSuite}. Returns true if the method
   * found a problem during the lookup process; the actual error message is reported to the
   * environment.
   */
private static boolean getPrerequisites(Environment env, Rule testSuite, String attrName, List<Target> targets) throws InterruptedException {
    List<Label> labels = NonconfigurableAttributeMapper.of(testSuite).get(attrName, BuildType.LABEL_LIST);
    Set<PackageIdentifier> pkgIdentifiers = new LinkedHashSet<>();
    for (Label label : labels) {
        pkgIdentifiers.add(label.getPackageIdentifier());
    }
    Map<SkyKey, ValueOrException<BuildFileNotFoundException>> packages = env.getValuesOrThrow(PackageValue.keys(pkgIdentifiers), BuildFileNotFoundException.class);
    if (env.valuesMissing()) {
        return false;
    }
    boolean hasError = false;
    Map<PackageIdentifier, Package> packageMap = new HashMap<>();
    for (Entry<SkyKey, ValueOrException<BuildFileNotFoundException>> entry : packages.entrySet()) {
        try {
            packageMap.put((PackageIdentifier) entry.getKey().argument(), ((PackageValue) entry.getValue().get()).getPackage());
        } catch (BuildFileNotFoundException e) {
            env.getListener().handle(Event.error(e.getMessage()));
            hasError = true;
        }
    }
    for (Label label : labels) {
        Package pkg = packageMap.get(label.getPackageIdentifier());
        if (pkg == null) {
            continue;
        }
        try {
            targets.add(pkg.getTarget(label.getName()));
        } catch (NoSuchTargetException e) {
            env.getListener().handle(Event.error(e.getMessage()));
            hasError = true;
        }
    }
    return hasError;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) HashMap(java.util.HashMap) Label(com.google.devtools.build.lib.cmdline.Label) ValueOrException(com.google.devtools.build.skyframe.ValueOrException) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Package(com.google.devtools.build.lib.packages.Package)

Example 3 with ValueOrException

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

the class AndroidSdkRepositoryFunction method getSubdirectoryListingValues.

/** Gets DirectoryListingValues for subdirectories of the directory or returns null. */
private static ImmutableMap<PathFragment, DirectoryListingValue> getSubdirectoryListingValues(final Path root, final PathFragment path, DirectoryListingValue directory, Environment env) throws RepositoryFunctionException, InterruptedException {
    Map<PathFragment, SkyKey> skyKeysForSubdirectoryLookups = Maps.transformEntries(Maps.uniqueIndex(directory.getDirents(), new Function<Dirent, PathFragment>() {

        @Override
        public PathFragment apply(Dirent input) {
            return path.getRelative(input.getName());
        }
    }), new EntryTransformer<PathFragment, Dirent, SkyKey>() {

        @Override
        public SkyKey transformEntry(PathFragment key, Dirent value) {
            return DirectoryListingValue.key(RootedPath.toRootedPath(root, root.getRelative(key)));
        }
    });
    Map<SkyKey, ValueOrException<InconsistentFilesystemException>> values = env.getValuesOrThrow(skyKeysForSubdirectoryLookups.values(), InconsistentFilesystemException.class);
    ImmutableMap.Builder<PathFragment, DirectoryListingValue> directoryListingValues = new ImmutableMap.Builder<>();
    for (PathFragment pathFragment : skyKeysForSubdirectoryLookups.keySet()) {
        try {
            SkyValue skyValue = values.get(skyKeysForSubdirectoryLookups.get(pathFragment)).get();
            if (skyValue == null) {
                return null;
            }
            directoryListingValues.put(pathFragment, (DirectoryListingValue) skyValue);
        } catch (InconsistentFilesystemException e) {
            throw new RepositoryFunctionException(new IOException(e), Transience.PERSISTENT);
        }
    }
    return directoryListingValues.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) InconsistentFilesystemException(com.google.devtools.build.lib.skyframe.InconsistentFilesystemException) ValueOrException(com.google.devtools.build.skyframe.ValueOrException) ImmutableMap(com.google.common.collect.ImmutableMap) SkyValue(com.google.devtools.build.skyframe.SkyValue) RepositoryFunction(com.google.devtools.build.lib.rules.repository.RepositoryFunction) Function(com.google.common.base.Function) DirectoryListingValue(com.google.devtools.build.lib.skyframe.DirectoryListingValue) Dirent(com.google.devtools.build.lib.vfs.Dirent)

Example 4 with ValueOrException

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

the class TargetPatternPhaseFunction method determineTests.

/**
   * Interpret test target labels from the command-line arguments and return the corresponding set
   * of targets, handling the filter flags, and expanding test suites.
   *
   * @param targetPatterns the list of command-line target patterns specified by the user
   * @param testFilter the test filter
   */
private static ResolvedTargets<Target> determineTests(Environment env, List<String> targetPatterns, String offset, TestFilter testFilter) throws InterruptedException {
    List<SkyKey> patternSkyKeys = new ArrayList<>();
    for (TargetPatternSkyKeyOrException keyOrException : TargetPatternValue.keys(targetPatterns, FilteringPolicies.FILTER_TESTS, offset)) {
        try {
            patternSkyKeys.add(keyOrException.getSkyKey());
        } catch (TargetParsingException e) {
        // Skip.
        }
    }
    Map<SkyKey, ValueOrException<TargetParsingException>> resolvedPatterns = env.getValuesOrThrow(patternSkyKeys, TargetParsingException.class);
    if (env.valuesMissing()) {
        return null;
    }
    List<SkyKey> expandedSuiteKeys = new ArrayList<>();
    for (SkyKey key : patternSkyKeys) {
        TargetPatternValue value;
        try {
            value = (TargetPatternValue) resolvedPatterns.get(key).get();
        } catch (TargetParsingException e) {
            // Skip.
            continue;
        }
        expandedSuiteKeys.add(TestSuiteExpansionValue.key(value.getTargets().getTargets()));
    }
    Map<SkyKey, SkyValue> expandedSuites = env.getValues(expandedSuiteKeys);
    if (env.valuesMissing()) {
        return null;
    }
    ResolvedTargets.Builder<Target> testTargetsBuilder = ResolvedTargets.builder();
    for (SkyKey key : patternSkyKeys) {
        TargetPatternKey pattern = (TargetPatternKey) key.argument();
        TargetPatternValue value;
        try {
            value = (TargetPatternValue) resolvedPatterns.get(key).get();
        } catch (TargetParsingException e) {
            // This was already reported in getTargetsToBuild (maybe merge the two code paths?).
            continue;
        }
        TestSuiteExpansionValue expandedSuitesValue = (TestSuiteExpansionValue) expandedSuites.get(TestSuiteExpansionValue.key(value.getTargets().getTargets()));
        if (pattern.isNegative()) {
            ResolvedTargets<Target> negativeTargets = expandedSuitesValue.getTargets();
            testTargetsBuilder.filter(Predicates.not(Predicates.in(negativeTargets.getTargets())));
            testTargetsBuilder.mergeError(negativeTargets.hasError());
        } else {
            ResolvedTargets<Target> positiveTargets = expandedSuitesValue.getTargets();
            testTargetsBuilder.addAll(positiveTargets.getTargets());
            testTargetsBuilder.mergeError(positiveTargets.hasError());
        }
    }
    testTargetsBuilder.filter(testFilter);
    return testTargetsBuilder.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) TargetPatternKey(com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey) ArrayList(java.util.ArrayList) TargetPatternSkyKeyOrException(com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternSkyKeyOrException) ValueOrException(com.google.devtools.build.skyframe.ValueOrException) SkyValue(com.google.devtools.build.skyframe.SkyValue) Target(com.google.devtools.build.lib.packages.Target) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) ResolvedTargets(com.google.devtools.build.lib.cmdline.ResolvedTargets)

Example 5 with ValueOrException

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

the class TargetPatternPhaseFunction method getTargetsToBuild.

/**
   * Interpret the command-line arguments.
   *
   * @param options the command-line arguments in structured form
   */
private static ResolvedTargets<Target> getTargetsToBuild(Environment env, TargetPatternList options) throws InterruptedException {
    List<SkyKey> patternSkyKeys = new ArrayList<>();
    for (TargetPatternSkyKeyOrException keyOrException : TargetPatternValue.keys(options.getTargetPatterns(), FilteringPolicies.FILTER_MANUAL, options.getOffset())) {
        try {
            patternSkyKeys.add(keyOrException.getSkyKey());
        } catch (TargetParsingException e) {
        // Skip.
        }
    }
    Map<SkyKey, ValueOrException<TargetParsingException>> resolvedPatterns = env.getValuesOrThrow(patternSkyKeys, TargetParsingException.class);
    if (env.valuesMissing()) {
        return null;
    }
    ResolvedTargets.Builder<Target> builder = ResolvedTargets.builder();
    for (SkyKey key : patternSkyKeys) {
        TargetPatternKey pattern = (TargetPatternKey) key.argument();
        TargetPatternValue value;
        try {
            value = (TargetPatternValue) resolvedPatterns.get(key).get();
        } catch (TargetParsingException e) {
            // TODO(ulfjack): Report to EventBus.
            String rawPattern = pattern.getPattern();
            String errorMessage = e.getMessage();
            env.getListener().handle(Event.error("Skipping '" + rawPattern + "': " + errorMessage));
            builder.setError();
            continue;
        }
        // TODO(ulfjack): This is terribly inefficient.
        ResolvedTargets<Target> asTargets = TestSuiteExpansionFunction.labelsToTargets(env, value.getTargets().getTargets(), value.getTargets().hasError());
        if (pattern.isNegative()) {
            builder.filter(Predicates.not(Predicates.in(asTargets.getTargets())));
        } else {
            builder.merge(asTargets);
        }
    }
    ResolvedTargets<Target> result = builder.filter(TargetUtils.tagFilter(options.getBuildTargetFilter())).build();
    if (options.getCompileOneDependency()) {
        TargetProvider targetProvider = new EnvironmentBackedRecursivePackageProvider(env);
        try {
            return new CompileOneDependencyTransformer(targetProvider).transformCompileOneDependency(env.getListener(), result);
        } catch (MissingDepException e) {
            return null;
        } catch (TargetParsingException e) {
            env.getListener().handle(Event.error(e.getMessage()));
            return ResolvedTargets.failed();
        }
    }
    return result;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) TargetPatternKey(com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey) TargetProvider(com.google.devtools.build.lib.pkgcache.TargetProvider) ArrayList(java.util.ArrayList) TargetPatternSkyKeyOrException(com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternSkyKeyOrException) ValueOrException(com.google.devtools.build.skyframe.ValueOrException) CompileOneDependencyTransformer(com.google.devtools.build.lib.pkgcache.CompileOneDependencyTransformer) Target(com.google.devtools.build.lib.packages.Target) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) ResolvedTargets(com.google.devtools.build.lib.cmdline.ResolvedTargets) MissingDepException(com.google.devtools.build.lib.skyframe.EnvironmentBackedRecursivePackageProvider.MissingDepException)

Aggregations

SkyKey (com.google.devtools.build.skyframe.SkyKey)9 ValueOrException (com.google.devtools.build.skyframe.ValueOrException)9 ArrayList (java.util.ArrayList)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)3 SkyValue (com.google.devtools.build.skyframe.SkyValue)3 Nullable (javax.annotation.Nullable)3 ImmutableList (com.google.common.collect.ImmutableList)2 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)2 BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)2 InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)2 ResolvedTargets (com.google.devtools.build.lib.cmdline.ResolvedTargets)2 Package (com.google.devtools.build.lib.packages.Package)2 Target (com.google.devtools.build.lib.packages.Target)2 TargetPatternKey (com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey)2 TargetPatternSkyKeyOrException (com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternSkyKeyOrException)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2