Rollup merge of #100852 - Samyak2:samyak/100459, r=Mark-Simulacrum

Use `getuid` to check instead of `USER` env var in rustbuild

This makes it consistent with `x.py` as changed in #95671

Fixes #100459
This commit is contained in:
Matthias Krüger 2022-09-01 21:37:08 +02:00 committed by GitHub
commit b05f97d594
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -793,6 +793,8 @@ class RustBuild(object):
def check_vendored_status(self): def check_vendored_status(self):
"""Check that vendoring is configured properly""" """Check that vendoring is configured properly"""
# keep this consistent with the equivalent check in rustbuild:
# https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/lib.rs#L399-L405
if 'SUDO_USER' in os.environ and not self.use_vendored_sources: if 'SUDO_USER' in os.environ and not self.use_vendored_sources:
if os.getuid() == 0: if os.getuid() == 0:
self.use_vendored_sources = True self.use_vendored_sources = True

View File

@ -395,13 +395,18 @@ impl Build {
let src = config.src.clone(); let src = config.src.clone();
let out = config.out.clone(); let out = config.out.clone();
#[cfg(unix)]
// keep this consistent with the equivalent check in x.py:
// https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/bootstrap.py#L796-L797
let is_sudo = match env::var_os("SUDO_USER") { let is_sudo = match env::var_os("SUDO_USER") {
Some(sudo_user) => match env::var_os("USER") { Some(_sudo_user) => {
Some(user) => user != sudo_user, let uid = unsafe { libc::getuid() };
None => false, uid == 0
}, }
None => false, None => false,
}; };
#[cfg(not(unix))]
let is_sudo = false;
let ignore_git = config.ignore_git; let ignore_git = config.ignore_git;
let rust_info = channel::GitInfo::new(ignore_git, &src); let rust_info = channel::GitInfo::new(ignore_git, &src);