Skip to content
This repository was archived by the owner on Apr 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
fetch-depth: 0

Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust_ast_gen"
version = "0.2.0"
version = "0.3.0"
edition = "2024"

[dependencies]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
73 changes: 72 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
Loading