-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
proc-macros that call out to cargo metadata break cargo fix #9706
Comments
@rustbot claim I am working on this. |
@ehuss Should we ignore cargo runs here that are not wanting cargo-fix (return false if no .rs file is found and execute the correct cargo command), at |
Sorry, I'm a bit confused about the comment about "return false if no .rs file is found". I was assuming this would just entail unsetting the FIX_ENV when executing the real |
Sorry, I complicated it. It should simply remove that env variable. I was thinking that even if the variable is set, but it turns out that no files are passed in that need fixing, then just go ahead and execute the real cargo command. Thanks for the reply! |
@ehuss I read the code again and it looks like we can't simply unset FIX_ENV because Line 35 in b51439f
|
Would it work to unset it around here? That's the process builder for the "real" rustc. |
Sorry, maybe I'm a bit confused. Why would the following not work? diff --git a/src/cargo/ops/fix.rs b/src/cargo/ops/fix.rs
index ddce0acca..3763da2d2 100644
--- a/src/cargo/ops/fix.rs
+++ b/src/cargo/ops/fix.rs
@@ -329,7 +329,8 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
let workspace_rustc = std::env::var("RUSTC_WORKSPACE_WRAPPER")
.map(PathBuf::from)
.ok();
- let rustc = ProcessBuilder::new(&args.rustc).wrapped(workspace_rustc.as_ref());
+ let mut rustc = ProcessBuilder::new(&args.rustc).wrapped(workspace_rustc.as_ref());
+ rustc.env_remove(FIX_ENV);
trace!("start rustfixing {:?}", args.file);
let fixes = rustfix_crate(&lock_addr, &rustc, &args.file, &args, config)?; |
Because we will first find the file to be fixed at Line 326 in b51439f
Line 763 in b51439f
So I understand that before we can remove the environment variable, the error is already returned and we exit. |
1 similar comment
This comment has been minimized.
This comment has been minimized.
Sorry, I'm still not following. AIUI, the issue is running So the chain of events is:
I think the line you are pointing at ( And just to be clear, this is the kind of use-case I am understanding this issue to be: // A proc-macro
use proc_macro::*;
#[proc_macro]
pub fn foo(_input: TokenStream) -> TokenStream {
let output = std::process::Command::new("cargo").arg("metadata").output().unwrap();
eprintln!("{}", std::str::from_utf8(&output.stderr).unwrap());
eprintln!("{}", std::str::from_utf8(&output.stdout).unwrap());
"".parse().unwrap()
} Perhaps you could write a cargo integration test to show what does or doesn't work? |
@rustbot claim |
Problem
It looks like
cargo fix
sets the environment variable__CARGO_FIX_PLZ
which alters behavior ofcargo
invocations with the same environment in a way that makes otherwise functionalcargo metadata
invocations fail withSteps
cargo metadata
(for example to find the workspace root)cargo fix
Notes
This came up here: launchbadge/sqlx#1229
The only reason SQLx'es proc-macro code calls
cargo metadata
is to find the workspace root. If there was an environment variable for that, akin toCARGO_MANIFEST_DIR
, that proc-macros wouldn't have to callcargo-metadata
in the first place.Happens both on Stable & Nightly:
cargo 1.53.0 (4369396ce 2021-04-27)
1.55.0-nightly (27277d966 2021-07-16)
The text was updated successfully, but these errors were encountered: