Skip to content

Commit

Permalink
Test color/verbose/warnings properly
Browse files Browse the repository at this point in the history
These weren't being passed in to bootstrap consistently before; in particular `serialize_and_parse` forgot to pass them in.
  • Loading branch information
jyn514 committed Jun 24, 2023
1 parent c5820b5 commit c7af6fb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
34 changes: 19 additions & 15 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ def __init__(self):
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"""
Expand All @@ -477,9 +479,11 @@ def __init__(self, config_toml="", args=FakeArgs()):

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:
Expand All @@ -491,6 +495,10 @@ def __init__(self, config_toml="", args=FakeArgs()):
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'

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

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


def download_toolchain(self):
"""Fetch the build system for Rust, written in Rust
Expand Down Expand Up @@ -859,22 +868,22 @@ def bootstrap_binary(self):
"""
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:
print("::group::Building bootstrap")
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):
Expand Down Expand Up @@ -928,10 +937,10 @@ def build_bootstrap_cmd(self, env, color, warnings, verbose_count):
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"

Expand All @@ -942,7 +951,7 @@ def build_bootstrap_cmd(self, env, color, warnings, verbose_count):
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:
Expand All @@ -952,9 +961,9 @@ def build_bootstrap_cmd(self, env, color, warnings, verbose_count):
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()
Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions src/bootstrap/bootstrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
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
Expand Down Expand Up @@ -130,10 +129,10 @@ def build_args(self, configure_args=[], args=[], env={}):
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"})
Expand Down

0 comments on commit c7af6fb

Please sign in to comment.