Skip to content

Commit 754521b

Browse files
committed
[build-script] Factor out helper for validating the args.
1 parent 893d353 commit 754521b

File tree

1 file changed

+56
-51
lines changed

1 file changed

+56
-51
lines changed

utils/build-script

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,55 @@ def call_without_sleeping(command, dry_run=False):
6868
class BuildScriptInvocation(object):
6969
"""Represent a single build script invocation."""
7070

71+
@staticmethod
72+
def validate_arguments(toolchain, args):
73+
if toolchain.cc is None or toolchain.cxx is None:
74+
diagnostics.fatal(
75+
"can't find clang (please install clang-3.5 or a "
76+
"later version)")
77+
78+
if toolchain.cmake is None:
79+
diagnostics.fatal("can't find CMake (please install CMake)")
80+
81+
if args.distcc:
82+
if toolchain.distcc is None:
83+
diagnostics.fatal(
84+
"can't find distcc (please install distcc)")
85+
if toolchain.distcc_pump is None:
86+
diagnostics.fatal(
87+
"can't find distcc-pump (please install distcc-pump)")
88+
89+
if args.host_target is None or args.stdlib_deployment_targets is None:
90+
diagnostics.fatal("unknown operating system")
91+
92+
if args.symbols_package:
93+
if not os.path.isabs(args.symbols_package):
94+
print(
95+
'--symbols-package must be an absolute path '
96+
'(was \'{}\')'.format(args.symbols_package))
97+
return 1
98+
if not args.install_symroot:
99+
diagnostics.fatal(
100+
"--install-symroot is required when specifying "
101+
"--symbols-package.")
102+
103+
if args.android:
104+
if args.android_ndk is None or \
105+
args.android_api_level is None or \
106+
args.android_icu_uc is None or \
107+
args.android_icu_uc_include is None or \
108+
args.android_icu_i18n is None or \
109+
args.android_icu_i18n_include is None:
110+
diagnostics.fatal(
111+
"when building for Android, --android-ndk, "
112+
"--android-ndk-version, --android-icu-uc, "
113+
"--android-icu-uc-include, --android-icu-i18n, "
114+
"and --android-icu-i18n-include must be specified")
115+
71116
@staticmethod
72117
def apply_default_arguments(toolchain, args):
73118
"""Preprocess an argument set to apply default behaviors."""
74-
119+
75120
# Build cmark if any cmark-related options were specified.
76121
if (args.cmark_build_variant is not None):
77122
args.build_cmark = True
@@ -237,7 +282,7 @@ class BuildScriptInvocation(object):
237282
if args.android:
238283
args.stdlib_deployment_targets.append(
239284
StdlibDeploymentTarget.Android.armv7)
240-
285+
241286
def __init__(self, toolchain, args):
242287
self.toolchain = toolchain
243288
self.args = args
@@ -286,7 +331,7 @@ class BuildScriptInvocation(object):
286331
# Create local shadows, for convenience.
287332
args = self.args
288333
toolchain = self.toolchain
289-
334+
290335
cmake = CMake(args=args,
291336
toolchain=self.toolchain)
292337

@@ -454,8 +499,8 @@ class BuildScriptInvocation(object):
454499
args.install_prefix),
455500
]
456501

457-
# If we have extra_swift_args, combine all of them together and then add
458-
# them as one command.
502+
# If we have extra_swift_args, combine all of them together and then
503+
# add them as one command.
459504
if args.extra_swift_args:
460505
impl_args += [
461506
"--extra-swift-args",
@@ -468,7 +513,7 @@ class BuildScriptInvocation(object):
468513
"--extra-cmake-options=%s" % ' '.join(
469514
pipes.quote(opt) for opt in args.extra_cmake_options)
470515
]
471-
516+
472517
if args.lto:
473518
impl_args += [
474519
"--llvm-enable-lto",
@@ -493,13 +538,12 @@ class BuildScriptInvocation(object):
493538

494539
return impl_args
495540

541+
496542
# Main entry point for the preset mode.
497543
def main_preset():
498544
parser = argparse.ArgumentParser(
499545
formatter_class=argparse.RawDescriptionHelpFormatter,
500-
description=
501-
502-
"""Builds Swift using a preset.""")
546+
description="""Builds Swift using a preset.""")
503547
parser.add_argument(
504548
"-n", "--dry-run",
505549
help="print the commands that would be executed, but do not execute "
@@ -1469,51 +1513,12 @@ details of the setups of other systems or automated environments.""")
14691513
if args.cmake is not None:
14701514
toolchain.cmake = args.cmake
14711515

1472-
if toolchain.cc is None or toolchain.cxx is None:
1473-
diagnostics.fatal(
1474-
"can't find clang (please install clang-3.5 or a later version)")
1475-
1476-
if toolchain.cmake is None:
1477-
diagnostics.fatal("can't find CMake (please install CMake)")
1478-
1479-
if args.distcc:
1480-
if toolchain.distcc is None:
1481-
diagnostics.fatal(
1482-
"can't find distcc (please install distcc)")
1483-
if toolchain.distcc_pump is None:
1484-
diagnostics.fatal(
1485-
"can't find distcc-pump (please install distcc-pump)")
1486-
1487-
if args.host_target is None or args.stdlib_deployment_targets is None:
1488-
diagnostics.fatal("unknown operating system")
1489-
1490-
if args.symbols_package:
1491-
if not os.path.isabs(args.symbols_package):
1492-
print(
1493-
'--symbols-package must be an absolute path '
1494-
'(was \'{}\')'.format(args.symbols_package))
1495-
return 1
1496-
if not args.install_symroot:
1497-
diagnostics.fatal(
1498-
"--install-symroot is required when specifying "
1499-
"--symbols-package.")
1500-
1501-
if args.android:
1502-
if args.android_ndk is None or \
1503-
args.android_api_level is None or \
1504-
args.android_icu_uc is None or \
1505-
args.android_icu_uc_include is None or \
1506-
args.android_icu_i18n is None or \
1507-
args.android_icu_i18n_include is None:
1508-
diagnostics.fatal("when building for Android, --android-ndk, "
1509-
"--android-ndk-version, --android-icu-uc, "
1510-
"--android-icu-uc-include, --android-icu-i18n, "
1511-
"and --android-icu-i18n-include must be "
1512-
"specified")
1516+
# Validate the arguments.
1517+
BuildScriptInvocation.validate_arguments(toolchain, args)
15131518

15141519
# Preprocess the arguments to apply defaults.
15151520
BuildScriptInvocation.apply_default_arguments(toolchain, args)
1516-
1521+
15171522
# Create the build script invocation.
15181523
invocation = BuildScriptInvocation(toolchain, args)
15191524

0 commit comments

Comments
 (0)