Skip to content

Commit ad30826

Browse files
Revert "Move llvm submodule updates to rustbuild"
1 parent 126561c commit ad30826

File tree

4 files changed

+13
-98
lines changed

4 files changed

+13
-98
lines changed

src/bootstrap/bootstrap.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -991,20 +991,28 @@ def update_submodules(self):
991991
).decode(default_encoding).splitlines()]
992992
filtered_submodules = []
993993
submodules_names = []
994+
llvm_checked_out = os.path.exists(os.path.join(self.rust_root, "src/llvm-project/.git"))
995+
external_llvm_provided = self.get_toml('llvm-config') or self.downloading_llvm()
996+
llvm_needed = not self.get_toml('codegen-backends', 'rust') \
997+
or "llvm" in self.get_toml('codegen-backends', 'rust')
994998
for module in submodules:
995-
# This is handled by native::Llvm in rustbuild, not here
996999
if module.endswith("llvm-project"):
997-
continue
1000+
# Don't sync the llvm-project submodule if an external LLVM was
1001+
# provided, if we are downloading LLVM or if the LLVM backend is
1002+
# not being built. Also, if the submodule has been initialized
1003+
# already, sync it anyways so that it doesn't mess up contributor
1004+
# pull requests.
1005+
if external_llvm_provided or not llvm_needed:
1006+
if self.get_toml('lld') != 'true' and not llvm_checked_out:
1007+
continue
9981008
check = self.check_submodule(module, slow_submodules)
9991009
filtered_submodules.append((module, check))
10001010
submodules_names.append(module)
10011011
recorded = subprocess.Popen(["git", "ls-tree", "HEAD"] + submodules_names,
10021012
cwd=self.rust_root, stdout=subprocess.PIPE)
10031013
recorded = recorded.communicate()[0].decode(default_encoding).strip().splitlines()
1004-
# { filename: hash }
10051014
recorded_submodules = {}
10061015
for data in recorded:
1007-
# [mode, kind, hash, filename]
10081016
data = data.split()
10091017
recorded_submodules[data[3]] = data[2]
10101018
for module in filtered_submodules:

src/bootstrap/lib.rs

-10
Original file line numberDiff line numberDiff line change
@@ -472,22 +472,12 @@ impl Build {
472472
slice::from_ref(&self.build.triple)
473473
}
474474

475-
/// If the LLVM submodule has been initialized already, sync it unconditionally. This avoids
476-
/// contributors checking in a submodule change by accident.
477-
pub fn maybe_update_llvm_submodule(&self) {
478-
if self.in_tree_llvm_info.is_git() {
479-
native::update_llvm_submodule(self);
480-
}
481-
}
482-
483475
/// Executes the entire build, as configured by the flags and configuration.
484476
pub fn build(&mut self) {
485477
unsafe {
486478
job::setup(self);
487479
}
488480

489-
self.maybe_update_llvm_submodule();
490-
491481
if let Subcommand::Format { check, paths } = &self.config.cmd {
492482
return format::format(self, *check, &paths);
493483
}

src/bootstrap/native.rs

+1-83
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use build_helper::{output, t};
2121
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
2222
use crate::config::TargetSelection;
2323
use crate::util::{self, exe};
24-
use crate::{Build, GitRepo};
24+
use crate::GitRepo;
2525
use build_helper::up_to_date;
2626

2727
pub struct Meta {
@@ -91,85 +91,6 @@ pub fn prebuilt_llvm_config(
9191
Err(Meta { stamp, build_llvm_config, out_dir, root: root.into() })
9292
}
9393

94-
// modified from `check_submodule` and `update_submodule` in bootstrap.py
95-
pub(crate) fn update_llvm_submodule(build: &Build) {
96-
let llvm_project = &Path::new("src").join("llvm-project");
97-
98-
fn dir_is_empty(dir: &Path) -> bool {
99-
t!(std::fs::read_dir(dir)).next().is_none()
100-
}
101-
102-
// NOTE: The check for the empty directory is here because when running x.py
103-
// the first time, the llvm submodule won't be checked out. Check it out
104-
// now so we can build it.
105-
if !build.in_tree_llvm_info.is_git() && !dir_is_empty(&build.config.src.join(llvm_project)) {
106-
return;
107-
}
108-
109-
// check_submodule
110-
let checked_out = if build.config.fast_submodules {
111-
Some(output(
112-
Command::new("git")
113-
.args(&["rev-parse", "HEAD"])
114-
.current_dir(build.config.src.join(llvm_project)),
115-
))
116-
} else {
117-
None
118-
};
119-
120-
// update_submodules
121-
let recorded = output(
122-
Command::new("git")
123-
.args(&["ls-tree", "HEAD"])
124-
.arg(llvm_project)
125-
.current_dir(&build.config.src),
126-
);
127-
let hash =
128-
recorded.split(' ').nth(2).unwrap_or_else(|| panic!("unexpected output `{}`", recorded));
129-
130-
// update_submodule
131-
if let Some(llvm_hash) = checked_out {
132-
if hash == llvm_hash {
133-
// already checked out
134-
return;
135-
}
136-
}
137-
138-
println!("Updating submodule {}", llvm_project.display());
139-
build.run(
140-
Command::new("git")
141-
.args(&["submodule", "-q", "sync"])
142-
.arg(llvm_project)
143-
.current_dir(&build.config.src),
144-
);
145-
146-
// Try passing `--progress` to start, then run git again without if that fails.
147-
let update = |progress: bool| {
148-
let mut git = Command::new("git");
149-
git.args(&["submodule", "update", "--init", "--recursive"]);
150-
if progress {
151-
git.arg("--progress");
152-
}
153-
git.arg(llvm_project).current_dir(&build.config.src);
154-
git
155-
};
156-
// NOTE: doesn't use `try_run` because this shouldn't print an error if it fails.
157-
if !update(true).status().map_or(false, |status| status.success()) {
158-
build.run(&mut update(false));
159-
}
160-
161-
build.run(
162-
Command::new("git")
163-
.args(&["reset", "-q", "--hard"])
164-
.current_dir(build.config.src.join(llvm_project)),
165-
);
166-
build.run(
167-
Command::new("git")
168-
.args(&["clean", "-qdfx"])
169-
.current_dir(build.config.src.join(llvm_project)),
170-
);
171-
}
172-
17394
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
17495
pub struct Llvm {
17596
pub target: TargetSelection,
@@ -207,9 +128,6 @@ impl Step for Llvm {
207128
Err(m) => m,
208129
};
209130

210-
if !builder.config.dry_run {
211-
update_llvm_submodule(builder);
212-
}
213131
if builder.config.llvm_link_shared
214132
&& (target.contains("windows") || target.contains("apple-darwin"))
215133
{

src/build_helper/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ pub fn make(host: &str) -> PathBuf {
130130
}
131131
}
132132

133-
#[track_caller]
134133
pub fn output(cmd: &mut Command) -> String {
135134
let output = match cmd.stderr(Stdio::inherit()).output() {
136135
Ok(status) => status,

0 commit comments

Comments
 (0)