Search in sources :

Example 26 with Runfiles

use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.

the class TestSuite method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws RuleErrorException {
    checkTestsAndSuites(ruleContext, "tests");
    if (ruleContext.hasErrors()) {
        return null;
    }
    //
    //  CAUTION!  Keep this logic consistent with lib.query2.TestsExpression!
    //
    List<String> tagsAttribute = new ArrayList<>(ruleContext.attributes().get("tags", Type.STRING_LIST));
    tagsAttribute.remove("manual");
    Pair<Collection<String>, Collection<String>> requiredExcluded = TestTargetUtils.sortTagsBySense(tagsAttribute);
    List<TransitiveInfoCollection> directTestsAndSuitesBuilder = new ArrayList<>();
    // Manual tests are already filtered out there. That is what $implicit_tests is about.
    for (TransitiveInfoCollection dep : Iterables.concat(getPrerequisites(ruleContext, "tests"), getPrerequisites(ruleContext, "$implicit_tests"))) {
        if (dep.getProvider(TestProvider.class) != null) {
            List<String> tags = dep.getProvider(TestProvider.class).getTestTags();
            if (!TestTargetUtils.testMatchesFilters(tags, requiredExcluded.first, requiredExcluded.second, true)) {
                // This test does not match our filter. Ignore it.
                continue;
            }
        }
        directTestsAndSuitesBuilder.add(dep);
    }
    Runfiles runfiles = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addTargets(directTestsAndSuitesBuilder, RunfilesProvider.DATA_RUNFILES).build();
    return new RuleConfiguredTargetBuilder(ruleContext).add(RunfilesProvider.class, RunfilesProvider.withData(Runfiles.EMPTY, runfiles)).add(TransitiveTestsProvider.class, new TransitiveTestsProvider()).build();
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) ArrayList(java.util.ArrayList) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Collection(java.util.Collection) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 27 with Runfiles

use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.

the class BazelProtoLibrary method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    ImmutableList<Artifact> protoSources = ruleContext.getPrerequisiteArtifacts("srcs", TARGET).list();
    NestedSet<Artifact> checkDepsProtoSources = ProtoCommon.getCheckDepsProtoSources(ruleContext, protoSources);
    ProtoCommon.checkSourceFilesAreInSamePackage(ruleContext);
    NestedSet<Artifact> transitiveImports = ProtoCommon.collectTransitiveImports(ruleContext, protoSources);
    NestedSet<Artifact> protosInDirectDeps = ProtoCommon.computeProtosInDirectDeps(ruleContext);
    final SupportData supportData = SupportData.create(Predicates.<TransitiveInfoCollection>alwaysTrue(), /* nonWeakDepsPredicate */
    protoSources, protosInDirectDeps, transitiveImports, !protoSources.isEmpty());
    Artifact descriptorSetOutput = ruleContext.getGenfilesArtifact(ruleContext.getLabel().getName() + "-descriptor-set.proto.bin");
    NestedSet<Artifact> dependenciesDescriptorSets = ProtoCommon.collectDependenciesDescriptorSets(ruleContext);
    NestedSet<Artifact> transitiveDescriptorSetOutput = NestedSetBuilder.fromNestedSet(dependenciesDescriptorSets).add(descriptorSetOutput).build();
    ProtoCompileActionBuilder.writeDescriptorSet(ruleContext, descriptorSetOutput.getExecPathString(), protoSources, transitiveImports, protosInDirectDeps, descriptorSetOutput, true, /* allowServices */
    dependenciesDescriptorSets);
    Runfiles dataRunfiles = ProtoCommon.createDataRunfilesProvider(transitiveImports, ruleContext).addArtifact(descriptorSetOutput).build();
    // TODO(bazel-team): this second constructor argument is superfluous and should be removed.
    ProtoSourcesProvider sourcesProvider = ProtoSourcesProvider.create(transitiveImports, transitiveImports, protoSources, checkDepsProtoSources, descriptorSetOutput, transitiveDescriptorSetOutput);
    return new RuleConfiguredTargetBuilder(ruleContext).setFilesToBuild(NestedSetBuilder.create(STABLE_ORDER, descriptorSetOutput)).addProvider(RunfilesProvider.withData(Runfiles.EMPTY, dataRunfiles)).addProvider(ProtoSourcesProvider.class, sourcesProvider).addProvider(ProtoSupportDataProvider.class, new ProtoSupportDataProvider(supportData)).addSkylarkTransitiveInfo(ProtoSourcesProvider.SKYLARK_NAME, sourcesProvider).build();
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 28 with Runfiles

use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testRunfilesSymlinkConflict.

@Test
public void testRunfilesSymlinkConflict() throws Exception {
    // Two different artifacts mapped to same path in runfiles
    Object result = evalRuleContextCode("artifacts = ruleContext.files.srcs", "prefix = ruleContext.workspace_name + '/' if ruleContext.workspace_name else ''", "ruleContext.runfiles(", "root_symlinks = {prefix + 'sym1': artifacts[0]},", "symlinks = {'sym1': artifacts[1]})");
    Runfiles runfiles = (Runfiles) result;
    // So it doesn't throw exception
    reporter.removeHandler(failFastHandler);
    runfiles.getRunfilesInputs(reporter, null);
    assertContainsEvent("ERROR <no location>: overwrote runfile");
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) Test(org.junit.Test)

Aggregations

Runfiles (com.google.devtools.build.lib.analysis.Runfiles)28 Artifact (com.google.devtools.build.lib.actions.Artifact)24 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)15 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)11 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)10 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)9 RunfilesSupplierImpl (com.google.devtools.build.lib.analysis.RunfilesSupplierImpl)7 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)7 Test (org.junit.Test)7 ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)6 EmptyRunfilesSupplier (com.google.devtools.build.lib.actions.EmptyRunfilesSupplier)6 RunfilesSupplier (com.google.devtools.build.lib.actions.RunfilesSupplier)6 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)6 ArrayList (java.util.ArrayList)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)3 LibraryToLink (com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink)3 InstrumentedFilesProvider (com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider)3 Label (com.google.devtools.build.lib.cmdline.Label)2 NestedSet (com.google.devtools.build.lib.collect.nestedset.NestedSet)2