mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
Auto merge of #43003 - milmazz:bootstrap-pep8, r=alexcrichton
bootstrap: Fix all the pep-8 issues reported by flake8 This commit also adds a few missing docstrings. Today, after reading this [article](https://blog.rust-lang.org/2017/06/27/Increasing-Rusts-Reach.html), I downloaded this project and started building from source. In the meantime, I began to read the `bootstrap.py`, to know more about the building process, and I made a few changes, this is my first contribution to the project, hope you like it. BTW, I have a few doubts about the `bootstrap.py`, any guidance is more than welcome: * Where can I find the unit tests for this script? In case it doesn't exist yet, do you like to include some unit tests with pytest? * Some methods like `fix_executable`, `get_string`, and `exe_suffix` in the `RustBuild` class should be converted to a function because it doesn't use `self` anywhere. What do you think?
This commit is contained in:
commit
c3a130cffc
@ -25,10 +25,11 @@ from time import time
|
||||
|
||||
|
||||
def get(url, path, verbose=False):
|
||||
sha_url = url + ".sha256"
|
||||
suffix = '.sha256'
|
||||
sha_url = url + suffix
|
||||
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
||||
temp_path = temp_file.name
|
||||
with tempfile.NamedTemporaryFile(suffix=".sha256", delete=False) as sha_file:
|
||||
with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as sha_file:
|
||||
sha_path = sha_file.name
|
||||
|
||||
try:
|
||||
@ -55,6 +56,7 @@ def get(url, path, verbose=False):
|
||||
|
||||
|
||||
def delete_if_present(path, verbose):
|
||||
"""Remove the given file if present"""
|
||||
if os.path.isfile(path):
|
||||
if verbose:
|
||||
print("removing " + path)
|
||||
@ -92,12 +94,13 @@ def _download(path, url, probably_big, verbose, exception):
|
||||
|
||||
|
||||
def verify(path, sha_path, verbose):
|
||||
"""Check if the sha256 sum of the given path is valid"""
|
||||
if verbose:
|
||||
print("verifying " + path)
|
||||
with open(path, "rb") as f:
|
||||
found = hashlib.sha256(f.read()).hexdigest()
|
||||
with open(sha_path, "r") as f:
|
||||
expected = f.readline().split()[0]
|
||||
with open(path, "rb") as source:
|
||||
found = hashlib.sha256(source.read()).hexdigest()
|
||||
with open(sha_path, "r") as sha256sum:
|
||||
expected = sha256sum.readline().split()[0]
|
||||
verified = found == expected
|
||||
if not verified:
|
||||
print("invalid checksum:\n"
|
||||
@ -107,6 +110,7 @@ def verify(path, sha_path, verbose):
|
||||
|
||||
|
||||
def unpack(tarball, dst, verbose=False, match=None):
|
||||
"""Unpack the given tarball file"""
|
||||
print("extracting " + tarball)
|
||||
fname = os.path.basename(tarball).replace(".tar.gz", "")
|
||||
with contextlib.closing(tarfile.open(tarball)) as tar:
|
||||
@ -128,6 +132,7 @@ def unpack(tarball, dst, verbose=False, match=None):
|
||||
shutil.move(tp, fp)
|
||||
shutil.rmtree(os.path.join(dst, fname))
|
||||
|
||||
|
||||
def run(args, verbose=False, exception=False, **kwargs):
|
||||
if verbose:
|
||||
print("running: " + ' '.join(args))
|
||||
@ -245,7 +250,8 @@ class RustBuild(object):
|
||||
return
|
||||
|
||||
# At this point we're pretty sure the user is running NixOS
|
||||
print("info: you seem to be running NixOS. Attempting to patch " + fname)
|
||||
nix_os_msg = "info: you seem to be running NixOS. Attempting to patch"
|
||||
print(nix_os_msg, fname)
|
||||
|
||||
try:
|
||||
interpreter = subprocess.check_output(
|
||||
@ -293,18 +299,22 @@ class RustBuild(object):
|
||||
return self._cargo_channel
|
||||
|
||||
def rustc_stamp(self):
|
||||
"""Return the path for .rustc-stamp"""
|
||||
return os.path.join(self.bin_root(), '.rustc-stamp')
|
||||
|
||||
def cargo_stamp(self):
|
||||
"""Return the path for .cargo-stamp"""
|
||||
return os.path.join(self.bin_root(), '.cargo-stamp')
|
||||
|
||||
def rustc_out_of_date(self):
|
||||
"""Check if rustc is out of date"""
|
||||
if not os.path.exists(self.rustc_stamp()) or self.clean:
|
||||
return True
|
||||
with open(self.rustc_stamp(), 'r') as f:
|
||||
return self.stage0_date() != f.read()
|
||||
|
||||
def cargo_out_of_date(self):
|
||||
"""Check if cargo is out of date"""
|
||||
if not os.path.exists(self.cargo_stamp()) or self.clean:
|
||||
return True
|
||||
with open(self.cargo_stamp(), 'r') as f:
|
||||
@ -357,8 +367,7 @@ class RustBuild(object):
|
||||
def exe_suffix(self):
|
||||
if sys.platform == 'win32':
|
||||
return '.exe'
|
||||
else:
|
||||
return ''
|
||||
return ''
|
||||
|
||||
def print_what_it_means_to_bootstrap(self):
|
||||
if hasattr(self, 'printed'):
|
||||
@ -366,7 +375,7 @@ class RustBuild(object):
|
||||
self.printed = True
|
||||
if os.path.exists(self.bootstrap_binary()):
|
||||
return
|
||||
if not '--help' in sys.argv or len(sys.argv) == 1:
|
||||
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')
|
||||
@ -461,8 +470,8 @@ class RustBuild(object):
|
||||
# always emit 'i386' on x86/amd64 systems). As such, isainfo -k
|
||||
# must be used instead.
|
||||
try:
|
||||
cputype = subprocess.check_output(['isainfo',
|
||||
'-k']).strip().decode(default_encoding)
|
||||
cputype = subprocess.check_output(
|
||||
['isainfo', '-k']).strip().decode(default_encoding)
|
||||
except (subprocess.CalledProcessError, OSError):
|
||||
err = "isainfo not found"
|
||||
if self.verbose:
|
||||
@ -562,21 +571,26 @@ class RustBuild(object):
|
||||
default_encoding = sys.getdefaultencoding()
|
||||
run(["git", "submodule", "-q", "sync"], cwd=self.rust_root)
|
||||
submodules = [s.split(' ', 1)[1] for s in subprocess.check_output(
|
||||
["git", "config", "--file", os.path.join(self.rust_root, ".gitmodules"),
|
||||
["git", "config", "--file",
|
||||
os.path.join(self.rust_root, ".gitmodules"),
|
||||
"--get-regexp", "path"]
|
||||
).decode(default_encoding).splitlines()]
|
||||
submodules = [module for module in submodules
|
||||
if not ((module.endswith("llvm") and
|
||||
(self.get_toml('llvm-config') or self.get_mk('CFG_LLVM_ROOT'))) or
|
||||
(self.get_toml('llvm-config') or
|
||||
self.get_mk('CFG_LLVM_ROOT'))) or
|
||||
(module.endswith("jemalloc") and
|
||||
(self.get_toml('jemalloc') or self.get_mk('CFG_JEMALLOC_ROOT'))))
|
||||
]
|
||||
(self.get_toml('jemalloc') or
|
||||
self.get_mk('CFG_JEMALLOC_ROOT'))))]
|
||||
run(["git", "submodule", "update",
|
||||
"--init"] + submodules, cwd=self.rust_root, verbose=self.verbose)
|
||||
"--init"] + submodules,
|
||||
cwd=self.rust_root, verbose=self.verbose)
|
||||
run(["git", "submodule", "-q", "foreach", "git",
|
||||
"reset", "-q", "--hard"], cwd=self.rust_root, verbose=self.verbose)
|
||||
"reset", "-q", "--hard"],
|
||||
cwd=self.rust_root, verbose=self.verbose)
|
||||
run(["git", "submodule", "-q", "foreach", "git",
|
||||
"clean", "-qdfx"], cwd=self.rust_root, verbose=self.verbose)
|
||||
"clean", "-qdfx"],
|
||||
cwd=self.rust_root, verbose=self.verbose)
|
||||
|
||||
|
||||
def bootstrap():
|
||||
@ -692,5 +706,6 @@ def main():
|
||||
format_build_time(time() - start_time))
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user