Skip to content

Commit f4dcfa6

Browse files
authored
Rollup merge of rust-lang#147233 - GuillaumeGomez:citool-submodule-init, r=Kobzol
Initialize llvm submodule if not already the case to run citool While working on rust-lang#146414, I ran the following command (to run CI docker locally): ``` cargo run --manifest-path src/ci/citool/Cargo.toml run-local --type pr x86_64-gnu-gcc ``` However, since I didn't have `src/llvm` submodule initialized, it failed. Apparently it's a common issue for people using this tool so this PR removes this small inconvenience. r? ``@Kobzol``
2 parents fbe6834 + 4baf920 commit f4dcfa6

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/ci/citool/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "citool"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[dependencies]
77
anyhow = "1"

src/ci/citool/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::github::JobInfoResolver;
2424
use crate::jobs::RunType;
2525
use crate::metrics::{JobMetrics, download_auto_job_metrics, download_job_metrics, load_metrics};
2626
use crate::test_dashboard::generate_test_dashboard;
27-
use crate::utils::{load_env_var, output_details};
27+
use crate::utils::{init_submodule_if_needed, load_env_var, output_details};
2828

2929
const CI_DIRECTORY: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/..");
3030
pub const DOCKER_DIRECTORY: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../docker");
@@ -121,6 +121,8 @@ fn run_workflow_locally(db: JobDatabase, job_type: JobType, name: String) -> any
121121
(key.clone(), value)
122122
}));
123123

124+
init_submodule_if_needed("src/llvm-project/")?;
125+
124126
let mut cmd = Command::new(Path::new(DOCKER_DIRECTORY).join("run.sh"));
125127
cmd.arg(job.image());
126128
cmd.envs(custom_env);

src/ci/citool/src/utils.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::borrow::Cow;
2+
use std::convert::AsRef;
23
use std::path::Path;
4+
use std::process::Command;
35

46
use anyhow::Context;
57

@@ -34,3 +36,19 @@ where
3436
pub fn normalize_path_delimiters(name: &str) -> Cow<'_, str> {
3537
if name.contains("\\") { name.replace('\\', "/").into() } else { name.into() }
3638
}
39+
40+
pub fn init_submodule_if_needed<P: AsRef<Path>>(path_to_submodule: P) -> anyhow::Result<()> {
41+
let path_to_submodule = path_to_submodule.as_ref();
42+
43+
if let Ok(mut iter) = path_to_submodule.read_dir()
44+
&& iter.any(|entry| entry.is_ok())
45+
{
46+
// Seems like the submodule is already initialized, nothing to be done here.
47+
return Ok(());
48+
}
49+
let mut child = Command::new("git")
50+
.args(&["submodule", "update", "--init"])
51+
.arg(path_to_submodule)
52+
.spawn()?;
53+
if !child.wait()?.success() { Err(anyhow::anyhow!("git command failed")) } else { Ok(()) }
54+
}

0 commit comments

Comments
 (0)