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();
}
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();
}
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");
}
Aggregations