Skip to content

Commit e8f2119

Browse files
authored
Merge pull request swiftlang#29603 from Rostepher/remove-diagnostics-module
[Build System: build-script] Remove the diagnostics module from swift_build_support.
2 parents ff49d97 + 4450ce3 commit e8f2119

File tree

5 files changed

+55
-76
lines changed

5 files changed

+55
-76
lines changed

utils/build-script

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ from build_swift.build_swift import presets
3131

3232
import six
3333

34-
from swift_build_support.swift_build_support import diagnostics
3534
from swift_build_support.swift_build_support import products
3635
from swift_build_support.swift_build_support import shell
3736
from swift_build_support.swift_build_support import targets
@@ -60,6 +59,25 @@ BUILD_SCRIPT_IMPL = os.path.join(
6059
# -----------------------------------------------------------------------------
6160
# Helpers
6261

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+
6381
def clean_delay():
6482
"""Provide a short delay so accidentally invoked clean builds can be
6583
canceled.
@@ -156,23 +174,23 @@ def tar(source, destination):
156174

157175
def validate_arguments(toolchain, args):
158176
if toolchain.cc is None or toolchain.cxx is None:
159-
diagnostics.fatal(
177+
fatal_error(
160178
"can't find clang (please install clang-3.5 or a "
161179
"later version)")
162180

163181
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)")
165183

166184
if args.distcc:
167185
if toolchain.distcc is None:
168-
diagnostics.fatal(
186+
fatal_error(
169187
"can't find distcc (please install distcc)")
170188
if toolchain.distcc_pump is None:
171-
diagnostics.fatal(
189+
fatal_error(
172190
"can't find distcc-pump (please install distcc-pump)")
173191

174192
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")
176194

177195
if args.symbols_package:
178196
if not os.path.isabs(args.symbols_package):
@@ -181,7 +199,7 @@ def validate_arguments(toolchain, args):
181199
'(was \'{}\')'.format(args.symbols_package))
182200
return 1
183201
if not args.install_symroot:
184-
diagnostics.fatal(
202+
fatal_error(
185203
"--install-symroot is required when specifying "
186204
"--symbols-package.")
187205

@@ -193,7 +211,7 @@ def validate_arguments(toolchain, args):
193211
args.android_icu_i18n is None or \
194212
args.android_icu_i18n_include is None or \
195213
args.android_icu_data is None:
196-
diagnostics.fatal(
214+
fatal_error(
197215
"when building for Android, --android-ndk, "
198216
"--android-api-level, --android-icu-uc, "
199217
"--android-icu-uc-include, --android-icu-i18n, "
@@ -210,7 +228,7 @@ def validate_arguments(toolchain, args):
210228
has_target_needing_toolchain = \
211229
bool(sum(getattr(args, x) for x in targets_needing_toolchain))
212230
if args.legacy_impl and has_target_needing_toolchain:
213-
diagnostics.fatal(
231+
fatal_error(
214232
"--legacy-impl is incompatible with building packages needing "
215233
"a toolchain (%s)" % ", ".join(targets_needing_toolchain))
216234

@@ -351,7 +369,7 @@ class BuildScriptInvocation(object):
351369

352370
def build_ninja(self):
353371
if not os.path.exists(self.workspace.source_dir("ninja")):
354-
diagnostics.fatal(
372+
fatal_error(
355373
"can't find source directory for ninja "
356374
"(tried %s)" % (self.workspace.source_dir("ninja")))
357375

@@ -434,7 +452,7 @@ class BuildScriptInvocation(object):
434452
source_dir = self.workspace.source_dir(product_source_name)
435453

436454
if not os.path.exists(source_dir):
437-
diagnostics.fatal(
455+
fatal_error(
438456
"can't find source directory for %s "
439457
"(tried %s)" % (product_name, source_dir))
440458

@@ -745,7 +763,7 @@ class BuildScriptInvocation(object):
745763
try:
746764
config = HostSpecificConfiguration(host_target, args)
747765
except argparse.ArgumentError as e:
748-
exit_rejecting_arguments(e.message)
766+
exit_rejecting_arguments(six.text_type(e))
749767

750768
# Convert into `build-script-impl` style variables.
751769
options[host_target] = {
@@ -850,7 +868,7 @@ class BuildScriptInvocation(object):
850868
try:
851869
config = HostSpecificConfiguration(host_target.name, self.args)
852870
except argparse.ArgumentError as e:
853-
exit_rejecting_arguments(e.message)
871+
exit_rejecting_arguments(six.text_type(e))
854872
print("Building the standard library for: {}".format(
855873
" ".join(config.swift_stdlib_build_targets)))
856874
if config.swift_test_run_targets and (
@@ -1047,7 +1065,7 @@ def main_preset():
10471065
try:
10481066
preset_parser.read_files(args.preset_file_names)
10491067
except presets.PresetError as e:
1050-
diagnostics.fatal(e.message)
1068+
fatal_error(six.text_type(e))
10511069

10521070
if args.show_presets:
10531071
for name in sorted(preset_parser.preset_names,
@@ -1056,7 +1074,7 @@ def main_preset():
10561074
return 0
10571075

10581076
if not args.preset:
1059-
diagnostics.fatal("missing --preset option")
1077+
fatal_error("missing --preset option")
10601078

10611079
args.preset_substitutions = {}
10621080
for arg in args.preset_substitutions_raw:
@@ -1068,12 +1086,12 @@ def main_preset():
10681086
args.preset,
10691087
vars=args.preset_substitutions)
10701088
except presets.PresetError as e:
1071-
diagnostics.fatal(e.message)
1089+
fatal_error(six.text_type(e))
10721090

10731091
preset_args = migration.migrate_swift_sdks(preset.args)
10741092

10751093
if args.distcc and (args.cmake_c_launcher or args.cmake_cxx_launcher):
1076-
diagnostics.fatal(
1094+
fatal_error(
10771095
'--distcc can not be used with' +
10781096
' --cmake-c-launcher or --cmake-cxx-launcher')
10791097

@@ -1106,7 +1124,7 @@ def main_preset():
11061124
if args.reconfigure:
11071125
build_script_args += ["--reconfigure"]
11081126

1109-
diagnostics.note('using preset "{}", which expands to \n\n{}\n'.format(
1127+
print_note('using preset "{}", which expands to \n\n{}\n'.format(
11101128
args.preset, printable_command))
11111129
shell.call_without_sleeping(build_script_args)
11121130
return 0
@@ -1139,7 +1157,7 @@ def main_normal():
11391157
xcrun_toolchain = os.environ.get('TOOLCHAINS',
11401158
defaults.DARWIN_XCRUN_TOOLCHAIN)
11411159

1142-
diagnostics.note('Using toolchain {}'.format(xcrun_toolchain))
1160+
print_note('Using toolchain {}'.format(xcrun_toolchain))
11431161
args.darwin_xcrun_toolchain = xcrun_toolchain
11441162

11451163
toolchain = host_toolchain(xcrun_toolchain=args.darwin_xcrun_toolchain)
@@ -1223,12 +1241,12 @@ def main_normal():
12231241

12241242
def main():
12251243
if not SWIFT_SOURCE_ROOT:
1226-
diagnostics.fatal(
1244+
fatal_error(
12271245
"could not infer source root directory " +
12281246
"(forgot to set $SWIFT_SOURCE_ROOT environment variable?)")
12291247

12301248
if not os.path.isdir(SWIFT_SOURCE_ROOT):
1231-
diagnostics.fatal(
1249+
fatal_error(
12321250
"source root directory \'" + SWIFT_SOURCE_ROOT +
12331251
"\' does not exist " +
12341252
"(forgot to set $SWIFT_SOURCE_ROOT environment variable?)")

utils/swift_build_support/swift_build_support/__init__.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,3 @@
1414
# utils/swift_build_support/ directory as a module.
1515
#
1616
# ----------------------------------------------------------------------------
17-
18-
__all__ = [
19-
"cmake",
20-
"debug",
21-
"diagnostics",
22-
"host_specific_configuration",
23-
"tar",
24-
"targets",
25-
"toolchain",
26-
"xcrun",
27-
]

utils/swift_build_support/swift_build_support/diagnostics.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

utils/swift_build_support/swift_build_support/host_specific_configuration.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
#
1111
# ----------------------------------------------------------------------------
1212

13+
import sys
1314
from argparse import ArgumentError
1415

15-
import diagnostics
16-
1716
from .targets import StdlibDeploymentTarget
1817

1918

@@ -64,8 +63,10 @@ def __init__(self, host_target, args):
6463
deployment_target = StdlibDeploymentTarget.get_target_for_name(
6564
deployment_target_name)
6665
if deployment_target is None:
67-
diagnostics.fatal("unknown target: %r" % (
68-
deployment_target_name,))
66+
sys.stderr.write('ERROR: unknown target: {}\n'.format(
67+
deployment_target_name))
68+
sys.stderr.flush()
69+
sys.exit(1)
6970

7071
# Add the SDK to use.
7172
deployment_platform = deployment_target.platform

utils/swift_build_support/swift_build_support/shell.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@
2323
import sys
2424
from contextlib import contextmanager
2525

26-
from . import diagnostics
27-
2826

2927
DEVNULL = getattr(subprocess, 'DEVNULL', subprocess.PIPE)
3028

3129
dry_run = False
3230

3331

32+
def _fatal_error(message):
33+
"""Raises a SystemExit error with the given message.
34+
"""
35+
36+
raise SystemExit('ERROR: {}\n'.format(message))
37+
38+
3439
def _quote(arg):
3540
return pipes.quote(str(arg))
3641

@@ -84,11 +89,11 @@ def call(command, stderr=None, env=None, dry_run=None, echo=True):
8489
try:
8590
subprocess.check_call(command, env=_env, stderr=stderr)
8691
except subprocess.CalledProcessError as e:
87-
diagnostics.fatal(
92+
_fatal_error(
8893
"command terminated with a non-zero exit status " +
8994
str(e.returncode) + ", aborting")
9095
except OSError as e:
91-
diagnostics.fatal(
96+
_fatal_error(
9297
"could not execute '" + quote_command(command) +
9398
"': " + e.strerror)
9499

@@ -135,13 +140,13 @@ def capture(command, stderr=None, env=None, dry_run=None, echo=True,
135140
return e.output
136141
if optional:
137142
return None
138-
diagnostics.fatal(
143+
_fatal_error(
139144
"command terminated with a non-zero exit status " +
140145
str(e.returncode) + ", aborting")
141146
except OSError as e:
142147
if optional:
143148
return None
144-
diagnostics.fatal(
149+
_fatal_error(
145150
"could not execute '" + quote_command(command) +
146151
"': " + e.strerror)
147152

0 commit comments

Comments
 (0)