Skip to content

Commit e69bd9b

Browse files
committed
Use less ambiguous absolute paths in JSON
1 parent 63d5a69 commit e69bd9b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/cargo/util/machine_message.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::Path;
1+
use std::path::{PathBuf, Path};
22
use std::collections::HashMap;
33
use std::borrow::Cow;
44

@@ -63,16 +63,22 @@ impl<'a> Message for BuildScript<'a> {
6363

6464
#[derive(Serialize)]
6565
pub struct RunProfile<'a> {
66-
pub program: Cow<'a, str>,
66+
pub program:PathBuf,
6767
pub args: Vec<Cow<'a, str>>,
6868
pub env: HashMap<&'a str, Option<Cow<'a, str>>>,
6969
pub cwd: Option<&'a Path>,
7070
}
7171

7272
impl<'a> RunProfile<'a> {
7373
pub fn new(process: &ProcessBuilder) -> RunProfile {
74+
let program = if let Some(cwd) = process.get_cwd() {
75+
cwd.join(process.get_program())
76+
} else {
77+
PathBuf::from(process.get_program())
78+
};
79+
assert!(program.is_absolute(), "Running program by relative path without cwd");
7480
RunProfile {
75-
program: process.get_program().to_string_lossy(),
81+
program: program,
7682
args: process.get_args().iter().map(|s| s.to_string_lossy()).collect(),
7783
env: process.get_envs().iter().map(|(k, v)| {
7884
(k.as_str(), v.as_ref().map(|s| s.to_string_lossy()))

tests/print_run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn single_bin() {
2626
.with_json(r#"
2727
{
2828
"reason": "run-profile",
29-
"program": "target\/debug\/foo",
29+
"program": "[..][/]foo[/]target[/]debug[/]foo",
3030
"env": {
3131
"LD_LIBRARY_PATH": "[..]",
3232
"CARGO_PKG_VERSION_PRE": "",

0 commit comments

Comments
 (0)