def bootstrap_rustc_docs(self, force=False): self.ensure_bootstrapped() rust_root = self.config["tools"]["rust-root"] docs_dir = path.join(rust_root, "doc") if not force and path.exists(docs_dir): print("Rust docs already downloaded.", end=" ") print("Use |bootstrap-rust-docs --force| to download again.") return if path.isdir(docs_dir): shutil.rmtree(docs_dir) docs_name = self.rust_path().replace("rustc-", "rust-docs-") docs_url = ("https://static-rust-lang-org.s3.amazonaws.com/dist/rust-docs-nightly-%s.tar.gz" % host_triple()) tgz_file = path.join(rust_root, 'doc.tar.gz') download_file("Rust docs", docs_url, tgz_file) print("Extracting Rust docs...") temp_dir = path.join(rust_root, "temp_docs") if path.isdir(temp_dir): shutil.rmtree(temp_dir) extract(tgz_file, temp_dir) shutil.move(path.join(temp_dir, docs_name.split("/")[1], "rust-docs", "share", "doc", "rust", "html"), docs_dir) shutil.rmtree(temp_dir) print("Rust docs ready.")
def windows_msvc(context, force=False): '''Bootstrapper for MSVC building on Windows.''' deps_dir = os.path.join(context.sharedir, "msvc-dependencies") deps_url = "https://servo-deps.s3.amazonaws.com/msvc-deps/" def version(package): return packages.WINDOWS_MSVC[package] def package_dir(package): return os.path.join(deps_dir, package, version(package)) def check_cmake(version): cmake_path = find_executable("cmake") if cmake_path: cmake = subprocess.Popen([cmake_path, "--version"], stdout=PIPE) cmake_version = cmake.stdout.read().splitlines()[0].replace( "cmake version ", "") if LooseVersion(cmake_version) >= LooseVersion(version): return True return False to_install = {} for package in packages.WINDOWS_MSVC: # Don't install CMake if it already exists in PATH if package == "cmake" and check_cmake(version("cmake")): continue if not os.path.isdir(package_dir(package)): to_install[package] = version(package) if not to_install: return 0 print("Installing missing MSVC dependencies...") for package in to_install: full_spec = '{}-{}'.format(package, version(package)) parent_dir = os.path.dirname(package_dir(package)) if not os.path.isdir(parent_dir): os.makedirs(parent_dir) zip_path = package_dir(package) + ".zip" if not os.path.isfile(zip_path): zip_url = "{}{}.zip".format(deps_url, full_spec) download_file(full_spec, zip_url, zip_path) print("Extracting {}...".format(full_spec), end='') extract(zip_path, deps_dir) print("done") extracted_path = os.path.join(deps_dir, full_spec) os.rename(extracted_path, package_dir(package)) return 0
def windows_msvc(context, force=False): '''Bootstrapper for MSVC building on Windows.''' deps_dir = os.path.join(context.sharedir, "msvc-dependencies") deps_url = "https://servo-deps.s3.amazonaws.com/msvc-deps/" def version(package): return packages.WINDOWS_MSVC[package] def package_dir(package): return os.path.join(deps_dir, package, version(package)) def check_cmake(version): cmake_path = find_executable("cmake") if cmake_path: cmake = subprocess.Popen([cmake_path, "--version"], stdout=PIPE) cmake_version = cmake.stdout.read().splitlines()[0].replace("cmake version ", "") if LooseVersion(cmake_version) >= LooseVersion(version): return True return False to_install = {} for package in packages.WINDOWS_MSVC: # Don't install CMake if it already exists in PATH if package == "cmake" and check_cmake(version("cmake")): continue if not os.path.isdir(package_dir(package)): to_install[package] = version(package) if not to_install: return 0 print("Installing missing MSVC dependencies...") for package in to_install: full_spec = '{}-{}'.format(package, version(package)) parent_dir = os.path.dirname(package_dir(package)) if not os.path.isdir(parent_dir): os.makedirs(parent_dir) zip_path = package_dir(package) + ".zip" if not os.path.isfile(zip_path): zip_url = "{}{}.zip".format(deps_url, full_spec) download_file(full_spec, zip_url, zip_path) print("Extracting {}...".format(full_spec), end='') extract(zip_path, deps_dir) print("done") extracted_path = os.path.join(deps_dir, full_spec) os.rename(extracted_path, package_dir(package)) return 0
def prepare_file(zip_path, full_spec): if not os.path.isfile(zip_path): zip_url = "{}{}.zip".format(deps_url, urllib.parse.quote(full_spec)) download_file(full_spec, zip_url, zip_path) print("Extracting {}...".format(full_spec), end='') try: extract(zip_path, deps_dir) except BadZipfile: print("\nError: %s.zip is not a valid zip file, redownload..." % full_spec) os.remove(zip_path) prepare_file(zip_path, full_spec) else: print("done")
def prepare_file(zip_path, full_spec): if not os.path.isfile(zip_path): zip_url = "{}{}.zip".format(deps_url, full_spec) download_file(full_spec, zip_url, zip_path) print("Extracting {}...".format(full_spec), end='') try: extract(zip_path, deps_dir) except BadZipfile: print("\nError: %s.zip is not a valid zip file, redownload..." % full_spec) os.remove(zip_path) prepare_file(zip_path, full_spec) else: print("done")
def windows_msvc(context, force=False): '''Bootstrapper for MSVC building on Windows.''' deps_dir = os.path.join(context.sharedir, "msvc-dependencies") deps_url = "https://servo-rust.s3.amazonaws.com/msvc-deps/" def version(package): return packages.WINDOWS_MSVC[package] def package_dir(package): return os.path.join(deps_dir, package, version(package)) to_install = {} for package in packages.WINDOWS_MSVC: # Don't install CMake if it already exists in PATH if package == "cmake" and find_executable(package): continue if not os.path.isdir(package_dir(package)): to_install[package] = version(package) if not to_install: return 0 print("Installing missing MSVC dependencies...") for package in to_install: full_spec = '{}-{}'.format(package, version(package)) parent_dir = os.path.dirname(package_dir(package)) if not os.path.isdir(parent_dir): os.makedirs(parent_dir) zip_path = package_dir(package) + ".zip" if not os.path.isfile(zip_path): zip_url = "{}{}.zip".format(deps_url, full_spec) download_file(full_spec, zip_url, zip_path) print("Extracting {}...".format(full_spec), end='') extract(zip_path, deps_dir) print("done") extracted_path = os.path.join(deps_dir, full_spec) os.rename(extracted_path, package_dir(package)) return 0
def windows_msvc(context, force=False): '''Bootstrapper for MSVC building on Windows.''' deps_dir = os.path.join(context.sharedir, "msvc-dependencies") deps_url = "https://servo-deps.s3.amazonaws.com/msvc-deps/" def version(package): return packages.WINDOWS_MSVC[package] def package_dir(package): return os.path.join(deps_dir, package, version(package)) to_install = {} for package in packages.WINDOWS_MSVC: # Don't install CMake if it already exists in PATH if package == "cmake" and find_executable(package): continue if not os.path.isdir(package_dir(package)): to_install[package] = version(package) if not to_install: return 0 print("Installing missing MSVC dependencies...") for package in to_install: full_spec = '{}-{}'.format(package, version(package)) parent_dir = os.path.dirname(package_dir(package)) if not os.path.isdir(parent_dir): os.makedirs(parent_dir) zip_path = package_dir(package) + ".zip" if not os.path.isfile(zip_path): zip_url = "{}{}.zip".format(deps_url, full_spec) download_file(full_spec, zip_url, zip_path) print("Extracting {}...".format(full_spec), end='') extract(zip_path, deps_dir) print("done") extracted_path = os.path.join(deps_dir, full_spec) os.rename(extracted_path, package_dir(package)) return 0
def bootstrap_cargo(self, force=False): cargo_dir = path.join(self.context.sharedir, "cargo", self.rust_nightly_date()) if not force and path.exists(path.join(cargo_dir, "cargo", "bin", "cargo" + BIN_SUFFIX)): print("Cargo already downloaded.", end=" ") print("Use |bootstrap-cargo --force| to download again.") return if path.isdir(cargo_dir): shutil.rmtree(cargo_dir) os.makedirs(cargo_dir) tgz_file = "cargo-nightly-%s.tar.gz" % host_triple() nightly_url = "%s/%s/%s" % (STATIC_RUST_LANG_ORG_DIST, self.rust_nightly_date(), tgz_file) download_file("Cargo nightly", nightly_url, tgz_file) print("Extracting Cargo nightly...") nightly_dir = path.join(cargo_dir, path.basename(tgz_file).replace(".tar.gz", "")) extract(tgz_file, cargo_dir, movedir=nightly_dir) print("Cargo ready.")
def bootstrap_cargo(self, force=False): cargo_dir = path.join(self.context.sharedir, "cargo", self.cargo_build_id()) if not force and path.exists(path.join(cargo_dir, "cargo", "bin", "cargo" + BIN_SUFFIX)): print("Cargo already downloaded.", end=" ") print("Use |bootstrap-cargo --force| to download again.") return if path.isdir(cargo_dir): shutil.rmtree(cargo_dir) os.makedirs(cargo_dir) tgz_file = "cargo-nightly-%s.tar.gz" % host_triple() nightly_url = "https://s3.amazonaws.com/rust-lang-ci/cargo-builds/%s/%s" % \ (self.cargo_build_id(), tgz_file) download_file("Cargo nightly", nightly_url, tgz_file) print("Extracting Cargo nightly...") nightly_dir = path.join(cargo_dir, path.basename(tgz_file).replace(".tar.gz", "")) extract(tgz_file, cargo_dir, movedir=nightly_dir) print("Cargo ready.")
def bootstrap_cargo(self, force=False): cargo_dir = path.join(self.context.sharedir, "cargo", self.cargo_build_id()) if not force and path.exists(path.join(cargo_dir, "cargo", "bin", "cargo" + BIN_SUFFIX)): print("Cargo already downloaded.", end=" ") print("Use |bootstrap-cargo --force| to download again.") return if path.isdir(cargo_dir): shutil.rmtree(cargo_dir) os.makedirs(cargo_dir) tgz_file = "cargo-nightly-%s.tar.gz" % host_triple() nightly_url = "https://s3.amazonaws.com/rust-lang-ci/rustc-builds/%s/%s" % \ (self.cargo_build_id()[len("rust-"):], tgz_file) download_file("Cargo nightly", nightly_url, tgz_file) print("Extracting Cargo nightly...") nightly_dir = path.join(cargo_dir, path.basename(tgz_file).replace(".tar.gz", "")) extract(tgz_file, cargo_dir, movedir=nightly_dir) print("Cargo ready.")
def download(target_dir, name, flatten=False): final = path.join(toolchains, target_dir) if path.isdir(final): return base_url = "https://dl.google.com/android/repository/" filename = name + ".zip" url = base_url + filename archive = path.join(toolchains, filename) if not path.isfile(archive): download_file(filename, url, archive) check_hash(archive, known_sha1[filename], "sha1") print("Extracting " + filename) remove = True # Set to False to avoid repeated downloads while debugging this script if flatten: extracted = final + "_" extract(archive, extracted, remove=remove) contents = os.listdir(extracted) assert len(contents) == 1 os.rename(path.join(extracted, contents[0]), final) os.rmdir(extracted) else: extract(archive, final, remove=remove)
def bootstrap_rustc(self, force=False, target=[], stable=False): self.set_use_stable_rust(stable) version = self.rust_version() rust_path = self.rust_path() rust_dir = path.join(self.context.sharedir, "rust", rust_path) install_dir = path.join(self.context.sharedir, "rust", version) if not self.config["build"]["llvm-assertions"]: if not self.use_stable_rust(): install_dir += "-alt" if not force and path.exists(path.join(rust_dir, "rustc", "bin", "rustc" + BIN_SUFFIX)): print("Rust compiler already downloaded.", end=" ") print("Use |bootstrap-rust --force| to download again.") else: if path.isdir(rust_dir): shutil.rmtree(rust_dir) os.makedirs(rust_dir) # The nightly Rust compiler is hosted on the nightly server under the date with a name # rustc-nightly-HOST-TRIPLE.tar.gz, whereas the stable compiler is named # rustc-VERSION-HOST-TRIPLE.tar.gz. We just need to pull down and extract it, # giving a directory name that will be the same as the tarball name (rustc is # in that directory). if stable: tarball = "rustc-%s-%s.tar.gz" % (version, host_triple()) rustc_url = "https://static-rust-lang-org.s3.amazonaws.com/dist/" + tarball else: tarball = "%s/rustc-nightly-%s.tar.gz" % (version, host_triple()) base_url = "https://s3.amazonaws.com/rust-lang-ci/rustc-builds" if not self.config["build"]["llvm-assertions"]: base_url += "-alt" rustc_url = base_url + "/" + tarball tgz_file = rust_dir + '-rustc.tar.gz' download_file("Rust compiler", rustc_url, tgz_file) print("Extracting Rust compiler...") extract(tgz_file, install_dir) print("Rust compiler ready.") # Each Rust stdlib has a name of the form `rust-std-nightly-TRIPLE.tar.gz` for the nightly # releases, or rust-std-VERSION-TRIPLE.tar.gz for stable releases, with # a directory of the name `rust-std-TRIPLE` inside and then a `lib` directory. # This `lib` directory needs to be extracted and merged with the `rustc/lib` # directory from the host compiler above. nightly_suffix = "" if stable else "-nightly" stable_version = "-{}".format(version) if stable else "" lib_dir = path.join(install_dir, "rustc{}{}-{}".format(nightly_suffix, stable_version, host_triple()), "rustc", "lib", "rustlib") # ensure that the libs for the host's target is downloaded host_target = host_triple() if host_target not in target: target.append(host_target) for target_triple in target: target_lib_dir = path.join(lib_dir, target_triple) if path.exists(target_lib_dir): # No need to check for force. If --force the directory is already deleted print("Rust lib for target {} already downloaded.".format(target_triple), end=" ") print("Use |bootstrap-rust --force| to download again.") continue if self.use_stable_rust(): std_url = ("https://static-rust-lang-org.s3.amazonaws.com/dist/rust-std-%s-%s.tar.gz" % (version, target_triple)) tgz_file = install_dir + ('rust-std-%s-%s.tar.gz' % (version, target_triple)) else: std_url = ("https://s3.amazonaws.com/rust-lang-ci/rustc-builds/%s/rust-std-nightly-%s.tar.gz" % (version, target_triple)) tgz_file = install_dir + ('rust-std-nightly-%s.tar.gz' % target_triple) download_file("Host rust library for target %s" % target_triple, std_url, tgz_file) print("Extracting Rust stdlib for target %s..." % target_triple) extract(tgz_file, install_dir) shutil.copytree(path.join(install_dir, "rust-std%s%s-%s" % (nightly_suffix, stable_version, target_triple), "rust-std-%s" % target_triple, "lib", "rustlib", target_triple), path.join(install_dir, "rustc%s%s-%s" % (nightly_suffix, stable_version, host_triple()), "rustc", "lib", "rustlib", target_triple)) shutil.rmtree(path.join(install_dir, "rust-std%s%s-%s" % (nightly_suffix, stable_version, target_triple))) print("Rust {} libs ready.".format(target_triple))
def bootstrap_rustc(self, force=False, target=[], stable=False): self.set_use_stable_rust(stable) rust_dir = path.join(self.context.sharedir, "rust", self.rust_path()) install_dir = path.join(self.context.sharedir, "rust", self.rust_install_dir()) version = self.rust_stable_version() if stable else "nightly" nightly_dist = STATIC_RUST_LANG_ORG_DIST + "/" + self.rust_nightly_date( ) if not force and path.exists( path.join(rust_dir, "rustc", "bin", "rustc" + BIN_SUFFIX)): print("Rust compiler already downloaded.", end=" ") print("Use |bootstrap-rust --force| to download again.") else: if path.isdir(rust_dir): shutil.rmtree(rust_dir) os.makedirs(rust_dir) # The nightly Rust compiler is hosted on the nightly server under the date with a name # rustc-nightly-HOST-TRIPLE.tar.gz, whereas the stable compiler is named # rustc-VERSION-HOST-TRIPLE.tar.gz. We just need to pull down and extract it, # giving a directory name that will be the same as the tarball name (rustc is # in that directory). if stable: base_url = STATIC_RUST_LANG_ORG_DIST elif self.config["build"]["llvm-assertions"]: base_url = nightly_dist else: import toml channel = nightly_dist + "/channel-rust-nightly.toml" manifest = toml.load(urllib2.urlopen(channel, **URLOPEN_KWARGS)) nightly_commit_hash = manifest["pkg"]["rustc"][ "git_commit_hash"] base_url = "https://s3.amazonaws.com/rust-lang-ci/rustc-builds-alt/" + nightly_commit_hash rustc_url = base_url + "/rustc-%s-%s.tar.gz" % (version, host_triple()) tgz_file = rust_dir + '-rustc.tar.gz' download_file("Rust compiler", rustc_url, tgz_file) print("Extracting Rust compiler...") extract(tgz_file, install_dir) print("Rust compiler ready.") # Each Rust stdlib has a name of the form `rust-std-nightly-TRIPLE.tar.gz` for the nightly # releases, or rust-std-VERSION-TRIPLE.tar.gz for stable releases, with # a directory of the name `rust-std-TRIPLE` inside and then a `lib` directory. # This `lib` directory needs to be extracted and merged with the `rustc/lib` # directory from the host compiler above. lib_dir = path.join(install_dir, "rustc-%s-%s" % (version, host_triple()), "rustc", "lib", "rustlib") # ensure that the libs for the host's target is downloaded host_target = host_triple() if host_target not in target: target.append(host_target) for target_triple in target: target_lib_dir = path.join(lib_dir, target_triple) if path.exists(target_lib_dir): # No need to check for force. If --force the directory is already deleted print("Rust lib for target {} already downloaded.".format( target_triple), end=" ") print("Use |bootstrap-rust --force| to download again.") continue tarball = "rust-std-%s-%s.tar.gz" % (version, target_triple) tgz_file = path.join(install_dir, tarball) if self.use_stable_rust(): std_url = STATIC_RUST_LANG_ORG_DIST + "/" + tarball else: std_url = nightly_dist + "/" + tarball download_file("Host rust library for target %s" % target_triple, std_url, tgz_file) print("Extracting Rust stdlib for target %s..." % target_triple) extract(tgz_file, install_dir) shutil.copytree( path.join(install_dir, "rust-std-%s-%s" % (version, target_triple), "rust-std-%s" % target_triple, "lib", "rustlib", target_triple), path.join(install_dir, "rustc-%s-%s" % (version, host_triple()), "rustc", "lib", "rustlib", target_triple)) shutil.rmtree( path.join(install_dir, "rust-std-%s-%s" % (version, target_triple))) print("Rust {} libs ready.".format(target_triple))
def bootstrap_rustc(self, force=False, target=[], stable=False): self.set_use_stable_rust(stable) rust_dir = path.join(self.context.sharedir, "rust", self.rust_path()) install_dir = path.join(self.context.sharedir, "rust", self.rust_install_dir()) version = self.rust_stable_version() if stable else "nightly" nightly_dist = STATIC_RUST_LANG_ORG_DIST + "/" + self.rust_nightly_date() if not force and path.exists(path.join(rust_dir, "rustc", "bin", "rustc" + BIN_SUFFIX)): print("Rust compiler already downloaded.", end=" ") print("Use |bootstrap-rust --force| to download again.") else: if path.isdir(rust_dir): shutil.rmtree(rust_dir) os.makedirs(rust_dir) # The nightly Rust compiler is hosted on the nightly server under the date with a name # rustc-nightly-HOST-TRIPLE.tar.gz, whereas the stable compiler is named # rustc-VERSION-HOST-TRIPLE.tar.gz. We just need to pull down and extract it, # giving a directory name that will be the same as the tarball name (rustc is # in that directory). if stable: base_url = STATIC_RUST_LANG_ORG_DIST elif self.config["build"]["llvm-assertions"]: base_url = nightly_dist else: import toml channel = nightly_dist + "/channel-rust-nightly.toml" manifest = toml.load(urllib2.urlopen(channel, **URLOPEN_KWARGS)) nightly_commit_hash = manifest["pkg"]["rustc"]["git_commit_hash"] base_url = "https://s3.amazonaws.com/rust-lang-ci/rustc-builds-alt/" + nightly_commit_hash rustc_url = base_url + "/rustc-%s-%s.tar.gz" % (version, host_triple()) tgz_file = rust_dir + '-rustc.tar.gz' download_file("Rust compiler", rustc_url, tgz_file) print("Extracting Rust compiler...") extract(tgz_file, install_dir) print("Rust compiler ready.") # Each Rust stdlib has a name of the form `rust-std-nightly-TRIPLE.tar.gz` for the nightly # releases, or rust-std-VERSION-TRIPLE.tar.gz for stable releases, with # a directory of the name `rust-std-TRIPLE` inside and then a `lib` directory. # This `lib` directory needs to be extracted and merged with the `rustc/lib` # directory from the host compiler above. lib_dir = path.join(install_dir, "rustc-%s-%s" % (version, host_triple()), "rustc", "lib", "rustlib") # ensure that the libs for the host's target is downloaded host_target = host_triple() if host_target not in target: target.append(host_target) for target_triple in target: target_lib_dir = path.join(lib_dir, target_triple) if path.exists(target_lib_dir): # No need to check for force. If --force the directory is already deleted print("Rust lib for target {} already downloaded.".format(target_triple), end=" ") print("Use |bootstrap-rust --force| to download again.") continue tarball = "rust-std-%s-%s.tar.gz" % (version, target_triple) tgz_file = path.join(install_dir, tarball) if self.use_stable_rust(): std_url = STATIC_RUST_LANG_ORG_DIST + "/" + tarball else: std_url = nightly_dist + "/" + tarball download_file("Host rust library for target %s" % target_triple, std_url, tgz_file) print("Extracting Rust stdlib for target %s..." % target_triple) extract(tgz_file, install_dir) shutil.copytree(path.join(install_dir, "rust-std-%s-%s" % (version, target_triple), "rust-std-%s" % target_triple, "lib", "rustlib", target_triple), path.join(install_dir, "rustc-%s-%s" % (version, host_triple()), "rustc", "lib", "rustlib", target_triple)) shutil.rmtree(path.join(install_dir, "rust-std-%s-%s" % (version, target_triple))) print("Rust {} libs ready.".format(target_triple))