From 61807ff563a3eebfe077db7849dfee5e819cbf50 Mon Sep 17 00:00:00 2001 From: Xavier Pinho Date: Wed, 22 Apr 2026 12:10:17 +0100 Subject: [PATCH 1/3] preserve the original .rs file extension in the output json file names --- Cargo.lock | 2 +- Cargo.toml | 2 +- .../rust2cpg/parser/RustNodeSyntax.scala | 2 +- src/config.rs | 73 ++++++++++++++++++- 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57c6493..b74ff9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1982,7 +1982,7 @@ dependencies = [ [[package]] name = "rust_ast_gen" -version = "0.2.0" +version = "0.3.0" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index b750a97..96df8f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust_ast_gen" -version = "0.2.0" +version = "0.3.0" edition = "2024" [dependencies] diff --git a/scala_tests/src/main/scala/io/joern/rust2cpg/parser/RustNodeSyntax.scala b/scala_tests/src/main/scala/io/joern/rust2cpg/parser/RustNodeSyntax.scala index ecd3a43..3512974 100644 --- a/scala_tests/src/main/scala/io/joern/rust2cpg/parser/RustNodeSyntax.scala +++ b/scala_tests/src/main/scala/io/joern/rust2cpg/parser/RustNodeSyntax.scala @@ -1,6 +1,6 @@ package io.joern.rust2cpg.parser -// Automatically generated by rust_ast_gen v0.2.0 +// Automatically generated by rust_ast_gen v0.3.0 // Do not edit directly! import ujson.Value diff --git a/src/config.rs b/src/config.rs index edf6c16..4365198 100644 --- a/src/config.rs +++ b/src/config.rs @@ -53,8 +53,79 @@ impl RustAstGenConfig { let output_file_full_path = self .output_dir_full_path .join(relative_to_input_path) - .with_extension("json"); + .with_added_extension("json"); Ok(output_file_full_path) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + #[cfg(unix)] + fn test_make_output_path_for_input_file_success_unix() -> Result<()> { + let input_dir = PathBuf::from("/input"); + let output_dir = PathBuf::from("/output"); + let config = RustAstGenConfig::new(input_dir.clone(), output_dir.clone(), 1)?; + + let input_file = input_dir.join("subdir").join("file.rs"); + let output_file = config.make_output_path_for_input_file(&input_file)?; + + let expected_output_file = output_dir.join("subdir").join("file.rs.json"); + assert_eq!(output_file, expected_output_file); + + Ok(()) + } + + #[test] + #[cfg(windows)] + fn test_make_output_path_for_input_file_success_windows() -> Result<()> { + let input_dir = PathBuf::from(r"C:\input"); + let output_dir = PathBuf::from(r"C:\output"); + let config = RustAstGenConfig::new(input_dir.clone(), output_dir.clone(), 1)?; + + let input_file = input_dir.join("subdir").join("file.rs"); + let output_file = config.make_output_path_for_input_file(&input_file)?; + + let expected_output_file = output_dir.join("subdir").join("file.rs.json"); + assert_eq!(output_file, expected_output_file); + + Ok(()) + } + + #[test] + #[cfg(unix)] + fn test_make_output_path_for_input_file_not_under_input_dir_unix() -> Result<()> { + let input_dir = PathBuf::from("/input"); + let output_dir = PathBuf::from("/output"); + let config = RustAstGenConfig::new(input_dir, output_dir, 1)?; + + let other_file = PathBuf::from("/other/file.rs"); + let result = config.make_output_path_for_input_file(&other_file); + + assert!(result.is_err()); + let error_message = format!("{}", result.unwrap_err()); + assert!(error_message.contains("not able to relativize")); + + Ok(()) + } + + #[test] + #[cfg(windows)] + fn test_make_output_path_for_input_file_not_under_input_dir_windows() -> Result<()> { + let input_dir = PathBuf::from(r"C:\input"); + let output_dir = PathBuf::from(r"C:\output"); + let config = RustAstGenConfig::new(input_dir, output_dir, 1)?; + + let other_file = PathBuf::from(r"C:\other\file.rs"); + let result = config.make_output_path_for_input_file(&other_file); + + assert!(result.is_err()); + let error_message = format!("{}", result.unwrap_err()); + assert!(error_message.contains("not able to relativize")); + + Ok(()) + } +} From d0301cfba967f91364f3c479c27292eb6d65ac14 Mon Sep 17 00:00:00 2001 From: Xavier Pinho Date: Wed, 22 Apr 2026 12:21:56 +0100 Subject: [PATCH 2/3] fix scala_tests --- .../scala/io/joern/rust2cpg/parser/RustAstGenTestFixture.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala_tests/src/test/scala/io/joern/rust2cpg/parser/RustAstGenTestFixture.scala b/scala_tests/src/test/scala/io/joern/rust2cpg/parser/RustAstGenTestFixture.scala index 32a7d51..ab1e34e 100644 --- a/scala_tests/src/test/scala/io/joern/rust2cpg/parser/RustAstGenTestFixture.scala +++ b/scala_tests/src/test/scala/io/joern/rust2cpg/parser/RustAstGenTestFixture.scala @@ -46,7 +46,7 @@ trait RustAstGenTestFixture { require(exitCode == 0, s"rust_ast_gen failed with exit code $exitCode") - val json = ujson.read(Files.readString(outputDir.resolve("src").resolve("main.json"))) + val json = ujson.read(Files.readString(outputDir.resolve("src").resolve("main.rs.json"))) RustNodeSyntax.createRustNode(sourceFileJson(json)).asInstanceOf[SourceFile] } finally { deleteRecursively(projectDir) From e26ac114682c460fc86874301fa4a86d5a64a3a8 Mon Sep 17 00:00:00 2001 From: Xavier Pinho Date: Wed, 22 Apr 2026 12:27:59 +0100 Subject: [PATCH 3/3] update actions/setup-java and actions/checkout --- .github/workflows/pr.yml | 4 ++-- .github/workflows/release.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 9be6eb4..c1441f9 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: fetch-depth: 0 @@ -27,7 +27,7 @@ jobs: run: cargo test --locked - name: Set up Java - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: distribution: temurin java-version: "21" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 221fe44..75498ec 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Set up Rust uses: dtolnay/rust-toolchain@stable @@ -51,7 +51,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Set up Rust uses: dtolnay/rust-toolchain@stable