use of com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder in project bazel by bazelbuild.
the class AppleStaticLibrary method create.
@Override
public final ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
PlatformType platformType = MultiArchSplitTransitionProvider.getPlatformType(ruleContext);
ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> configToDepsCollectionMap = ruleContext.getPrerequisitesByConfiguration("deps", Mode.SPLIT);
ImmutableListMultimap<BuildConfiguration, ObjcProvider> configToObjcAvoidDepsMap = ruleContext.getPrerequisitesByConfiguration(AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME, Mode.SPLIT, ObjcProvider.class);
ImmutableListMultimap<BuildConfiguration, CcLinkParamsProvider> configToCcAvoidDepsMap = ruleContext.getPrerequisitesByConfiguration(AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME, Mode.SPLIT, CcLinkParamsProvider.class);
Set<BuildConfiguration> childConfigurations = getChildConfigurations(ruleContext);
IntermediateArtifacts ruleIntermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext);
NestedSetBuilder<Artifact> librariesToLipo = NestedSetBuilder.<Artifact>stableOrder();
NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder().add(ruleIntermediateArtifacts.combinedArchitectureArchive());
ObjcProvider.Builder objcProviderBuilder = new ObjcProvider.Builder();
for (BuildConfiguration childConfig : childConfigurations) {
ProtobufSupport protoSupport = new ProtobufSupport(ruleContext, childConfig).registerGenerationActions().registerCompilationActions();
Optional<ObjcProvider> protosObjcProvider = protoSupport.getObjcProvider();
IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext, childConfig);
ObjcCommon common = common(ruleContext, childConfig, intermediateArtifacts, nullToEmptyList(configToDepsCollectionMap.get(childConfig)), protosObjcProvider);
ObjcProvider objcProvider = common.getObjcProvider().subtractSubtrees(configToObjcAvoidDepsMap.get(childConfig), configToCcAvoidDepsMap.get(childConfig));
librariesToLipo.add(intermediateArtifacts.strippedSingleArchitectureLibrary());
CompilationSupport.createForConfig(ruleContext, childConfig).registerCompileAndArchiveActions(common).registerFullyLinkAction(objcProvider, intermediateArtifacts.strippedSingleArchitectureLibrary()).validateAttributes();
ruleContext.assertNoErrors();
addTransitivePropagatedKeys(objcProviderBuilder, objcProvider);
}
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
new LipoSupport(ruleContext).registerCombineArchitecturesAction(librariesToLipo.build(), ruleIntermediateArtifacts.combinedArchitectureArchive(), appleConfiguration.getMultiArchPlatform(platformType));
RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build());
objcProviderBuilder.add(MULTI_ARCH_LINKED_ARCHIVES, ruleIntermediateArtifacts.combinedArchitectureArchive());
targetBuilder.addProvider(ObjcProvider.class, objcProviderBuilder.build());
return targetBuilder.build();
}
use of com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder in project bazel by bazelbuild.
the class ObjcImport method create.
@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
ObjcCommon common = new ObjcCommon.Builder(ruleContext).setCompilationAttributes(CompilationAttributes.Builder.fromRuleContext(ruleContext).build()).setResourceAttributes(new ResourceAttributes(ruleContext)).setIntermediateArtifacts(ObjcRuleClasses.intermediateArtifacts(ruleContext)).setAlwayslink(ruleContext.attributes().get("alwayslink", Type.BOOLEAN)).setHasModuleMap().addExtraImportLibraries(ruleContext.getPrerequisiteArtifacts("archives", Mode.TARGET).list()).addDepObjcProviders(ruleContext.getPrerequisites("bundles", Mode.TARGET, ObjcProvider.class)).build();
XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder();
NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder();
CompilationAttributes compilationAttributes = CompilationAttributes.Builder.fromRuleContext(ruleContext).build();
IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext);
Iterable<Artifact> publicHeaders = compilationAttributes.hdrs();
CppModuleMap moduleMap = intermediateArtifacts.moduleMap();
CompilationSupport.create(ruleContext).registerGenerateModuleMapAction(moduleMap, publicHeaders).addXcodeSettings(xcodeProviderBuilder, common).validateAttributes();
new ResourceSupport(ruleContext).validateAttributes().addXcodeSettings(xcodeProviderBuilder);
new XcodeSupport(ruleContext).addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), LIBRARY_STATIC).addDependencies(xcodeProviderBuilder, new Attribute("bundles", Mode.TARGET)).registerActions(xcodeProviderBuilder.build()).addFilesToBuild(filesToBuild);
return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()).addProvider(XcodeProvider.class, xcodeProviderBuilder.build()).addProvider(ObjcProvider.class, common.getObjcProvider()).build();
}
use of com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder in project bazel by bazelbuild.
the class MultiArchBinarySupport method registerActions.
/**
* Registers actions to create a multi-arch Apple binary.
*
* @param platform the platform for which the binary is targeted
* @param extraLinkArgs the extra linker args to add to link actions linking single-architecture
* binaries together
* @param configurationToObjcProvider a map from from dependency configuration to the
* {@link ObjcProvider} which comprises all information about the dependencies in that
* configuration. Can be obtained via {@link #objcProviderByDepConfiguration}
* @param extraLinkInputs the extra linker inputs to be made available during link actions
* @param configToDepsCollectionMap a multimap from dependency configuration to the
* list of provider collections which are propagated from the dependencies of that
* configuration
* @param outputLipoBinary the artifact (lipo'ed binary) which should be output as a result of
* this support
* @throws RuleErrorException if there are attribute errors in the current rule context
*/
public void registerActions(Platform platform, ExtraLinkArgs extraLinkArgs, Map<BuildConfiguration, ObjcProvider> configurationToObjcProvider, Iterable<Artifact> extraLinkInputs, ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> configToDepsCollectionMap, Artifact outputLipoBinary) throws RuleErrorException, InterruptedException {
NestedSetBuilder<Artifact> binariesToLipo = NestedSetBuilder.<Artifact>stableOrder();
for (BuildConfiguration childConfig : configurationToObjcProvider.keySet()) {
IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext, childConfig);
ImmutableList.Builder<J2ObjcMappingFileProvider> j2ObjcMappingFileProviders = ImmutableList.builder();
J2ObjcEntryClassProvider.Builder j2ObjcEntryClassProviderBuilder = new J2ObjcEntryClassProvider.Builder();
for (TransitiveInfoCollection dep : configToDepsCollectionMap.get(childConfig)) {
if (dep.getProvider(J2ObjcMappingFileProvider.class) != null) {
j2ObjcMappingFileProviders.add(dep.getProvider(J2ObjcMappingFileProvider.class));
}
if (dep.getProvider(J2ObjcEntryClassProvider.class) != null) {
j2ObjcEntryClassProviderBuilder.addTransitive(dep.getProvider(J2ObjcEntryClassProvider.class));
}
}
J2ObjcMappingFileProvider j2ObjcMappingFileProvider = J2ObjcMappingFileProvider.union(j2ObjcMappingFileProviders.build());
J2ObjcEntryClassProvider j2ObjcEntryClassProvider = j2ObjcEntryClassProviderBuilder.build();
binariesToLipo.add(intermediateArtifacts.strippedSingleArchitectureBinary());
ObjcProvider objcProvider = configurationToObjcProvider.get(childConfig);
CompilationArtifacts compilationArtifacts = CompilationSupport.compilationArtifacts(ruleContext, ObjcRuleClasses.intermediateArtifacts(ruleContext, childConfig));
CompilationSupport.createForConfig(ruleContext, childConfig).registerCompileAndArchiveActions(compilationArtifacts, objcProvider).registerLinkActions(objcProvider, j2ObjcMappingFileProvider, j2ObjcEntryClassProvider, extraLinkArgs, extraLinkInputs, DsymOutputType.APP).validateAttributes();
ruleContext.assertNoErrors();
}
new LipoSupport(ruleContext).registerCombineArchitecturesAction(binariesToLipo.build(), outputLipoBinary, platform);
}
use of com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder in project bazel by bazelbuild.
the class ObjcBundleLibrary method create.
@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
ObjcCommon common = common(ruleContext);
Bundling bundling = bundling(ruleContext, common);
XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder();
NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder();
new ResourceSupport(ruleContext).validateAttributes().addXcodeSettings(xcodeProviderBuilder);
if (ruleContext.hasErrors()) {
return null;
}
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
// Platform is purposefully not validated on this BundleSupport. Multi-arch validation and
// resource de-duplication should only take place at the level of the bundling rule.
new BundleSupport(ruleContext, appleConfiguration, appleConfiguration.getMultiArchPlatform(PlatformType.IOS), bundling, new ExtraActoolArgs()).validateResources(common.getObjcProvider()).registerActions(common.getObjcProvider()).addXcodeSettings(xcodeProviderBuilder);
if (ruleContext.hasErrors()) {
return null;
}
new XcodeSupport(ruleContext).addFilesToBuild(filesToBuild).addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), BUNDLE).addDependencies(xcodeProviderBuilder, new Attribute("bundles", Mode.TARGET)).registerActions(xcodeProviderBuilder.build());
ObjcProvider nestedBundleProvider = new ObjcProvider.Builder().add(NESTED_BUNDLE, bundling).build();
return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()).addProvider(XcodeProvider.class, xcodeProviderBuilder.build()).addProvider(ObjcProvider.class, nestedBundleProvider).build();
}
use of com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder in project bazel by bazelbuild.
the class ReleaseBundlingTargetFactory method create.
@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
validateAttributes(ruleContext);
ObjcCommon common = common(ruleContext);
XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder();
NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder();
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
ReleaseBundlingSupport releaseBundlingSupport = new ReleaseBundlingSupport(ruleContext, common.getObjcProvider(), LinkedBinary.DEPENDENCIES_ONLY, bundleDirFormat, bundleName(ruleContext), bundleMinimumOsVersion(ruleContext), appleConfiguration.getMultiArchPlatform(PlatformType.IOS));
releaseBundlingSupport.registerActions(DsymOutputType.APP).addXcodeSettings(xcodeProviderBuilder).addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.APP)).validateResources().validateAttributes();
XcodeSupport xcodeSupport = new XcodeSupport(ruleContext).addFilesToBuild(filesToBuild).addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), xcodeProductType, ruleContext.getFragment(AppleConfiguration.class).getDependencySingleArchitecture(), configurationDistinguisher).addDummySource(xcodeProviderBuilder);
for (Attribute attribute : dependencyAttributes) {
xcodeSupport.addDependencies(xcodeProviderBuilder, attribute);
}
xcodeSupport.registerActions(xcodeProviderBuilder.build());
RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()).addProvider(XcTestAppProvider.class, releaseBundlingSupport.xcTestAppProvider()).addProvider(XcodeProvider.class, xcodeProviderBuilder.build()).addProvider(InstrumentedFilesProvider.class, InstrumentedFilesCollector.forward(ruleContext, "binary"));
ObjcProvider exposedObjcProvider = exposedObjcProvider(ruleContext, releaseBundlingSupport);
if (exposedObjcProvider != null) {
targetBuilder.addProvider(ObjcProvider.class, exposedObjcProvider);
}
configureTarget(targetBuilder, ruleContext, releaseBundlingSupport);
return targetBuilder.build();
}
Aggregations