Bug 1319860 - mozboot: Prompt to add rust to PATH after install. r=nalexander
We were checking for success installing rust with the same code
we checked for upgrade success, but in the case of a clean install
this will likely fail because the binaries installed by rustup
won't be in path. Instead, print the help message about adding
them after installation completes.
MozReview-Commit-ID: xa5PKIDKzZ
--- a/python/mozboot/mozboot/base.py
+++ b/python/mozboot/mozboot/base.py
@@ -70,18 +70,19 @@ We recommend the following tools for ins
pyenv -- https://github.com/yyuu/pyenv)
pythonz -- https://github.com/saghul/pythonz
official installers -- http://www.python.org/
'''
RUST_NOT_IN_PATH = '''
You have some rust files in %(cargo_bin)s, but they're not part of the
-standard PATH.
+standard PATH.'''
+RUST_PATH_ADVICE = '''
To make these available, please add this directory to the PATH variable
in your shell initialization script, which may be called ~/.bashrc or
~/.bash_profile or ~/.profile. Edit this and add the following line:
source %(cargo_home)s/env
Then restart your shell and run the bootstrap script again.
'''
@@ -509,35 +510,39 @@ class BaseBootstrapper(object):
cargo = self.which('cargo')
our = self._parse_version(rustc)
if not our:
return False, None
return our >= MODERN_RUST_VERSION, our
+ def cargo_home(self):
+ cargo_home = os.environ.get('CARGO_HOME',
+ os.path.expanduser(os.path.join('~', '.cargo')))
+ cargo_bin = os.path.join(cargo_home, 'bin')
+ return cargo_home, cargo_bin
+
def ensure_rust_modern(self):
modern, version = self.is_rust_modern()
if modern:
print('Your version of Rust (%s) is new enough.' % version)
return
if not version:
# Rust wasn't in PATH. Try the standard path.
- cargo_home = os.environ.get('CARGO_HOME',
- os.path.expanduser(os.path.join('~', '.cargo')))
- cargo_bin = os.path.join(cargo_home, 'bin')
+ cargo_home, cargo_bin = self.cargo_home()
try_rustc = os.path.join(cargo_bin, 'rustc' + rust.exe_suffix())
try_cargo = os.path.join(cargo_bin, 'cargo' + rust.exe_suffix())
have_rustc = os.path.exists(try_rustc)
have_cargo = os.path.exists(try_cargo)
if have_rustc or have_cargo:
- print(RUST_NOT_IN_PATH % { 'cargo_bin': cargo_bin,
- 'cargo_home': cargo_home })
+ print(RUST_NOT_IN_PATH % { 'cargo_bin': cargo_bin })
+ print(RUST_PATH_ADVICE % { 'cargo_home': cargo_home })
sys.exit(1)
rustup = self.which('rustup')
if rustup:
rustup_version = self._parse_version(rustup)
if not rustup_version:
print(RUSTUP_OLD)
sys.exit(1)
@@ -545,27 +550,26 @@ class BaseBootstrapper(object):
# We have rustup but no rustc.
# Try running rustup; maybe it will fix things.
print('Found rustup. Will try to upgrade.')
else:
# We have both rustup and rustc.
print('Your version of Rust (%s) is too old. Will try to upgrade.' %
version)
self.upgrade_rust(rustup)
+
+ modern, after = self.is_rust_modern()
+ if not modern:
+ print(RUST_UPGRADE_FAILED % (MODERN_RUST_VERSION, after))
+ sys.exit(1)
else:
# No rustc or rustup.
print('Will try to install Rust.')
self.install_rust()
- modern, after = self.is_rust_modern()
-
- if not modern:
- print(RUST_UPGRADE_FAILED % (MODERN_RUST_VERSION, after))
- sys.exit(1)
-
def upgrade_rust(self, rustup):
"""Upgrade Rust.
Invoke rustup from the given path to update the rust install."""
subprocess.check_call([rustup, 'update'])
def install_rust(self):
"""Download and run the rustup installer."""
@@ -586,17 +590,20 @@ class BaseBootstrapper(object):
mode = os.stat(rustup_init).st_mode
os.chmod(rustup_init, mode | stat.S_IRWXU)
print('Ok')
print('Running rustup-init...')
subprocess.check_call([rustup_init, '-y',
'--default-toolchain', 'stable',
'--default-host', platform,
])
+ cargo_home, cargo_bin = self.cargo_home()
print('Rust installation complete.')
+ print('You should now have rustc and cargo in %s' % cargo_bin)
+ print(RUST_PATH_ADVICE % { 'cargo_home': cargo_home })
finally:
try:
os.remove(rustup_init)
except OSError as e:
if e.errno != errno.ENOENT:
raise
def http_download_and_save(self, url, dest, sha256hexhash):