Skip to content

[Build System: build-script] Remove the diagnostics module from swift_build_support. #29603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 39 additions & 21 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ from build_swift.build_swift import presets

import six

from swift_build_support.swift_build_support import diagnostics
from swift_build_support.swift_build_support import products
from swift_build_support.swift_build_support import shell
from swift_build_support.swift_build_support import targets
Expand Down Expand Up @@ -60,6 +59,25 @@ BUILD_SCRIPT_IMPL = os.path.join(
# -----------------------------------------------------------------------------
# Helpers

def print_note(message, stream=sys.stdout):
"""Writes a diagnostic message to the given stream. By default this
function outputs to stdout.
"""

stream.write('[{}] NOTE: {}\n'.format(sys.argv[0], message))
stream.flush()


def fatal_error(message, stream=sys.stderr):
"""Writes a message to the given stream and exits. By default this
function outputs to stderr.
"""

stream.write('[{}] ERROR: {}\n'.format(sys.argv[0], message))
stream.flush()
sys.exit(1)


def clean_delay():
"""Provide a short delay so accidentally invoked clean builds can be
canceled.
Expand Down Expand Up @@ -156,23 +174,23 @@ def tar(source, destination):

def validate_arguments(toolchain, args):
if toolchain.cc is None or toolchain.cxx is None:
diagnostics.fatal(
fatal_error(
"can't find clang (please install clang-3.5 or a "
"later version)")

if toolchain.cmake is None:
diagnostics.fatal("can't find CMake (please install CMake)")
fatal_error("can't find CMake (please install CMake)")

if args.distcc:
if toolchain.distcc is None:
diagnostics.fatal(
fatal_error(
"can't find distcc (please install distcc)")
if toolchain.distcc_pump is None:
diagnostics.fatal(
fatal_error(
"can't find distcc-pump (please install distcc-pump)")

if args.host_target is None or args.stdlib_deployment_targets is None:
diagnostics.fatal("unknown operating system")
fatal_error("unknown operating system")

if args.symbols_package:
if not os.path.isabs(args.symbols_package):
Expand All @@ -181,7 +199,7 @@ def validate_arguments(toolchain, args):
'(was \'{}\')'.format(args.symbols_package))
return 1
if not args.install_symroot:
diagnostics.fatal(
fatal_error(
"--install-symroot is required when specifying "
"--symbols-package.")

Expand All @@ -193,7 +211,7 @@ def validate_arguments(toolchain, args):
args.android_icu_i18n is None or \
args.android_icu_i18n_include is None or \
args.android_icu_data is None:
diagnostics.fatal(
fatal_error(
"when building for Android, --android-ndk, "
"--android-api-level, --android-icu-uc, "
"--android-icu-uc-include, --android-icu-i18n, "
Expand All @@ -210,7 +228,7 @@ def validate_arguments(toolchain, args):
has_target_needing_toolchain = \
bool(sum(getattr(args, x) for x in targets_needing_toolchain))
if args.legacy_impl and has_target_needing_toolchain:
diagnostics.fatal(
fatal_error(
"--legacy-impl is incompatible with building packages needing "
"a toolchain (%s)" % ", ".join(targets_needing_toolchain))

Expand Down Expand Up @@ -351,7 +369,7 @@ class BuildScriptInvocation(object):

def build_ninja(self):
if not os.path.exists(self.workspace.source_dir("ninja")):
diagnostics.fatal(
fatal_error(
"can't find source directory for ninja "
"(tried %s)" % (self.workspace.source_dir("ninja")))

Expand Down Expand Up @@ -434,7 +452,7 @@ class BuildScriptInvocation(object):
source_dir = self.workspace.source_dir(product_source_name)

if not os.path.exists(source_dir):
diagnostics.fatal(
fatal_error(
"can't find source directory for %s "
"(tried %s)" % (product_name, source_dir))

Expand Down Expand Up @@ -745,7 +763,7 @@ class BuildScriptInvocation(object):
try:
config = HostSpecificConfiguration(host_target, args)
except argparse.ArgumentError as e:
exit_rejecting_arguments(e.message)
exit_rejecting_arguments(six.text_type(e))

# Convert into `build-script-impl` style variables.
options[host_target] = {
Expand Down Expand Up @@ -850,7 +868,7 @@ class BuildScriptInvocation(object):
try:
config = HostSpecificConfiguration(host_target.name, self.args)
except argparse.ArgumentError as e:
exit_rejecting_arguments(e.message)
exit_rejecting_arguments(six.text_type(e))
print("Building the standard library for: {}".format(
" ".join(config.swift_stdlib_build_targets)))
if config.swift_test_run_targets and (
Expand Down Expand Up @@ -1047,7 +1065,7 @@ def main_preset():
try:
preset_parser.read_files(args.preset_file_names)
except presets.PresetError as e:
diagnostics.fatal(e.message)
fatal_error(six.text_type(e))

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

if not args.preset:
diagnostics.fatal("missing --preset option")
fatal_error("missing --preset option")

args.preset_substitutions = {}
for arg in args.preset_substitutions_raw:
Expand All @@ -1068,12 +1086,12 @@ def main_preset():
args.preset,
vars=args.preset_substitutions)
except presets.PresetError as e:
diagnostics.fatal(e.message)
fatal_error(six.text_type(e))

preset_args = migration.migrate_swift_sdks(preset.args)

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

Expand Down Expand Up @@ -1106,7 +1124,7 @@ def main_preset():
if args.reconfigure:
build_script_args += ["--reconfigure"]

diagnostics.note('using preset "{}", which expands to \n\n{}\n'.format(
print_note('using preset "{}", which expands to \n\n{}\n'.format(
args.preset, printable_command))
shell.call_without_sleeping(build_script_args)
return 0
Expand Down Expand Up @@ -1139,7 +1157,7 @@ def main_normal():
xcrun_toolchain = os.environ.get('TOOLCHAINS',
defaults.DARWIN_XCRUN_TOOLCHAIN)

diagnostics.note('Using toolchain {}'.format(xcrun_toolchain))
print_note('Using toolchain {}'.format(xcrun_toolchain))
args.darwin_xcrun_toolchain = xcrun_toolchain

toolchain = host_toolchain(xcrun_toolchain=args.darwin_xcrun_toolchain)
Expand Down Expand Up @@ -1223,12 +1241,12 @@ def main_normal():

def main():
if not SWIFT_SOURCE_ROOT:
diagnostics.fatal(
fatal_error(
"could not infer source root directory " +
"(forgot to set $SWIFT_SOURCE_ROOT environment variable?)")

if not os.path.isdir(SWIFT_SOURCE_ROOT):
diagnostics.fatal(
fatal_error(
"source root directory \'" + SWIFT_SOURCE_ROOT +
"\' does not exist " +
"(forgot to set $SWIFT_SOURCE_ROOT environment variable?)")
Expand Down
11 changes: 0 additions & 11 deletions utils/swift_build_support/swift_build_support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,3 @@
# utils/swift_build_support/ directory as a module.
#
# ----------------------------------------------------------------------------

__all__ = [
"cmake",
"debug",
"diagnostics",
"host_specific_configuration",
"tar",
"targets",
"toolchain",
"xcrun",
]
34 changes: 0 additions & 34 deletions utils/swift_build_support/swift_build_support/diagnostics.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
#
# ----------------------------------------------------------------------------

import sys
from argparse import ArgumentError

import diagnostics

from .targets import StdlibDeploymentTarget


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

# Add the SDK to use.
deployment_platform = deployment_target.platform
Expand Down
17 changes: 11 additions & 6 deletions utils/swift_build_support/swift_build_support/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@
import sys
from contextlib import contextmanager

from . import diagnostics


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

dry_run = False


def _fatal_error(message):
"""Raises a SystemExit error with the given message.
"""

raise SystemExit('ERROR: {}\n'.format(message))


def _quote(arg):
return pipes.quote(str(arg))

Expand Down Expand Up @@ -84,11 +89,11 @@ def call(command, stderr=None, env=None, dry_run=None, echo=True):
try:
subprocess.check_call(command, env=_env, stderr=stderr)
except subprocess.CalledProcessError as e:
diagnostics.fatal(
_fatal_error(
"command terminated with a non-zero exit status " +
str(e.returncode) + ", aborting")
except OSError as e:
diagnostics.fatal(
_fatal_error(
"could not execute '" + quote_command(command) +
"': " + e.strerror)

Expand Down Expand Up @@ -135,13 +140,13 @@ def capture(command, stderr=None, env=None, dry_run=None, echo=True,
return e.output
if optional:
return None
diagnostics.fatal(
_fatal_error(
"command terminated with a non-zero exit status " +
str(e.returncode) + ", aborting")
except OSError as e:
if optional:
return None
diagnostics.fatal(
_fatal_error(
"could not execute '" + quote_command(command) +
"': " + e.strerror)

Expand Down