Skip to content

Commit 0adbce2

Browse files
Merge #713
713: Convert --target-dir to use absolute paths. r=Emilgardis a=Alexhuszagh Converts relative target directories to absolute paths, to avoid creating the target directory in the sysroot. This keeps the prior behavior if the provided target directory is an absolute path. Fixes #581. Co-authored-by: Alex Huszagh <[email protected]>
2 parents 4deac83 + 2504e04 commit 0adbce2

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77

8+
- #713 - convert relative target directories to absolute paths.
89
- #709 - Update Emscripten targets to `emcc` version 3.1.10
910
- #707, #708 - Set `BINDGEN_EXTRA_CLANG_ARGS` environment variable to pass sysroot to `rust-bindgen`
1011
- #696 - bump freebsd to 12.3

src/cli.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::str::FromStr;
22
use std::{env, path::PathBuf};
33

44
use crate::cargo::Subcommand;
5+
use crate::errors::Result;
56
use crate::rustc::TargetList;
67
use crate::Target;
78

@@ -15,7 +16,16 @@ pub struct Args {
1516
pub docker_in_docker: bool,
1617
}
1718

18-
pub fn parse(target_list: &TargetList) -> Args {
19+
// Fix for issue #581. target_dir must be absolute.
20+
fn absolute_path(path: PathBuf) -> Result<PathBuf> {
21+
Ok(if path.is_absolute() {
22+
path
23+
} else {
24+
env::current_dir()?.join(path)
25+
})
26+
}
27+
28+
pub fn parse(target_list: &TargetList) -> Result<Args> {
1929
let mut channel = None;
2030
let mut target = None;
2131
let mut target_dir = None;
@@ -44,12 +54,12 @@ pub fn parse(target_list: &TargetList) -> Args {
4454
} else if arg == "--target-dir" {
4555
all.push(arg);
4656
if let Some(td) = args.next() {
47-
target_dir = Some(PathBuf::from(&td));
57+
target_dir = Some(absolute_path(PathBuf::from(&td))?);
4858
all.push("/target".to_string());
4959
}
5060
} else if arg.starts_with("--target-dir=") {
5161
if let Some((_, td)) = arg.split_once('=') {
52-
target_dir = Some(PathBuf::from(&td));
62+
target_dir = Some(absolute_path(PathBuf::from(&td))?);
5363
all.push("--target-dir=/target".into());
5464
}
5565
} else {
@@ -66,12 +76,12 @@ pub fn parse(target_list: &TargetList) -> Args {
6676
.map(|s| bool::from_str(&s).unwrap_or_default())
6777
.unwrap_or_default();
6878

69-
Args {
79+
Ok(Args {
7080
all,
7181
subcommand: sc,
7282
channel,
7383
target,
7484
target_dir,
7585
docker_in_docker,
76-
}
86+
})
7787
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ pub fn main() -> Result<()> {
263263

264264
fn run() -> Result<ExitStatus> {
265265
let target_list = rustc::target_list(false)?;
266-
let args = cli::parse(&target_list);
266+
let args = cli::parse(&target_list)?;
267267

268268
if args.all.iter().any(|a| a == "--version" || a == "-V") && args.subcommand.is_none() {
269269
println!(

0 commit comments

Comments
 (0)