Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feaf: introduce RAP_RECURSIVE to check packages recursively and RAP_CLEAN to run cargo clean before check #72

Merged
merged 18 commits into from
Nov 14, 2024
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
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

env:
CARGO_TERM_COLOR: always
RAP_RECURSIVE: deep

jobs:
build:
Expand All @@ -33,3 +34,9 @@ jobs:
run: |
chmod +x ./install.sh
./install.sh

- name: Check test cases
run: cd tests && cargo +nightly-2024-06-30 rap -F -M

- name: Check rap
run: cd rap && cargo +nightly-2024-06-30 rap -F -M
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ Check out supported options with `-help`:
cargo +nightly-2024-06-30 rap -help
```

Environment variables (Values are case insensitive):

| var | default when absent | one of these values | description |
|-----------------|---------------------|---------------------|------------------------------|
| `RAP_LOG` | info | debug, info, warn | verbosity of logging |
| `RAP_CLEAN` | true | ture, false | run cargo clean before check |
| `RAP_RECURSIVE` | none | none, shallow, deep | scope of packages to check |

For `RAP_RECURSIVE`:
* none: check for current folder
* shallow: check for current workpace members
* deep: check for all workspaces from current folder

NOTE: for shallow or deep, rap will enter each member folder to do the check.

### Use-After-Free Detection
Detect bugs such as use-after-free and double free in Rust crates caused by unsafe code.
```shell
Expand Down
119 changes: 105 additions & 14 deletions rap/Cargo.lock

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

3 changes: 2 additions & 1 deletion rap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ fern = {version = "0.6.2", features = ["colored"]}
wait-timeout = "0.2.0"
rustc-demangle = "0.1.21"
colorful = "0.2.1"
#stopwatch = "0.0.7"
regex = "1.11.1"
walkdir = "2"
cargo_metadata = "0.18"

[features]
backtraces = ["snafu/backtraces", "snafu/backtraces-impl-backtrace-crate"]
Expand Down
33 changes: 25 additions & 8 deletions rap/src/bin/cargo-rap/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct Arguments {
/// options as second half after -- in args
args_group2: Vec<String>,
current_exe_path: PathBuf,
rap_clean: bool,
}

impl Arguments {
Expand Down Expand Up @@ -39,15 +40,28 @@ impl Arguments {
}

fn new() -> Self {
fn rap_clean() -> bool {
match env::var("RAP_CLEAN")
.ok()
.map(|s| s.trim().to_ascii_lowercase())
.as_deref()
{
Some("false") => false,
_ => true, // clean is the preferred behavior
}
}

let args: Vec<_> = env::args().collect();
let path = env::current_exe().expect("Current executable path invalid.");
rap_debug!("Current exe: {path:?}\tReceived args: {args:?}");
let [args_group1, args_group2] = split_args_by_double_dash(&args);

Arguments {
args,
args_group1,
args_group2,
current_exe_path: path,
rap_clean: rap_clean(),
}
}

Expand All @@ -64,6 +78,10 @@ impl Arguments {
}
}

pub fn rap_clean() -> bool {
ARGS.rap_clean
}

fn split_args_by_double_dash(args: &[String]) -> [Vec<String>; 2] {
let mut args = args.iter().skip(2).map(|arg| arg.to_owned());
let rap_args = args.by_ref().take_while(|arg| *arg != "--").collect();
Expand Down Expand Up @@ -95,15 +113,14 @@ pub fn is_current_compile_crate() -> bool {
/// For example, checking proc-macro crates or build.rs can cause linking errors in rap.
pub fn filter_crate_type() -> bool {
if let Some(s) = get_arg_flag_value("--crate-type") {
if s == "proc-macro" {
return false;
}
if s == "bin" && get_arg_flag_value("--crate-name") == Some("build_script_build") {
return false;
}
return match s {
"proc-macro" => false,
"bin" if get_arg_flag_value("--crate-name") == Some("build_script_build") => false,
_ => true,
};
}
// NOTE: tests don't have --crate-type, they are handled with --test by rustc
return true;
// NOTE: tests don't have --crate-type, they are handled with --test by rustc.
true
}

pub fn get_arg(pos: usize) -> Option<&'static str> {
Expand Down
Loading