Format bootstrap.py using autopep8

This commit is contained in:
Tatsuyuki Ishi 2017-05-19 20:16:29 +09:00
parent d552e34e20
commit 1fea55ba51

View file

@ -40,7 +40,8 @@ def get(url, path, verbose=False):
return return
else: else:
if verbose: if verbose:
print("ignoring already-download file " + path + " due to failed verification") print("ignoring already-download file " +
path + " due to failed verification")
os.unlink(path) os.unlink(path)
download(temp_path, url, True, verbose) download(temp_path, url, True, verbose)
if not verify(temp_path, sha_path, verbose): if not verify(temp_path, sha_path, verbose):
@ -141,6 +142,7 @@ def run(args, verbose=False, exception=False, **kwargs):
raise RuntimeError(err) raise RuntimeError(err)
sys.exit(err) sys.exit(err)
def stage0_data(rust_root): def stage0_data(rust_root):
nightlies = os.path.join(rust_root, "src/stage0.txt") nightlies = os.path.join(rust_root, "src/stage0.txt")
data = {} data = {}
@ -153,11 +155,13 @@ def stage0_data(rust_root):
data[a] = b data[a] = b
return data return data
def format_build_time(duration): def format_build_time(duration):
return str(datetime.timedelta(seconds=int(duration))) return str(datetime.timedelta(seconds=int(duration)))
class RustBuild(object): class RustBuild(object):
def download_stage0(self): def download_stage0(self):
cache_dst = os.path.join(self.build_dir, "cache") cache_dst = os.path.join(self.build_dir, "cache")
rustc_cache = os.path.join(cache_dst, self.stage0_date()) rustc_cache = os.path.join(cache_dst, self.stage0_date())
@ -172,11 +176,13 @@ class RustBuild(object):
self.print_what_it_means_to_bootstrap() self.print_what_it_means_to_bootstrap()
if os.path.exists(self.bin_root()): if os.path.exists(self.bin_root()):
shutil.rmtree(self.bin_root()) shutil.rmtree(self.bin_root())
filename = "rust-std-{}-{}.tar.gz".format(rustc_channel, self.build) filename = "rust-std-{}-{}.tar.gz".format(
rustc_channel, self.build)
url = self._download_url + "/dist/" + self.stage0_date() url = self._download_url + "/dist/" + self.stage0_date()
tarball = os.path.join(rustc_cache, filename) tarball = os.path.join(rustc_cache, filename)
if not os.path.exists(tarball): if not os.path.exists(tarball):
get("{}/{}".format(url, filename), tarball, verbose=self.verbose) get("{}/{}".format(url, filename),
tarball, verbose=self.verbose)
unpack(tarball, self.bin_root(), unpack(tarball, self.bin_root(),
match="rust-std-" + self.build, match="rust-std-" + self.build,
verbose=self.verbose) verbose=self.verbose)
@ -185,20 +191,25 @@ class RustBuild(object):
url = self._download_url + "/dist/" + self.stage0_date() url = self._download_url + "/dist/" + self.stage0_date()
tarball = os.path.join(rustc_cache, filename) tarball = os.path.join(rustc_cache, filename)
if not os.path.exists(tarball): if not os.path.exists(tarball):
get("{}/{}".format(url, filename), tarball, verbose=self.verbose) get("{}/{}".format(url, filename),
unpack(tarball, self.bin_root(), match="rustc", verbose=self.verbose) tarball, verbose=self.verbose)
unpack(tarball, self.bin_root(),
match="rustc", verbose=self.verbose)
self.fix_executable(self.bin_root() + "/bin/rustc") self.fix_executable(self.bin_root() + "/bin/rustc")
self.fix_executable(self.bin_root() + "/bin/rustdoc") self.fix_executable(self.bin_root() + "/bin/rustdoc")
with open(self.rustc_stamp(), 'w') as f: with open(self.rustc_stamp(), 'w') as f:
f.write(self.stage0_date()) f.write(self.stage0_date())
if "pc-windows-gnu" in self.build: if "pc-windows-gnu" in self.build:
filename = "rust-mingw-{}-{}.tar.gz".format(rustc_channel, self.build) filename = "rust-mingw-{}-{}.tar.gz".format(
rustc_channel, self.build)
url = self._download_url + "/dist/" + self.stage0_date() url = self._download_url + "/dist/" + self.stage0_date()
tarball = os.path.join(rustc_cache, filename) tarball = os.path.join(rustc_cache, filename)
if not os.path.exists(tarball): if not os.path.exists(tarball):
get("{}/{}".format(url, filename), tarball, verbose=self.verbose) get("{}/{}".format(url, filename),
unpack(tarball, self.bin_root(), match="rust-mingw", verbose=self.verbose) tarball, verbose=self.verbose)
unpack(tarball, self.bin_root(),
match="rust-mingw", verbose=self.verbose)
if self.cargo().startswith(self.bin_root()) and \ if self.cargo().startswith(self.bin_root()) and \
(not os.path.exists(self.cargo()) or self.cargo_out_of_date()): (not os.path.exists(self.cargo()) or self.cargo_out_of_date()):
@ -207,8 +218,10 @@ class RustBuild(object):
url = self._download_url + "/dist/" + self.stage0_date() url = self._download_url + "/dist/" + self.stage0_date()
tarball = os.path.join(rustc_cache, filename) tarball = os.path.join(rustc_cache, filename)
if not os.path.exists(tarball): if not os.path.exists(tarball):
get("{}/{}".format(url, filename), tarball, verbose=self.verbose) get("{}/{}".format(url, filename),
unpack(tarball, self.bin_root(), match="cargo", verbose=self.verbose) tarball, verbose=self.verbose)
unpack(tarball, self.bin_root(),
match="cargo", verbose=self.verbose)
self.fix_executable(self.bin_root() + "/bin/cargo") self.fix_executable(self.bin_root() + "/bin/cargo")
with open(self.cargo_stamp(), 'w') as f: with open(self.cargo_stamp(), 'w') as f:
f.write(self.stage0_date()) f.write(self.stage0_date())
@ -218,7 +231,8 @@ class RustBuild(object):
default_encoding = sys.getdefaultencoding() default_encoding = sys.getdefaultencoding()
try: try:
ostype = subprocess.check_output(['uname', '-s']).strip().decode(default_encoding) ostype = subprocess.check_output(
['uname', '-s']).strip().decode(default_encoding)
except (subprocess.CalledProcessError, WindowsError): except (subprocess.CalledProcessError, WindowsError):
return return
@ -234,7 +248,8 @@ class RustBuild(object):
print("info: you seem to be running NixOS. Attempting to patch " + fname) print("info: you seem to be running NixOS. Attempting to patch " + fname)
try: try:
interpreter = subprocess.check_output(["patchelf", "--print-interpreter", fname]) interpreter = subprocess.check_output(
["patchelf", "--print-interpreter", fname])
interpreter = interpreter.strip().decode(default_encoding) interpreter = interpreter.strip().decode(default_encoding)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print("warning: failed to call patchelf: %s" % e) print("warning: failed to call patchelf: %s" % e)
@ -243,7 +258,8 @@ class RustBuild(object):
loader = interpreter.split("/")[-1] loader = interpreter.split("/")[-1]
try: try:
ldd_output = subprocess.check_output(['ldd', '/run/current-system/sw/bin/sh']) ldd_output = subprocess.check_output(
['ldd', '/run/current-system/sw/bin/sh'])
ldd_output = ldd_output.strip().decode(default_encoding) ldd_output = ldd_output.strip().decode(default_encoding)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print("warning: unable to call ldd: %s" % e) print("warning: unable to call ldd: %s" % e)
@ -261,7 +277,8 @@ class RustBuild(object):
correct_interpreter = loader_path + loader correct_interpreter = loader_path + loader
try: try:
subprocess.check_output(["patchelf", "--set-interpreter", correct_interpreter, fname]) subprocess.check_output(
["patchelf", "--set-interpreter", correct_interpreter, fname])
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print("warning: failed to call patchelf: %s" % e) print("warning: failed to call patchelf: %s" % e)
return return
@ -404,8 +421,10 @@ class RustBuild(object):
if config: if config:
return config return config
try: try:
ostype = subprocess.check_output(['uname', '-s']).strip().decode(default_encoding) ostype = subprocess.check_output(
cputype = subprocess.check_output(['uname', '-m']).strip().decode(default_encoding) ['uname', '-s']).strip().decode(default_encoding)
cputype = subprocess.check_output(
['uname', '-m']).strip().decode(default_encoding)
except (subprocess.CalledProcessError, OSError): except (subprocess.CalledProcessError, OSError):
if sys.platform == 'win32': if sys.platform == 'win32':
return 'x86_64-pc-windows-msvc' return 'x86_64-pc-windows-msvc'
@ -417,7 +436,8 @@ class RustBuild(object):
# The goal here is to come up with the same triple as LLVM would, # The goal here is to come up with the same triple as LLVM would,
# at least for the subset of platforms we're willing to target. # at least for the subset of platforms we're willing to target.
if ostype == 'Linux': if ostype == 'Linux':
os_from_sp = subprocess.check_output(['uname', '-o']).strip().decode(default_encoding) os_from_sp = subprocess.check_output(
['uname', '-o']).strip().decode(default_encoding)
if os_from_sp == 'Android': if os_from_sp == 'Android':
ostype = 'linux-android' ostype = 'linux-android'
else: else:
@ -611,7 +631,7 @@ def bootstrap():
if rb.use_vendored_sources: if rb.use_vendored_sources:
if not os.path.exists('.cargo'): if not os.path.exists('.cargo'):
os.makedirs('.cargo') os.makedirs('.cargo')
with open('.cargo/config','w') as f: with open('.cargo/config', 'w') as f:
f.write(""" f.write("""
[source.crates-io] [source.crates-io]
replace-with = 'vendored-sources' replace-with = 'vendored-sources'
@ -651,13 +671,16 @@ def bootstrap():
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid()) env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
run(args, env=env, verbose=rb.verbose) run(args, env=env, verbose=rb.verbose)
def main(): def main():
start_time = time() start_time = time()
help_triggered = ('-h' in sys.argv) or ('--help' in sys.argv) or (len(sys.argv) == 1) help_triggered = (
'-h' in sys.argv) or ('--help' in sys.argv) or (len(sys.argv) == 1)
try: try:
bootstrap() bootstrap()
if not help_triggered: if not help_triggered:
print("Build completed successfully in %s" % format_build_time(time() - start_time)) print("Build completed successfully in %s" %
format_build_time(time() - start_time))
except (SystemExit, KeyboardInterrupt) as e: except (SystemExit, KeyboardInterrupt) as e:
if hasattr(e, 'code') and isinstance(e.code, int): if hasattr(e, 'code') and isinstance(e.code, int):
exit_code = e.code exit_code = e.code
@ -665,7 +688,8 @@ def main():
exit_code = 1 exit_code = 1
print(e) print(e)
if not help_triggered: if not help_triggered:
print("Build completed unsuccessfully in %s" % format_build_time(time() - start_time)) print("Build completed unsuccessfully in %s" %
format_build_time(time() - start_time))
sys.exit(exit_code) sys.exit(exit_code)
if __name__ == '__main__': if __name__ == '__main__':