Search in sources :

Example 36 with TransitiveInfoCollection

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

the class SkylarkRuleContext method instrumentCoverage.

@SkylarkCallable(name = "coverage_instrumented", doc = "Returns whether code coverage instrumentation should be generated when performing " + "compilation actions for this rule or, if <code>target</code> is provided, the rule " + "specified by that Target. (If a non-rule Target is provided, this returns False.) This " + "differs from <code>coverage_enabled</code> in the <a href=\"configuration.html\">" + "configuration</a>, which notes whether coverage data collection is enabled for the " + "entire run, but not whether a specific target should be instrumented.", parameters = { @Param(name = "target", type = TransitiveInfoCollection.class, defaultValue = "None", noneable = true, named = true, doc = "A Target specifying a rule. If not provided, defaults to the current rule.") })
public boolean instrumentCoverage(Object targetUnchecked) {
    BuildConfiguration config = ruleContext.getConfiguration();
    if (!config.isCodeCoverageEnabled()) {
        return false;
    }
    if (targetUnchecked == Runtime.NONE) {
        return InstrumentedFilesCollector.shouldIncludeLocalSources(ruleContext);
    }
    TransitiveInfoCollection target = (TransitiveInfoCollection) targetUnchecked;
    return (target.getProvider(InstrumentedFilesProvider.class) != null) && InstrumentedFilesCollector.shouldIncludeLocalSources(config, target);
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) InstrumentedFilesProvider(com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) SkylarkCallable(com.google.devtools.build.lib.skylarkinterface.SkylarkCallable)

Example 37 with TransitiveInfoCollection

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

the class AarImport method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    if (!AndroidSdkProvider.verifyPresence(ruleContext)) {
        return null;
    }
    RuleConfiguredTargetBuilder ruleBuilder = new RuleConfiguredTargetBuilder(ruleContext);
    Artifact aar = ruleContext.getPrerequisiteArtifact("aar", Mode.TARGET);
    Artifact allAarJars = createAarTreeArtifact(ruleContext, "jars");
    Artifact jarMergingParams = createAarArtifact(ruleContext, "jar_merging_params");
    ruleContext.registerAction(createAarEmbeddedJarsExtractorActions(ruleContext, aar, allAarJars, jarMergingParams));
    Artifact mergedJar = createAarArtifact(ruleContext, MERGED_JAR);
    ruleContext.registerAction(createAarJarsMergingActions(ruleContext, allAarJars, mergedJar, jarMergingParams));
    // AndroidManifest.xml is required in every AAR.
    Artifact androidManifestArtifact = createAarArtifact(ruleContext, ANDROID_MANIFEST);
    ruleContext.registerAction(createSingleFileExtractorActions(ruleContext, aar, ANDROID_MANIFEST, androidManifestArtifact));
    Artifact resourcesManifest = createAarArtifact(ruleContext, "resource_manifest");
    ruleContext.registerAction(createManifestExtractorActions(ruleContext, aar, "res/.*", resourcesManifest));
    Artifact resources = createAarTreeArtifact(ruleContext, "resources");
    ruleContext.registerAction(createManifestFileEntriesExtractorActions(ruleContext, aar, resourcesManifest, resources));
    ApplicationManifest androidManifest = ApplicationManifest.fromExplicitManifest(ruleContext, androidManifestArtifact);
    FileProvider resourcesProvider = new FileProvider(new NestedSetBuilder<Artifact>(Order.NAIVE_LINK_ORDER).add(resources).build());
    Artifact resourcesZip = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP);
    ResourceApk resourceApk = androidManifest.packWithDataAndResources(ruleContext, new LocalResourceContainer.Builder(ruleContext).withResources(ImmutableList.of(resourcesProvider)).build(), ResourceDependencies.fromRuleDeps(ruleContext, JavaCommon.isNeverLink(ruleContext)), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_SYMBOLS), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST), resourcesZip, /* alwaysExportManifest = */
    true);
    // There isn't really any use case for building an aar_import target on its own, so the files to
    // build could be empty. The resources zip and merged jars are added here as a sanity check for
    // Bazel developers so that `bazel build java/com/my_aar_import` will fail if the resource
    // processing or jar merging steps fail.
    NestedSetBuilder<Artifact> filesToBuildBuilder = NestedSetBuilder.<Artifact>stableOrder().add(resourcesZip).add(mergedJar);
    Artifact nativeLibs = createAarArtifact(ruleContext, "native_libs.zip");
    ruleContext.registerAction(createAarNativeLibsFilterActions(ruleContext, aar, nativeLibs));
    JavaRuleOutputJarsProvider.Builder jarProviderBuilder = new JavaRuleOutputJarsProvider.Builder().addOutputJar(mergedJar, null, ImmutableList.<Artifact>of());
    for (TransitiveInfoCollection export : ruleContext.getPrerequisites("exports", Mode.TARGET)) {
        for (OutputJar jar : JavaProvider.getProvider(JavaRuleOutputJarsProvider.class, export).getOutputJars()) {
            jarProviderBuilder.addOutputJar(jar);
            filesToBuildBuilder.add(jar.getClassJar());
        }
    }
    ImmutableList<TransitiveInfoCollection> targets = ImmutableList.<TransitiveInfoCollection>copyOf(ruleContext.getPrerequisites("exports", Mode.TARGET));
    JavaCommon common = new JavaCommon(ruleContext, javaSemantics, /* sources = */
    ImmutableList.<Artifact>of(), /* compileDeps = */
    targets, /* runtimeDeps = */
    targets, /* bothDeps = */
    targets);
    common.setJavaCompilationArtifacts(new JavaCompilationArtifacts.Builder().addRuntimeJar(mergedJar).addCompileTimeJar(mergedJar).build());
    return ruleBuilder.setFilesToBuild(filesToBuildBuilder.build()).addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY).addProvider(AndroidResourcesProvider.class, resourceApk.toResourceProvider(ruleContext.getLabel())).addProvider(NativeLibsZipsProvider.class, new NativeLibsZipsProvider(AndroidCommon.collectTransitiveNativeLibsZips(ruleContext).add(nativeLibs).build())).addProvider(JavaRuntimeJarProvider.class, new JavaRuntimeJarProvider(ImmutableList.of(mergedJar))).addProvider(JavaCompilationArgsProvider.class, JavaCompilationArgsProvider.create(common.collectJavaCompilationArgs(/* recursive = */
    false, JavaCommon.isNeverLink(ruleContext), /* srcLessDepsExport = */
    false), common.collectJavaCompilationArgs(/* recursive = */
    true, JavaCommon.isNeverLink(ruleContext), /* srcLessDepsExport = */
    false))).addProvider(JavaRuleOutputJarsProvider.class, jarProviderBuilder.build()).build();
}
Also used : JavaRuleOutputJarsProvider(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider) OutputJar(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) JavaRuntimeJarProvider(com.google.devtools.build.lib.rules.java.JavaRuntimeJarProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) FileProvider(com.google.devtools.build.lib.analysis.FileProvider) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) JavaCommon(com.google.devtools.build.lib.rules.java.JavaCommon)

Example 38 with TransitiveInfoCollection

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

the class AndroidSdk method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    // If the user didn't specify --proguard_top, go with the proguard attribute in the android_sdk
    // rule. Otherwise, use what she told us to.
    FilesToRunProvider proguard = ruleContext.getFragment(JavaConfiguration.class).getProguardBinary() == null ? ruleContext.getExecutablePrerequisite("proguard", Mode.HOST) : ruleContext.getExecutablePrerequisite(":proguard", Mode.HOST);
    String buildToolsVersion = AggregatingAttributeMapper.of(ruleContext.getRule()).get("build_tools_version", Type.STRING);
    Revision parsedBuildToolsVersion = null;
    try {
        parsedBuildToolsVersion = Strings.isNullOrEmpty(buildToolsVersion) ? null : Revision.parseRevision(buildToolsVersion);
    } catch (NumberFormatException nfe) {
        ruleContext.attributeError("build_tools_version", "Invalid version: " + buildToolsVersion);
    }
    boolean aaptSupportsMainDexGeneration = parsedBuildToolsVersion == null || parsedBuildToolsVersion.compareTo(new Revision(24)) >= 0;
    FilesToRunProvider aidl = ruleContext.getExecutablePrerequisite("aidl", Mode.HOST);
    FilesToRunProvider aapt = ruleContext.getExecutablePrerequisite("aapt", Mode.HOST);
    FilesToRunProvider apkBuilder = ruleContext.getExecutablePrerequisite("apkbuilder", Mode.HOST);
    FilesToRunProvider apkSigner = ruleContext.getExecutablePrerequisite("apksigner", Mode.HOST);
    FilesToRunProvider adb = ruleContext.getExecutablePrerequisite("adb", Mode.HOST);
    FilesToRunProvider dx = ruleContext.getExecutablePrerequisite("dx", Mode.HOST);
    FilesToRunProvider mainDexListCreator = ruleContext.getExecutablePrerequisite("main_dex_list_creator", Mode.HOST);
    FilesToRunProvider zipalign = ruleContext.getExecutablePrerequisite("zipalign", Mode.HOST);
    FilesToRunProvider jack = ruleContext.getExecutablePrerequisite("jack", Mode.HOST);
    FilesToRunProvider jill = ruleContext.getExecutablePrerequisite("jill", Mode.HOST);
    FilesToRunProvider resourceExtractor = ruleContext.getExecutablePrerequisite("resource_extractor", Mode.HOST);
    Artifact frameworkAidl = ruleContext.getPrerequisiteArtifact("framework_aidl", Mode.HOST);
    TransitiveInfoCollection aidlLib = ruleContext.getPrerequisite("aidl_lib", Mode.TARGET);
    Artifact androidJar = ruleContext.getPrerequisiteArtifact("android_jar", Mode.HOST);
    Artifact shrinkedAndroidJar = ruleContext.getPrerequisiteArtifact("shrinked_android_jar", Mode.HOST);
    // Because all Jack actions using this android_sdk will need Jack versions of the Android and
    // Java classpaths, pre-translate the jars for Android and Java targets here. (They will only
    // be run if needed, as usual for Bazel.)
    NestedSet<Artifact> androidBaseClasspathForJack = convertClasspathJarsToJack(ruleContext, jack, jill, resourceExtractor, ImmutableList.of(androidJar));
    NestedSet<Artifact> javaBaseClasspathForJack = convertClasspathJarsToJack(ruleContext, jack, jill, resourceExtractor, JavaCompilationHelper.getBootClasspath(JavaToolchainProvider.fromRuleContext(ruleContext)));
    Artifact annotationsJar = ruleContext.getPrerequisiteArtifact("annotations_jar", Mode.HOST);
    Artifact mainDexClasses = ruleContext.getPrerequisiteArtifact("main_dex_classes", Mode.HOST);
    if (ruleContext.hasErrors()) {
        return null;
    }
    return new RuleConfiguredTargetBuilder(ruleContext).add(AndroidSdkProvider.class, AndroidSdkProvider.create(buildToolsVersion, aaptSupportsMainDexGeneration, frameworkAidl, aidlLib, androidJar, shrinkedAndroidJar, androidBaseClasspathForJack, javaBaseClasspathForJack, annotationsJar, mainDexClasses, adb, dx, mainDexListCreator, aidl, aapt, apkBuilder, apkSigner, proguard, zipalign, jack, jill, resourceExtractor)).add(RunfilesProvider.class, RunfilesProvider.EMPTY).setFilesToBuild(NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER)).build();
}
Also used : FilesToRunProvider(com.google.devtools.build.lib.analysis.FilesToRunProvider) Revision(com.android.repository.Revision) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) JavaConfiguration(com.google.devtools.build.lib.rules.java.JavaConfiguration) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 39 with TransitiveInfoCollection

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

the class CcLibraryHelper method collectTransitiveLipoInfo.

private TransitiveLipoInfoProvider collectTransitiveLipoInfo(CcCompilationOutputs outputs) {
    if (fdoSupport.getFdoSupport().getFdoRoot() == null) {
        return TransitiveLipoInfoProvider.EMPTY;
    }
    NestedSetBuilder<IncludeScannable> scannableBuilder = NestedSetBuilder.stableOrder();
    // TODO(bazel-team): Only fetch the STL prerequisite in one place.
    TransitiveInfoCollection stl = ruleContext.getPrerequisite(":stl", Mode.TARGET);
    if (stl != null) {
        TransitiveLipoInfoProvider provider = stl.getProvider(TransitiveLipoInfoProvider.class);
        if (provider != null) {
            scannableBuilder.addTransitive(provider.getTransitiveIncludeScannables());
        }
    }
    for (TransitiveLipoInfoProvider dep : AnalysisUtils.getProviders(deps, TransitiveLipoInfoProvider.class)) {
        scannableBuilder.addTransitive(dep.getTransitiveIncludeScannables());
    }
    for (IncludeScannable scannable : outputs.getLipoScannables()) {
        Preconditions.checkState(scannable.getIncludeScannerSources().size() == 1);
        scannableBuilder.add(scannable);
    }
    return new TransitiveLipoInfoProvider(scannableBuilder.build());
}
Also used : TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 40 with TransitiveInfoCollection

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

the class AndroidBinary method getStubDex.

private static Artifact getStubDex(RuleContext ruleContext, JavaSemantics javaSemantics, boolean split) throws InterruptedException {
    String attribute = split ? "$incremental_split_stub_application" : "$incremental_stub_application";
    TransitiveInfoCollection dep = ruleContext.getPrerequisite(attribute, Mode.TARGET);
    if (dep == null) {
        ruleContext.attributeError(attribute, "Stub application cannot be found");
        return null;
    }
    JavaCompilationArgsProvider provider = dep.getProvider(JavaCompilationArgsProvider.class);
    if (provider == null) {
        ruleContext.attributeError(attribute, "'" + dep.getLabel() + "' should be a Java target");
        return null;
    }
    JavaTargetAttributes attributes = new JavaTargetAttributes.Builder(javaSemantics).addRuntimeClassPathEntries(provider.getJavaCompilationArgs().getRuntimeJars()).build();
    Function<Artifact, Artifact> desugaredJars = Functions.identity();
    if (AndroidCommon.getAndroidConfig(ruleContext).desugarJava8()) {
        desugaredJars = collectDesugaredJarsFromAttributes(ruleContext, ImmutableList.of(attribute)).build().collapseToFunction();
    }
    Artifact stubDeployJar = getDxArtifact(ruleContext, split ? "split_stub_deploy.jar" : "stub_deploy.jar");
    new DeployArchiveBuilder(javaSemantics, ruleContext).setOutputJar(stubDeployJar).setAttributes(attributes).setDerivedJarFunction(desugaredJars).build();
    Artifact stubDex = getDxArtifact(ruleContext, split ? "split_stub_application/classes.dex" : "stub_application/classes.dex");
    AndroidCommon.createDexAction(ruleContext, stubDeployJar, stubDex, ImmutableList.<String>of(), false, null);
    return stubDex;
}
Also used : JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) MultimapBuilder(com.google.common.collect.MultimapBuilder) Builder(com.google.devtools.build.lib.analysis.actions.SpawnAction.Builder) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) DeployArchiveBuilder(com.google.devtools.build.lib.rules.java.DeployArchiveBuilder) DeployArchiveBuilder(com.google.devtools.build.lib.rules.java.DeployArchiveBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) JavaTargetAttributes(com.google.devtools.build.lib.rules.java.JavaTargetAttributes) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)54 Artifact (com.google.devtools.build.lib.actions.Artifact)27 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)14 FileProvider (com.google.devtools.build.lib.analysis.FileProvider)11 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)11 Label (com.google.devtools.build.lib.cmdline.Label)10 ImmutableList (com.google.common.collect.ImmutableList)8 ArrayList (java.util.ArrayList)8 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)7 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)5 Test (org.junit.Test)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)4 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)4 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)4 Pair (com.google.devtools.build.lib.util.Pair)4 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 Map (java.util.Map)4 CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)3 CcLinkParamsProvider (com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider)3