Skip to content

Commit c7af6fb

Browse files
committed
Test color/verbose/warnings properly
These weren't being passed in to bootstrap consistently before; in particular `serialize_and_parse` forgot to pass them in.
1 parent c5820b5 commit c7af6fb

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

src/bootstrap/bootstrap.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ def __init__(self):
466466
self.clean = False
467467
self.verbose = False
468468
self.json_output = False
469+
self.color = 'auto'
470+
self.warnings = 'default'
469471

470472
class RustBuild(object):
471473
"""Provide all the methods required to build Rust"""
@@ -477,9 +479,11 @@ def __init__(self, config_toml="", args=FakeArgs()):
477479

478480
self.config_toml = config_toml
479481

480-
self.verbose = args.verbose != 0
481482
self.clean = args.clean
482483
self.json_output = args.json_output
484+
self.verbose = args.verbose
485+
self.color = args.color
486+
self.warnings = args.warnings
483487

484488
profile = self.get_toml('profile')
485489
if profile is not None:
@@ -491,6 +495,10 @@ def __init__(self, config_toml="", args=FakeArgs()):
491495
with open(include_path) as included_toml:
492496
self.config_toml += os.linesep + included_toml.read()
493497

498+
config_verbose_count = self.get_toml('verbose', 'build')
499+
if config_verbose_count is not None:
500+
self.verbose = max(self.verbose, int(config_verbose_count))
501+
494502
self.use_vendored_sources = self.get_toml('vendor', 'build') == 'true'
495503
self.use_locked_deps = self.get_toml('locked-deps', 'build') == 'true'
496504

@@ -505,6 +513,7 @@ def __init__(self, config_toml="", args=FakeArgs()):
505513

506514
self.build = args.build or self.build_triple()
507515

516+
508517
def download_toolchain(self):
509518
"""Fetch the build system for Rust, written in Rust
510519
@@ -859,22 +868,22 @@ def bootstrap_binary(self):
859868
"""
860869
return os.path.join(self.build_dir, "bootstrap", "debug", "bootstrap")
861870

862-
def build_bootstrap(self, color, warnings, verbose_count):
871+
def build_bootstrap(self):
863872
"""Build bootstrap"""
864873
env = os.environ.copy()
865874
if "GITHUB_ACTIONS" in env:
866875
print("::group::Building bootstrap")
867876
else:
868877
print("Building bootstrap", file=sys.stderr)
869878

870-
args = self.build_bootstrap_cmd(env, color, warnings, verbose_count)
879+
args = self.build_bootstrap_cmd(env)
871880
# Run this from the source directory so cargo finds .cargo/config
872881
run(args, env=env, verbose=self.verbose, cwd=self.rust_root)
873882

874883
if "GITHUB_ACTIONS" in env:
875884
print("::endgroup::")
876885

877-
def build_bootstrap_cmd(self, env, color, warnings, verbose_count):
886+
def build_bootstrap_cmd(self, env):
878887
"""For tests."""
879888
build_dir = os.path.join(self.build_dir, "bootstrap")
880889
if self.clean and os.path.exists(build_dir):
@@ -928,10 +937,10 @@ def build_bootstrap_cmd(self, env, color, warnings, verbose_count):
928937
if target_linker is not None:
929938
env["RUSTFLAGS"] += " -C linker=" + target_linker
930939
env["RUSTFLAGS"] += " -Wrust_2018_idioms -Wunused_lifetimes"
931-
if warnings == "default":
940+
if self.warnings == "default":
932941
deny_warnings = self.get_toml("deny-warnings", "rust") != "false"
933942
else:
934-
deny_warnings = warnings == "deny"
943+
deny_warnings = self.warnings == "deny"
935944
if deny_warnings:
936945
env["RUSTFLAGS"] += " -Dwarnings"
937946

@@ -942,7 +951,7 @@ def build_bootstrap_cmd(self, env, color, warnings, verbose_count):
942951
self.cargo()))
943952
args = [self.cargo(), "build", "--manifest-path",
944953
os.path.join(self.rust_root, "src/bootstrap/Cargo.toml")]
945-
args.extend("--verbose" for _ in range(verbose_count))
954+
args.extend("--verbose" for _ in range(self.verbose))
946955
if self.use_locked_deps:
947956
args.append("--locked")
948957
if self.use_vendored_sources:
@@ -952,9 +961,9 @@ def build_bootstrap_cmd(self, env, color, warnings, verbose_count):
952961
args.append("build-metrics")
953962
if self.json_output:
954963
args.append("--message-format=json")
955-
if color == "always":
964+
if self.color == "always":
956965
args.append("--color=always")
957-
elif color == "never":
966+
elif self.color == "never":
958967
args.append("--color=never")
959968
try:
960969
args += env["CARGOFLAGS"].split()
@@ -1049,18 +1058,13 @@ def bootstrap(args):
10491058
build = RustBuild(config_toml, args)
10501059
build.check_vendored_status()
10511060

1052-
verbose_count = args.verbose
1053-
config_verbose_count = build.get_toml('verbose', 'build')
1054-
if config_verbose_count is not None:
1055-
verbose_count = max(args.verbose, int(config_verbose_count))
1056-
10571061
if not os.path.exists(build.build_dir):
10581062
os.makedirs(build.build_dir)
10591063

10601064
# Fetch/build the bootstrap
10611065
build.download_toolchain()
10621066
sys.stdout.flush()
1063-
build.build_bootstrap(args.color, args.warnings, verbose_count)
1067+
build.build_bootstrap()
10641068
sys.stdout.flush()
10651069

10661070
# Run the bootstrap

src/bootstrap/bootstrap_test.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
import bootstrap
1616
import configure
1717

18-
def serialize_and_parse(args):
18+
def serialize_and_parse(configure_args, bootstrap_args=bootstrap.FakeArgs()):
1919
from io import StringIO
2020

21-
section_order, sections, targets = configure.parse_args(args)
21+
section_order, sections, targets = configure.parse_args(configure_args)
2222
buffer = StringIO()
2323
configure.write_config_toml(buffer, section_order, targets, sections)
24-
build = bootstrap.RustBuild()
25-
build.config_toml = buffer.getvalue()
24+
build = bootstrap.RustBuild(config_toml=buffer.getvalue(), args=bootstrap_args)
2625

2726
try:
2827
import tomllib
@@ -130,10 +129,10 @@ def build_args(self, configure_args=[], args=[], env={}):
130129
env = env.copy()
131130
env["PATH"] = os.environ["PATH"]
132131

133-
build = serialize_and_parse(configure_args)
134-
build.build_dir = os.environ["BUILD_DIR"]
135132
parsed = bootstrap.parse_args(args)
136-
return build.build_bootstrap_cmd(env, parsed.color, parsed.warnings, parsed.verbose), env
133+
build = serialize_and_parse(configure_args, parsed)
134+
build.build_dir = os.environ["BUILD_DIR"]
135+
return build.build_bootstrap_cmd(env), env
137136

138137
def test_cargoflags(self):
139138
args, _ = self.build_args(env={"CARGOFLAGS": "--timings"})

0 commit comments

Comments
 (0)