mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Enable colors in FileCheck and Swift tests
If we're attached to a tty, pass `--color` to FileCheck and `--color-diagnostics` to Swift invocations in tests.
This commit is contained in:
@@ -365,6 +365,8 @@ config.abi_symbol_checker = make_path(config.swift_utils, 'swift-abi-symbol-chec
|
||||
config.link = lit.util.which('link', config.environment.get('PATH', '')) or \
|
||||
lit.util.which('lld-link', config.environment.get('PATH', ''))
|
||||
|
||||
config.color_output = lit_config.params.get('color_output', None) is not None
|
||||
|
||||
# Find the resource directory. Assume it's near the swift compiler if not set.
|
||||
test_resource_dir = lit_config.params.get('test_resource_dir')
|
||||
config.resource_dir_opt = ""
|
||||
@@ -1953,6 +1955,10 @@ config.substitutions.append(('%cache-tool', config.swift_cache_tool))
|
||||
config.target_swift_frontend += " -typo-correction-limit 10 "
|
||||
subst_target_swift_frontend_mock_sdk += " -typo-correction-limit 10 "
|
||||
|
||||
# Enable colors if we have them.
|
||||
if config.color_output:
|
||||
config.target_swift_frontend += " -color-diagnostics"
|
||||
|
||||
config.substitutions.append(('%module-target-triple',
|
||||
target_specific_module_triple))
|
||||
config.substitutions.append(('%module-target-future', target_future))
|
||||
@@ -2728,7 +2734,7 @@ if hasattr(config, 'target_link_sdk_future_version'):
|
||||
config.substitutions.append(('%target-link-sdk-future-version',
|
||||
config.target_link_sdk_future_version))
|
||||
|
||||
run_filecheck = '%s %s --allow-unused-prefixes --sanitize BUILD_DIR=%s --sanitize SOURCE_DIR=%s --use-filecheck %s %s' % (
|
||||
run_filecheck = '%s %s --allow-unused-prefixes --sanitize BUILD_DIR=%s --sanitize SOURCE_DIR=%s --use-filecheck %s %s %s' % (
|
||||
shell_quote(sys.executable),
|
||||
shell_quote(config.PathSanitizingFileCheck),
|
||||
# LLVM Lit performs realpath with the config path, so all paths are relative
|
||||
@@ -2740,6 +2746,7 @@ run_filecheck = '%s %s --allow-unused-prefixes --sanitize BUILD_DIR=%s --sanitiz
|
||||
shell_quote(lit.util.abs_path_preserve_drive(swift_obj_root).replace("\\", "/")),
|
||||
shell_quote(lit.util.abs_path_preserve_drive(config.swift_src_root).replace("\\", "/")),
|
||||
shell_quote(config.filecheck),
|
||||
'--color' if config.color_output else '',
|
||||
'--enable-windows-compatibility' if kIsWindows else '')
|
||||
|
||||
config.substitutions.append(('%FileCheck', run_filecheck))
|
||||
|
||||
@@ -313,6 +313,10 @@ def apply_default_arguments(toolchain, args):
|
||||
if ninja_required and toolchain.ninja is None:
|
||||
args.build_ninja = True
|
||||
|
||||
# Enable test colors if we're on a tty and aren't generating for Xcode.
|
||||
if args.color_in_tests and sys.stdout.isatty() and args.cmake_generator != "Xcode":
|
||||
args.lit_args += " --param color_output"
|
||||
|
||||
# Set the default stdlib-deployment-targets, if none were provided.
|
||||
if args.stdlib_deployment_targets is None:
|
||||
stdlib_targets = default_stdlib_deployment_targets(args)
|
||||
|
||||
@@ -572,6 +572,9 @@ def create_argument_parser():
|
||||
metavar='LITARGS',
|
||||
help='lit args to use when testing')
|
||||
|
||||
option('--color-in-tests', toggle_true, default=True,
|
||||
help='Enable color output in lit tests')
|
||||
|
||||
option('--coverage-db', store_path,
|
||||
help='coverage database to use when prioritizing testing')
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ EXPECTED_DEFAULTS = {
|
||||
'cmake_generator': 'Ninja',
|
||||
'cmark_assertions': True,
|
||||
'cmark_build_variant': 'Debug',
|
||||
'color_in_tests': True,
|
||||
'compiler_vendor': defaults.COMPILER_VENDOR,
|
||||
'coverage_db': None,
|
||||
'cross_compile_append_host_target_to_destdir': True,
|
||||
@@ -580,6 +581,7 @@ EXPECTED_OPTIONS = [
|
||||
EnableOption('--build-swift-remote-mirror'),
|
||||
EnableOption('--build-swift-external-generic-metadata-builder'),
|
||||
EnableOption('--cross-compile-append-host-target-to-destdir'),
|
||||
EnableOption('--color-in-tests'),
|
||||
EnableOption('--distcc'),
|
||||
EnableOption('--sccache'),
|
||||
EnableOption('--enable-asan'),
|
||||
|
||||
@@ -127,6 +127,8 @@ def main():
|
||||
parser.add_argument("--build-jobs",
|
||||
type=int,
|
||||
help="The number of parallel build jobs to use")
|
||||
parser.add_argument("--color", choices=["true", "false"], default="true",
|
||||
help="Whether to enable color output (default: true)")
|
||||
parser.add_argument("--target",
|
||||
type=argparse.types.ShellSplitType(),
|
||||
action=argparse.actions.AppendAction,
|
||||
@@ -265,6 +267,10 @@ def main():
|
||||
for param in args.param:
|
||||
test_args += ['--param', param]
|
||||
|
||||
# Enable colors if we're on a tty.
|
||||
if args.color == 'true' and sys.stdout.isatty():
|
||||
test_args += ['--param', 'color_output']
|
||||
|
||||
if args.result_dir:
|
||||
test_args += ['--param', 'swift_test_results_dir=%s' % args.result_dir,
|
||||
'--xunit-xml-output=%s' % os.path.join(args.result_dir,
|
||||
|
||||
Reference in New Issue
Block a user