Skip to content
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
2 changes: 2 additions & 0 deletions crates/ruff_charon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
//! A `MAY_DISPATCH` row is never a confirmed caller (crai-rs RS-F07). Nothing
//! is inferred from names.

pub mod store;

use std::fmt::Write as _;
use std::path::Path;

Expand Down
67 changes: 67 additions & 0 deletions crates/ruff_charon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
//! - `rows`: `relation subject object grade file start end`, then `residual` rows and one
//! `receipt` row. Exit 3 if the receipt does not conserve.
//! - `kythe`: Kythe entries, one JSON object per line.
//!
//! The offline store (`ruff_charon::store`):
//! - `import <dir> <file.llbc> <crate_name>`: import or refresh one crate;
//! - `stale <dir> <workspace root>`: the crates with a changed or missing file;
//! - `dangling <dir>`: call rows whose callee no stored crate defines. Exit 1 if any.

use std::path::Path;
use std::process::ExitCode;

fn main() -> ExitCode {
let args: Vec<String> = std::env::args().collect();
if let Some(code) = store_mode(&args) {
return code;
}
let flag = |name: &str| {
args.iter()
.position(|a| a == name)
Expand Down Expand Up @@ -77,3 +85,62 @@ fn main() -> ExitCode {
}
ExitCode::SUCCESS
}

fn store_mode(args: &[String]) -> Option<ExitCode> {
use ruff_charon::store::Store;
let fail = |e: std::io::Error| {
eprintln!("ruff_charon: {e}");
ExitCode::from(2)
};
match (
args.get(1).map(String::as_str),
args.get(2),
args.get(3),
args.get(4),
) {
(Some("import"), Some(dir), Some(file), Some(krate)) => {
let llbc = match ruff_charon::load(Path::new(file)) {
Ok(l) => l,
Err(e) => {
eprintln!("ruff_charon: {e:#}");
return Some(ExitCode::from(2));
}
};
Some(match Store::new(dir).import(&llbc, krate) {
Ok(r) => {
println!(
"imported\t{krate}\tharvested={}\trepresented={}\tresidual={}",
r.harvested, r.represented, r.residual
);
ExitCode::SUCCESS
}
Err(e) => fail(e),
})
}
(Some("stale"), Some(dir), Some(root), _) => {
Some(match Store::new(dir).stale(Path::new(root)) {
Ok(set) => {
for c in set {
println!("stale\t{c}");
}
ExitCode::SUCCESS
}
Err(e) => fail(e),
})
}
(Some("dangling"), Some(dir), _, _) => Some(match Store::new(dir).dangling() {
Ok(rows) => {
for r in &rows {
println!("dangling\t{}\t{}\t{}", r.predicate, r.subject, r.object);
}
if rows.is_empty() {
ExitCode::SUCCESS
} else {
ExitCode::from(1)
}
}
Err(e) => fail(e),
}),
_ => None,
}
}
Loading
Loading