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:
def delete_if_present(path, verbose):
+ """Remove the given file if present"""
if os.path.isfile(path):
if verbose:
print("removing " + path)
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"
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:
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))
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(" ".join([nix_os_msg, fname]))
try:
interpreter = subprocess.check_output(
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:
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'):
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')
# 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:
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():
format_build_time(time() - start_time))
sys.exit(exit_code)
+
if __name__ == '__main__':
main()