Search in sources :

Example 1 with TargetProvider

use of com.google.devtools.build.lib.pkgcache.TargetProvider 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)

Example 2 with TargetProvider

use of com.google.devtools.build.lib.pkgcache.TargetProvider in project bazel by bazelbuild.

the class TestTargetUtilsTest method testExpandTestSuitesInterrupted.

@Test
public void testExpandTestSuitesInterrupted() throws Exception {
    reporter.removeHandler(failFastHandler);
    scratch.file("broken/BUILD", "test_suite(name = 'broken', tests = ['//missing:missing_test'])");
    try {
        TestTargetUtils.expandTestSuites(new TargetProvider() {

            @Override
            public Target getTarget(ExtendedEventHandler eventHandler, Label label) throws InterruptedException {
                throw new InterruptedException();
            }
        }, reporter, Sets.newHashSet(getTarget("//broken")), /*strict=*/
        false, /*keep_going=*/
        true);
    } catch (TargetParsingException e) {
        assertNotNull(e.getMessage());
    }
    assertTrue(Thread.currentThread().isInterrupted());
}
Also used : TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) TargetProvider(com.google.devtools.build.lib.pkgcache.TargetProvider) Label(com.google.devtools.build.lib.cmdline.Label) ExtendedEventHandler(com.google.devtools.build.lib.events.ExtendedEventHandler) Test(org.junit.Test)

Aggregations

TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)2 TargetProvider (com.google.devtools.build.lib.pkgcache.TargetProvider)2 Label (com.google.devtools.build.lib.cmdline.Label)1 ResolvedTargets (com.google.devtools.build.lib.cmdline.ResolvedTargets)1 ExtendedEventHandler (com.google.devtools.build.lib.events.ExtendedEventHandler)1 Target (com.google.devtools.build.lib.packages.Target)1 CompileOneDependencyTransformer (com.google.devtools.build.lib.pkgcache.CompileOneDependencyTransformer)1 MissingDepException (com.google.devtools.build.lib.skyframe.EnvironmentBackedRecursivePackageProvider.MissingDepException)1 TargetPatternKey (com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey)1 TargetPatternSkyKeyOrException (com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternSkyKeyOrException)1 SkyKey (com.google.devtools.build.skyframe.SkyKey)1 ValueOrException (com.google.devtools.build.skyframe.ValueOrException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1