Search in sources :

Example 1 with CppConfiguration

use of com.google.devtools.build.lib.rules.cpp.CppConfiguration in project bazel by bazelbuild.

the class JavaBinary method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    final JavaCommon common = new JavaCommon(ruleContext, semantics);
    DeployArchiveBuilder deployArchiveBuilder = new DeployArchiveBuilder(semantics, ruleContext);
    Runfiles.Builder runfilesBuilder = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles());
    List<String> jvmFlags = new ArrayList<>();
    JavaTargetAttributes.Builder attributesBuilder = common.initCommon();
    attributesBuilder.addClassPathResources(ruleContext.getPrerequisiteArtifacts("classpath_resources", Mode.TARGET).list());
    // Add Java8 timezone resource data
    addTimezoneResourceForJavaBinaries(ruleContext, attributesBuilder);
    List<String> userJvmFlags = JavaCommon.getJvmFlags(ruleContext);
    ruleContext.checkSrcsSamePackage(true);
    boolean createExecutable = ruleContext.attributes().get("create_executable", Type.BOOLEAN);
    if (!createExecutable) {
        // TODO(cushon): disallow combining launcher=JDK_LAUNCHER_LABEL with create_executable=0
        // and use isAttributeExplicitlySpecified here
        Label launcherAttribute = ruleContext.attributes().get("launcher", BuildType.LABEL);
        if (launcherAttribute != null && !JavaHelper.isJdkLauncher(ruleContext, launcherAttribute)) {
            ruleContext.ruleError("launcher specified but create_executable is false");
        }
    }
    semantics.checkRule(ruleContext, common);
    semantics.checkForProtoLibraryAndJavaProtoLibraryOnSameProto(ruleContext, common);
    String mainClass = semantics.getMainClass(ruleContext, common.getSrcsArtifacts());
    String originalMainClass = mainClass;
    if (ruleContext.hasErrors()) {
        return null;
    }
    // Collect the transitive dependencies.
    JavaCompilationHelper helper = new JavaCompilationHelper(ruleContext, semantics, common.getJavacOpts(), attributesBuilder);
    List<TransitiveInfoCollection> deps = // Do not remove <TransitiveInfoCollection>: workaround for Java 7 type inference.
    Lists.<TransitiveInfoCollection>newArrayList(common.targetsTreatedAsDeps(ClasspathType.COMPILE_ONLY));
    helper.addLibrariesToAttributes(deps);
    attributesBuilder.addNativeLibraries(collectNativeLibraries(common.targetsTreatedAsDeps(ClasspathType.BOTH)));
    // deploy_env is valid for java_binary, but not for java_test.
    if (ruleContext.getRule().isAttrDefined("deploy_env", BuildType.LABEL_LIST)) {
        for (JavaRuntimeClasspathProvider envTarget : ruleContext.getPrerequisites("deploy_env", Mode.TARGET, JavaRuntimeClasspathProvider.class)) {
            attributesBuilder.addExcludedArtifacts(envTarget.getRuntimeClasspath());
        }
    }
    Artifact srcJar = ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_BINARY_SOURCE_JAR);
    JavaSourceJarsProvider.Builder javaSourceJarsProviderBuilder = JavaSourceJarsProvider.builder().addSourceJar(srcJar).addAllTransitiveSourceJars(common.collectTransitiveSourceJars(srcJar));
    Artifact classJar = ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_BINARY_CLASS_JAR);
    JavaRuleOutputJarsProvider.Builder ruleOutputJarsProviderBuilder = JavaRuleOutputJarsProvider.builder().addOutputJar(classJar, null, /* iJar */
    ImmutableList.of(srcJar));
    CppConfiguration cppConfiguration = ruleContext.getConfiguration().getFragment(CppConfiguration.class);
    boolean stripAsDefault = cppConfiguration.useFission() && cppConfiguration.getCompilationMode() == CompilationMode.OPT;
    Artifact launcher = semantics.getLauncher(ruleContext, common, deployArchiveBuilder, runfilesBuilder, jvmFlags, attributesBuilder, stripAsDefault);
    DeployArchiveBuilder unstrippedDeployArchiveBuilder = null;
    Artifact unstrippedLauncher = null;
    if (stripAsDefault) {
        unstrippedDeployArchiveBuilder = new DeployArchiveBuilder(semantics, ruleContext);
        unstrippedLauncher = semantics.getLauncher(ruleContext, common, unstrippedDeployArchiveBuilder, runfilesBuilder, jvmFlags, attributesBuilder, false);
    }
    JavaCompilationArtifacts.Builder javaArtifactsBuilder = new JavaCompilationArtifacts.Builder();
    Artifact instrumentationMetadata = helper.createInstrumentationMetadata(classJar, javaArtifactsBuilder);
    NestedSetBuilder<Artifact> filesBuilder = NestedSetBuilder.stableOrder();
    Artifact executableForRunfiles = null;
    if (createExecutable) {
        // This artifact is named as the rule itself, e.g. //foo:bar_bin -> bazel-bin/foo/bar_bin
        executableForRunfiles = ruleContext.createOutputArtifact();
        filesBuilder.add(classJar).add(executableForRunfiles);
        if (ruleContext.getConfiguration().isCodeCoverageEnabled()) {
            mainClass = semantics.addCoverageSupport(helper, attributesBuilder, executableForRunfiles, instrumentationMetadata, javaArtifactsBuilder, mainClass);
        }
    } else {
        filesBuilder.add(classJar);
    }
    JavaTargetAttributes attributes = helper.getAttributes();
    List<Artifact> nativeLibraries = attributes.getNativeLibraries();
    if (!nativeLibraries.isEmpty()) {
        jvmFlags.add("-Djava.library.path=" + JavaCommon.javaLibraryPath(nativeLibraries, ruleContext.getRule().getPackage().getWorkspaceName()));
    }
    JavaConfiguration javaConfig = ruleContext.getFragment(JavaConfiguration.class);
    if (attributes.hasMessages()) {
        helper.setTranslations(semantics.translate(ruleContext, javaConfig, attributes.getMessages()));
    }
    if (attributes.hasSourceFiles() || attributes.hasSourceJars() || attributes.hasResources() || attributes.hasClassPathResources()) {
        // We only want to add a jar to the classpath of a dependent rule if it has content.
        javaArtifactsBuilder.addRuntimeJar(classJar);
    }
    GeneratedExtensionRegistryProvider generatedExtensionRegistryProvider = semantics.createGeneratedExtensionRegistry(ruleContext, common, filesBuilder, javaArtifactsBuilder, ruleOutputJarsProviderBuilder, javaSourceJarsProviderBuilder);
    Artifact outputDepsProto = helper.createOutputDepsProtoArtifact(classJar, javaArtifactsBuilder);
    ruleOutputJarsProviderBuilder.setJdeps(outputDepsProto);
    JavaCompilationArtifacts javaArtifacts = javaArtifactsBuilder.build();
    common.setJavaCompilationArtifacts(javaArtifacts);
    Artifact manifestProtoOutput = helper.createManifestProtoOutput(classJar);
    // The gensrc jar is created only if the target uses annotation processing. Otherwise,
    // it is null, and the source jar action will not depend on the compile action.
    Artifact genSourceJar = null;
    Artifact genClassJar = null;
    if (helper.usesAnnotationProcessing()) {
        genClassJar = helper.createGenJar(classJar);
        genSourceJar = helper.createGensrcJar(classJar);
        helper.createGenJarAction(classJar, manifestProtoOutput, genClassJar);
    }
    helper.createCompileAction(classJar, manifestProtoOutput, genSourceJar, outputDepsProto, instrumentationMetadata);
    helper.createSourceJarAction(srcJar, genSourceJar);
    common.setClassPathFragment(new ClasspathConfiguredFragment(javaArtifacts, attributes, false, helper.getBootclasspathOrDefault()));
    // Collect the action inputs for the runfiles collector here because we need to access the
    // analysis environment, and that may no longer be safe when the runfiles collector runs.
    Iterable<Artifact> dynamicRuntimeActionInputs = CppHelper.getToolchain(ruleContext, ":cc_toolchain").getDynamicRuntimeLinkInputs();
    Iterables.addAll(jvmFlags, semantics.getJvmFlags(ruleContext, common.getSrcsArtifacts(), userJvmFlags));
    if (ruleContext.hasErrors()) {
        return null;
    }
    Artifact executableToRun = executableForRunfiles;
    if (createExecutable) {
        // Create a shell stub for a Java application
        executableToRun = semantics.createStubAction(ruleContext, common, jvmFlags, executableForRunfiles, mainClass, JavaCommon.getJavaBinSubstitution(ruleContext, launcher));
        if (!executableToRun.equals(executableForRunfiles)) {
            filesBuilder.add(executableToRun);
            runfilesBuilder.addArtifact(executableToRun);
        }
    }
    JavaSourceJarsProvider sourceJarsProvider = javaSourceJarsProviderBuilder.build();
    NestedSet<Artifact> transitiveSourceJars = sourceJarsProvider.getTransitiveSourceJars();
    // TODO(bazel-team): if (getOptions().sourceJars) then make this a dummy prerequisite for the
    // DeployArchiveAction ? Needs a few changes there as we can't pass inputs
    SingleJarActionBuilder.createSourceJarAction(ruleContext, ImmutableMap.<PathFragment, Artifact>of(), transitiveSourceJars.toCollection(), ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_BINARY_DEPLOY_SOURCE_JAR));
    RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext);
    builder.add(JavaPrimaryClassProvider.class, new JavaPrimaryClassProvider(semantics.getPrimaryClass(ruleContext, common.getSrcsArtifacts())));
    semantics.addProviders(ruleContext, common, jvmFlags, classJar, srcJar, genClassJar, genSourceJar, ImmutableMap.<Artifact, Artifact>of(), filesBuilder, builder);
    if (generatedExtensionRegistryProvider != null) {
        builder.add(GeneratedExtensionRegistryProvider.class, generatedExtensionRegistryProvider);
    }
    Artifact deployJar = ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_BINARY_DEPLOY_JAR);
    boolean runProguard = applyProguardIfRequested(ruleContext, deployJar, common.getBootClasspath(), mainClass, semantics, filesBuilder);
    if (javaConfig.isEnforceOneVersion()) {
        Artifact oneVersionOutput = ruleContext.getAnalysisEnvironment().getDerivedArtifact(replaceExtension(classJar.getRootRelativePath(), "-one-version.txt"), classJar.getRoot());
        filesBuilder.add(oneVersionOutput);
        NestedSet<Artifact> transitiveDependencies = NestedSetBuilder.fromNestedSet(attributes.getRuntimeClassPath()).add(classJar).build();
        OneVersionCheckActionBuilder.build(ruleContext, transitiveDependencies, oneVersionOutput);
    }
    NestedSet<Artifact> filesToBuild = filesBuilder.build();
    // Need not include normal runtime classpath in runfiles if Proguard is used because _deploy.jar
    // is used as classpath instead.  Keeping runfiles unchanged has however the advantage that
    // manually running executable without --singlejar works (although it won't depend on Proguard).
    collectDefaultRunfiles(runfilesBuilder, ruleContext, common, javaArtifacts, filesToBuild, launcher, dynamicRuntimeActionInputs);
    Runfiles defaultRunfiles = runfilesBuilder.build();
    RunfilesSupport runfilesSupport = null;
    if (createExecutable) {
        List<String> extraArgs = new ArrayList<>(semantics.getExtraArguments(ruleContext, common.getSrcsArtifacts()));
        if (runProguard) {
            // Instead of changing the classpath written into the wrapper script, pass --singlejar when
            // running the script (which causes the deploy.jar written by Proguard to be used instead of
            // the normal classpath). It's a bit odd to do this b/c manually running the script wouldn't
            // use Proguard's output unless --singlejar is explicitly supplied.  On the other hand the
            // behavior of the script is more consistent: the (proguarded) deploy.jar is only used with
            // --singlejar.  Moreover, people will almost always run tests using blaze test, which does
            // use Proguard's output thanks to this extra arg when enabled.  Also, it's actually hard to
            // get the classpath changed in the wrapper script (would require calling
            // JavaCommon.setClasspathFragment with a new fragment at the *end* of this method because
            // the classpath is evaluated lazily when generating the wrapper script) and the wrapper
            // script would essentially have an if (--singlejar was set), set classpath to deploy jar,
            // otherwise, set classpath to deploy jar.
            extraArgs.add("--wrapper_script_flag=--singlejar");
        }
        // The executable we pass here will be used when creating the runfiles directory. E.g. for the
        // stub script called bazel-bin/foo/bar_bin, the runfiles directory will be created under
        // bazel-bin/foo/bar_bin.runfiles . On platforms where there's an extra stub script (Windows)
        // which dispatches to this one, we still create the runfiles directory for the shell script,
        // but use the dispatcher script (a batch file) as the RunfilesProvider's executable.
        runfilesSupport = RunfilesSupport.withExecutable(ruleContext, defaultRunfiles, executableForRunfiles, extraArgs);
    }
    RunfilesProvider runfilesProvider = RunfilesProvider.withData(defaultRunfiles, new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).merge(runfilesSupport).build());
    ImmutableList<String> deployManifestLines = getDeployManifestLines(ruleContext, originalMainClass);
    // When running Proguard:
    // (1) write single jar to intermediate destination; Proguard will write _deploy.jar file
    // (2) Don't depend on runfiles to avoid circular dependency, since _deploy.jar is itself part
    //     of runfiles when Proguard runs (because executable then needs it) and _deploy.jar depends
    //     on this single jar.
    // (3) Don't bother with compression since Proguard will write the final jar anyways
    deployArchiveBuilder.setOutputJar(runProguard ? ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_BINARY_MERGED_JAR) : deployJar).setJavaStartClass(mainClass).setDeployManifestLines(deployManifestLines).setAttributes(attributes).addRuntimeJars(javaArtifacts.getRuntimeJars()).setIncludeBuildData(true).setRunfilesMiddleman(runProguard || runfilesSupport == null ? null : runfilesSupport.getRunfilesMiddleman()).setCompression(runProguard ? UNCOMPRESSED : COMPRESSED).setLauncher(launcher).build();
    Artifact unstrippedDeployJar = ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_UNSTRIPPED_BINARY_DEPLOY_JAR);
    if (stripAsDefault) {
        unstrippedDeployArchiveBuilder.setOutputJar(unstrippedDeployJar).setJavaStartClass(mainClass).setDeployManifestLines(deployManifestLines).setAttributes(attributes).addRuntimeJars(javaArtifacts.getRuntimeJars()).setIncludeBuildData(true).setRunfilesMiddleman(runfilesSupport == null ? null : runfilesSupport.getRunfilesMiddleman()).setCompression(COMPRESSED).setLauncher(unstrippedLauncher);
        unstrippedDeployArchiveBuilder.build();
    } else {
        // Write an empty file as the name_deploy.jar.unstripped when the default output jar is not
        // stripped.
        ruleContext.registerAction(FileWriteAction.create(ruleContext, unstrippedDeployJar, "", false));
    }
    JavaRuleOutputJarsProvider ruleOutputJarsProvider = ruleOutputJarsProviderBuilder.build();
    JavaSkylarkApiProvider.Builder skylarkApiProvider = JavaSkylarkApiProvider.builder().setRuleOutputJarsProvider(ruleOutputJarsProvider).setSourceJarsProvider(sourceJarsProvider);
    common.addTransitiveInfoProviders(builder, skylarkApiProvider, filesToBuild, classJar);
    common.addGenJarsProvider(builder, skylarkApiProvider, genClassJar, genSourceJar);
    return builder.setFilesToBuild(filesToBuild).addSkylarkTransitiveInfo(JavaSkylarkApiProvider.NAME, skylarkApiProvider.build()).add(JavaRuleOutputJarsProvider.class, ruleOutputJarsProvider).add(RunfilesProvider.class, runfilesProvider).setRunfilesSupport(runfilesSupport, executableToRun).add(JavaRuntimeClasspathProvider.class, new JavaRuntimeClasspathProvider(common.getRuntimeClasspath())).add(JavaSourceInfoProvider.class, JavaSourceInfoProvider.fromJavaTargetAttributes(attributes, semantics)).add(JavaSourceJarsProvider.class, sourceJarsProvider).addOutputGroup(JavaSemantics.SOURCE_JARS_OUTPUT_GROUP, transitiveSourceJars).build();
}
Also used : NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) ArrayList(java.util.ArrayList) Label(com.google.devtools.build.lib.cmdline.Label) RunfilesSupport(com.google.devtools.build.lib.analysis.RunfilesSupport) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) Runfiles(com.google.devtools.build.lib.analysis.Runfiles) CppConfiguration(com.google.devtools.build.lib.rules.cpp.CppConfiguration) GeneratedExtensionRegistryProvider(com.google.devtools.build.lib.rules.java.proto.GeneratedExtensionRegistryProvider) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 2 with CppConfiguration

use of com.google.devtools.build.lib.rules.cpp.CppConfiguration in project bazel by bazelbuild.

the class NativeDepsHelper method createNativeDepsAction.

public static NativeDepsRunfiles createNativeDepsAction(final RuleContext ruleContext, CcLinkParams linkParams, Collection<String> extraLinkOpts, BuildConfiguration configuration, CcToolchainProvider toolchain, Artifact nativeDeps, String libraryIdentifier, Root bindirIfShared, boolean useDynamicRuntime) throws InterruptedException {
    Preconditions.checkState(ruleContext.isLegalFragment(CppConfiguration.class), "%s does not have access to CppConfiguration", ruleContext.getRule().getRuleClass());
    List<String> linkopts = new ArrayList<>(extraLinkOpts);
    linkopts.addAll(linkParams.flattenedLinkopts());
    Map<Artifact, NestedSet<Artifact>> linkstamps = CppHelper.resolveLinkstamps(ruleContext, linkParams);
    List<Artifact> buildInfoArtifacts = linkstamps.isEmpty() ? ImmutableList.<Artifact>of() : ruleContext.getAnalysisEnvironment().getBuildInfo(ruleContext, CppBuildInfo.KEY, configuration);
    boolean shareNativeDeps = configuration.getFragment(CppConfiguration.class).shareNativeDeps();
    NestedSet<LibraryToLink> linkerInputs = linkParams.getLibraries();
    Artifact sharedLibrary;
    if (shareNativeDeps) {
        PathFragment sharedPath = getSharedNativeDepsPath(LinkerInputs.toLibraryArtifacts(linkerInputs), linkopts, linkstamps.keySet(), buildInfoArtifacts, ruleContext.getFeatures());
        libraryIdentifier = sharedPath.getPathString();
        sharedLibrary = ruleContext.getShareableArtifact(sharedPath.replaceName(sharedPath.getBaseName() + ".so"), configuration.getBinDirectory(ruleContext.getRule().getRepository()));
    } else {
        sharedLibrary = nativeDeps;
    }
    FdoSupportProvider fdoSupport = CppHelper.getFdoSupport(ruleContext, ":cc_toolchain");
    CppLinkActionBuilder builder = new CppLinkActionBuilder(ruleContext, sharedLibrary, configuration, toolchain, fdoSupport);
    if (useDynamicRuntime) {
        builder.setRuntimeInputs(ArtifactCategory.DYNAMIC_LIBRARY, toolchain.getDynamicRuntimeLinkMiddleman(), toolchain.getDynamicRuntimeLinkInputs());
    } else {
        builder.setRuntimeInputs(ArtifactCategory.STATIC_LIBRARY, toolchain.getStaticRuntimeLinkMiddleman(), toolchain.getStaticRuntimeLinkInputs());
    }
    CppLinkAction linkAction = builder.setLinkArtifactFactory(SHAREABLE_LINK_ARTIFACT_FACTORY).setCrosstoolInputs(toolchain.getLink()).addLibraries(linkerInputs).setLinkType(LinkTargetType.DYNAMIC_LIBRARY).setLinkStaticness(LinkStaticness.MOSTLY_STATIC).setLibraryIdentifier(libraryIdentifier).addLinkopts(linkopts).setNativeDeps(true).addLinkstamps(linkstamps).build();
    ruleContext.registerAction(linkAction);
    Artifact linkerOutput = linkAction.getPrimaryOutput();
    if (shareNativeDeps) {
        // Collect dynamic-linker-resolvable symlinks for C++ runtime library dependencies.
        // Note we only need these symlinks when --share_native_deps is on, as shared native deps
        // mangle path names such that the library's conventional _solib RPATH entry
        // no longer resolves (because the target directory's relative depth gets lost).
        List<Artifact> runtimeSymlinks;
        if (useDynamicRuntime) {
            runtimeSymlinks = new LinkedList<>();
            for (final Artifact runtimeInput : toolchain.getDynamicRuntimeLinkInputs()) {
                final Artifact runtimeSymlink = ruleContext.getPackageRelativeArtifact(getRuntimeLibraryPath(ruleContext, runtimeInput), bindirIfShared);
                // Since runtime library symlinks are underneath the target's output directory and
                // multiple targets may share the same output directory, we need to make sure this
                // symlink's generating action is only set once.
                ruleContext.registerAction(new SymlinkAction(ruleContext.getActionOwner(), runtimeInput, runtimeSymlink, null));
                runtimeSymlinks.add(runtimeSymlink);
            }
        } else {
            runtimeSymlinks = ImmutableList.of();
        }
        ruleContext.registerAction(new SymlinkAction(ruleContext.getActionOwner(), linkerOutput, nativeDeps, null));
        return new NativeDepsRunfiles(nativeDeps, runtimeSymlinks);
    }
    return new NativeDepsRunfiles(linkerOutput, ImmutableList.<Artifact>of());
}
Also used : NestedSet(com.google.devtools.build.lib.collect.nestedset.NestedSet) FdoSupportProvider(com.google.devtools.build.lib.rules.cpp.FdoSupportProvider) SymlinkAction(com.google.devtools.build.lib.analysis.actions.SymlinkAction) ArrayList(java.util.ArrayList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact) LibraryToLink(com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink) CppLinkAction(com.google.devtools.build.lib.rules.cpp.CppLinkAction) CppConfiguration(com.google.devtools.build.lib.rules.cpp.CppConfiguration) CppLinkActionBuilder(com.google.devtools.build.lib.rules.cpp.CppLinkActionBuilder)

Example 3 with CppConfiguration

use of com.google.devtools.build.lib.rules.cpp.CppConfiguration in project bazel by bazelbuild.

the class AndroidStudioInfoAspect method createIdeBuildArtifact.

private AndroidStudioInfoFilesProvider createIdeBuildArtifact(ConfiguredTarget base, RuleContext ruleContext, DependenciesResult dependenciesResult, AndroidStudioInfoFilesProvider.Builder providerBuilder) {
    Artifact ideInfoFile = derivedArtifact(base, ruleContext, ASWB_BUILD_SUFFIX);
    Artifact ideInfoTextFile = derivedArtifact(base, ruleContext, ASWB_BUILD_TEXT_SUFFIX);
    providerBuilder.ideInfoFilesBuilder().add(ideInfoFile);
    providerBuilder.ideInfoTextFilesBuilder().add(ideInfoTextFile);
    NestedSetBuilder<Artifact> ideResolveArtifacts = providerBuilder.ideResolveFilesBuilder();
    TargetIdeInfo.Builder outputBuilder = TargetIdeInfo.newBuilder();
    outputBuilder.setLabel(base.getLabel().toString());
    outputBuilder.setBuildFileArtifactLocation(makeArtifactLocation(ruleContext.getRule().getPackage(), ruleContext.getLabel()));
    outputBuilder.setKindString(ruleContext.getRule().getRuleClass());
    // Java rules
    JavaRuleOutputJarsProvider outputJarsProvider = JavaProvider.getProvider(JavaRuleOutputJarsProvider.class, base);
    if (outputJarsProvider != null && !androidStudioInfoSemantics.suppressJavaRuleInfo(base)) {
        JavaIdeInfo javaIdeInfo = makeJavaIdeInfo(base, ruleContext, outputJarsProvider, providerBuilder);
        outputBuilder.setJavaIdeInfo(javaIdeInfo);
    }
    // C rules
    if (isCppRule(base)) {
        CppCompilationContext cppCompilationContext = base.getProvider(CppCompilationContext.class);
        if (cppCompilationContext != null) {
            CIdeInfo cIdeInfo = makeCIdeInfo(base, ruleContext, cppCompilationContext, ideResolveArtifacts);
            outputBuilder.setCIdeInfo(cIdeInfo);
        }
    }
    // CCToolchain rule
    CcToolchainProvider ccToolchainProvider = base.getProvider(CcToolchainProvider.class);
    if (ccToolchainProvider != null) {
        CppConfiguration cppConfiguration = ccToolchainProvider.getCppConfiguration();
        if (cppConfiguration != null) {
            CToolchainIdeInfo cToolchainIdeInfo = makeCToolchainIdeInfo(ruleContext, cppConfiguration);
            if (cToolchainIdeInfo != null) {
                outputBuilder.setCToolchainIdeInfo(cToolchainIdeInfo);
            }
        }
    }
    // Android rules
    AndroidIdeInfoProvider androidIdeInfoProvider = base.getProvider(AndroidIdeInfoProvider.class);
    if (androidIdeInfoProvider != null) {
        outputBuilder.setAndroidIdeInfo(makeAndroidIdeInfo(androidIdeInfoProvider, dependenciesResult, ideResolveArtifacts));
    }
    // Python rules
    if (isPythonRule(base)) {
        outputBuilder.setPyIdeInfo(makePyIdeInfo(base, ruleContext, ideResolveArtifacts));
    }
    // Test rules
    if (TargetUtils.isTestRule(base.getTarget())) {
        TestInfo.Builder builder = TestInfo.newBuilder();
        String attr = NonconfigurableAttributeMapper.of(base.getTarget().getAssociatedRule()).get("size", Type.STRING);
        if (attr != null) {
            builder.setSize(attr);
        }
        outputBuilder.setTestInfo(builder);
    }
    // Java toolchain rule
    JavaToolchainProvider javaToolchainProvider = base.getProvider(JavaToolchainProvider.class);
    if (javaToolchainProvider != null) {
        outputBuilder.setJavaToolchainIdeInfo(JavaToolchainIdeInfo.newBuilder().setSourceVersion(javaToolchainProvider.getSourceVersion()).setTargetVersion(javaToolchainProvider.getTargetVersion()));
    }
    androidStudioInfoSemantics.augmentRuleInfo(outputBuilder, base, ruleContext, ideResolveArtifacts);
    AndroidStudioInfoFilesProvider provider = providerBuilder.build();
    outputBuilder.addAllDependencies(transform(dependenciesResult.deps, LABEL_TO_STRING));
    outputBuilder.addAllRuntimeDeps(transform(dependenciesResult.runtimeDeps, LABEL_TO_STRING));
    outputBuilder.addAllTags(base.getTarget().getAssociatedRule().getRuleTags());
    final TargetIdeInfo targetIdeInfo = outputBuilder.build();
    ruleContext.registerAction(makeProtoWriteAction(ruleContext.getActionOwner(), targetIdeInfo, ideInfoFile));
    ruleContext.registerAction(makeProtoTextWriteAction(ruleContext.getActionOwner(), targetIdeInfo, ideInfoTextFile));
    return provider;
}
Also used : JavaRuleOutputJarsProvider(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider) CcToolchainProvider(com.google.devtools.build.lib.rules.cpp.CcToolchainProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) LibraryArtifact(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact) TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) CppCompilationContext(com.google.devtools.build.lib.rules.cpp.CppCompilationContext) CToolchainIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo) CppConfiguration(com.google.devtools.build.lib.rules.cpp.CppConfiguration) JavaToolchainProvider(com.google.devtools.build.lib.rules.java.JavaToolchainProvider) AndroidIdeInfoProvider(com.google.devtools.build.lib.rules.android.AndroidIdeInfoProvider) CIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo) TestInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TestInfo) JavaIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo)

Example 4 with CppConfiguration

use of com.google.devtools.build.lib.rules.cpp.CppConfiguration in project bazel by bazelbuild.

the class AppleCcToolchain method getEnvironmentBuildVariables.

private ImmutableMap<String, String> getEnvironmentBuildVariables(RuleContext ruleContext) {
    Map<String, String> builder = new LinkedHashMap<>();
    CppConfiguration cppConfiguration = ruleContext.getFragment(CppConfiguration.class);
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    builder.putAll(appleConfiguration.getAppleHostSystemEnv());
    if (Platform.isApplePlatform(cppConfiguration.getTargetCpu())) {
        builder.putAll(appleConfiguration.appleTargetPlatformEnv(Platform.forTargetCpu(cppConfiguration.getTargetCpu())));
    }
    return ImmutableMap.copyOf(builder);
}
Also used : CppConfiguration(com.google.devtools.build.lib.rules.cpp.CppConfiguration) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

CppConfiguration (com.google.devtools.build.lib.rules.cpp.CppConfiguration)4 Artifact (com.google.devtools.build.lib.actions.Artifact)3 ArrayList (java.util.ArrayList)2 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)1 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)1 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)1 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)1 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)1 SymlinkAction (com.google.devtools.build.lib.analysis.actions.SymlinkAction)1 Label (com.google.devtools.build.lib.cmdline.Label)1 NestedSet (com.google.devtools.build.lib.collect.nestedset.NestedSet)1 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)1 AndroidIdeInfoProvider (com.google.devtools.build.lib.rules.android.AndroidIdeInfoProvider)1 AppleConfiguration (com.google.devtools.build.lib.rules.apple.AppleConfiguration)1 CcToolchainProvider (com.google.devtools.build.lib.rules.cpp.CcToolchainProvider)1 CppCompilationContext (com.google.devtools.build.lib.rules.cpp.CppCompilationContext)1 CppLinkAction (com.google.devtools.build.lib.rules.cpp.CppLinkAction)1 CppLinkActionBuilder (com.google.devtools.build.lib.rules.cpp.CppLinkActionBuilder)1 FdoSupportProvider (com.google.devtools.build.lib.rules.cpp.FdoSupportProvider)1 LibraryToLink (com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink)1