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.
This commit is contained in:
jyn 2023-06-04 12:50:15 -05:00
parent c5820b50c5
commit c7af6fb5b8
2 changed files with 25 additions and 22 deletions

View File

@ -466,6 +466,8 @@ class FakeArgs:
self.clean = False
self.verbose = False
self.json_output = False
self.color = 'auto'
self.warnings = 'default'
class RustBuild(object):
"""Provide all the methods required to build Rust"""
@ -477,9 +479,11 @@ class RustBuild(object):
self.config_toml = config_toml
self.verbose = args.verbose != 0
self.clean = args.clean
self.json_output = args.json_output
self.verbose = args.verbose
self.color = args.color
self.warnings = args.warnings
profile = self.get_toml('profile')
if profile is not None:
@ -491,6 +495,10 @@ class RustBuild(object):
with open(include_path) as included_toml:
self.config_toml += os.linesep + included_toml.read()
config_verbose_count = self.get_toml('verbose', 'build')
if config_verbose_count is not None:
self.verbose = max(self.verbose, int(config_verbose_count))
self.use_vendored_sources = self.get_toml('vendor', 'build') == 'true'
self.use_locked_deps = self.get_toml('locked-deps', 'build') == 'true'
@ -505,6 +513,7 @@ class RustBuild(object):
self.build = args.build or self.build_triple()
def download_toolchain(self):
"""Fetch the build system for Rust, written in Rust
@ -859,7 +868,7 @@ class RustBuild(object):
"""
return os.path.join(self.build_dir, "bootstrap", "debug", "bootstrap")
def build_bootstrap(self, color, warnings, verbose_count):
def build_bootstrap(self):
"""Build bootstrap"""
env = os.environ.copy()
if "GITHUB_ACTIONS" in env:
@ -867,14 +876,14 @@ class RustBuild(object):
else:
print("Building bootstrap", file=sys.stderr)
args = self.build_bootstrap_cmd(env, color, warnings, verbose_count)
args = self.build_bootstrap_cmd(env)
# Run this from the source directory so cargo finds .cargo/config
run(args, env=env, verbose=self.verbose, cwd=self.rust_root)
if "GITHUB_ACTIONS" in env:
print("::endgroup::")
def build_bootstrap_cmd(self, env, color, warnings, verbose_count):
def build_bootstrap_cmd(self, env):
"""For tests."""
build_dir = os.path.join(self.build_dir, "bootstrap")
if self.clean and os.path.exists(build_dir):
@ -928,10 +937,10 @@ class RustBuild(object):
if target_linker is not None:
env["RUSTFLAGS"] += " -C linker=" + target_linker
env["RUSTFLAGS"] += " -Wrust_2018_idioms -Wunused_lifetimes"
if warnings == "default":
if self.warnings == "default":
deny_warnings = self.get_toml("deny-warnings", "rust") != "false"
else:
deny_warnings = warnings == "deny"
deny_warnings = self.warnings == "deny"
if deny_warnings:
env["RUSTFLAGS"] += " -Dwarnings"
@ -942,7 +951,7 @@ class RustBuild(object):
self.cargo()))
args = [self.cargo(), "build", "--manifest-path",
os.path.join(self.rust_root, "src/bootstrap/Cargo.toml")]
args.extend("--verbose" for _ in range(verbose_count))
args.extend("--verbose" for _ in range(self.verbose))
if self.use_locked_deps:
args.append("--locked")
if self.use_vendored_sources:
@ -952,9 +961,9 @@ class RustBuild(object):
args.append("build-metrics")
if self.json_output:
args.append("--message-format=json")
if color == "always":
if self.color == "always":
args.append("--color=always")
elif color == "never":
elif self.color == "never":
args.append("--color=never")
try:
args += env["CARGOFLAGS"].split()
@ -1049,18 +1058,13 @@ def bootstrap(args):
build = RustBuild(config_toml, args)
build.check_vendored_status()
verbose_count = args.verbose
config_verbose_count = build.get_toml('verbose', 'build')
if config_verbose_count is not None:
verbose_count = max(args.verbose, int(config_verbose_count))
if not os.path.exists(build.build_dir):
os.makedirs(build.build_dir)
# Fetch/build the bootstrap
build.download_toolchain()
sys.stdout.flush()
build.build_bootstrap(args.color, args.warnings, verbose_count)
build.build_bootstrap()
sys.stdout.flush()
# Run the bootstrap

View File

@ -15,14 +15,13 @@ from shutil import rmtree
import bootstrap
import configure
def serialize_and_parse(args):
def serialize_and_parse(configure_args, bootstrap_args=bootstrap.FakeArgs()):
from io import StringIO
section_order, sections, targets = configure.parse_args(args)
section_order, sections, targets = configure.parse_args(configure_args)
buffer = StringIO()
configure.write_config_toml(buffer, section_order, targets, sections)
build = bootstrap.RustBuild()
build.config_toml = buffer.getvalue()
build = bootstrap.RustBuild(config_toml=buffer.getvalue(), args=bootstrap_args)
try:
import tomllib
@ -130,10 +129,10 @@ class BuildBootstrap(unittest.TestCase):
env = env.copy()
env["PATH"] = os.environ["PATH"]
build = serialize_and_parse(configure_args)
build.build_dir = os.environ["BUILD_DIR"]
parsed = bootstrap.parse_args(args)
return build.build_bootstrap_cmd(env, parsed.color, parsed.warnings, parsed.verbose), env
build = serialize_and_parse(configure_args, parsed)
build.build_dir = os.environ["BUILD_DIR"]
return build.build_bootstrap_cmd(env), env
def test_cargoflags(self):
args, _ = self.build_args(env={"CARGOFLAGS": "--timings"})