Skip to content

Commit aad54a8

Browse files
committed
invoke functions from methods
1 parent 621af4a commit aad54a8

File tree

1 file changed

+28
-204
lines changed

1 file changed

+28
-204
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 28 additions & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,14 +1469,7 @@ impl Config {
14691469

14701470
/// Returns the content of the given file at a specific commit.
14711471
pub(crate) fn read_file_by_commit(&self, file: &Path, commit: &str) -> String {
1472-
assert!(
1473-
self.rust_info.is_managed_git_subrepository(),
1474-
"`Config::read_file_by_commit` is not supported in non-git sources."
1475-
);
1476-
1477-
let mut git = helpers::git(Some(&self.src));
1478-
git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap()));
1479-
git.run_capture_stdout(self).stdout()
1472+
read_file_by_commit(&self.exec_ctx, &self.src, &self.rust_info, file, commit)
14801473
}
14811474

14821475
/// Bootstrap embeds a version number into the name of shared libraries it uploads in CI.
@@ -1547,8 +1540,7 @@ impl Config {
15471540

15481541
/// The absolute path to the downloaded LLVM artifacts.
15491542
pub(crate) fn ci_llvm_root(&self) -> PathBuf {
1550-
assert!(self.llvm_from_ci);
1551-
self.out.join(self.host_target).join("ci-llvm")
1543+
ci_llvm_root(self.llvm_from_ci, &self.out, &self.host_target)
15521544
}
15531545

15541546
/// Directory where the extracted `rustc-dev` component is stored.
@@ -1711,115 +1703,13 @@ impl Config {
17111703
),
17121704
)]
17131705
pub(crate) fn update_submodule(&self, relative_path: &str) {
1714-
if self.rust_info.is_from_tarball() || !self.submodules() {
1715-
return;
1716-
}
1717-
1718-
let absolute_path = self.src.join(relative_path);
1719-
1720-
// NOTE: This check is required because `jj git clone` doesn't create directories for
1721-
// submodules, they are completely ignored. The code below assumes this directory exists,
1722-
// so create it here.
1723-
if !absolute_path.exists() {
1724-
t!(fs::create_dir_all(&absolute_path));
1725-
}
1726-
1727-
// NOTE: The check for the empty directory is here because when running x.py the first time,
1728-
// the submodule won't be checked out. Check it out now so we can build it.
1729-
if !self.git_info(false, &absolute_path).is_managed_git_subrepository()
1730-
&& !helpers::dir_is_empty(&absolute_path)
1731-
{
1732-
return;
1733-
}
1734-
1735-
// Submodule updating actually happens during in the dry run mode. We need to make sure that
1736-
// all the git commands below are actually executed, because some follow-up code
1737-
// in bootstrap might depend on the submodules being checked out. Furthermore, not all
1738-
// the command executions below work with an empty output (produced during dry run).
1739-
// Therefore, all commands below are marked with `run_in_dry_run()`, so that they also run in
1740-
// dry run mode.
1741-
let submodule_git = || {
1742-
let mut cmd = helpers::git(Some(&absolute_path));
1743-
cmd.run_in_dry_run();
1744-
cmd
1745-
};
1746-
1747-
// Determine commit checked out in submodule.
1748-
let checked_out_hash =
1749-
submodule_git().args(["rev-parse", "HEAD"]).run_capture_stdout(self).stdout();
1750-
let checked_out_hash = checked_out_hash.trim_end();
1751-
// Determine commit that the submodule *should* have.
1752-
let recorded = helpers::git(Some(&self.src))
1753-
.run_in_dry_run()
1754-
.args(["ls-tree", "HEAD"])
1755-
.arg(relative_path)
1756-
.run_capture_stdout(self)
1757-
.stdout();
1758-
1759-
let actual_hash = recorded
1760-
.split_whitespace()
1761-
.nth(2)
1762-
.unwrap_or_else(|| panic!("unexpected output `{recorded}`"));
1763-
1764-
if actual_hash == checked_out_hash {
1765-
// already checked out
1766-
return;
1767-
}
1768-
1769-
println!("Updating submodule {relative_path}");
1770-
1771-
helpers::git(Some(&self.src))
1772-
.allow_failure()
1773-
.run_in_dry_run()
1774-
.args(["submodule", "-q", "sync"])
1775-
.arg(relative_path)
1776-
.run(self);
1777-
1778-
// Try passing `--progress` to start, then run git again without if that fails.
1779-
let update = |progress: bool| {
1780-
// Git is buggy and will try to fetch submodules from the tracking branch for *this* repository,
1781-
// even though that has no relation to the upstream for the submodule.
1782-
let current_branch = helpers::git(Some(&self.src))
1783-
.allow_failure()
1784-
.run_in_dry_run()
1785-
.args(["symbolic-ref", "--short", "HEAD"])
1786-
.run_capture(self);
1787-
1788-
let mut git = helpers::git(Some(&self.src)).allow_failure();
1789-
git.run_in_dry_run();
1790-
if current_branch.is_success() {
1791-
// If there is a tag named after the current branch, git will try to disambiguate by prepending `heads/` to the branch name.
1792-
// This syntax isn't accepted by `branch.{branch}`. Strip it.
1793-
let branch = current_branch.stdout();
1794-
let branch = branch.trim();
1795-
let branch = branch.strip_prefix("heads/").unwrap_or(branch);
1796-
git.arg("-c").arg(format!("branch.{branch}.remote=origin"));
1797-
}
1798-
git.args(["submodule", "update", "--init", "--recursive", "--depth=1"]);
1799-
if progress {
1800-
git.arg("--progress");
1801-
}
1802-
git.arg(relative_path);
1803-
git
1804-
};
1805-
if !update(true).allow_failure().run(self) {
1806-
update(false).allow_failure().run(self);
1807-
}
1808-
1809-
// Save any local changes, but avoid running `git stash pop` if there are none (since it will exit with an error).
1810-
// diff-index reports the modifications through the exit status
1811-
let has_local_modifications =
1812-
!submodule_git().allow_failure().args(["diff-index", "--quiet", "HEAD"]).run(self);
1813-
if has_local_modifications {
1814-
submodule_git().allow_failure().args(["stash", "push"]).run(self);
1815-
}
1816-
1817-
submodule_git().allow_failure().args(["reset", "-q", "--hard"]).run(self);
1818-
submodule_git().allow_failure().args(["clean", "-qdfx"]).run(self);
1819-
1820-
if has_local_modifications {
1821-
submodule_git().allow_failure().args(["stash", "pop"]).run(self);
1822-
}
1706+
update_submodule(
1707+
&self.submodules,
1708+
&self.exec_ctx,
1709+
&self.src,
1710+
&self.rust_info,
1711+
relative_path,
1712+
);
18231713
}
18241714

18251715
/// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
@@ -1829,78 +1719,18 @@ impl Config {
18291719
debug_assertions_requested: bool,
18301720
llvm_assertions: bool,
18311721
) -> Option<String> {
1832-
if !is_download_ci_available(&self.host_target.triple, llvm_assertions) {
1833-
return None;
1834-
}
1835-
1836-
// If `download-rustc` is not set, default to rebuilding.
1837-
let if_unchanged = match download_rustc {
1838-
// Globally default `download-rustc` to `false`, because some contributors don't use
1839-
// profiles for reasons such as:
1840-
// - They need to seamlessly switch between compiler/library work.
1841-
// - They don't want to use compiler profile because they need to override too many
1842-
// things and it's easier to not use a profile.
1843-
None | Some(StringOrBool::Bool(false)) => return None,
1844-
Some(StringOrBool::Bool(true)) => false,
1845-
Some(StringOrBool::String(s)) if s == "if-unchanged" => {
1846-
if !self.rust_info.is_managed_git_subrepository() {
1847-
println!(
1848-
"ERROR: `download-rustc=if-unchanged` is only compatible with Git managed sources."
1849-
);
1850-
crate::exit!(1);
1851-
}
1852-
1853-
true
1854-
}
1855-
Some(StringOrBool::String(other)) => {
1856-
panic!("unrecognized option for download-rustc: {other}")
1857-
}
1858-
};
1859-
1860-
let commit = if self.rust_info.is_managed_git_subrepository() {
1861-
// Look for a version to compare to based on the current commit.
1862-
// Only commits merged by bors will have CI artifacts.
1863-
let freshness = self.check_path_modifications(RUSTC_IF_UNCHANGED_ALLOWED_PATHS);
1864-
self.verbose(|| {
1865-
eprintln!("rustc freshness: {freshness:?}");
1866-
});
1867-
match freshness {
1868-
PathFreshness::LastModifiedUpstream { upstream } => upstream,
1869-
PathFreshness::HasLocalModifications { upstream } => {
1870-
if if_unchanged {
1871-
return None;
1872-
}
1873-
1874-
if self.is_running_on_ci {
1875-
eprintln!("CI rustc commit matches with HEAD and we are in CI.");
1876-
eprintln!(
1877-
"`rustc.download-ci` functionality will be skipped as artifacts are not available."
1878-
);
1879-
return None;
1880-
}
1881-
1882-
upstream
1883-
}
1884-
PathFreshness::MissingUpstream => {
1885-
eprintln!("No upstream commit found");
1886-
return None;
1887-
}
1888-
}
1889-
} else {
1890-
channel::read_commit_info_file(&self.src)
1891-
.map(|info| info.sha.trim().to_owned())
1892-
.expect("git-commit-info is missing in the project root")
1893-
};
1894-
1895-
if debug_assertions_requested {
1896-
eprintln!(
1897-
"WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
1898-
rustc is not currently built with debug assertions."
1899-
);
1900-
return None;
1901-
}
1902-
1903-
Some(commit)
1722+
download_ci_rustc_commit(
1723+
&self.stage0_metadata,
1724+
self.path_modification_cache.clone(),
1725+
&self.src,
1726+
self.is_running_on_ci,
1727+
&self.exec_ctx,
1728+
&self.rust_info,
1729+
&self.host_target,
1730+
download_rustc,
1731+
debug_assertions_requested,
1732+
llvm_assertions,
1733+
)
19041734
}
19051735

19061736
pub fn parse_download_ci_llvm(
@@ -1966,10 +1796,12 @@ impl Config {
19661796

19671797
/// Returns true if any of the `paths` have been modified locally.
19681798
pub fn has_changes_from_upstream(&self, paths: &[&'static str]) -> bool {
1969-
match self.check_path_modifications(paths) {
1970-
PathFreshness::LastModifiedUpstream { .. } => false,
1971-
PathFreshness::HasLocalModifications { .. } | PathFreshness::MissingUpstream => true,
1972-
}
1799+
has_changes_from_upstream(
1800+
&self.stage0_metadata,
1801+
&self.src,
1802+
self.path_modification_cache.clone(),
1803+
paths,
1804+
)
19731805
}
19741806

19751807
/// Checks whether any of the given paths have been modified w.r.t. upstream.
@@ -2077,15 +1909,7 @@ impl Config {
20771909
///
20781910
/// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set.
20791911
pub fn is_system_llvm(&self, target: TargetSelection) -> bool {
2080-
match self.target_config.get(&target) {
2081-
Some(Target { llvm_config: Some(_), .. }) => {
2082-
let ci_llvm = self.llvm_from_ci && self.is_host_target(target);
2083-
!ci_llvm
2084-
}
2085-
// We're building from the in-tree src/llvm-project sources.
2086-
Some(Target { llvm_config: None, .. }) => false,
2087-
None => false,
2088-
}
1912+
is_system_llvm(&self.host_target, self.llvm_from_ci, &self.target_config, target)
20891913
}
20901914

20911915
/// Returns `true` if this is our custom, patched, version of LLVM.

0 commit comments

Comments
 (0)