Add bazel flags to support on-device testing.
PiperOrigin-RevId: 195843181
diff --git a/src/TulsiGenerator/Scripts/bazel_build.py b/src/TulsiGenerator/Scripts/bazel_build.py
index 04c2d9b..db47da6 100755
--- a/src/TulsiGenerator/Scripts/bazel_build.py
+++ b/src/TulsiGenerator/Scripts/bazel_build.py
@@ -33,6 +33,7 @@
from apfs_clone_copy import CopyOnWrite
import bazel_build_events
+from bazel_build_flags import bazel_build_flags
import bazel_options
from bootstrap_lldbinit import BootstrapLLDBInit
from bootstrap_lldbinit import TULSI_LLDBINIT_FILE
@@ -234,8 +235,8 @@
else:
self._WarnUnknownPlatform()
config_platform = 'ios'
- self.build_options[_OptionsParser.ALL_CONFIGS].append(
- '--config=%s_%s' % (config_platform, arch))
+ self.build_options[_OptionsParser.ALL_CONFIGS].extend(
+ bazel_build_flags(config_platform, arch))
self.verbose = 0
self.bazel_bin_path = 'bazel-bin'
@@ -534,7 +535,7 @@
self.update_symbol_cache = UpdateSymbolCache()
# Target architecture. Must be defined for correct setting of
- # the --config flag
+ # the --cpu flag
self.arch = os.environ.get('CURRENT_ARCH')
if not self.arch:
_PrintXcodeError('Tulsi requires env variable CURRENT_ARCH to be '
diff --git a/src/TulsiGenerator/Scripts/bazel_build_flags.py b/src/TulsiGenerator/Scripts/bazel_build_flags.py
new file mode 100644
index 0000000..e98a8bb
--- /dev/null
+++ b/src/TulsiGenerator/Scripts/bazel_build_flags.py
@@ -0,0 +1,44 @@
+# Copyright 2016 The Tulsi Authors. 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.
+
+"""Bazel flags for architecture / platform combinations.
+
+Every platform has the --apple_platform_type flag set (macOS uses 'darwin'
+instead of 'macos').
+
+macOS and iOS use the base --cpu flag, while tvOS and watchOS use --tvos_cpus
+and --watchos_cpus respectively.
+
+For iOS apps, the --watchos_cpus flag is also set separately.
+"""
+
+
+def bazel_build_flags(config_platform, arch):
+ """Returns an array of command line flags for bazel."""
+ if config_platform == 'darwin':
+ options = ['--apple_platform_type=macos']
+ else:
+ options = ['--apple_platform_type=%s' % config_platform]
+ if config_platform in ['ios', 'darwin']:
+ options.append('--cpu=%s_%s' % (config_platform, arch))
+ else:
+ options.append('--%scpus=%s' % (config_platform, arch))
+ # Set watchos_cpus for bundled watch apps.
+ if config_platform == 'ios':
+ if arch.startswith('arm'):
+ options.append('--watchos_cpus=armv7k')
+ else:
+ options.append('--watchos_cpus=i386')
+
+ return options
diff --git a/src/TulsiGenerator/TulsiXcodeProjectGenerator.swift b/src/TulsiGenerator/TulsiXcodeProjectGenerator.swift
index de2f28a..f4ca13a 100644
--- a/src/TulsiGenerator/TulsiXcodeProjectGenerator.swift
+++ b/src/TulsiGenerator/TulsiXcodeProjectGenerator.swift
@@ -50,6 +50,7 @@
buildScript: bundle.url(forResource: "bazel_build", withExtension: "py")!,
cleanScript: bundle.url(forResource: "bazel_clean", withExtension: "sh")!,
extraBuildScripts: [bundle.url(forResource: "tulsi_logging", withExtension: "py")!,
+ bundle.url(forResource: "bazel_build_flags", withExtension: "py")!,
bundle.url(forResource: "bazel_options", withExtension: "py")!,
bundle.url(forResource: "apfs_clone_copy", withExtension: "py")!,
bundle.url(forResource: "bazel_build_events", withExtension: "py")!,