Auto merge of #62549 - ehuss:update-cargo-vendor, r=alexcrichton
Update cargo-vendor usage This contains a variety of updates to clean up the usage of cargo-vendor. - Remove the install step for the old cargo-vendor now that it is built-in to cargo and available in the stage0 install. - Update installation instructions, dealing with vendoring. The current instructions of running `sudo ./x.py install` is broken, it will almost always fail (since the vendor directory doesn't exist). Since the steps for properly handling this are numerous, I'm recommending removing the suggestion to use `sudo` altogether. - If the sudo-forced-vendoring detects that the vendor directory is not available, abort with instructions on how to fix. - Now that cargo-vendor is built-in, automatically run it if it looks like it is needed. - Update instructions on how to install cargo. - Remove the unused markdown link references in README/CONTRIBUTING. This reverts most of #44935. These references don't do anything if they are unused. Closes #49269 cc #61142 #48771 #40108
This commit is contained in:
commit
cd1381e91f
4 changed files with 72 additions and 96 deletions
|
|
@ -735,6 +735,47 @@ class RustBuild(object):
|
|||
"""Set download URL for development environment"""
|
||||
self._download_url = 'https://dev-static.rust-lang.org'
|
||||
|
||||
def check_vendored_status(self):
|
||||
"""Check that vendoring is configured properly"""
|
||||
vendor_dir = os.path.join(self.rust_root, 'vendor')
|
||||
if 'SUDO_USER' in os.environ and not self.use_vendored_sources:
|
||||
if os.environ.get('USER') != os.environ['SUDO_USER']:
|
||||
self.use_vendored_sources = True
|
||||
print('info: looks like you are running this command under `sudo`')
|
||||
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(' Run `cargo vendor` without sudo to initialize the '
|
||||
'vendor directory.')
|
||||
raise Exception("{} not found".format(vendor_dir))
|
||||
|
||||
if self.use_vendored_sources:
|
||||
if not os.path.exists('.cargo'):
|
||||
os.makedirs('.cargo')
|
||||
with output('.cargo/config') as cargo_config:
|
||||
cargo_config.write(
|
||||
"[source.crates-io]\n"
|
||||
"replace-with = 'vendored-sources'\n"
|
||||
"registry = 'https://example.com'\n"
|
||||
"\n"
|
||||
"[source.vendored-sources]\n"
|
||||
"directory = '{}/vendor'\n"
|
||||
.format(self.rust_root))
|
||||
else:
|
||||
if os.path.exists('.cargo'):
|
||||
shutil.rmtree('.cargo')
|
||||
|
||||
def ensure_vendored(self):
|
||||
"""Ensure that the vendored sources are available if needed"""
|
||||
vendor_dir = os.path.join(self.rust_root, 'vendor')
|
||||
# Note that this does not handle updating the vendored dependencies if
|
||||
# the rust git repository is updated. Normal development usually does
|
||||
# not use vendoring, so hopefully this isn't too much of a problem.
|
||||
if self.use_vendored_sources and not os.path.exists(vendor_dir):
|
||||
run([self.cargo(), "vendor"],
|
||||
verbose=self.verbose, cwd=self.rust_root)
|
||||
|
||||
|
||||
def bootstrap(help_triggered):
|
||||
"""Configure, fetch, build and run the initial bootstrap"""
|
||||
|
|
@ -776,30 +817,7 @@ def bootstrap(help_triggered):
|
|||
|
||||
build.use_locked_deps = '\nlocked-deps = true' in build.config_toml
|
||||
|
||||
if 'SUDO_USER' in os.environ and not build.use_vendored_sources:
|
||||
if os.environ.get('USER') != os.environ['SUDO_USER']:
|
||||
build.use_vendored_sources = True
|
||||
print('info: looks like you are running this command under `sudo`')
|
||||
print(' and so in order to preserve your $HOME this will now')
|
||||
print(' use vendored sources by default. Note that if this')
|
||||
print(' does not work you should run a normal build first')
|
||||
print(' before running a command like `sudo ./x.py install`')
|
||||
|
||||
if build.use_vendored_sources:
|
||||
if not os.path.exists('.cargo'):
|
||||
os.makedirs('.cargo')
|
||||
with output('.cargo/config') as cargo_config:
|
||||
cargo_config.write("""
|
||||
[source.crates-io]
|
||||
replace-with = 'vendored-sources'
|
||||
registry = 'https://example.com'
|
||||
|
||||
[source.vendored-sources]
|
||||
directory = '{}/vendor'
|
||||
""".format(build.rust_root))
|
||||
else:
|
||||
if os.path.exists('.cargo'):
|
||||
shutil.rmtree('.cargo')
|
||||
build.check_vendored_status()
|
||||
|
||||
data = stage0_data(build.rust_root)
|
||||
build.date = data['date']
|
||||
|
|
@ -815,6 +833,7 @@ def bootstrap(help_triggered):
|
|||
build.build = args.build or build.build_triple()
|
||||
build.download_stage0()
|
||||
sys.stdout.flush()
|
||||
build.ensure_vendored()
|
||||
build.build_bootstrap()
|
||||
sys.stdout.flush()
|
||||
|
||||
|
|
|
|||
|
|
@ -935,8 +935,6 @@ impl Step for Src {
|
|||
}
|
||||
}
|
||||
|
||||
const CARGO_VENDOR_VERSION: &str = "0.1.22";
|
||||
|
||||
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
|
||||
pub struct PlainSourceTarball;
|
||||
|
||||
|
|
@ -998,26 +996,6 @@ impl Step for PlainSourceTarball {
|
|||
|
||||
// If we're building from git sources, we need to vendor a complete distribution.
|
||||
if builder.rust_info.is_git() {
|
||||
// Get cargo-vendor installed, if it isn't already.
|
||||
let mut has_cargo_vendor = false;
|
||||
let mut cmd = Command::new(&builder.initial_cargo);
|
||||
for line in output(cmd.arg("install").arg("--list")).lines() {
|
||||
has_cargo_vendor |= line.starts_with("cargo-vendor ");
|
||||
}
|
||||
if !has_cargo_vendor {
|
||||
let mut cmd = builder.cargo(
|
||||
builder.compiler(0, builder.config.build),
|
||||
Mode::ToolBootstrap,
|
||||
builder.config.build,
|
||||
"install"
|
||||
);
|
||||
cmd.arg("--force")
|
||||
.arg("--debug")
|
||||
.arg("--vers").arg(CARGO_VENDOR_VERSION)
|
||||
.arg("cargo-vendor");
|
||||
builder.run(&mut cmd);
|
||||
}
|
||||
|
||||
// Vendor all Cargo dependencies
|
||||
let mut cmd = Command::new(&builder.initial_cargo);
|
||||
cmd.arg("vendor")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue