1
1
#!/usr/bin/env python
2
- # utils/build-script - The ultimate tool for building Swift -*- python -*-
3
- #
2
+
4
3
# This source file is part of the Swift.org open source project
5
4
#
6
- # Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5
+ # Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
7
6
# Licensed under Apache License v2.0 with Runtime Library Exception
8
7
#
9
8
# See https://swift.org/LICENSE.txt for license information
10
9
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11
10
12
- from __future__ import print_function
11
+
12
+ """
13
+ The ultimate tool for building Swift.
14
+ """
15
+
16
+
17
+ from __future__ import absolute_import , print_function , unicode_literals
13
18
14
19
import json
15
20
import os
@@ -26,13 +31,11 @@ from build_swift.build_swift import presets
26
31
27
32
import six
28
33
29
- from swift_build_support .swift_build_support import (
30
- diagnostics ,
31
- products ,
32
- shell ,
33
- targets ,
34
- workspace
35
- )
34
+ from swift_build_support .swift_build_support import diagnostics
35
+ from swift_build_support .swift_build_support import products
36
+ from swift_build_support .swift_build_support import shell
37
+ from swift_build_support .swift_build_support import targets
38
+ from swift_build_support .swift_build_support import workspace
36
39
from swift_build_support .swift_build_support .SwiftBuildSupport import (
37
40
HOME ,
38
41
SWIFT_BUILD_ROOT ,
@@ -46,10 +49,30 @@ from swift_build_support.swift_build_support.targets import \
46
49
StdlibDeploymentTarget
47
50
from swift_build_support .swift_build_support .toolchain import host_toolchain
48
51
49
- build_script_impl = os .path .join (
52
+
53
+ # -----------------------------------------------------------------------------
54
+ # Constants
55
+
56
+ BUILD_SCRIPT_IMPL = os .path .join (
50
57
SWIFT_SOURCE_ROOT , SWIFT_REPO_NAME , "utils" , "build-script-impl" )
51
58
52
59
60
+ # -----------------------------------------------------------------------------
61
+ # Helpers
62
+
63
+ def clean_delay ():
64
+ """Provide a short delay so accidentally invoked clean builds can be
65
+ canceled.
66
+ """
67
+
68
+ sys .stdout .write ('Starting clean build in ' )
69
+ for i in range (3 , 0 , - 1 ):
70
+ sys .stdout .write ('\b %d' % i )
71
+ sys .stdout .flush ()
72
+ time .sleep (1 )
73
+ print ('\b \b \b \b now.' )
74
+
75
+
53
76
def exit_rejecting_arguments (message , parser = None ):
54
77
print (message , file = sys .stderr )
55
78
if parser :
@@ -107,9 +130,12 @@ def tar(source, destination):
107
130
shell .call (args + [source ], stderr = shell .DEVNULL )
108
131
109
132
110
- class BuildScriptInvocation (object ):
133
+ # -----------------------------------------------------------------------------
134
+ # Build Script Impl Wrapping
111
135
112
- """Represent a single build script invocation."""
136
+ class BuildScriptInvocation (object ):
137
+ """Represent a single build script invocation.
138
+ """
113
139
114
140
@staticmethod
115
141
def validate_arguments (toolchain , args ):
@@ -290,7 +316,7 @@ class BuildScriptInvocation(object):
290
316
'-DSWIFT_DARWIN_MODULE_ARCHS:STRING={}' .format (
291
317
args .swift_darwin_module_archs ))
292
318
293
- # ---
319
+ # ---------------------------------------------------------------------- ---
294
320
295
321
def __init__ (self , toolchain , args ):
296
322
self .toolchain = toolchain
@@ -795,7 +821,7 @@ class BuildScriptInvocation(object):
795
821
# `build-script-impl`.
796
822
if self .args .legacy_impl :
797
823
# Execute the underlying build script implementation.
798
- shell .call_without_sleeping ([build_script_impl ] + self .impl_args ,
824
+ shell .call_without_sleeping ([BUILD_SCRIPT_IMPL ] + self .impl_args ,
799
825
env = self .impl_env , echo = True )
800
826
return
801
827
@@ -917,23 +943,15 @@ class BuildScriptInvocation(object):
917
943
918
944
def _execute_action (self , action_name ):
919
945
shell .call_without_sleeping (
920
- [build_script_impl ] + self .impl_args +
946
+ [BUILD_SCRIPT_IMPL ] + self .impl_args +
921
947
["--only-execute" , action_name ],
922
948
env = self .impl_env , echo = self .args .verbose_build )
923
949
924
950
925
- # Provide a short delay so accidentally invoked clean builds can be canceled.
926
- def clean_delay ():
927
- sys .stdout .write ('Starting clean build in ' )
928
- for i in range (3 , 0 , - 1 ):
929
- sys .stdout .write ('\b %d' % i )
930
- sys .stdout .flush ()
931
- time .sleep (1 )
932
- print ('\b \b \b \b now.' )
951
+ # -----------------------------------------------------------------------------
952
+ # Main (preset)
933
953
934
-
935
- # Main entry point for the preset mode.
936
- def main_preset ():
954
+ def parse_preset_args ():
937
955
parser = argparse .ArgumentParser (
938
956
formatter_class = argparse .RawDescriptionHelpFormatter ,
939
957
description = """Builds Swift using a preset.""" )
@@ -1006,7 +1024,13 @@ def main_preset():
1006
1024
help = "Reconfigure all projects as we build" ,
1007
1025
action = "store_true" ,
1008
1026
default = False )
1009
- args = parser .parse_args ()
1027
+
1028
+ return parser .parse_args ()
1029
+
1030
+
1031
+ def main_preset ():
1032
+ args = parse_preset_args ()
1033
+
1010
1034
if len (args .preset_file_names ) == 0 :
1011
1035
args .preset_file_names = [
1012
1036
os .path .join (
@@ -1088,7 +1112,9 @@ def main_preset():
1088
1112
return 0
1089
1113
1090
1114
1091
- # Main entry point for the normal mode.
1115
+ # -----------------------------------------------------------------------------
1116
+ # Main (normal)
1117
+
1092
1118
def main_normal ():
1093
1119
parser = driver_arguments .create_argument_parser ()
1094
1120
@@ -1098,7 +1124,7 @@ def main_normal():
1098
1124
# If we received any impl args, check if `build-script-impl` would
1099
1125
# accept them or not before any further processing.
1100
1126
try :
1101
- migration .check_impl_args (build_script_impl ,
1127
+ migration .check_impl_args (BUILD_SCRIPT_IMPL ,
1102
1128
args .build_script_impl_args )
1103
1129
except ValueError as e :
1104
1130
exit_rejecting_arguments (e , parser )
@@ -1193,6 +1219,8 @@ def main_normal():
1193
1219
return 0
1194
1220
1195
1221
1222
+ # -----------------------------------------------------------------------------
1223
+
1196
1224
def main ():
1197
1225
if not SWIFT_SOURCE_ROOT :
1198
1226
diagnostics .fatal (
0 commit comments