use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.
the class IosApplication method configureTarget.
@Override
protected void configureTarget(RuleConfiguredTargetBuilder target, RuleContext ruleContext, ReleaseBundlingSupport releaseBundlingSupport) throws InterruptedException {
// If this is an application built for the simulator, make it runnable.
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
if (appleConfiguration.getMultiArchPlatform(PlatformType.IOS) == Platform.IOS_SIMULATOR) {
Artifact runnerScript = ObjcRuleClasses.intermediateArtifacts(ruleContext).runnerScript();
Artifact ipaFile = ruleContext.getImplicitOutputArtifact(ReleaseBundlingSupport.IPA);
releaseBundlingSupport.registerGenerateRunnerScriptAction(runnerScript, ipaFile);
target.setRunfilesSupport(releaseBundlingSupport.runfilesSupport(runnerScript), runnerScript);
}
}
use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.
the class AppleBinary method create.
@Override
public final ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
PlatformType platformType = MultiArchSplitTransitionProvider.getPlatformType(ruleContext);
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
Platform platform = appleConfiguration.getMultiArchPlatform(platformType);
ImmutableListMultimap<BuildConfiguration, ObjcProvider> configurationToNonPropagatedObjcMap = ruleContext.getPrerequisitesByConfiguration("non_propagated_deps", Mode.SPLIT, ObjcProvider.class);
ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> configToDepsCollectionMap = ruleContext.getPrerequisitesByConfiguration("deps", Mode.SPLIT);
Set<BuildConfiguration> childConfigurations = getChildConfigurations(ruleContext);
Artifact outputArtifact = ObjcRuleClasses.intermediateArtifacts(ruleContext).combinedArchitectureBinary();
MultiArchBinarySupport multiArchBinarySupport = new MultiArchBinarySupport(ruleContext);
Map<BuildConfiguration, ObjcProvider> objcProviderByDepConfiguration = multiArchBinarySupport.objcProviderByDepConfiguration(childConfigurations, configToDepsCollectionMap, configurationToNonPropagatedObjcMap, getDylibProviders(ruleContext), getDylibProtoProviders(ruleContext));
multiArchBinarySupport.registerActions(platform, getExtraLinkArgs(ruleContext), objcProviderByDepConfiguration, getExtraLinkInputs(ruleContext), configToDepsCollectionMap, outputArtifact);
NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder().add(outputArtifact);
RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build());
ObjcProvider.Builder objcProviderBuilder = new ObjcProvider.Builder();
for (ObjcProvider objcProvider : objcProviderByDepConfiguration.values()) {
objcProviderBuilder.addTransitiveAndPropagate(objcProvider);
}
objcProviderBuilder.add(MULTI_ARCH_LINKED_BINARIES, outputArtifact);
ObjcProvider objcProvider = objcProviderBuilder.build();
// TODO(cparsons): Stop propagating ObjcProvider directly from this rule.
targetBuilder.addProvider(ObjcProvider.class, objcProvider);
switch(getBinaryType(ruleContext)) {
case EXECUTABLE:
targetBuilder.addNativeDeclaredProvider(new AppleExecutableBinaryProvider(outputArtifact, objcProvider));
break;
case DYLIB:
targetBuilder.addNativeDeclaredProvider(new AppleDylibBinaryProvider(outputArtifact, objcProvider));
break;
case LOADABLE_BUNDLE:
targetBuilder.addNativeDeclaredProvider(new AppleLoadableBundleBinaryProvider(outputArtifact));
break;
}
AppleDebugOutputsProvider.Builder builder = AppleDebugOutputsProvider.Builder.create();
for (BuildConfiguration childConfig : childConfigurations) {
AppleConfiguration childAppleConfig = childConfig.getFragment(AppleConfiguration.class);
ObjcConfiguration childObjcConfig = childConfig.getFragment(ObjcConfiguration.class);
IntermediateArtifacts intermediateArtifacts = new IntermediateArtifacts(ruleContext, /*archiveFileNameSuffix*/
"", /*outputPrefix*/
"", childConfig);
String arch = childAppleConfig.getSingleArchitecture();
if (childAppleConfig.getBitcodeMode() == AppleBitcodeMode.EMBEDDED) {
Artifact bitcodeSymbol = intermediateArtifacts.bitcodeSymbolMap();
builder.addOutput(arch, OutputType.BITCODE_SYMBOLS, bitcodeSymbol);
}
if (childObjcConfig.generateDsym()) {
Artifact dsymBinary = intermediateArtifacts.dsymSymbol(DsymOutputType.APP);
builder.addOutput(arch, OutputType.DSYM_BINARY, dsymBinary);
}
if (childObjcConfig.generateLinkmap()) {
Artifact linkmap = intermediateArtifacts.linkmap();
builder.addOutput(arch, OutputType.LINKMAP, linkmap);
}
}
targetBuilder.addNativeDeclaredProvider(builder.build());
return targetBuilder.build();
}
use of com.google.devtools.build.lib.rules.apple.AppleConfiguration 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);
}
use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.
the class IosDevice method create.
@Override
public ConfiguredTarget create(RuleContext context) throws InterruptedException, RuleErrorException {
AppleConfiguration appleConfiguration = context.getFragment(AppleConfiguration.class);
String iosVersionAttribute = context.attributes().get(IosDeviceRule.IOS_VERSION_ATTR_NAME, STRING);
XcodeVersionProperties xcodeVersionProperties = (XcodeVersionProperties) context.getPrerequisite(IosDeviceRule.XCODE_ATTR_NAME, Mode.TARGET, XcodeVersionProperties.SKYLARK_CONSTRUCTOR.getKey());
DottedVersion xcodeVersion = null;
if (xcodeVersionProperties != null && xcodeVersionProperties.getXcodeVersion().isPresent()) {
xcodeVersion = xcodeVersionProperties.getXcodeVersion().get();
} else if (appleConfiguration.getXcodeVersion() != null) {
xcodeVersion = appleConfiguration.getXcodeVersion();
}
DottedVersion iosVersion;
if (!Strings.isNullOrEmpty(iosVersionAttribute)) {
iosVersion = DottedVersion.fromString(iosVersionAttribute);
} else if (xcodeVersionProperties != null) {
iosVersion = xcodeVersionProperties.getDefaultIosSdkVersion();
} else {
iosVersion = appleConfiguration.getSdkVersionForPlatform(Platform.IOS_SIMULATOR);
}
IosDeviceProvider provider = new IosDeviceProvider.Builder().setType(context.attributes().get(IosDeviceRule.TYPE_ATTR_NAME, STRING)).setIosVersion(iosVersion).setLocale(context.attributes().get(IosDeviceRule.LOCALE_ATTR_NAME, STRING)).setXcodeVersion(xcodeVersion).build();
return new RuleConfiguredTargetBuilder(context).add(RunfilesProvider.class, RunfilesProvider.EMPTY).addNativeDeclaredProvider(provider).add(IosTestSubstitutionProvider.class, provider.iosTestSubstitutionProvider()).build();
}
use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.
the class IosTest method create.
/**
* {@inheritDoc}
*
* Creates a target, including registering actions, just as {@link #create(RuleContext)} does.
* The difference between {@link #create(RuleContext)} and this method is that this method does
* only what is needed to support tests on the environment besides generate the Xcodeproj file
* and build the app and test {@code .ipa}s. The {@link #create(RuleContext)} method delegates
* to this method.
*/
@Override
public final ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
ProtobufSupport protoSupport = new ProtobufSupport(ruleContext).registerGenerationActions().registerCompilationActions();
Optional<ObjcProvider> protosObjcProvider = protoSupport.getObjcProvider();
Optional<XcodeProvider> protosXcodeProvider = protoSupport.getXcodeProvider();
ObjcCommon common = common(ruleContext, protosObjcProvider);
if (!common.getCompilationArtifacts().get().getArchive().isPresent()) {
ruleContext.ruleError(REQUIRES_SOURCE_ERROR);
}
if (!ruleContext.getFragment(AppleConfiguration.class).getIosMultiCpus().isEmpty()) {
ruleContext.ruleError(NO_MULTI_CPUS_ERROR);
}
XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder().addPropagatedDependencies(protosXcodeProvider.asSet());
NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder();
addResourceFilesToBuild(ruleContext, common.getObjcProvider(), filesToBuild);
XcodeProductType productType = getProductType(ruleContext);
ExtraLinkArgs extraLinkArgs;
Iterable<Artifact> extraLinkInputs;
String bundleFormat;
if (!isXcTest(ruleContext)) {
extraLinkArgs = new ExtraLinkArgs();
extraLinkInputs = ImmutableList.of();
bundleFormat = ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT;
} else {
xcodeProviderBuilder.setProductType(productType);
XcodeProvider appIpaXcodeProvider = ruleContext.getPrerequisite(XCTEST_APP_ATTR, Mode.TARGET, XcodeProvider.class);
if (appIpaXcodeProvider != null) {
xcodeProviderBuilder.setTestHost(appIpaXcodeProvider);
}
XcTestAppProvider testApp = xcTestAppProvider(ruleContext);
Artifact bundleLoader = testApp.getBundleLoader();
// -bundle causes this binary to be linked as a bundle and not require an entry point
// (i.e. main())
// -bundle_loader causes the code in this test to have access to the symbols in the test rig,
// or more specifically, the flag causes ld to consider the given binary when checking for
// missing symbols.
// -rpath @loader_path/Frameworks allows test bundles to load dylibs from the app's
// Frameworks directory.
extraLinkArgs = new ExtraLinkArgs("-bundle", "-bundle_loader", bundleLoader.getExecPathString(), "-Xlinker", "-rpath", "-Xlinker", "@loader_path/Frameworks");
extraLinkInputs = ImmutableList.of(bundleLoader);
bundleFormat = ReleaseBundlingSupport.XCTEST_BUNDLE_DIR_FORMAT;
filesToBuild.add(testApp.getIpa());
}
J2ObjcMappingFileProvider j2ObjcMappingFileProvider = J2ObjcMappingFileProvider.union(ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcMappingFileProvider.class));
J2ObjcEntryClassProvider j2ObjcEntryClassProvider = new J2ObjcEntryClassProvider.Builder().addTransitive(ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcEntryClassProvider.class)).build();
CompilationSupport.create(ruleContext).registerLinkActions(common.getObjcProvider(), j2ObjcMappingFileProvider, j2ObjcEntryClassProvider, extraLinkArgs, extraLinkInputs, DsymOutputType.TEST).registerCompileAndArchiveActions(common).registerFullyLinkAction(common.getObjcProvider(), ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB)).addXcodeSettings(xcodeProviderBuilder, common).validateAttributes();
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
new ReleaseBundlingSupport(ruleContext, common.getObjcProvider(), LinkedBinary.LOCAL_AND_DEPENDENCIES, bundleFormat, appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS), appleConfiguration.getMultiArchPlatform(PlatformType.IOS)).registerActions(DsymOutputType.TEST).addXcodeSettings(xcodeProviderBuilder).addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.TEST)).validateResources().validateAttributes();
new ResourceSupport(ruleContext).validateAttributes().addXcodeSettings(xcodeProviderBuilder);
new XcodeSupport(ruleContext).addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), productType).addDependencies(xcodeProviderBuilder, new Attribute("bundles", Mode.TARGET)).addDependencies(xcodeProviderBuilder, new Attribute("deps", Mode.TARGET)).addNonPropagatedDependencies(xcodeProviderBuilder, new Attribute("non_propagated_deps", Mode.TARGET)).addFilesToBuild(filesToBuild).registerActions(xcodeProviderBuilder.build());
XcodeProvider xcodeProvider = xcodeProviderBuilder.build();
NestedSet<Artifact> filesToBuildSet = filesToBuild.build();
Runfiles.Builder runfilesBuilder = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES);
NestedSetBuilder<Artifact> filesToBuildBuilder = NestedSetBuilder.<Artifact>stableOrder().addTransitive(filesToBuildSet);
InstrumentedFilesProvider instrumentedFilesProvider = CompilationSupport.create(ruleContext).getInstrumentedFilesProvider(common);
TestSupport testSupport = new TestSupport(ruleContext).registerTestRunnerActions().addRunfiles(runfilesBuilder, instrumentedFilesProvider).addFilesToBuild(filesToBuildBuilder);
Artifact executable = testSupport.generatedTestScript();
Runfiles runfiles = runfilesBuilder.build();
RunfilesSupport runfilesSupport = RunfilesSupport.withExecutable(ruleContext, runfiles, executable);
ImmutableMap.Builder<String, String> execInfoMapBuilder = new ImmutableMap.Builder<>();
execInfoMapBuilder.put(ExecutionRequirements.REQUIRES_DARWIN, "");
if (ruleContext.getFragment(ObjcConfiguration.class).runMemleaks()) {
execInfoMapBuilder.put("nosandbox", "");
}
return new RuleConfiguredTargetBuilder(ruleContext).setFilesToBuild(filesToBuildBuilder.build()).addProvider(xcodeProvider).addProvider(RunfilesProvider.simple(runfiles)).addNativeDeclaredProvider(new ExecutionInfoProvider(execInfoMapBuilder.build())).addNativeDeclaredProviders(testSupport.getExtraProviders()).addProvider(InstrumentedFilesProvider.class, instrumentedFilesProvider).setRunfilesSupport(runfilesSupport, executable).build();
}
Aggregations