Search in sources :

Example 1 with JavaSourceInfoProvider

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);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Mode(com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode) Label(com.google.devtools.build.lib.cmdline.Label) JavaExportsProvider(com.google.devtools.build.lib.rules.java.JavaExportsProvider) JavaSourceInfoProvider(com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Nullable(javax.annotation.Nullable)

Example 2 with JavaSourceInfoProvider

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();
}
Also used : ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) JavaSourceInfoProvider(com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 3 with JavaSourceInfoProvider

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);
}
Also used : JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) ImmutableSet(com.google.common.collect.ImmutableSet) JavaSourceInfoProvider(com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider) JavaGenJarsProvider(com.google.devtools.build.lib.rules.java.JavaGenJarsProvider) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) ProtoCompileActionBuilder(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

JavaSourceInfoProvider (com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider)3 Artifact (com.google.devtools.build.lib.actions.Artifact)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ConfiguredAspect (com.google.devtools.build.lib.analysis.ConfiguredAspect)1 Mode (com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode)1 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)1 Label (com.google.devtools.build.lib.cmdline.Label)1 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)1 JavaCompilationArgsProvider (com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider)1 JavaExportsProvider (com.google.devtools.build.lib.rules.java.JavaExportsProvider)1 JavaGenJarsProvider (com.google.devtools.build.lib.rules.java.JavaGenJarsProvider)1 ProtoCompileActionBuilder (com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 Nullable (javax.annotation.Nullable)1