Search in sources :

Example 21 with TransitiveInfoCollection

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

the class AndroidSdkProvider method fromRuleContext.

/**
   * Returns the Android SDK associated with the rule being analyzed or null if the Android SDK is
   * not specified.
   */
public static AndroidSdkProvider fromRuleContext(RuleContext ruleContext) {
    TransitiveInfoCollection androidSdkDep = ruleContext.getPrerequisite(":android_sdk", Mode.TARGET);
    AndroidSdkProvider androidSdk = androidSdkDep == null ? null : androidSdkDep.getProvider(AndroidSdkProvider.class);
    return androidSdk;
}
Also used : TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 22 with TransitiveInfoCollection

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

the class AndroidToolsDefaultsJar method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    if (!ruleContext.getLabel().getPackageName().equals("tools/defaults")) {
        // Guard against extraordinarily inquisitive individuals.
        ruleContext.ruleError("The android_tools_defaults_jar rule should not be used in BUILD files." + " It is a rule internal to the build tool.");
        return null;
    }
    TransitiveInfoCollection androidSdk = ruleContext.getPrerequisite(":android_sdk", Mode.TARGET);
    AndroidSdkProvider sdkProvider = androidSdk.getProvider(AndroidSdkProvider.class);
    Artifact androidJar = sdkProvider != null ? sdkProvider.getAndroidJar() : findAndroidJar(androidSdk.getProvider(FileProvider.class).getFilesToBuild());
    NestedSet<Artifact> filesToBuild = androidJar == null ? NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER) : NestedSetBuilder.create(Order.STABLE_ORDER, androidJar);
    return new RuleConfiguredTargetBuilder(ruleContext).add(RunfilesProvider.class, RunfilesProvider.EMPTY).setFilesToBuild(filesToBuild).build();
}
Also used : FileProvider(com.google.devtools.build.lib.analysis.FileProvider) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 23 with TransitiveInfoCollection

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

the class ApplicationManifest method packWithResources.

/**
   * Packages up the manifest with resources, and generates the R.java.
   * @throws InterruptedException
   *
   * @deprecated in favor of {@link ApplicationManifest#packWithDataAndResources}.
   */
@Deprecated
public ResourceApk packWithResources(Artifact resourceApk, RuleContext ruleContext, ResourceDependencies resourceDeps, boolean createSource, Artifact proguardCfg, @Nullable Artifact mainDexProguardCfg) throws InterruptedException {
    TransitiveInfoCollection resourcesPrerequisite = ruleContext.getPrerequisite("resources", Mode.TARGET);
    ResourceContainer resourceContainer = Iterables.getOnlyElement(resourcesPrerequisite.getProvider(AndroidResourcesProvider.class).getDirectAndroidResources());
    // It's ugly, but flattening now is more performant given the rest of the checks.
    List<ResourceContainer> resourceContainers = ImmutableList.<ResourceContainer>builder().addAll(resourceDeps.getResources()).build();
    // Dealing with Android library projects
    if (Iterables.size(resourceDeps.getResources()) > 1) {
        if (resourceContainer.getConstantsInlined() && !resourceContainer.getArtifacts(ResourceType.RESOURCES).isEmpty()) {
            ruleContext.ruleError("This android_binary depends on an android_library, so the" + " resources '" + AndroidCommon.getAndroidResources(ruleContext).getLabel() + "' should have the attribute inline_constants set to 0");
            return null;
        }
    }
    // This binary depends on a library project, so we need to regenerate the
    // resources. The resulting sources and apk will combine all the resources
    // contained in the transitive closure of the binary.
    AndroidAaptActionHelper aaptActionHelper = new AndroidAaptActionHelper(ruleContext, getManifest(), Lists.newArrayList(resourceContainers));
    String resourceConfigurationFilters = ResourceConfigurationFilter.extractFilters(ruleContext);
    List<String> uncompressedExtensions = ruleContext.getTokenizedStringListAttr("nocompress_extensions");
    ImmutableList.Builder<String> additionalAaptOpts = ImmutableList.<String>builder();
    for (String extension : uncompressedExtensions) {
        additionalAaptOpts.add("-0").add(extension);
    }
    if (!resourceConfigurationFilters.isEmpty()) {
        additionalAaptOpts.add("-c").add(resourceConfigurationFilters);
    }
    Artifact javaSourcesJar = null;
    if (createSource) {
        javaSourcesJar = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_JAVA_SOURCE_JAR);
        aaptActionHelper.createGenerateResourceSymbolsAction(javaSourcesJar, null, resourceContainer.getJavaPackage(), true);
    }
    List<String> densities = ruleContext.getTokenizedStringListAttr("densities");
    aaptActionHelper.createGenerateApkAction(resourceApk, resourceContainer.getRenameManifestPackage(), additionalAaptOpts.build(), densities);
    ResourceContainer updatedResources = resourceContainer.toBuilder().setLabel(ruleContext.getLabel()).setApk(resourceApk).setManifest(getManifest()).setJavaSourceJar(javaSourcesJar).setJavaClassJar(null).setSymbols(null).build();
    aaptActionHelper.createGenerateProguardAction(proguardCfg, mainDexProguardCfg);
    return new ResourceApk(resourceApk, updatedResources.getJavaSourceJar(), updatedResources.getJavaClassJar(), resourceDeps, updatedResources, manifest, proguardCfg, mainDexProguardCfg, true);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 24 with TransitiveInfoCollection

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

the class ProtoCompileActionBuilderTest method commandLine_basic.

@Test
public void commandLine_basic() throws Exception {
    FilesToRunProvider plugin = new FilesToRunProvider(ImmutableList.<Artifact>of(), null, /* runfilesSupport */
    artifact("//:dont-care", "protoc-gen-javalite.exe"));
    ProtoLangToolchainProvider toolchainNoPlugin = ProtoLangToolchainProvider.create("--java_out=param1,param2:$(OUT)", null, /* pluginExecutable */
    mock(TransitiveInfoCollection.class), /* runtime */
    NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER));
    ProtoLangToolchainProvider toolchainWithPlugin = ProtoLangToolchainProvider.create("--$(PLUGIN_OUT)=param3,param4:$(OUT)", plugin, mock(TransitiveInfoCollection.class), /* runtime */
    NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER));
    SupportData supportData = SupportData.create(Predicates.<TransitiveInfoCollection>alwaysFalse(), ImmutableList.of(artifact("//:dont-care", "source_file.proto")), NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER), /* protosInDirectDeps */
    NestedSetBuilder.create(STABLE_ORDER, artifact("//:dont-care", "import1.proto"), artifact("//:dont-care", "import2.proto")), true);
    CustomCommandLine cmdLine = createCommandLineFromToolchains(ImmutableList.of(new ToolchainInvocation("dontcare_because_no_plugin", toolchainNoPlugin, "foo.srcjar"), new ToolchainInvocation("pluginName", toolchainWithPlugin, "bar.srcjar")), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), null, /* protosInDirectDeps */
    "//foo:bar", true, /* allowServices */
    ImmutableList.<String>of());
    assertThat(cmdLine.arguments()).containsExactly("--java_out=param1,param2:foo.srcjar", "--PLUGIN_pluginName_out=param3,param4:bar.srcjar", "--plugin=protoc-gen-PLUGIN_pluginName=protoc-gen-javalite.exe", "-Iimport1.proto=import1.proto", "-Iimport2.proto=import2.proto", "source_file.proto").inOrder();
}
Also used : ToolchainInvocation(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder.ToolchainInvocation) CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) FilesToRunProvider(com.google.devtools.build.lib.analysis.FilesToRunProvider) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Test(org.junit.Test)

Example 25 with TransitiveInfoCollection

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

the class ProtoCompileActionBuilderTest method commandLine_strictDeps.

@Test
public void commandLine_strictDeps() throws Exception {
    ProtoLangToolchainProvider toolchain = ProtoLangToolchainProvider.create("--java_out=param1,param2:$(OUT)", null, /* pluginExecutable */
    mock(TransitiveInfoCollection.class), /* runtime */
    NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER));
    SupportData supportData = SupportData.create(Predicates.<TransitiveInfoCollection>alwaysFalse(), ImmutableList.of(artifact("//:dont-care", "source_file.proto")), NestedSetBuilder.create(STABLE_ORDER, artifact("//:dont-care", "import1.proto")), NestedSetBuilder.create(STABLE_ORDER, artifact("//:dont-care", "import1.proto"), artifact("//:dont-care", "import2.proto")), true);
    CustomCommandLine cmdLine = createCommandLineFromToolchains(ImmutableList.of(new ToolchainInvocation("dontcare", toolchain, "foo.srcjar")), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), supportData.getProtosInDirectDeps(), "//foo:bar", true, /* allowServices */
    ImmutableList.<String>of());
    assertThat(cmdLine.arguments()).containsExactly("--java_out=param1,param2:foo.srcjar", "-Iimport1.proto=import1.proto", "-Iimport2.proto=import2.proto", "--direct_dependencies=import1.proto", createStrictProtoDepsViolationErrorMessage("//foo:bar"), "source_file.proto").inOrder();
}
Also used : ToolchainInvocation(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder.ToolchainInvocation) CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Test(org.junit.Test)

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