Skip to content

Commit

Permalink
Rollup merge of rust-lang#48569 - Phlosioneer:x-py-help-optimization,…
Browse files Browse the repository at this point in the history
… r=petrochenkov

Fixes rust-lang#47311.
r? @nrc
  • Loading branch information
Manishearth committed Mar 2, 2018
2 parents a6f6f2e + 2269ff5 commit 03f32b9
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ def __init__(self):
self.build_dir = os.path.join(os.getcwd(), "build")
self.clean = False
self.config_toml = ''
self.printed = False
self.rust_root = os.path.abspath(os.path.join(__file__, '../../..'))
self.use_locked_deps = ''
self.use_vendored_sources = ''
Expand All @@ -336,7 +335,6 @@ def download_stage0(self):
if self.rustc().startswith(self.bin_root()) and \
(not os.path.exists(self.rustc()) or
self.program_out_of_date(self.rustc_stamp())):
self.print_what_bootstrap_means()
if os.path.exists(self.bin_root()):
shutil.rmtree(self.bin_root())
filename = "rust-std-{}-{}.tar.gz".format(
Expand All @@ -362,7 +360,6 @@ def download_stage0(self):
if self.cargo().startswith(self.bin_root()) and \
(not os.path.exists(self.cargo()) or
self.program_out_of_date(self.cargo_stamp())):
self.print_what_bootstrap_means()
filename = "cargo-{}-{}.tar.gz".format(cargo_channel, self.build)
self._download_stage0_helper(filename, "cargo")
self.fix_executable("{}/bin/cargo".format(self.bin_root()))
Expand Down Expand Up @@ -563,23 +560,6 @@ def exe_suffix():
return '.exe'
return ''

def print_what_bootstrap_means(self):
"""Prints more information about the build system"""
if hasattr(self, 'printed'):
return
self.printed = True
if os.path.exists(self.bootstrap_binary()):
return
if '--help' not in sys.argv or len(sys.argv) == 1:
return

print('info: the build system for Rust is written in Rust, so this')
print(' script is now going to download a stage0 rust compiler')
print(' and then compile the build system itself')
print('')
print('info: in the meantime you can read more about rustbuild at')
print(' src/bootstrap/README.md before the download finishes')

def bootstrap_binary(self):
"""Return the path of the boostrap binary
Expand All @@ -593,7 +573,6 @@ def bootstrap_binary(self):

def build_bootstrap(self):
"""Build bootstrap"""
self.print_what_bootstrap_means()
build_dir = os.path.join(self.build_dir, "bootstrap")
if self.clean and os.path.exists(build_dir):
shutil.rmtree(build_dir)
Expand Down Expand Up @@ -678,8 +657,16 @@ def set_dev_environment(self):
self._download_url = 'https://dev-static.rust-lang.org'


def bootstrap():
def bootstrap(help_triggered):
"""Configure, fetch, build and run the initial bootstrap"""

# If the user is asking for help, let them know that the whole download-and-build
# process has to happen before anything is printed out.
if help_triggered:
print("info: Downloading and building bootstrap before processing --help")
print(" command. See src/bootstrap/README.md for help with common")
print(" commands.")

parser = argparse.ArgumentParser(description='Build rust')
parser.add_argument('--config')
parser.add_argument('--build')
Expand Down Expand Up @@ -716,7 +703,7 @@ def bootstrap():
print(' and so in order to preserve your $HOME this will now')
print(' use vendored sources by default. Note that if this')
print(' does not work you should run a normal build first')
print(' before running a command like `sudo make install`')
print(' before running a command like `sudo ./x.py install`')

if build.use_vendored_sources:
if not os.path.exists('.cargo'):
Expand All @@ -742,7 +729,10 @@ def bootstrap():
if 'dev' in data:
build.set_dev_environment()

build.update_submodules()
# No help text depends on submodules. This check saves ~1 minute of git commands, even if
# all the submodules are present and downloaded!
if not help_triggered:
build.update_submodules()

# Fetch/build the bootstrap
build.build = args.build or build.build_triple()
Expand All @@ -768,7 +758,7 @@ def main():
help_triggered = (
'-h' in sys.argv) or ('--help' in sys.argv) or (len(sys.argv) == 1)
try:
bootstrap()
bootstrap(help_triggered)
if not help_triggered:
print("Build completed successfully in {}".format(
format_build_time(time() - start_time)))
Expand Down

0 comments on commit 03f32b9

Please sign in to comment.