Skip to content

Commit

Permalink
fix build.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
robertohuertasm committed Oct 30, 2024
1 parent 3c0a461 commit bf21bf8
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions crates/static-analysis-kernel/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::{env, fs};

/// Executes a [`Command`], returning true if the command finished with exit status 0, otherwise false
fn run<F>(name: &str, mut configure: F) -> bool
Expand Down Expand Up @@ -249,9 +249,16 @@ fn main() {
// 2. Build the project
let base_dir = env::current_dir().unwrap();
for proj in &tree_sitter_projects {
let project_dir = format!(".vendor/{}@{}", &proj.name, &proj.commit_hash);
if !Path::new(&project_dir).exists() {
assert!(run("mkdir", |cmd| { cmd.args(["-p", &project_dir]) }));
let project_dir: PathBuf = [
Path::new(".vendor"),
Path::new(&format!("{}@{}", proj.name, proj.commit_hash)),
]
.iter()
.collect();

if !project_dir.exists() {
fs::create_dir_all(&project_dir).expect("Failed to create project directory");

env::set_current_dir(&project_dir).unwrap();
assert!(run("git", |cmd| { cmd.args(["init", "-q"]) }));
assert!(run("git", |cmd| {
Expand All @@ -275,7 +282,8 @@ fn main() {
assert!(run("git", |cmd| {
cmd.args(["checkout", "-q", "FETCH_HEAD"])
}));
assert!(run("rm", |cmd| { cmd.args(["-rf", ".git"]) }));

fs::remove_dir_all(".git").expect("Failed to remove .git directory");
env::set_current_dir(&base_dir).unwrap();
}
env::set_current_dir(&project_dir).unwrap();
Expand Down

0 comments on commit bf21bf8

Please sign in to comment.