use of com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider in project bazel by bazelbuild.
the class AndroidStudioInfoAspect method processDependencies.
private DependenciesResult processDependencies(ConfiguredTarget base, RuleContext ruleContext, AndroidStudioInfoFilesProvider.Builder providerBuilder) {
// Calculate direct dependencies
ImmutableList.Builder<TransitiveInfoCollection> directDepsBuilder = ImmutableList.builder();
for (PrerequisiteAttr prerequisiteAttr : prerequisiteAttrs) {
if (ruleContext.attributes().has(prerequisiteAttr.name, prerequisiteAttr.type)) {
Mode mode = ruleContext.getAttributeMode(prerequisiteAttr.name);
if (mode == Mode.TARGET || mode == Mode.SPLIT) {
directDepsBuilder.addAll(ruleContext.getPrerequisites(prerequisiteAttr.name, Mode.TARGET));
}
}
}
List<TransitiveInfoCollection> directDeps = directDepsBuilder.build();
// Add exports from direct dependencies
NestedSetBuilder<Label> dependenciesBuilder = NestedSetBuilder.stableOrder();
for (AndroidStudioInfoFilesProvider depProvider : AnalysisUtils.getProviders(directDeps, AndroidStudioInfoFilesProvider.class)) {
dependenciesBuilder.addTransitive(depProvider.getExportedDeps());
}
for (TransitiveInfoCollection dep : directDeps) {
dependenciesBuilder.add(dep.getLabel());
}
NestedSet<Label> dependencies = dependenciesBuilder.build();
// Propagate my own exports
JavaExportsProvider javaExportsProvider = base.getProvider(JavaExportsProvider.class);
if (javaExportsProvider != null) {
providerBuilder.exportedDepsBuilder().addTransitive(javaExportsProvider.getTransitiveExports());
}
// android_library without sources exports all its deps
if (ruleContext.getRule().getRuleClass().equals("android_library")) {
JavaSourceInfoProvider sourceInfoProvider = base.getProvider(JavaSourceInfoProvider.class);
boolean hasSources = sourceInfoProvider != null && !sourceInfoProvider.getSourceFiles().isEmpty();
if (!hasSources) {
for (TransitiveInfoCollection dep : directDeps) {
providerBuilder.exportedDepsBuilder().add(dep.getLabel());
}
}
}
// runtime_deps
List<? extends TransitiveInfoCollection> runtimeDeps = ImmutableList.of();
NestedSetBuilder<Label> runtimeDepsBuilder = NestedSetBuilder.stableOrder();
if (ruleContext.attributes().has("runtime_deps", BuildType.LABEL_LIST)) {
runtimeDeps = ruleContext.getPrerequisites("runtime_deps", Mode.TARGET);
for (TransitiveInfoCollection dep : runtimeDeps) {
runtimeDepsBuilder.add(dep.getLabel());
}
}
// resources
@Nullable TransitiveInfoCollection resources = ruleContext.attributes().has("resources", BuildType.LABEL) ? ruleContext.getPrerequisite("resources", Mode.TARGET) : null;
// Propagate providers from all prerequisites (deps + runtime_deps)
ImmutableList.Builder<TransitiveInfoCollection> prerequisitesBuilder = ImmutableList.builder();
prerequisitesBuilder.addAll(directDeps);
prerequisitesBuilder.addAll(runtimeDeps);
if (resources != null) {
prerequisitesBuilder.add(resources);
}
List<TransitiveInfoCollection> prerequisites = prerequisitesBuilder.build();
for (AndroidStudioInfoFilesProvider depProvider : AnalysisUtils.getProviders(prerequisites, AndroidStudioInfoFilesProvider.class)) {
providerBuilder.ideInfoFilesBuilder().addTransitive(depProvider.getIdeInfoFiles());
providerBuilder.ideInfoTextFilesBuilder().addTransitive(depProvider.getIdeInfoTextFiles());
providerBuilder.ideResolveFilesBuilder().addTransitive(depProvider.getIdeResolveFiles());
}
return new DependenciesResult(dependencies, runtimeDepsBuilder.build(), resources != null ? resources.getLabel() : null);
}
use of com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider in project bazel by bazelbuild.
the class JackAspect method create.
@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext, AspectParameters params) {
if (base.getProvider(JackLibraryProvider.class) != null) {
return new ConfiguredAspect.Builder(this, params, ruleContext).build();
}
JavaSourceInfoProvider sourceProvider = base.getProvider(JavaSourceInfoProvider.class);
PathFragment rulePath = ruleContext.getLabel().toPathFragment();
PathFragment jackLibraryPath = rulePath.replaceName("lib" + rulePath.getBaseName() + ".jack");
Artifact jackLibraryOutput = ruleContext.getAnalysisEnvironment().getDerivedArtifact(jackLibraryPath, ruleContext.getBinOrGenfilesDirectory());
if (!AndroidSdkProvider.verifyPresence(ruleContext)) {
return null;
}
AndroidSdkProvider androidSdk = AndroidSdkProvider.fromRuleContext(ruleContext);
JackCompilationHelper jackHelper = new JackCompilationHelper.Builder().setRuleContext(ruleContext).setOutputArtifact(jackLibraryOutput).setJackBinary(androidSdk.getJack()).setJillBinary(androidSdk.getJill()).setResourceExtractorBinary(androidSdk.getResourceExtractor()).setJackBaseClasspath(androidSdk.getJavaBaseClasspathForJack()).addJavaSources(sourceProvider.getSourceFiles()).addSourceJars(sourceProvider.getSourceJars()).addCompiledJars(sourceProvider.getJarFiles()).addResources(sourceProvider.getResources()).addProcessorNames(sourceProvider.getProcessorNames()).addProcessorClasspathJars(sourceProvider.getProcessorPath()).addExports(getPotentialDependency(ruleContext, "exports")).addDeps(getPotentialDependency(ruleContext, "deps")).addRuntimeDeps(getPotentialDependency(ruleContext, "runtime_deps")).build();
JackLibraryProvider result = JavaCommon.isNeverLink(ruleContext) ? jackHelper.compileAsNeverlinkLibrary() : jackHelper.compileAsLibrary();
return new ConfiguredAspect.Builder(this, params, ruleContext).addProvider(result).build();
}
use of com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider in project bazel by bazelbuild.
the class J2ObjcAspect method java.
private ConfiguredAspect java(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException {
JavaCompilationArgsProvider compilationArgsProvider = base.getProvider(JavaCompilationArgsProvider.class);
JavaSourceInfoProvider sourceInfoProvider = base.getProvider(JavaSourceInfoProvider.class);
JavaGenJarsProvider genJarProvider = base.getProvider(JavaGenJarsProvider.class);
ImmutableSet.Builder<Artifact> javaSourceFilesBuilder = ImmutableSet.builder();
ImmutableSet.Builder<Artifact> javaSourceJarsBuilder = ImmutableSet.builder();
if (sourceInfoProvider != null) {
javaSourceFilesBuilder.addAll(sourceInfoProvider.getSourceFiles());
javaSourceJarsBuilder.addAll(sourceInfoProvider.getSourceJars()).addAll(sourceInfoProvider.getSourceJarsForJarFiles());
}
if (genJarProvider != null && genJarProvider.getGenSourceJar() != null) {
javaSourceJarsBuilder.add(genJarProvider.getGenSourceJar());
}
ImmutableSet<Artifact> javaSourceFiles = javaSourceFilesBuilder.build();
ImmutableSet<Artifact> javaSourceJars = javaSourceJarsBuilder.build();
J2ObjcSource j2ObjcSource = javaJ2ObjcSource(ruleContext, javaSourceFiles, javaSourceJars);
J2ObjcMappingFileProvider depJ2ObjcMappingFileProvider = depJ2ObjcMappingFileProvider(ruleContext);
J2ObjcMappingFileProvider directJ2ObjcMappingFileProvider;
if (Iterables.isEmpty(j2ObjcSource.getObjcSrcs())) {
directJ2ObjcMappingFileProvider = new J2ObjcMappingFileProvider.Builder().build();
} else {
directJ2ObjcMappingFileProvider = createJ2ObjcTranspilationAction(ruleContext, javaSourceFiles, javaSourceJars, depJ2ObjcMappingFileProvider, compilationArgsProvider, j2ObjcSource);
}
return buildAspect(base, ruleContext, parameters, j2ObjcSource, directJ2ObjcMappingFileProvider, JAVA_DEPENDENT_ATTRIBUTES);
}
Aggregations