use of com.google.devtools.build.lib.rules.cpp.CcToolchainProvider in project bazel by bazelbuild.
the class CrosstoolCompilationSupport method registerLinkActions.
@Override
CompilationSupport registerLinkActions(ObjcProvider objcProvider, J2ObjcMappingFileProvider j2ObjcMappingFileProvider, J2ObjcEntryClassProvider j2ObjcEntryClassProvider, ExtraLinkArgs extraLinkArgs, Iterable<Artifact> extraLinkInputs, DsymOutputType dsymOutputType) throws InterruptedException {
Iterable<Artifact> prunedJ2ObjcArchives = computeAndStripPrunedJ2ObjcArchives(j2ObjcEntryClassProvider, j2ObjcMappingFileProvider, objcProvider);
ImmutableList<Artifact> bazelBuiltLibraries = Iterables.isEmpty(prunedJ2ObjcArchives) ? objcProvider.getObjcLibraries() : substituteJ2ObjcPrunedLibraries(objcProvider);
Artifact inputFileList = intermediateArtifacts.linkerObjList();
ImmutableSet<Artifact> forceLinkArtifacts = getForceLoadArtifacts(objcProvider);
Iterable<Artifact> objFiles = Iterables.concat(bazelBuiltLibraries, objcProvider.get(IMPORTED_LIBRARY), objcProvider.getCcLibraries());
// Clang loads archives specified in filelists and also specified as -force_load twice,
// resulting in duplicate symbol errors unless they are deduped.
objFiles = Iterables.filter(objFiles, Predicates.not(Predicates.in(forceLinkArtifacts)));
registerObjFilelistAction(objFiles, inputFileList);
LinkTargetType linkType = (objcProvider.is(Flag.USES_CPP)) ? LinkTargetType.OBJCPP_EXECUTABLE : LinkTargetType.OBJC_EXECUTABLE;
ObjcVariablesExtension extension = new ObjcVariablesExtension.Builder().setRuleContext(ruleContext).setObjcProvider(objcProvider).setConfiguration(ruleContext.getConfiguration()).setIntermediateArtifacts(intermediateArtifacts).setFrameworkNames(frameworkNames(objcProvider)).setLibraryNames(libraryNames(objcProvider)).setForceLoadArtifacts(getForceLoadArtifacts(objcProvider)).setAttributeLinkopts(attributes.linkopts()).addVariableCategory(VariableCategory.EXECUTABLE_LINKING_VARIABLES).build();
Artifact binaryToLink = getBinaryToLink();
CcToolchainProvider ccToolchain = CppHelper.getToolchain(ruleContext, ":cc_toolchain");
FdoSupportProvider fdoSupport = CppHelper.getFdoSupport(ruleContext, ":cc_toolchain");
CppLinkAction executableLinkAction = new CppLinkActionBuilder(ruleContext, binaryToLink, ccToolchain, fdoSupport).setMnemonic("ObjcLink").addActionInputs(bazelBuiltLibraries).addActionInputs(objcProvider.getCcLibraries()).addTransitiveActionInputs(objcProvider.get(IMPORTED_LIBRARY)).addTransitiveActionInputs(objcProvider.get(STATIC_FRAMEWORK_FILE)).addTransitiveActionInputs(objcProvider.get(DYNAMIC_FRAMEWORK_FILE)).setCrosstoolInputs(ccToolchain.getLink()).addActionInputs(prunedJ2ObjcArchives).addActionInput(inputFileList).setLinkType(linkType).setLinkStaticness(LinkStaticness.FULLY_STATIC).addLinkopts(ImmutableList.copyOf(extraLinkArgs)).addVariablesExtension(extension).setFeatureConfiguration(getFeatureConfiguration(ruleContext, buildConfiguration)).build();
ruleContext.registerAction(executableLinkAction);
if (objcConfiguration.shouldStripBinary()) {
registerBinaryStripAction(binaryToLink, StrippingType.DEFAULT);
}
return this;
}
use of com.google.devtools.build.lib.rules.cpp.CcToolchainProvider in project bazel by bazelbuild.
the class AndroidBinary method init.
private static RuleConfiguredTargetBuilder init(RuleContext ruleContext, NestedSetBuilder<Artifact> filesBuilder, ResourceDependencies resourceDeps, JavaCommon javaCommon, AndroidCommon androidCommon, JavaSemantics javaSemantics, AndroidSemantics androidSemantics) throws InterruptedException, RuleErrorException {
validateRuleContext(ruleContext);
// TODO(bazel-team): Find a way to simplify this code.
// treeKeys() means that the resulting map sorts the entries by key, which is necessary to
// ensure determinism.
Multimap<String, TransitiveInfoCollection> depsByArchitecture = MultimapBuilder.treeKeys().arrayListValues().build();
AndroidConfiguration androidConfig = ruleContext.getFragment(AndroidConfiguration.class);
for (Map.Entry<Optional<String>, ? extends List<? extends TransitiveInfoCollection>> entry : ruleContext.getSplitPrerequisites("deps").entrySet()) {
String cpu = entry.getKey().or(androidConfig.getCpu());
depsByArchitecture.putAll(cpu, entry.getValue());
}
Map<String, BuildConfiguration> configurationMap = new LinkedHashMap<>();
Map<String, CcToolchainProvider> toolchainMap = new LinkedHashMap<>();
for (Map.Entry<Optional<String>, ? extends List<? extends TransitiveInfoCollection>> entry : ruleContext.getSplitPrerequisites(":cc_toolchain_split").entrySet()) {
String cpu = entry.getKey().or(androidConfig.getCpu());
TransitiveInfoCollection dep = Iterables.getOnlyElement(entry.getValue());
CcToolchainProvider toolchain = CppHelper.getToolchain(ruleContext, dep);
configurationMap.put(cpu, dep.getConfiguration());
toolchainMap.put(cpu, toolchain);
}
NativeLibs nativeLibs = NativeLibs.fromLinkedNativeDeps(ruleContext, androidSemantics.getNativeDepsFileName(), depsByArchitecture, toolchainMap, configurationMap);
// TODO(bazel-team): Resolve all the different cases of resource handling so this conditional
// can go away: recompile from android_resources, and recompile from android_binary attributes.
ApplicationManifest applicationManifest;
ResourceApk resourceApk;
ResourceApk incrementalResourceApk;
ResourceApk instantRunResourceApk;
ResourceApk splitResourceApk;
if (LocalResourceContainer.definesAndroidResources(ruleContext.attributes())) {
// Retrieve and compile the resources defined on the android_binary rule.
LocalResourceContainer.validateRuleContext(ruleContext);
ApplicationManifest ruleManifest = androidSemantics.getManifestForRule(ruleContext);
applicationManifest = ruleManifest.mergeWith(ruleContext, resourceDeps);
resourceApk = applicationManifest.packWithDataAndResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_APK), ruleContext, false, /* isLibrary */
resourceDeps, ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT), null, /* Artifact symbolsTxt */
ResourceConfigurationFilter.fromRuleContext(ruleContext), ruleContext.getTokenizedStringListAttr("nocompress_extensions"), ruleContext.attributes().get("crunch_png", Type.BOOLEAN), ruleContext.getTokenizedStringListAttr("densities"), false, /* incremental */
ProguardHelper.getProguardConfigArtifact(ruleContext, ""), createMainDexProguardSpec(ruleContext), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP), DataBinding.isEnabled(ruleContext) ? DataBinding.getLayoutInfoFile(ruleContext) : null);
ruleContext.assertNoErrors();
incrementalResourceApk = applicationManifest.addMobileInstallStubApplication(ruleContext).packWithDataAndResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_INCREMENTAL_RESOURCES_APK), ruleContext, false, /* isLibrary */
resourceDeps, null, /* Artifact rTxt */
null, /* Artifact symbolsTxt */
ResourceConfigurationFilter.fromRuleContext(ruleContext), ruleContext.getTokenizedStringListAttr("nocompress_extensions"), ruleContext.attributes().get("crunch_png", Type.BOOLEAN), ruleContext.getTokenizedStringListAttr("densities"), true, /* incremental */
ProguardHelper.getProguardConfigArtifact(ruleContext, "incremental"), null, /* mainDexProguardCfg */
null, /* manifestOut */
null, /* mergedResourcesOut */
null);
ruleContext.assertNoErrors();
instantRunResourceApk = applicationManifest.addInstantRunStubApplication(ruleContext).packWithDataAndResources(getDxArtifact(ruleContext, "android_instant_run.ap_"), ruleContext, false, /* isLibrary */
resourceDeps, null, /* Artifact rTxt */
null, /* Artifact symbolsTxt */
ResourceConfigurationFilter.fromRuleContext(ruleContext), ruleContext.getTokenizedStringListAttr("nocompress_extensions"), ruleContext.attributes().get("crunch_png", Type.BOOLEAN), ruleContext.getTokenizedStringListAttr("densities"), true, /* incremental */
ProguardHelper.getProguardConfigArtifact(ruleContext, "instant_run"), null, /* mainDexProguardCfg */
null, /* manifestOut */
null, /* mergedResourcesOut */
null);
ruleContext.assertNoErrors();
splitResourceApk = applicationManifest.createSplitManifest(ruleContext, "android_resources", false).packWithDataAndResources(getDxArtifact(ruleContext, "android_resources.ap_"), ruleContext, false, /* isLibrary */
resourceDeps, null, /* Artifact rTxt */
null, /* Artifact symbolsTxt */
ResourceConfigurationFilter.fromRuleContext(ruleContext), ruleContext.getTokenizedStringListAttr("nocompress_extensions"), ruleContext.attributes().get("crunch_png", Type.BOOLEAN), ruleContext.getTokenizedStringListAttr("densities"), true, /* incremental */
ProguardHelper.getProguardConfigArtifact(ruleContext, "incremental_split"), null, /* mainDexProguardCfg */
null, /* manifestOut */
null, /* mergedResourcesOut */
null);
ruleContext.assertNoErrors();
} else {
if (!ruleContext.attributes().get("crunch_png", Type.BOOLEAN)) {
ruleContext.throwWithRuleError("Setting crunch_png = 0 is not supported for android_binary" + " rules which depend on android_resources rules.");
}
// Retrieve the resources from the resources attribute on the android_binary rule
// and recompile them if necessary.
ApplicationManifest resourcesManifest = ApplicationManifest.fromResourcesRule(ruleContext);
if (resourcesManifest == null) {
throw new RuleErrorException();
}
applicationManifest = resourcesManifest.mergeWith(ruleContext, resourceDeps);
// Always recompiling resources causes AndroidTest to fail in certain circumstances.
if (shouldRegenerate(ruleContext, resourceDeps)) {
resourceApk = applicationManifest.packWithResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_APK), ruleContext, resourceDeps, true, /* createSource */
ProguardHelper.getProguardConfigArtifact(ruleContext, ""), createMainDexProguardSpec(ruleContext));
ruleContext.assertNoErrors();
} else {
resourceApk = applicationManifest.useCurrentResources(ruleContext, ProguardHelper.getProguardConfigArtifact(ruleContext, ""), createMainDexProguardSpec(ruleContext));
ruleContext.assertNoErrors();
}
incrementalResourceApk = applicationManifest.addMobileInstallStubApplication(ruleContext).packWithResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_INCREMENTAL_RESOURCES_APK), ruleContext, resourceDeps, false, /* createSource */
ProguardHelper.getProguardConfigArtifact(ruleContext, "incremental"), null);
ruleContext.assertNoErrors();
instantRunResourceApk = applicationManifest.addInstantRunStubApplication(ruleContext).packWithResources(getDxArtifact(ruleContext, "android_instant_run.ap_"), ruleContext, resourceDeps, false, /* createSource */
ProguardHelper.getProguardConfigArtifact(ruleContext, "instant_run"), null);
ruleContext.assertNoErrors();
splitResourceApk = applicationManifest.createSplitManifest(ruleContext, "android_resources", false).packWithResources(getDxArtifact(ruleContext, "android_resources.ap_"), ruleContext, resourceDeps, false, /* createSource */
ProguardHelper.getProguardConfigArtifact(ruleContext, "incremental_split"), null);
ruleContext.assertNoErrors();
}
boolean shrinkResources = shouldShrinkResources(ruleContext);
JavaTargetAttributes resourceClasses = androidCommon.init(javaSemantics, androidSemantics, resourceApk, ruleContext.getConfiguration().isCodeCoverageEnabled(), true, /* collectJavaCompilationArgs */
true);
ruleContext.assertNoErrors();
Function<Artifact, Artifact> derivedJarFunction = collectDesugaredJars(ruleContext, androidCommon, androidSemantics, resourceClasses);
Artifact deployJar = createDeployJar(ruleContext, javaSemantics, androidCommon, resourceClasses, derivedJarFunction);
Artifact proguardMapping = ruleContext.getPrerequisiteArtifact("proguard_apply_mapping", Mode.TARGET);
return createAndroidBinary(ruleContext, filesBuilder, deployJar, derivedJarFunction, /* isBinaryJarFiltered */
false, javaCommon, androidCommon, javaSemantics, androidSemantics, nativeLibs, applicationManifest, resourceApk, incrementalResourceApk, instantRunResourceApk, splitResourceApk, shrinkResources, resourceClasses, ImmutableList.<Artifact>of(), ImmutableList.<Artifact>of(), proguardMapping);
}
use of com.google.devtools.build.lib.rules.cpp.CcToolchainProvider 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;
}
use of com.google.devtools.build.lib.rules.cpp.CcToolchainProvider in project bazel by bazelbuild.
the class J2ObjcAspect method buildAspect.
private ConfiguredAspect buildAspect(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters, J2ObjcSource j2ObjcSource, J2ObjcMappingFileProvider directJ2ObjcMappingFileProvider, Iterable<Attribute> depAttributes) throws InterruptedException {
ConfiguredAspect.Builder builder = new ConfiguredAspect.Builder(this, parameters, ruleContext);
ObjcCommon common;
XcodeProvider xcodeProvider;
if (!Iterables.isEmpty(j2ObjcSource.getObjcSrcs())) {
common = common(ruleContext, j2ObjcSource.getObjcSrcs(), j2ObjcSource.getObjcHdrs(), j2ObjcSource.getHeaderSearchPaths(), depAttributes);
xcodeProvider = xcodeProvider(ruleContext, common, j2ObjcSource.getObjcHdrs(), j2ObjcSource.getHeaderSearchPaths(), depAttributes);
try {
CcToolchainProvider ccToolchain = CppHelper.getToolchain(ruleContext, ":j2objc_cc_toolchain");
FdoSupportProvider fdoSupport = CppHelper.getFdoSupport(ruleContext, ":j2objc_cc_toolchain");
CompilationSupport compilationSupport = CompilationSupport.createWithSelectedImplementation(ruleContext, ruleContext.getConfiguration(), ObjcRuleClasses.j2objcIntermediateArtifacts(ruleContext), CompilationAttributes.Builder.fromRuleContext(ruleContext).build());
compilationSupport.registerCompileAndArchiveActions(common.getCompilationArtifacts().get(), common.getObjcProvider(), EXTRA_COMPILE_ARGS, ImmutableList.<PathFragment>of(), ccToolchain, fdoSupport).registerFullyLinkAction(common.getObjcProvider(), ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB), ccToolchain, fdoSupport);
} catch (RuleErrorException e) {
ruleContext.ruleError(e.getMessage());
}
} else {
common = common(ruleContext, ImmutableList.<Artifact>of(), ImmutableList.<Artifact>of(), ImmutableList.<PathFragment>of(), depAttributes);
xcodeProvider = xcodeProvider(ruleContext, common, ImmutableList.<Artifact>of(), ImmutableList.<PathFragment>of(), depAttributes);
}
return builder.addProvider(exportedJ2ObjcMappingFileProvider(base, ruleContext, directJ2ObjcMappingFileProvider)).addProvider(common.getObjcProvider()).addProvider(xcodeProvider).build();
}
Aggregations