use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.
the class AppleCcToolchain method getBuildVariables.
@Override
protected Map<String, String> getBuildVariables(RuleContext ruleContext) throws RuleErrorException {
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
if (appleConfiguration.getXcodeVersion() == null) {
ruleContext.throwWithRuleError("Xcode version must be specified to use an Apple CROSSTOOL");
}
Platform platform = appleConfiguration.getSingleArchPlatform();
Map<String, String> appleEnv = getEnvironmentBuildVariables(ruleContext);
return ImmutableMap.<String, String>builder().put(XCODE_VERSION_KEY, appleConfiguration.getXcodeVersion().toStringWithMinimumComponents(2)).put(IOS_SDK_VERSION_KEY, appleConfiguration.getSdkVersionForPlatform(Platform.IOS_SIMULATOR).toStringWithMinimumComponents(2)).put(MACOS_SDK_VERSION_KEY, appleConfiguration.getSdkVersionForPlatform(Platform.MACOS).toStringWithMinimumComponents(2)).put(TVOS_SDK_VERSION_KEY, appleConfiguration.getSdkVersionForPlatform(Platform.TVOS_SIMULATOR).toStringWithMinimumComponents(2)).put(WATCHOS_SDK_VERSION_KEY, appleConfiguration.getSdkVersionForPlatform(Platform.WATCHOS_SIMULATOR).toStringWithMinimumComponents(2)).put(SDK_DIR_KEY, AppleToolchain.sdkDir()).put(SDK_FRAMEWORK_DIR_KEY, AppleToolchain.sdkFrameworkDir(platform, appleConfiguration)).put(PLATFORM_DEVELOPER_FRAMEWORK_DIR, AppleToolchain.platformDeveloperFrameworkDir(appleConfiguration)).put(XCODE_VERISON_OVERRIDE_VALUE_KEY, appleEnv.getOrDefault(AppleConfiguration.XCODE_VERSION_ENV_NAME, "")).put(APPLE_SDK_VERSION_OVERRIDE_VALUE_KEY, appleEnv.getOrDefault(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME, "")).put(APPLE_SDK_PLATFORM_VALUE_KEY, appleEnv.getOrDefault(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME, "")).put(VERSION_MIN_KEY, appleConfiguration.getMinimumOsForPlatformType(platform.getType()).toString()).build();
}
use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.
the class LegacyCompilationSupport method registerCompileActionTemplate.
/**
* Registers a SpawnActionTemplate to compile the source file tree artifact, {@code sourceFiles},
* which can contain multiple concrete source files unknown at analysis time. At execution time,
* the SpawnActionTemplate will register one ObjcCompile action for each individual source file
* under {@code sourceFiles}.
*
* <p>Note that this method currently does not support code coverage and sources other than ObjC
* sources.
*
* @param sourceFiles tree artifact containing source files to compile
* @param objFiles tree artifact containing object files compiled from {@code sourceFiles}
* @param objcProvider ObjcProvider instance for this invocation
* @param priorityHeaders priority headers to be included before the dependency headers
* @param moduleMap the module map generated from the associated headers
* @param compilationArtifacts the CompilationArtifacts instance for this invocation
* @param otherFlags extra compilation flags to add to the compile action command line
*/
private void registerCompileActionTemplate(Artifact sourceFiles, Artifact objFiles, ObjcProvider objcProvider, Iterable<PathFragment> priorityHeaders, Optional<CppModuleMap> moduleMap, CompilationArtifacts compilationArtifacts, Iterable<String> otherFlags) {
CustomCommandLine commandLine = compileActionCommandLine(sourceFiles, objFiles, objcProvider, priorityHeaders, moduleMap, compilationArtifacts.getPchFile(), Optional.<Artifact>absent(), otherFlags, /* runCodeCoverage=*/
false, /* isCPlusPlusSource=*/
false);
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
Platform platform = appleConfiguration.getSingleArchPlatform();
NestedSet<Artifact> moduleMapInputs = NestedSetBuilder.emptySet(Order.STABLE_ORDER);
if (objcConfiguration.moduleMapsEnabled()) {
moduleMapInputs = objcProvider.get(MODULE_MAP);
}
ruleContext.registerAction(new SpawnActionTemplate.Builder(sourceFiles, objFiles).setMnemonics("ObjcCompileActionTemplate", "ObjcCompile").setExecutable(xcrunwrapper(ruleContext)).setCommandLineTemplate(commandLine).setEnvironment(ObjcRuleClasses.appleToolchainEnvironment(appleConfiguration, platform)).setExecutionInfo(ObjcRuleClasses.darwinActionExecutionRequirement()).setOutputPathMapper(COMPILE_ACTION_TEMPLATE_OUTPUT_PATH_MAPPER).addCommonTransitiveInputs(objcProvider.get(HEADER)).addCommonTransitiveInputs(moduleMapInputs).addCommonInputs(compilationArtifacts.getPrivateHdrs()).addCommonTransitiveInputs(objcProvider.get(STATIC_FRAMEWORK_FILE)).addCommonTransitiveInputs(objcProvider.get(DYNAMIC_FRAMEWORK_FILE)).addCommonInputs(compilationArtifacts.getPchFile().asSet()).build(ruleContext.getActionOwner()));
}
use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.
the class WatchExtensionSupport method createBundle.
void createBundle(NestedSetBuilder<Artifact> filesToBuild, ObjcProvider.Builder exposedObjcProviderBuilder, XcodeProvider.Builder xcodeProviderBuilder) throws InterruptedException {
ObjcProvider releaseBundlingObjcProvider = releaseBundlingObjcProvider();
WatchUtils.addXcodeSettings(ruleContext, xcodeProviderBuilder);
registerWatchExtensionAutomaticPlistAction();
ImmutableSet<TargetDeviceFamily> families = attributes.families();
if (families.isEmpty()) {
ruleContext.attributeError(FAMILIES_ATTR, ReleaseBundling.INVALID_FAMILIES_ERROR);
}
ReleaseBundling.Builder releaseBundling = new ReleaseBundling.Builder().setIpaArtifact(ipaArtifact).setBundleId(attributes.bundleId()).setProvisioningProfile(attributes.provisioningProfile()).setProvisioningProfileAttributeName(WATCH_EXT_PROVISIONING_PROFILE_ATTR).setTargetDeviceFamilies(families).setIntermediateArtifacts(intermediateArtifacts).setInfoPlistsFromRule(attributes.infoPlists()).addInfoplistInput(watchExtensionAutomaticPlist()).setEntitlements(attributes.entitlements());
if (attributes.isBundleIdExplicitySpecified()) {
releaseBundling.setPrimaryBundleId(attributes.bundleId());
} else {
releaseBundling.setFallbackBundleId(attributes.bundleId());
}
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
ReleaseBundlingSupport releaseBundlingSupport = new ReleaseBundlingSupport(ruleContext, releaseBundlingObjcProvider, LinkedBinary.DEPENDENCIES_ONLY, ReleaseBundlingSupport.EXTENSION_BUNDLE_DIR_FORMAT, bundleName, WatchUtils.determineMinimumIosVersion(appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS)), releaseBundling.build(), appleConfiguration.getMultiArchPlatform(PlatformType.IOS));
releaseBundlingSupport.registerActions(DsymOutputType.APP);
releaseBundlingSupport.addXcodeSettings(xcodeProviderBuilder);
releaseBundlingSupport.addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.APP)).validateResources().validateAttributes().addExportedDebugArtifacts(exposedObjcProviderBuilder, DsymOutputType.APP);
XcodeSupport xcodeSupport = new XcodeSupport(ruleContext).addFilesToBuild(filesToBuild).addXcodeSettings(xcodeProviderBuilder, releaseBundlingObjcProvider, WatchOSVersion.OS1.getExtensionXcodeProductType(), ruleContext.getFragment(AppleConfiguration.class).getDependencySingleArchitecture(), configurationDistinguisher).addDummySource(xcodeProviderBuilder);
for (Attribute attribute : dependencyAttributes) {
xcodeSupport.addDependencies(xcodeProviderBuilder, attribute);
}
// Generate xcodeproj for watch OS 1 extension as the main target with watch application
// target as the dependency.
xcodeProviderBuilder.addPropagatedDependencies(ImmutableList.of(watchApplicationXcodeProvider));
xcodeSupport.registerActions(xcodeProviderBuilder.build());
}
use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.
the class WatchUtils method registerActionsToAddWatchSupport.
/**
* Adds WatchKitSupport stub to the final ipa and exposes it to given @{link ObjcProvider.Builder}
* based on watch OS version.
*
* For example, for watch OS 1, the resulting ipa will have:
* Payload/TestApp.app
* WatchKitSupport
* WatchKitSupport/WK
*/
static void registerActionsToAddWatchSupport(RuleContext ruleContext, ObjcProvider.Builder objcProviderBuilder, WatchOSVersion watchOSVersion) {
Artifact watchSupportZip = watchSupportZip(ruleContext);
String workingDirectory = watchSupportZip.getExecPathString().substring(0, watchSupportZip.getExecPathString().lastIndexOf('/'));
String watchKitSupportDirName = watchOSVersion.getWatchKitSupportDirName();
String watchKitSupportPath = workingDirectory + "/" + watchKitSupportDirName;
ImmutableList<String> command = ImmutableList.of(// 1. Copy WK stub binary to watchKitSupportPath.
"mkdir -p " + watchKitSupportPath, "&&", String.format("cp -f %s %s", WATCH_KIT_STUB_PATH, watchKitSupportPath), // 2. cd to working directory.
"&&", "cd " + workingDirectory, // 3. Zip watchSupport.
"&&", String.format("/usr/bin/zip -q -r -0 %s %s", watchSupportZip.getFilename(), watchKitSupportDirName));
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
ruleContext.registerAction(ObjcRuleClasses.spawnAppleEnvActionBuilder(appleConfiguration, appleConfiguration.getMultiArchPlatform(PlatformType.WATCHOS)).setProgressMessage("Copying Watchkit support to app bundle").setShellCommand(ImmutableList.of("/bin/bash", "-c", Joiner.on(" ").join(command))).addOutput(watchSupportZip).build(ruleContext));
objcProviderBuilder.add(ROOT_MERGE_ZIP, watchSupportZip(ruleContext));
}
use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.
the class ReleaseBundlingSupport method automaticEntries.
/**
* Returns a map containing entries that should be added to the merged plist. These are usually
* generated by Xcode automatically during the build process.
*/
private NSDictionary automaticEntries() {
List<Integer> uiDeviceFamily = TargetDeviceFamily.UI_DEVICE_FAMILY_VALUES.get(bundleSupport.targetDeviceFamilies());
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
NSDictionary result = new NSDictionary();
if (uiDeviceFamily != null) {
result.put("UIDeviceFamily", uiDeviceFamily.toArray());
}
result.put("DTPlatformName", platform.getLowerCaseNameInPlist());
result.put("DTSDKName", platform.getLowerCaseNameInPlist() + appleConfiguration.getSdkVersionForPlatform(platform));
result.put("CFBundleSupportedPlatforms", new NSArray(NSObject.wrap(platform.getNameInPlist())));
result.put("MinimumOSVersion", bundling.getMinimumOsVersion().toString());
return result;
}
Aggregations