Skip to content

Commit

Permalink
Consistently use a string to represent a submodule.
Browse files Browse the repository at this point in the history
This makes it easier to call these functions without needing to form a
Path.
  • Loading branch information
ehuss committed Jul 27, 2024
1 parent f76ab64 commit 9b0115c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl LdFlags {
/// if not).
pub fn prebuilt_llvm_config(builder: &Builder<'_>, target: TargetSelection) -> LlvmBuildStatus {
// If we have llvm submodule initialized already, sync it.
builder.update_existing_submodule(&Path::new("src").join("llvm-project"));
builder.update_existing_submodule("src/llvm-project");

builder.config.maybe_download_ci_llvm();

Expand Down
20 changes: 10 additions & 10 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ impl Build {
// Cargo.toml files.
let rust_submodules = ["library/backtrace", "library/stdarch"];
for s in rust_submodules {
build.update_submodule(Path::new(s));
build.update_submodule(s);
}
// Now, update all existing submodules.
build.update_existing_submodules();
Expand Down Expand Up @@ -479,7 +479,7 @@ impl Build {
/// tarball). Typically [`Build::require_and_update_submodule`] should be
/// used instead to provide a nice error to the user if the submodule is
/// missing.
fn update_submodule(&self, relative_path: &Path) {
fn update_submodule(&self, relative_path: &str) {
if !self.config.submodules() {
return;
}
Expand Down Expand Up @@ -527,7 +527,7 @@ impl Build {
return;
}

println!("Updating submodule {}", relative_path.display());
println!("Updating submodule {relative_path}");
helpers::git(Some(&self.src))
.run_always()
.args(["submodule", "-q", "sync"])
Expand Down Expand Up @@ -596,9 +596,8 @@ impl Build {
if cfg!(test) && !self.config.submodules() {
return;
}
let relative_path = Path::new(submodule);
self.update_submodule(relative_path);
let absolute_path = self.config.src.join(relative_path);
self.update_submodule(submodule);
let absolute_path = self.config.src.join(submodule);
if dir_is_empty(&absolute_path) {
let maybe_enable = if !self.config.submodules()
&& self.config.rust_info.is_managed_git_subrepository()
Expand Down Expand Up @@ -642,22 +641,23 @@ impl Build {
for line in output.lines() {
// Look for `submodule.$name.path = $path`
// Sample output: `submodule.src/rust-installer.path src/tools/rust-installer`
let submodule = Path::new(line.split_once(' ').unwrap().1);
let submodule = line.split_once(' ').unwrap().1;
let path = Path::new(submodule);
// Don't update the submodule unless it's already been cloned.
if GitInfo::new(false, submodule).is_managed_git_subrepository() {
if GitInfo::new(false, path).is_managed_git_subrepository() {
self.update_submodule(submodule);
}
}
}

/// Updates the given submodule only if it's initialized already; nothing happens otherwise.
pub fn update_existing_submodule(&self, submodule: &Path) {
pub fn update_existing_submodule(&self, submodule: &str) {
// Avoid running git when there isn't a git checkout.
if !self.config.submodules() {
return;
}

if GitInfo::new(false, submodule).is_managed_git_subrepository() {
if GitInfo::new(false, Path::new(submodule)).is_managed_git_subrepository() {
self.update_submodule(submodule);
}
}
Expand Down

0 comments on commit 9b0115c

Please sign in to comment.