Skip to content

Commit 5f3c2bf

Browse files
committed
[build-script] Split execute_one_impl_action.
execute_one_impl_action is checking for the validity of its arguments, when it can be enforced by the structure by using smaller focused methods that trickle down into a common function. This structure will eventually allow different builders to participate in a script invocation. Each builder will be told to build/test/install, and they will not have to deal with anything else. The content of these smaller methods will end up as part of the builder that uses build-script-impl.
1 parent 207bf78 commit 5f3c2bf

File tree

1 file changed

+41
-26
lines changed

1 file changed

+41
-26
lines changed

utils/build-script

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -904,35 +904,18 @@ class BuildScriptInvocation(object):
904904
"""Execute the invocation with the configured arguments."""
905905

906906
# Convert to a build-script-impl invocation.
907-
(impl_env, impl_args) = self.convert_to_impl_arguments()
907+
(self.impl_env, self.impl_args) = self.convert_to_impl_arguments()
908908

909909
# If using the legacy implementation, delegate all behavior to
910910
# `build-script-impl`.
911911
if self.args.legacy_impl:
912912
# Execute the underlying build script implementation.
913-
shell.call_without_sleeping([build_script_impl] + impl_args,
914-
env=impl_env, echo=True)
913+
shell.call_without_sleeping([build_script_impl] + self.impl_args,
914+
env=self.impl_env, echo=True)
915915
return
916916

917917
# Otherwise, we compute and execute the individual actions ourselves.
918918

919-
def execute_one_impl_action(host=None, product_class=None, name=None):
920-
if host is None:
921-
assert (product_class is None and
922-
name == "merged-hosts-lipo"), "invalid action"
923-
action_name = name
924-
elif product_class is None:
925-
assert name in ("package", "extractsymbols"), "invalid action"
926-
action_name = "{}-{}".format(host.name, name)
927-
else:
928-
assert name is not None, "invalid action"
929-
action_name = "{}-{}-{}".format(
930-
host.name, product_class.product_name(), name)
931-
shell.call_without_sleeping(
932-
[build_script_impl] + impl_args + [
933-
"--only-execute", action_name],
934-
env=impl_env, echo=self.args.verbose_build)
935-
936919
# Compute the list of hosts to operate on.
937920
all_host_names = [
938921
self.args.host_target] + self.args.cross_compile_hosts
@@ -965,17 +948,17 @@ class BuildScriptInvocation(object):
965948
" ".join(config.swift_benchmark_run_targets)))
966949

967950
for product_class in impl_product_classes:
968-
execute_one_impl_action(host_target, product_class, "build")
951+
self._execute_build_action(host_target, product_class)
969952

970953
# Test...
971954
for host_target in all_hosts:
972955
for product_class in impl_product_classes:
973-
execute_one_impl_action(host_target, product_class, "test")
956+
self._execute_test_action(host_target, product_class)
974957

975958
# Install...
976959
for host_target in all_hosts:
977960
for product_class in impl_product_classes:
978-
execute_one_impl_action(host_target, product_class, "install")
961+
self._execute_install_action(host_target, product_class)
979962

980963
# Non-build-script-impl products...
981964
# Note: currently only supports building for the host.
@@ -996,14 +979,46 @@ class BuildScriptInvocation(object):
996979

997980
# Extract symbols...
998981
for host_target in all_hosts:
999-
execute_one_impl_action(host_target, name="extractsymbols")
982+
self._execute_extract_symbols_action(host_target)
1000983

1001984
# Package...
1002985
for host_target in all_hosts:
1003-
execute_one_impl_action(host_target, name="package")
986+
self._execute_package_action(host_target)
1004987

1005988
# Lipo...
1006-
execute_one_impl_action(name="merged-hosts-lipo")
989+
self._execute_merged_host_lipo_action()
990+
991+
def _execute_build_action(self, host_target, product_class):
992+
action_name = "{}-{}-build".format(host_target.name,
993+
product_class.product_name())
994+
self._execute_action(action_name)
995+
996+
def _execute_test_action(self, host_target, product_class):
997+
action_name = "{}-{}-test".format(host_target.name,
998+
product_class.product_name())
999+
self._execute_action(action_name)
1000+
1001+
def _execute_install_action(self, host_target, product_class):
1002+
action_name = "{}-{}-install".format(host_target.name,
1003+
product_class.product_name())
1004+
self._execute_action(action_name)
1005+
1006+
def _execute_extract_symbols_action(self, host_target):
1007+
action_name = "{}-extractsymbols".format(host_target.name)
1008+
self._execute_action(action_name)
1009+
1010+
def _execute_package_action(self, host_target):
1011+
action_name = "{}-package".format(host_target.name)
1012+
self._execute_action(action_name)
1013+
1014+
def _execute_merged_host_lipo_action(self):
1015+
self._execute_action("merged-hosts-lipo")
1016+
1017+
def _execute_action(self, action_name):
1018+
shell.call_without_sleeping(
1019+
[build_script_impl] + self.impl_args +
1020+
["--only-execute", action_name],
1021+
env=self.impl_env, echo=self.args.verbose_build)
10071022

10081023

10091024
# Provide a short delay so accidentally invoked clean builds can be canceled.

0 commit comments

Comments
 (0)