Skip to content

Commit 5ba7b40

Browse files
authored
Merge pull request #587 from apple/add-prerequisite-xcode-targets
Add pretargets field in XcodeBuild action
2 parents 41d5699 + 080e05e commit 5ba7b40

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

project_future.py

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ def test(self, sandbox_profile, stdout=sys.stdout, stderr=sys.stderr,
8686
class XcodeTarget(ProjectTarget):
8787
"""An Xcode workspace scheme."""
8888

89-
def __init__(self, swiftc, project, target, destination, env,
89+
def __init__(self, swiftc, project, target, destination, pretargets, env,
9090
added_xcodebuild_flags, is_workspace, has_scheme,
9191
clean_build):
9292
self._swiftc = swiftc
9393
self._project = project
9494
self._target = target
9595
self._destination = destination
96+
self._pretargets = pretargets
9697
self._env = env
9798
self._added_xcodebuild_flags = added_xcodebuild_flags
9899
self._is_workspace = is_workspace
@@ -124,7 +125,7 @@ def get_build_command(self, incremental=False):
124125
build_dir = os.path.join(build_parent_dir, 'build')
125126

126127
build = []
127-
if self._clean_build and not incremental:
128+
if self._clean_build and not incremental and not self._pretargets:
128129
build += ['clean']
129130
build += ['build']
130131

@@ -154,6 +155,55 @@ def get_build_command(self, incremental=False):
154155

155156
return command
156157

158+
def get_prebuild_command(self, incremental=False):
159+
project_param = self.project_param
160+
target_param = self.target_param
161+
try:
162+
build_parent_dir = common.check_execute_output([
163+
'git', '-C', os.path.dirname(self._project),
164+
'rev-parse', '--show-toplevel']).rstrip()
165+
except common.ExecuteCommandFailure as error:
166+
build_parent_dir = os.path.dirname(self._project)
167+
168+
build_dir = os.path.join(build_parent_dir, 'build')
169+
170+
build = []
171+
if self._clean_build and not incremental:
172+
build += ['clean']
173+
174+
if self._pretargets:
175+
build += ['build']
176+
177+
dir_override = []
178+
if self._has_scheme:
179+
dir_override += ['-derivedDataPath', build_dir]
180+
elif not 'SYMROOT' in self._env:
181+
dir_override += ['SYMROOT=' + build_dir]
182+
dir_override += [k + "=" + v for k, v in self._env.items()]
183+
184+
project_target_params = [project_param, self._project,
185+
'-destination', self._destination]
186+
for pretarget in self._pretargets:
187+
project_target_params += [target_param, pretarget]
188+
189+
command = (['xcodebuild']
190+
+ build
191+
+ project_target_params
192+
+ dir_override
193+
+ ['CODE_SIGN_IDENTITY=',
194+
'CODE_SIGNING_REQUIRED=NO',
195+
'ENTITLEMENTS_REQUIRED=NO',
196+
'ENABLE_BITCODE=NO',
197+
'INDEX_ENABLE_DATA_STORE=NO',
198+
'GCC_TREAT_WARNINGS_AS_ERRORS=NO',
199+
'SWIFT_TREAT_WARNINGS_AS_ERRORS=NO'])
200+
command += self._added_xcodebuild_flags
201+
202+
if self._destination == 'generic/platform=watchOS':
203+
command += ['ARCHS=armv7k']
204+
205+
return command
206+
157207
def get_test_command(self, incremental=False):
158208
project_param = self.project_param
159209
target_param = self.target_param
@@ -180,6 +230,10 @@ def build(self, sandbox_profile, stdout=sys.stdout, stderr=sys.stderr,
180230
incremental=False, time_reporter=None):
181231
"""Build the project target."""
182232

233+
if self._pretargets:
234+
common.check_execute(self.get_prebuild_command(incremental=incremental),
235+
sandbox_profile=sandbox_profile,
236+
stdout=stdout, stderr=stdout)
183237
start_time = None
184238
if time_reporter:
185239
start_time = time.time()
@@ -360,6 +414,10 @@ def dispatch(root_path, repo, action, swiftc, swift_version,
360414
if 'environment' in action:
361415
build_env = action['environment']
362416

417+
pretargets = []
418+
if 'pretargets' in action:
419+
pretargets = action['pretargets']
420+
363421
other_swift_flags = []
364422
if swift_version:
365423
if '.' not in swift_version:
@@ -393,6 +451,7 @@ def dispatch(root_path, repo, action, swiftc, swift_version,
393451
project_path,
394452
action[match.group(3).lower()],
395453
action['destination'],
454+
pretargets,
396455
build_env,
397456
initial_xcodebuild_flags + added_xcodebuild_flags,
398457
is_workspace,

0 commit comments

Comments
 (0)