diff options
-rwxr-xr-x | compile.sh | 2 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java | 2 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java | 47 | ||||
-rw-r--r-- | src/test/shell/bazel/BUILD | 1 | ||||
-rwxr-xr-x | src/test/shell/bazel/test-setup.sh | 1 | ||||
-rwxr-xr-x | src/test/shell/bazel/testenv.sh | 1 | ||||
-rw-r--r-- | src/tools/xcode/environment/BUILD | 11 | ||||
-rw-r--r-- | src/tools/xcode/environment/README | 5 | ||||
-rwxr-xr-x | src/tools/xcode/environment/environment_plist.sh | 74 |
9 files changed, 120 insertions, 24 deletions
diff --git a/compile.sh b/compile.sh index 3881bd741d..3f157e2ec7 100755 --- a/compile.sh +++ b/compile.sh @@ -127,6 +127,8 @@ if [ $DO_TOOLS_COMPILATION ]; then tools/objc/StdRedirect.dylib 0755 fi bazel_bootstrap //src/tools/xcode/realpath:realpath tools/objc/realpath 0755 + bazel_bootstrap //src/tools/xcode/environment:environment_plist \ + tools/objc/environment_plist.sh 0755 fi fi diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java index 7b53bcae59..3f4b60c659 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java @@ -981,6 +981,8 @@ public class ObjcRuleClasses { })) .add(attr("$bundlemerge", LABEL).cfg(HOST).exec() .value(env.getLabel("//tools/objc:bundlemerge"))) + .add(attr("$environment_plist_sh", LABEL).cfg(HOST) + .value(env.getLabel("//tools/objc:environment_plist.sh"))) .build(); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java index f6a3af6eb0..78acdaed12 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java @@ -21,6 +21,7 @@ import static com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.UI_DEV import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; +import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -302,32 +303,22 @@ public final class ReleaseBundlingSupport { private void registerEnvironmentPlistAction() { ObjcConfiguration configuration = ObjcRuleClasses.objcConfiguration(ruleContext); // Generates a .plist that contains environment values (such as the SDK used to build, the Xcode - // version, etc), which are parsed from various .plist files of the OS, namely XCodes' and + // version, etc), which are parsed from various .plist files of the OS, namely Xcodes' and // Platforms' plists. // The resulting file is meant to be merged with the final bundle. - String command = Joiner.on(" && ").join( - "PLATFORM_PLIST=" + IosSdkCommands.platformDir(configuration) + "/Info.plist", - "PLIST=$(mktemp -d -t bazel_environment)/env.plist", - "os_build=$(/usr/bin/defaults read \"${PLATFORM_PLIST}\" BuildMachineOSBuild)", - "compiler=$(/usr/bin/defaults read \"${PLATFORM_PLIST}\" DTCompiler)", - "platform_version=$(/usr/bin/defaults read \"${PLATFORM_PLIST}\" Version)", - "sdk_build=$(/usr/bin/defaults read \"${PLATFORM_PLIST}\" DTSDKBuild)", - "platform_build=$(/usr/bin/defaults read \"${PLATFORM_PLIST}\" DTPlatformBuild)", - "xcode_build=$(/usr/bin/defaults read \"${PLATFORM_PLIST}\" DTXcodeBuild)", - "xcode_version=$(/usr/bin/defaults read \"${PLATFORM_PLIST}\" DTXcode)", - "/usr/bin/defaults write \"${PLIST}\" DTPlatformBuild -string ${platform_build}", - "/usr/bin/defaults write \"${PLIST}\" DTSDKBuild -string ${sdk_build}", - "/usr/bin/defaults write \"${PLIST}\" DTPlatformVersion -string ${platform_version}", - "/usr/bin/defaults write \"${PLIST}\" DTXcode -string ${xcode_version}", - "/usr/bin/defaults write \"${PLIST}\" DTXCodeBuild -string ${xcode_build}", - "/usr/bin/defaults write \"${PLIST}\" DTCompiler -string ${compiler}", - "/usr/bin/defaults write \"${PLIST}\" BuildMachineOSBuild -string ${os_build}", - "cat \"${PLIST}\" > " + getGeneratedEnvironmentPlist().getShellEscapedExecPathString(), - "rm -rf \"${PLIST}\""); - ruleContext.registerAction(ObjcRuleClasses.spawnBashOnDarwinActionBuilder(ruleContext, command) - .setMnemonic("EnvironmentPlist") - .addOutput(getGeneratedEnvironmentPlist()) - .build(ruleContext)); + String platformWithVersion = + String.format("%s%s", configuration.getBundlingPlatform().getLowerCaseNameInPlist(), + Strings.nullToEmpty(configuration.getIosSdkVersion())); + ruleContext.registerAction( + ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext) + .setMnemonic("EnvironmentPlist") + .addInput(attributes.environmentPlistScript()) + .setExecutable(attributes.environmentPlistScript()) + .addArguments("--platform", platformWithVersion) + .addArguments( + "--output", getGeneratedEnvironmentPlist().getShellEscapedExecPathString()) + .addOutput(getGeneratedEnvironmentPlist()) + .build(ruleContext)); } private Artifact registerBundleSigningActions(Artifact ipaOutput) throws InterruptedException { @@ -877,6 +868,14 @@ public final class ReleaseBundlingSupport { return ruleContext.getPrerequisiteArtifact("$swiftstdlibtoolzip_deploy", Mode.HOST); } + /** + * Returns the location of the environment_plist.sh. + */ + public Artifact environmentPlistScript() { + return checkNotNull( + ruleContext.getPrerequisiteArtifact("$environment_plist_sh", Mode.HOST)); + } + String bundleId() { return checkNotNull(stringAttribute("bundle_id")); } diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD index 24139bfa93..22ad141d60 100644 --- a/src/test/shell/bazel/BUILD +++ b/src/test/shell/bazel/BUILD @@ -24,6 +24,7 @@ filegroup( "//src/objc_tools/xcodegen:xcodegen_deploy.jar", "//src/tools/xcode-common/java/com/google/devtools/build/xcode/actoolzip:actoolzip_deploy.jar", "//src/tools/xcode-common/java/com/google/devtools/build/xcode/swiftstdlibtoolzip:swiftstdlibtoolzip_deploy.jar", + "//src/tools/xcode/environment:environment_plist", "//src/tools/xcode/ibtoolwrapper", "//src/tools/xcode/realpath", "//src/tools/xcode/stdredirect:StdRedirect.dylib", diff --git a/src/test/shell/bazel/test-setup.sh b/src/test/shell/bazel/test-setup.sh index e5de41bd2d..237106dc13 100755 --- a/src/test/shell/bazel/test-setup.sh +++ b/src/test/shell/bazel/test-setup.sh @@ -299,6 +299,7 @@ function setup_objc_test_support() { [ -e tools/objc/precomp_xcodegen_deploy.jar ] || ln -sv ${xcodegen_path} tools/objc/precomp_xcodegen_deploy.jar [ -e tools/objc/StdRedirect.dylib ] || ln -sv ${stdredirect_path} tools/objc/StdRedirect.dylib [ -e tools/objc/realpath ] || ln -sv ${realpath_path} tools/objc/realpath + [ -e tools/objc/environment_plist.sh ] || ln -sv ${environment_plist_path} tools/objc/environment_plist.sh mkdir -p third_party/iossim [ -e third_party/iossim/iossim ] || ln -sv ${iossim_path} third_party/iossim/iossim diff --git a/src/test/shell/bazel/testenv.sh b/src/test/shell/bazel/testenv.sh index 6a1fadf9af..24141c86ea 100755 --- a/src/test/shell/bazel/testenv.sh +++ b/src/test/shell/bazel/testenv.sh @@ -62,6 +62,7 @@ plmerge_path="${TEST_SRCDIR}/src/objc_tools/plmerge/plmerge_deploy.jar" xcodegen_path="${TEST_SRCDIR}/src/objc_tools/xcodegen/xcodegen_deploy.jar" stdredirect_path="${TEST_SRCDIR}/src/tools/xcode/stdredirect/StdRedirect.dylib" realpath_path="${TEST_SRCDIR}/src/tools/xcode/realpath/realpath" +environment_plist_path="${TEST_SRCDIR}/src/tools/xcode/environment/environment_plist.sh" # Test data testdata_path=${TEST_SRCDIR}/src/test/shell/bazel/testdata diff --git a/src/tools/xcode/environment/BUILD b/src/tools/xcode/environment/BUILD new file mode 100644 index 0000000000..50ed625a56 --- /dev/null +++ b/src/tools/xcode/environment/BUILD @@ -0,0 +1,11 @@ +package(default_visibility = ["//src:__subpackages__"]) + +filegroup( + name = "srcs", + srcs = glob(["**"]), +) + +sh_binary( + name = "environment_plist", + srcs = ["environment_plist.sh"], +) diff --git a/src/tools/xcode/environment/README b/src/tools/xcode/environment/README new file mode 100644 index 0000000000..5f1592cdf5 --- /dev/null +++ b/src/tools/xcode/environment/README @@ -0,0 +1,5 @@ +environment_plist generates a plist file that contains some +environment variables of the host machine (like DTPlatformBuild +or BuildMachineOSBuild) given a target platform. + +environment_plist only runs on Darwin. diff --git a/src/tools/xcode/environment/environment_plist.sh b/src/tools/xcode/environment/environment_plist.sh new file mode 100755 index 0000000000..b142f7d68d --- /dev/null +++ b/src/tools/xcode/environment/environment_plist.sh @@ -0,0 +1,74 @@ +#!/bin/bash +# Copyright 2015 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# environment_plist generates a plist file that contains some +# environment variables of the host machine (like DTPlatformBuild +# or BuildMachineOSBuild) given a target platform. +# +# This script only runs on darwin and you must have Xcode installed. +# +# --output - the path to place the output plist file. +# --platform - the target platform, e.g. 'iphoneos' or 'iphonesimulator8.3' +# + +set -eu + +while [[ $# > 1 ]] +do +key="$1" + +case $key in + --platform) + PLATFORM="$2" + shift + ;; + --output) + OUTPUT="$2" + shift + ;; + *) + # unknown option + ;; +esac +shift +done + +XCODE_CONTENTS_DIR=$(dirname $(/usr/bin/xcode-select --print-path)) +PLATFORM_DIR=$(/usr/bin/xcrun --sdk "${PLATFORM}" --show-sdk-platform-path) +SDK_DIR=$(/usr/bin/xcrun --sdk "${PLATFORM}" --show-sdk-path) +XCODE_PLIST="${XCODE_CONTENTS_DIR}"/Info.plist +XCODE_VERSION_PLIST="${XCODE_CONTENTS_DIR}"/version.plist +PLATFORM_PLIST="${PLATFORM_DIR}"/Info.plist +PLATFORM_VERSION_PLIST="${PLATFORM_DIR}"/version.plist +SDK_VERSION_PLIST="${SDK_DIR}"/System/Library/CoreServices/SystemVersion.plist +PLIST=$(mktemp -d -t bazel_environment)/env.plist +trap 'rm -rf "${PLIST}"' ERR EXIT + +os_build=$(/usr/bin/sw_vers -buildVersion) +compiler=$(/usr/bin/defaults read "${PLATFORM_PLIST}" DefaultProperties | grep DEFAULT_COMPILER | cut -d '"' -f4) +platform_version=$(/usr/bin/defaults read "${PLATFORM_PLIST}" Version) +platform_build=$(/usr/bin/defaults read "${PLATFORM_VERSION_PLIST}" ProductBuildVersion) +sdk_build=$(/usr/bin/defaults read "${SDK_VERSION_PLIST}" ProductBuildVersion) +xcode_build=$(/usr/bin/defaults read "${XCODE_VERSION_PLIST}" ProductBuildVersion) +xcode_version=$(/usr/bin/defaults read "${XCODE_PLIST}" DTXcode) + +/usr/bin/defaults write "${PLIST}" DTPlatformBuild -string ${platform_build} +/usr/bin/defaults write "${PLIST}" DTSDKBuild -string ${sdk_build} +/usr/bin/defaults write "${PLIST}" DTPlatformVersion -string ${platform_version} +/usr/bin/defaults write "${PLIST}" DTXcode -string ${xcode_version} +/usr/bin/defaults write "${PLIST}" DTXCodeBuild -string ${xcode_build} +/usr/bin/defaults write "${PLIST}" DTCompiler -string ${compiler} +/usr/bin/defaults write "${PLIST}" BuildMachineOSBuild -string ${os_build} +cat "${PLIST}" > "${OUTPUT}" |