Skip to content

Commit

Permalink
fix(windows): allow to compile in a windows machine (#542)
Browse files Browse the repository at this point in the history
## What problem are you trying to solve?

While trying to compile the project in my Windows 11 machine I found out I was unable to compile the project due to some issues:

1. use of unix commands in build.rs
1. walkdir dependency mismatch

## What is your solution?

1. I replaced the UNIX commands for Rust commands.
1. Updated Walkdir to 2.5.0, which is the latest version. For some reason, the version we had in Cargo.toml (2.3.3) didn't have the `follow_root_links` method that we're using in `file_utils.rs`. Not sure how, in Mac we're getting the right version (maybe through another dependency), but this is not true in Windows, so I decided to update the dependency.

## Alternatives considered

## What the reviewer should know

Tested this in a Windows 11 machine and it works.

RE #541
  • Loading branch information
robertohuertasm authored Oct 31, 2024
1 parent 1124ae0 commit 2e96cc1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ git2 = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
derive_builder = { workspace = true }
num_cpus = { workspace = true}
num_cpus = { workspace = true }
serde-sarif = { workspace = true }
sha2 = { workspace = true }
uuid = { workspace = true }
Expand All @@ -29,7 +29,7 @@ percent-encoding = "2.3.1"
prettytable-rs = "0.10.0"
reqwest = { version = "0.11", features = ["blocking", "json"] }
valico = "4.0.0"
walkdir = "2.3.3"
walkdir = "2.5.0"
itertools = "0.12.1"

[dev-dependencies]
Expand Down
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 2e96cc1

Please sign in to comment.