File tree 3 files changed +19
-9
lines changed
3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -93,13 +93,21 @@ pub fn is_manifest_command(arg: &str) -> bool {
93
93
|| path. file_name ( ) == Some ( OsStr :: new ( "Cargo.toml" ) )
94
94
}
95
95
96
- pub fn exec_manifest_command ( config : & Config , cmd : & str , args : & [ OsString ] ) -> CliResult {
96
+ pub fn exec_manifest_command ( config : & mut Config , cmd : & str , args : & [ OsString ] ) -> CliResult {
97
97
if !config. cli_unstable ( ) . script {
98
98
return Err ( anyhow:: anyhow!( "running `{cmd}` requires `-Zscript`" ) . into ( ) ) ;
99
99
}
100
100
101
101
let manifest_path = Path :: new ( cmd) ;
102
102
let manifest_path = root_manifest ( Some ( manifest_path) , config) ?;
103
+
104
+ // Treat `cargo foo.rs` like `cargo install --path foo` and re-evaluate the config based on the
105
+ // environment where the script resides, rather than the environment from where its being run.
106
+ let parent_path = manifest_path
107
+ . parent ( )
108
+ . expect ( "a file should always have a parent" ) ;
109
+ config. reload_rooted_at ( parent_path) ?;
110
+
103
111
let mut ws = Workspace :: new ( & manifest_path, config) ?;
104
112
if config. cli_unstable ( ) . avoid_dev_deps {
105
113
ws. set_require_optional_deps ( false ) ;
Original file line number Diff line number Diff line change @@ -1481,6 +1481,9 @@ A parameter is identified as a manifest-command if it has one of:
1481
1481
- A ` .rs ` extension
1482
1482
- The file name is ` Cargo.toml `
1483
1483
1484
+ Differences between ` cargo run --manifest-path <path> ` and ` cargo <path> `
1485
+ - ` cargo <path> ` runs with the config for ` <path> ` and not the current dir, more like ` cargo install --path <path> `
1486
+
1484
1487
### ` [lints] `
1485
1488
1486
1489
* Tracking Issue: [ #12115 ] ( https://github.com/rust-lang/cargo/issues/12115 )
Original file line number Diff line number Diff line change @@ -352,7 +352,7 @@ rustc = "non-existent-rustc"
352
352
. build ( ) ;
353
353
354
354
// Verify the config is bad
355
- p. cargo ( "-Zscript script.rs" )
355
+ p. cargo ( "-Zscript script.rs -NotAnArg " )
356
356
. masquerade_as_nightly_cargo ( & [ "script" ] )
357
357
. with_status ( 101 )
358
358
. with_stderr_contains (
@@ -362,14 +362,13 @@ rustc = "non-existent-rustc"
362
362
)
363
363
. run ( ) ;
364
364
365
- // Verify that the config is still used
366
- p. cargo ( "-Zscript ../script/script.rs" )
365
+ // Verify that the config isn't used
366
+ p. cargo ( "-Zscript ../script/script.rs -NotAnArg " )
367
367
. masquerade_as_nightly_cargo ( & [ "script" ] )
368
- . with_status ( 101 )
369
- . with_stderr_contains (
370
- "\
371
- [ERROR] could not execute process `non-existent-rustc -vV` (never executed)
372
- " ,
368
+ . with_stdout (
369
+ r#"bin: [..]/debug/script[EXE]
370
+ args: ["-NotAnArg"]
371
+ "# ,
373
372
)
374
373
. run ( ) ;
375
374
}
You can’t perform that action at this time.
0 commit comments