Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce python3 and deprecate the use of python2 #82433

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@ try() {
}

try python3 "$@"
try python2.7 "$@"
try python27 "$@"
try python2 "$@"
exec python $script "$@"
76 changes: 49 additions & 27 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import argparse
import contextlib
import datetime
Expand All @@ -14,6 +13,7 @@

from time import time


def support_xz():
try:
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
Expand All @@ -24,6 +24,7 @@ def support_xz():
except tarfile.CompressionError:
return False


def get(url, path, verbose=False, do_verify=True):
suffix = '.sha256'
sha_url = url + suffix
Expand All @@ -43,7 +44,7 @@ def get(url, path, verbose=False, do_verify=True):
else:
if verbose:
print("ignoring already-download file",
path, "due to failed verification")
path, "due to failed verification")
os.unlink(path)
download(temp_path, url, True, verbose)
if do_verify and not verify(temp_path, sha_path, verbose):
Expand Down Expand Up @@ -274,7 +275,7 @@ def default_build_triple(verbose):

if cputype == 'powerpc' and ostype == 'unknown-freebsd':
cputype = subprocess.check_output(
['uname', '-p']).strip().decode(default_encoding)
['uname', '-p']).strip().decode(default_encoding)
cputype_mapper = {
'BePC': 'i686',
'aarch64': 'aarch64',
Expand Down Expand Up @@ -362,6 +363,7 @@ def output(filepath):

class RustBuild(object):
"""Provide all the methods required to build Rust"""

def __init__(self):
self.date = ''
self._download_url = ''
Expand Down Expand Up @@ -413,7 +415,8 @@ def download_stage0(self):
lib_dir = "{}/lib".format(self.bin_root())
for lib in os.listdir(lib_dir):
if lib.endswith(".so"):
self.fix_bin_or_dylib(os.path.join(lib_dir, lib), rpath_libz=True)
self.fix_bin_or_dylib(os.path.join(
lib_dir, lib), rpath_libz=True)
with output(self.rustc_stamp()) as rust_stamp:
rust_stamp.write(self.date)

Expand All @@ -424,10 +427,13 @@ def download_stage0(self):
if rustfmt_channel:
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
[channel, date] = rustfmt_channel.split('-', 1)
filename = "rustfmt-{}-{}{}".format(channel, self.build, tarball_suffix)
self._download_stage0_helper(filename, "rustfmt-preview", tarball_suffix, date)
filename = "rustfmt-{}-{}{}".format(
channel, self.build, tarball_suffix)
self._download_stage0_helper(
filename, "rustfmt-preview", tarball_suffix, date)
self.fix_bin_or_dylib("{}/bin/rustfmt".format(self.bin_root()))
self.fix_bin_or_dylib("{}/bin/cargo-fmt".format(self.bin_root()))
self.fix_bin_or_dylib(
"{}/bin/cargo-fmt".format(self.bin_root()))
with output(self.rustfmt_stamp()) as rustfmt_stamp:
rustfmt_stamp.write(self.rustfmt_channel)

Expand Down Expand Up @@ -456,10 +462,12 @@ def download_stage0(self):
if self.program_out_of_date(self.llvm_stamp(), llvm_sha + str(llvm_assertions)):
self._download_ci_llvm(llvm_sha, llvm_assertions)
for binary in ["llvm-config", "FileCheck"]:
self.fix_bin_or_dylib(os.path.join(llvm_root, "bin", binary), rpath_libz=True)
self.fix_bin_or_dylib(os.path.join(
llvm_root, "bin", binary), rpath_libz=True)
for lib in os.listdir(llvm_lib):
if lib.endswith(".so"):
self.fix_bin_or_dylib(os.path.join(llvm_lib, lib), rpath_libz=True)
self.fix_bin_or_dylib(os.path.join(
llvm_lib, lib), rpath_libz=True)
with output(self.llvm_stamp()) as llvm_stamp:
llvm_stamp.write(llvm_sha + str(llvm_assertions))

Expand Down Expand Up @@ -493,7 +501,8 @@ def _download_stage0_helper(self, filename, pattern, tarball_suffix, date=None):
tarball = os.path.join(rustc_cache, filename)
if not os.path.exists(tarball):
get("{}/{}".format(url, filename), tarball, verbose=self.verbose)
unpack(tarball, tarball_suffix, self.bin_root(), match=pattern, verbose=self.verbose)
unpack(tarball, tarball_suffix, self.bin_root(),
match=pattern, verbose=self.verbose)

def _download_ci_llvm(self, llvm_sha, llvm_assertions):
cache_prefix = "llvm-{}-{}".format(llvm_sha, llvm_assertions)
Expand All @@ -502,7 +511,8 @@ def _download_ci_llvm(self, llvm_sha, llvm_assertions):
if not os.path.exists(rustc_cache):
os.makedirs(rustc_cache)

url = "https://ci-artifacts.rust-lang.org/rustc-builds/{}".format(llvm_sha)
url = "https://ci-artifacts.rust-lang.org/rustc-builds/{}".format(
llvm_sha)
if llvm_assertions:
url = url.replace('rustc-builds', 'rustc-builds-alt')
# ci-artifacts are only stored as .xz, not .gz
Expand All @@ -514,10 +524,11 @@ def _download_ci_llvm(self, llvm_sha, llvm_assertions):
filename = "rust-dev-nightly-" + self.build + tarball_suffix
tarball = os.path.join(rustc_cache, filename)
if not os.path.exists(tarball):
get("{}/{}".format(url, filename), tarball, verbose=self.verbose, do_verify=False)
get("{}/{}".format(url, filename), tarball,
verbose=self.verbose, do_verify=False)
unpack(tarball, tarball_suffix, self.llvm_root(),
match="rust-dev",
verbose=self.verbose)
match="rust-dev",
verbose=self.verbose)

def fix_bin_or_dylib(self, fname, rpath_libz=False):
"""Modifies the interpreter section of 'fname' to fix the dynamic linker,
Expand Down Expand Up @@ -604,7 +615,8 @@ def fix_bin_or_dylib(self, fname, rpath_libz=False):
# Finally, set the corret .interp for binaries
bintools_dir = "{}/stdenv.cc.bintools".format(nix_deps_dir)
with open("{}/nix-support/dynamic-linker".format(bintools_dir)) as dynamic_linker:
patchelf_args += ["--set-interpreter", dynamic_linker.read().rstrip()]
patchelf_args += ["--set-interpreter",
dynamic_linker.read().rstrip()]

try:
subprocess.check_output([patchelf] + patchelf_args + [fname])
Expand Down Expand Up @@ -642,7 +654,6 @@ def llvm_stamp(self):
"""
return os.path.join(self.llvm_root(), '.llvm-stamp')


def program_out_of_date(self, stamp_path, key):
"""Check if the given program stamp is out of date"""
if not os.path.exists(stamp_path) or self.clean:
Expand Down Expand Up @@ -829,7 +840,8 @@ def build_bootstrap(self):
elif self.get_toml("crt-static", build_section) == "false":
target_features += ["-crt-static"]
if target_features:
env["RUSTFLAGS"] += " -C target-feature=" + (",".join(target_features))
env["RUSTFLAGS"] += " -C target-feature=" + \
(",".join(target_features))
target_linker = self.get_toml("linker", build_section)
if target_linker is not None:
env["RUSTFLAGS"] += " -C linker=" + target_linker
Expand Down Expand Up @@ -866,7 +878,8 @@ def build_triple(self):
def check_submodule(self, module, slow_submodules):
if not slow_submodules:
checked_out = subprocess.Popen(["git", "rev-parse", "HEAD"],
cwd=os.path.join(self.rust_root, module),
cwd=os.path.join(
self.rust_root, module),
stdout=subprocess.PIPE)
return checked_out
else:
Expand All @@ -877,7 +890,8 @@ def update_submodule(self, module, checked_out, recorded_submodules):

if checked_out is not None:
default_encoding = sys.getdefaultencoding()
checked_out = checked_out.communicate()[0].decode(default_encoding).strip()
checked_out = checked_out.communicate(
)[0].decode(default_encoding).strip()
if recorded_submodules[module] == checked_out:
return

Expand All @@ -890,7 +904,8 @@ def update_submodule(self, module, checked_out, recorded_submodules):
if self.git_version >= distutils.version.LooseVersion("2.11.0"):
update_args.append("--progress")
update_args.append(module)
run(update_args, cwd=self.rust_root, verbose=self.verbose, exception=True)
run(update_args, cwd=self.rust_root,
verbose=self.verbose, exception=True)

run(["git", "reset", "-q", "--hard"],
cwd=module_path, verbose=self.verbose)
Expand All @@ -906,7 +921,8 @@ def update_submodules(self):
default_encoding = sys.getdefaultencoding()

# check the existence and version of 'git' command
git_version_str = require(['git', '--version']).split()[2].decode(default_encoding)
git_version_str = require(
['git', '--version']).split()[2].decode(default_encoding)
self.git_version = distutils.version.LooseVersion(git_version_str)

slow_submodules = self.get_toml('fast-submodules') == "false"
Expand All @@ -923,8 +939,10 @@ def update_submodules(self):
).decode(default_encoding).splitlines()]
filtered_submodules = []
submodules_names = []
llvm_checked_out = os.path.exists(os.path.join(self.rust_root, "src/llvm-project/.git"))
external_llvm_provided = self.get_toml('llvm-config') or self.downloading_llvm()
llvm_checked_out = os.path.exists(os.path.join(
self.rust_root, "src/llvm-project/.git"))
external_llvm_provided = self.get_toml(
'llvm-config') or self.downloading_llvm()
llvm_needed = not self.get_toml('codegen-backends', 'rust') \
or "llvm" in self.get_toml('codegen-backends', 'rust')
for module in submodules:
Expand All @@ -942,7 +960,8 @@ def update_submodules(self):
submodules_names.append(module)
recorded = subprocess.Popen(["git", "ls-tree", "HEAD"] + submodules_names,
cwd=self.rust_root, stdout=subprocess.PIPE)
recorded = recorded.communicate()[0].decode(default_encoding).strip().splitlines()
recorded = recorded.communicate()[0].decode(
default_encoding).strip().splitlines()
recorded_submodules = {}
for data in recorded:
data = data.split()
Expand Down Expand Up @@ -975,7 +994,8 @@ def check_vendored_status(self):
print(' and so in order to preserve your $HOME this will now')
print(' use vendored sources by default.')
if not os.path.exists(vendor_dir):
print('error: vendoring required, but vendor directory does not exist.')
print(
'error: vendoring required, but vendor directory does not exist.')
print(' Run `cargo vendor` without sudo to initialize the '
'vendor directory.')
raise Exception("{} not found".format(vendor_dir))
Expand Down Expand Up @@ -1052,7 +1072,8 @@ def bootstrap(help_triggered):
profile = build.get_toml('profile')
if profile is not None:
include_file = 'config.{}.toml'.format(profile)
include_dir = os.path.join(build.rust_root, 'src', 'bootstrap', 'defaults')
include_dir = os.path.join(
build.rust_root, 'src', 'bootstrap', 'defaults')
include_path = os.path.join(include_dir, include_file)
# HACK: This works because `build.get_toml()` returns the first match it finds for a
# specific key, so appending our defaults at the end allows the user to override them
Expand All @@ -1070,7 +1091,8 @@ def bootstrap(help_triggered):
build.check_vendored_status()

build_dir = build.get_toml('build-dir', 'build') or 'build'
build.build_dir = os.path.abspath(build_dir.replace("$ROOT", build.rust_root))
build.build_dir = os.path.abspath(
build_dir.replace("$ROOT", build.rust_root))

data = stage0_data(build.rust_root)
build.date = data['date']
Expand Down
19 changes: 13 additions & 6 deletions src/bootstrap/bootstrap_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Bootstrap tests"""

from __future__ import absolute_import, division, print_function
import os
import doctest
import unittest
Expand All @@ -15,25 +14,29 @@

class Stage0DataTestCase(unittest.TestCase):
"""Test Case for stage0_data"""

def setUp(self):
self.rust_root = tempfile.mkdtemp()
os.mkdir(os.path.join(self.rust_root, "src"))
with open(os.path.join(self.rust_root, "src",
"stage0.txt"), "w") as stage0:
stage0.write("#ignore\n\ndate: 2017-06-15\nrustc: beta\ncargo: beta\nrustfmt: beta")
stage0.write(
"#ignore\n\ndate: 2017-06-15\nrustc: beta\ncargo: beta\nrustfmt: beta")

def tearDown(self):
rmtree(self.rust_root)

def test_stage0_data(self):
"""Extract data from stage0.txt"""
expected = {"date": "2017-06-15", "rustc": "beta", "cargo": "beta", "rustfmt": "beta"}
expected = {"date": "2017-06-15", "rustc": "beta",
"cargo": "beta", "rustfmt": "beta"}
data = bootstrap.stage0_data(self.rust_root)
self.assertDictEqual(data, expected)


class VerifyTestCase(unittest.TestCase):
"""Test Case for verify"""

def setUp(self):
self.container = tempfile.mkdtemp()
self.src = os.path.join(self.container, "src.txt")
Expand Down Expand Up @@ -62,6 +65,7 @@ def test_invalid_file(self):

class ProgramOutOfDate(unittest.TestCase):
"""Test if a program is out of date"""

def setUp(self):
self.container = tempfile.mkdtemp()
os.mkdir(os.path.join(self.container, "stage0"))
Expand All @@ -79,19 +83,22 @@ def test_stamp_path_does_not_exists(self):
"""Return True when the stamp file does not exists"""
if os.path.exists(self.rustc_stamp_path):
os.unlink(self.rustc_stamp_path)
self.assertTrue(self.build.program_out_of_date(self.rustc_stamp_path, self.key))
self.assertTrue(self.build.program_out_of_date(
self.rustc_stamp_path, self.key))

def test_dates_are_different(self):
"""Return True when the dates are different"""
with open(self.rustc_stamp_path, "w") as rustc_stamp:
rustc_stamp.write("2017-06-14None")
self.assertTrue(self.build.program_out_of_date(self.rustc_stamp_path, self.key))
self.assertTrue(self.build.program_out_of_date(
self.rustc_stamp_path, self.key))

def test_same_dates(self):
"""Return False both dates match"""
with open(self.rustc_stamp_path, "w") as rustc_stamp:
rustc_stamp.write("2017-06-15None")
self.assertFalse(self.build.program_out_of_date(self.rustc_stamp_path, self.key))
self.assertFalse(self.build.program_out_of_date(
self.rustc_stamp_path, self.key))


if __name__ == '__main__':
Expand Down
Loading