-
Notifications
You must be signed in to change notification settings - Fork 524
Add cargo_warnings
config to control the use of the cargo warning instruction
#917
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
Merged
Merged
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
01e6e98
fix some instances of broken cargo:warning instruction
scootermon e7af292
allow disabling cargo warnings for compilation
scootermon 4a90bd8
comply with MSRV
scootermon 40bb482
allow dead_code to make ci pass
scootermon 7d51284
make print thread optional
scootermon cf795f2
simplify warnings using macros
scootermon 17535c3
add a test case
scootermon 67213e0
this line in the docstring is no longer true
scootermon afada42
apply review suggestions
scootermon a3b4614
write warnings to buffered stdout
scootermon c8c61a2
add proper output tests
scootermon 3079bb0
reduce import diff and always print stdout in tests
scootermon 00e980c
correct println
scootermon fc72499
add an output abstraction
scootermon fc2fb66
hopefully make the tests work on win32
scootermon 690269a
msvc-compatible warnings
scootermon a629690
turns out we can't capture warnings for msvc...
scootermon 19174cb
fix unconditional metadata output
scootermon 4b5cdf4
skip warnings_on test for msvc
scootermon 4ab4158
Update src/lib.rs
scootermon 02f8895
Update src/lib.rs
scootermon 7495e35
Update src/lib.rs
scootermon d475e93
Update src/lib.rs
scootermon 00ae7e0
Merge branch 'main' into disable-warnings
scootermon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#error "if you see this, cargo_warnings(false) didn't do its job" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* just an empty file */ | ||
|
||
void dummy(void) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::fs; | ||
use std::path::PathBuf; | ||
|
||
#[test] | ||
fn cargo_warnings_on() { | ||
if env!("TEST_WARNINGS_ON") == "0" { | ||
// in some cases we don't catch compiler warnings and turn them into cargo | ||
// instructions. | ||
return; | ||
} | ||
let (stdout, stderr) = load_output("warnings-on"); | ||
assert!(stderr.is_empty()); | ||
assert!(stdout.contains("cargo:warning=")); | ||
} | ||
|
||
#[test] | ||
fn cargo_warnings_off() { | ||
let (stdout, stderr) = load_output("warnings-off"); | ||
assert!(stderr.is_empty()); | ||
assert!(!stdout.contains("cargo:warning=")); | ||
} | ||
|
||
#[test] | ||
fn cargo_metadata_on() { | ||
let (stdout, stderr) = load_output("metadata-on"); | ||
assert!(stderr.is_empty()); | ||
assert!(stdout.contains("cargo:rustc-link-lib=")); | ||
assert!(stdout.contains("cargo:rustc-link-search=")); | ||
} | ||
|
||
#[test] | ||
fn cargo_metadata_off() { | ||
let (stdout, stderr) = load_output("metadata-off"); | ||
assert!(stderr.is_empty()); | ||
|
||
// most of the instructions aren't currently used | ||
const INSTRUCTIONS: &[&str] = &[ | ||
"cargo:rerun-if-changed=", | ||
"cargo:rerun-if-env-changed=", | ||
"cargo:rustc-cdylib-link-arg=", | ||
"cargo:rustc-cfg=", | ||
"cargo:rustc-env=", | ||
"cargo:rustc-flags=", | ||
"cargo:rustc-link-arg-benches=", | ||
"cargo:rustc-link-arg-bin=", | ||
"cargo:rustc-link-arg-bins=", | ||
"cargo:rustc-link-arg-examples=", | ||
"cargo:rustc-link-arg-tests=", | ||
"cargo:rustc-link-arg=", | ||
"cargo:rustc-link-lib=", | ||
"cargo:rustc-link-search=", | ||
]; | ||
for instr in INSTRUCTIONS { | ||
assert!(!stdout.contains(instr), "instruction present: {}", instr); | ||
} | ||
} | ||
|
||
#[track_caller] | ||
fn load_output(action: &str) -> (String, String) { | ||
// these files are written by the `run_forked_capture_output` function in the | ||
// build script. | ||
let action_dir = PathBuf::from(env!("OUT_DIR")).join(action); | ||
let stdout = fs::read_to_string(action_dir.join("stdout")).unwrap(); | ||
let stderr = fs::read_to_string(action_dir.join("stderr")).unwrap(); | ||
println!("compile stdout: {:?}", stdout); | ||
println!("compile stderr: {:?}", stderr); | ||
(stdout, stderr) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.