add LLVM 18.x as a git submodule (#399)

This changeset is based on https://github.com/paritytech/revive/pull/346
This commit is contained in:
kvpanch
2025-11-18 16:10:15 -05:00
committed by GitHub
parent a1090cfa5a
commit e78f3cc419
18 changed files with 89 additions and 310 deletions
+38 -19
View File
@@ -1,32 +1,51 @@
use assert_fs::fixture::FileWriteStr;
use assert_fs::TempDir;
pub const REVIVE_LLVM: &str = "revive-llvm";
pub const REVIVE_LLVM_REPO_URL: &str = "https://github.com/llvm/llvm-project";
pub const REVIVE_LLVM_REPO_TEST_BRANCH: &str = "release/18.x";
pub struct TestDir {
_lockfile: assert_fs::NamedTempFile,
_tempdir: TempDir,
path: std::path::PathBuf,
}
/// Creates a temporary lock file for testing.
/// Creates a temporary directory for testing with submodule setup.
impl TestDir {
pub fn with_lockfile(reference: Option<String>) -> anyhow::Result<Self> {
let file =
assert_fs::NamedTempFile::new(revive_llvm_builder::lock::LLVM_LOCK_DEFAULT_PATH)?;
let lock = revive_llvm_builder::Lock {
url: REVIVE_LLVM_REPO_URL.to_string(),
branch: REVIVE_LLVM_REPO_TEST_BRANCH.to_string(),
r#ref: reference,
};
file.write_str(toml::to_string(&lock)?.as_str())?;
pub fn new() -> anyhow::Result<Self> {
let tempdir = TempDir::new()?;
let tmppath = tempdir.path();
// Initialize a git repo and add the LLVM submodule
std::process::Command::new("git")
.args(["init"])
.current_dir(tmppath)
.output()?;
std::process::Command::new("git")
.args([
"submodule",
"add",
"-b",
"release/18.x",
"https://github.com/llvm/llvm-project.git",
"llvm",
])
.current_dir(tmppath)
.output()?;
std::process::Command::new("git")
.args([
"submodule",
"update",
"--init",
"--recursive",
"--force",
"--depth 1",
])
.current_dir(tmppath)
.output()?;
Ok(Self {
path: file
.parent()
.expect("lockfile parent dir always exists")
.into(),
_lockfile: file,
path: tmppath.to_path_buf(),
_tempdir: tempdir,
})
}