@@ -31,7 +31,6 @@ from build_swift.build_swift import presets
31
31
32
32
import six
33
33
34
- from swift_build_support .swift_build_support import diagnostics
35
34
from swift_build_support .swift_build_support import products
36
35
from swift_build_support .swift_build_support import shell
37
36
from swift_build_support .swift_build_support import targets
@@ -60,6 +59,25 @@ BUILD_SCRIPT_IMPL = os.path.join(
60
59
# -----------------------------------------------------------------------------
61
60
# Helpers
62
61
62
+ def print_note (message , stream = sys .stdout ):
63
+ """Writes a diagnostic message to the given stream. By default this
64
+ function outputs to stdout.
65
+ """
66
+
67
+ stream .write ('[{}] NOTE: {}\n ' .format (sys .argv [0 ], message ))
68
+ stream .flush ()
69
+
70
+
71
+ def fatal_error (message , stream = sys .stderr ):
72
+ """Writes a message to the given stream and exits. By default this
73
+ function outputs to stderr.
74
+ """
75
+
76
+ stream .write ('[{}] ERROR: {}\n ' .format (sys .argv [0 ], message ))
77
+ stream .flush ()
78
+ sys .exit (1 )
79
+
80
+
63
81
def clean_delay ():
64
82
"""Provide a short delay so accidentally invoked clean builds can be
65
83
canceled.
@@ -156,23 +174,23 @@ def tar(source, destination):
156
174
157
175
def validate_arguments (toolchain , args ):
158
176
if toolchain .cc is None or toolchain .cxx is None :
159
- diagnostics . fatal (
177
+ fatal_error (
160
178
"can't find clang (please install clang-3.5 or a "
161
179
"later version)" )
162
180
163
181
if toolchain .cmake is None :
164
- diagnostics . fatal ("can't find CMake (please install CMake)" )
182
+ fatal_error ("can't find CMake (please install CMake)" )
165
183
166
184
if args .distcc :
167
185
if toolchain .distcc is None :
168
- diagnostics . fatal (
186
+ fatal_error (
169
187
"can't find distcc (please install distcc)" )
170
188
if toolchain .distcc_pump is None :
171
- diagnostics . fatal (
189
+ fatal_error (
172
190
"can't find distcc-pump (please install distcc-pump)" )
173
191
174
192
if args .host_target is None or args .stdlib_deployment_targets is None :
175
- diagnostics . fatal ("unknown operating system" )
193
+ fatal_error ("unknown operating system" )
176
194
177
195
if args .symbols_package :
178
196
if not os .path .isabs (args .symbols_package ):
@@ -181,7 +199,7 @@ def validate_arguments(toolchain, args):
181
199
'(was \' {}\' )' .format (args .symbols_package ))
182
200
return 1
183
201
if not args .install_symroot :
184
- diagnostics . fatal (
202
+ fatal_error (
185
203
"--install-symroot is required when specifying "
186
204
"--symbols-package." )
187
205
@@ -193,7 +211,7 @@ def validate_arguments(toolchain, args):
193
211
args .android_icu_i18n is None or \
194
212
args .android_icu_i18n_include is None or \
195
213
args .android_icu_data is None :
196
- diagnostics . fatal (
214
+ fatal_error (
197
215
"when building for Android, --android-ndk, "
198
216
"--android-api-level, --android-icu-uc, "
199
217
"--android-icu-uc-include, --android-icu-i18n, "
@@ -210,7 +228,7 @@ def validate_arguments(toolchain, args):
210
228
has_target_needing_toolchain = \
211
229
bool (sum (getattr (args , x ) for x in targets_needing_toolchain ))
212
230
if args .legacy_impl and has_target_needing_toolchain :
213
- diagnostics . fatal (
231
+ fatal_error (
214
232
"--legacy-impl is incompatible with building packages needing "
215
233
"a toolchain (%s)" % ", " .join (targets_needing_toolchain ))
216
234
@@ -351,7 +369,7 @@ class BuildScriptInvocation(object):
351
369
352
370
def build_ninja (self ):
353
371
if not os .path .exists (self .workspace .source_dir ("ninja" )):
354
- diagnostics . fatal (
372
+ fatal_error (
355
373
"can't find source directory for ninja "
356
374
"(tried %s)" % (self .workspace .source_dir ("ninja" )))
357
375
@@ -434,7 +452,7 @@ class BuildScriptInvocation(object):
434
452
source_dir = self .workspace .source_dir (product_source_name )
435
453
436
454
if not os .path .exists (source_dir ):
437
- diagnostics . fatal (
455
+ fatal_error (
438
456
"can't find source directory for %s "
439
457
"(tried %s)" % (product_name , source_dir ))
440
458
@@ -745,7 +763,7 @@ class BuildScriptInvocation(object):
745
763
try :
746
764
config = HostSpecificConfiguration (host_target , args )
747
765
except argparse .ArgumentError as e :
748
- exit_rejecting_arguments (e . message )
766
+ exit_rejecting_arguments (six . text_type ( e ) )
749
767
750
768
# Convert into `build-script-impl` style variables.
751
769
options [host_target ] = {
@@ -850,7 +868,7 @@ class BuildScriptInvocation(object):
850
868
try :
851
869
config = HostSpecificConfiguration (host_target .name , self .args )
852
870
except argparse .ArgumentError as e :
853
- exit_rejecting_arguments (e . message )
871
+ exit_rejecting_arguments (six . text_type ( e ) )
854
872
print ("Building the standard library for: {}" .format (
855
873
" " .join (config .swift_stdlib_build_targets )))
856
874
if config .swift_test_run_targets and (
@@ -1047,7 +1065,7 @@ def main_preset():
1047
1065
try :
1048
1066
preset_parser .read_files (args .preset_file_names )
1049
1067
except presets .PresetError as e :
1050
- diagnostics . fatal ( e . message )
1068
+ fatal_error ( six . text_type ( e ) )
1051
1069
1052
1070
if args .show_presets :
1053
1071
for name in sorted (preset_parser .preset_names ,
@@ -1056,7 +1074,7 @@ def main_preset():
1056
1074
return 0
1057
1075
1058
1076
if not args .preset :
1059
- diagnostics . fatal ("missing --preset option" )
1077
+ fatal_error ("missing --preset option" )
1060
1078
1061
1079
args .preset_substitutions = {}
1062
1080
for arg in args .preset_substitutions_raw :
@@ -1068,12 +1086,12 @@ def main_preset():
1068
1086
args .preset ,
1069
1087
vars = args .preset_substitutions )
1070
1088
except presets .PresetError as e :
1071
- diagnostics . fatal ( e . message )
1089
+ fatal_error ( six . text_type ( e ) )
1072
1090
1073
1091
preset_args = migration .migrate_swift_sdks (preset .args )
1074
1092
1075
1093
if args .distcc and (args .cmake_c_launcher or args .cmake_cxx_launcher ):
1076
- diagnostics . fatal (
1094
+ fatal_error (
1077
1095
'--distcc can not be used with' +
1078
1096
' --cmake-c-launcher or --cmake-cxx-launcher' )
1079
1097
@@ -1106,7 +1124,7 @@ def main_preset():
1106
1124
if args .reconfigure :
1107
1125
build_script_args += ["--reconfigure" ]
1108
1126
1109
- diagnostics . note ('using preset "{}", which expands to \n \n {}\n ' .format (
1127
+ print_note ('using preset "{}", which expands to \n \n {}\n ' .format (
1110
1128
args .preset , printable_command ))
1111
1129
shell .call_without_sleeping (build_script_args )
1112
1130
return 0
@@ -1139,7 +1157,7 @@ def main_normal():
1139
1157
xcrun_toolchain = os .environ .get ('TOOLCHAINS' ,
1140
1158
defaults .DARWIN_XCRUN_TOOLCHAIN )
1141
1159
1142
- diagnostics . note ('Using toolchain {}' .format (xcrun_toolchain ))
1160
+ print_note ('Using toolchain {}' .format (xcrun_toolchain ))
1143
1161
args .darwin_xcrun_toolchain = xcrun_toolchain
1144
1162
1145
1163
toolchain = host_toolchain (xcrun_toolchain = args .darwin_xcrun_toolchain )
@@ -1223,12 +1241,12 @@ def main_normal():
1223
1241
1224
1242
def main ():
1225
1243
if not SWIFT_SOURCE_ROOT :
1226
- diagnostics . fatal (
1244
+ fatal_error (
1227
1245
"could not infer source root directory " +
1228
1246
"(forgot to set $SWIFT_SOURCE_ROOT environment variable?)" )
1229
1247
1230
1248
if not os .path .isdir (SWIFT_SOURCE_ROOT ):
1231
- diagnostics . fatal (
1249
+ fatal_error (
1232
1250
"source root directory \' " + SWIFT_SOURCE_ROOT +
1233
1251
"\' does not exist " +
1234
1252
"(forgot to set $SWIFT_SOURCE_ROOT environment variable?)" )
0 commit comments