use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection in project bazel by bazelbuild.
the class JavaCommon method getRunfiles.
public static Runfiles getRunfiles(RuleContext ruleContext, JavaSemantics semantics, JavaCompilationArtifacts javaArtifacts, boolean neverLink) {
// runfiles from this target or its dependencies.
if (neverLink) {
return Runfiles.EMPTY;
}
Runfiles.Builder runfilesBuilder = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addArtifacts(javaArtifacts.getRuntimeJars());
runfilesBuilder.addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES);
runfilesBuilder.add(ruleContext, JavaRunfilesProvider.TO_RUNFILES);
List<TransitiveInfoCollection> depsForRunfiles = new ArrayList<>();
if (ruleContext.getRule().isAttrDefined("runtime_deps", BuildType.LABEL_LIST)) {
depsForRunfiles.addAll(ruleContext.getPrerequisites("runtime_deps", Mode.TARGET));
}
if (ruleContext.getRule().isAttrDefined("exports", BuildType.LABEL_LIST)) {
depsForRunfiles.addAll(ruleContext.getPrerequisites("exports", Mode.TARGET));
}
runfilesBuilder.addTargets(depsForRunfiles, RunfilesProvider.DEFAULT_RUNFILES);
runfilesBuilder.addTargets(depsForRunfiles, JavaRunfilesProvider.TO_RUNFILES);
TransitiveInfoCollection launcher = JavaHelper.launcherForTarget(semantics, ruleContext);
if (launcher != null) {
runfilesBuilder.addTarget(launcher, RunfilesProvider.DATA_RUNFILES);
}
semantics.addRunfilesForLibrary(ruleContext, runfilesBuilder);
return runfilesBuilder.build();
}
use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection in project bazel by bazelbuild.
the class JavaCompilationHelper method addLibrariesToAttributes.
/**
* Adds the compile time and runtime Java libraries in the transitive closure
* of the deps to the attributes.
*
* @param deps the dependencies to be included as roots of the transitive
* closure
*/
public void addLibrariesToAttributes(Iterable<? extends TransitiveInfoCollection> deps) {
// Enforcing strict Java dependencies: when the --strict_java_deps flag is
// WARN or ERROR, or is DEFAULT and strict_java_deps attribute is unset,
// we use a stricter javac compiler to perform direct deps checks.
attributes.setStrictJavaDeps(getStrictJavaDeps());
addLibrariesToAttributesInternal(deps);
JavaClasspathMode classpathMode = getJavaConfiguration().getReduceJavaClasspath();
if (isStrict() && classpathMode != JavaClasspathMode.OFF) {
List<JavaCompilationArgsProvider> compilationArgsProviders = new LinkedList<>();
for (TransitiveInfoCollection dep : deps) {
JavaCompilationArgsProvider provider = JavaProvider.getProvider(JavaCompilationArgsProvider.class, dep);
if (provider != null) {
compilationArgsProviders.add(provider);
}
}
addDependencyArtifactsToAttributes(attributes, compilationArgsProviders);
}
}
use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection 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.TransitiveInfoCollection in project bazel by bazelbuild.
the class TestSuite method checkTestsAndSuites.
private void checkTestsAndSuites(RuleContext ruleContext, String attributeName) {
if (!ruleContext.attributes().has(attributeName, BuildType.LABEL_LIST)) {
return;
}
for (TransitiveInfoCollection dep : ruleContext.getPrerequisites(attributeName, Mode.TARGET)) {
// TODO(bazel-team): Maybe convert the TransitiveTestsProvider into an inner interface.
TransitiveTestsProvider provider = dep.getProvider(TransitiveTestsProvider.class);
TestProvider testProvider = dep.getProvider(TestProvider.class);
if (provider == null && testProvider == null) {
ruleContext.attributeError(attributeName, "expecting a test or a test_suite rule but '" + dep.getLabel() + "' is not one");
}
}
}
use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection in project bazel by bazelbuild.
the class MultiArchBinarySupport method registerActions.
/**
* Registers actions to create a multi-arch Apple binary.
*
* @param platform the platform for which the binary is targeted
* @param extraLinkArgs the extra linker args to add to link actions linking single-architecture
* binaries together
* @param configurationToObjcProvider a map from from dependency configuration to the
* {@link ObjcProvider} which comprises all information about the dependencies in that
* configuration. Can be obtained via {@link #objcProviderByDepConfiguration}
* @param extraLinkInputs the extra linker inputs to be made available during link actions
* @param configToDepsCollectionMap a multimap from dependency configuration to the
* list of provider collections which are propagated from the dependencies of that
* configuration
* @param outputLipoBinary the artifact (lipo'ed binary) which should be output as a result of
* this support
* @throws RuleErrorException if there are attribute errors in the current rule context
*/
public void registerActions(Platform platform, ExtraLinkArgs extraLinkArgs, Map<BuildConfiguration, ObjcProvider> configurationToObjcProvider, Iterable<Artifact> extraLinkInputs, ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> configToDepsCollectionMap, Artifact outputLipoBinary) throws RuleErrorException, InterruptedException {
NestedSetBuilder<Artifact> binariesToLipo = NestedSetBuilder.<Artifact>stableOrder();
for (BuildConfiguration childConfig : configurationToObjcProvider.keySet()) {
IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext, childConfig);
ImmutableList.Builder<J2ObjcMappingFileProvider> j2ObjcMappingFileProviders = ImmutableList.builder();
J2ObjcEntryClassProvider.Builder j2ObjcEntryClassProviderBuilder = new J2ObjcEntryClassProvider.Builder();
for (TransitiveInfoCollection dep : configToDepsCollectionMap.get(childConfig)) {
if (dep.getProvider(J2ObjcMappingFileProvider.class) != null) {
j2ObjcMappingFileProviders.add(dep.getProvider(J2ObjcMappingFileProvider.class));
}
if (dep.getProvider(J2ObjcEntryClassProvider.class) != null) {
j2ObjcEntryClassProviderBuilder.addTransitive(dep.getProvider(J2ObjcEntryClassProvider.class));
}
}
J2ObjcMappingFileProvider j2ObjcMappingFileProvider = J2ObjcMappingFileProvider.union(j2ObjcMappingFileProviders.build());
J2ObjcEntryClassProvider j2ObjcEntryClassProvider = j2ObjcEntryClassProviderBuilder.build();
binariesToLipo.add(intermediateArtifacts.strippedSingleArchitectureBinary());
ObjcProvider objcProvider = configurationToObjcProvider.get(childConfig);
CompilationArtifacts compilationArtifacts = CompilationSupport.compilationArtifacts(ruleContext, ObjcRuleClasses.intermediateArtifacts(ruleContext, childConfig));
CompilationSupport.createForConfig(ruleContext, childConfig).registerCompileAndArchiveActions(compilationArtifacts, objcProvider).registerLinkActions(objcProvider, j2ObjcMappingFileProvider, j2ObjcEntryClassProvider, extraLinkArgs, extraLinkInputs, DsymOutputType.APP).validateAttributes();
ruleContext.assertNoErrors();
}
new LipoSupport(ruleContext).registerCombineArchitecturesAction(binariesToLipo.build(), outputLipoBinary, platform);
}
Aggregations