Skip to content

Commit

Permalink
Merge #713
Browse files Browse the repository at this point in the history
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 <ahuszagh@gmail.com>
  • Loading branch information
bors[bot] and Alexhuszagh authored May 24, 2022
2 parents 4deac83 + 2504e04 commit 0adbce2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- #713 - convert relative target directories to absolute paths.
- #709 - Update Emscripten targets to `emcc` version 3.1.10
- #707, #708 - Set `BINDGEN_EXTRA_CLANG_ARGS` environment variable to pass sysroot to `rust-bindgen`
- #696 - bump freebsd to 12.3
Expand Down
20 changes: 15 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::str::FromStr;
use std::{env, path::PathBuf};

use crate::cargo::Subcommand;
use crate::errors::Result;
use crate::rustc::TargetList;
use crate::Target;

Expand All @@ -15,7 +16,16 @@ pub struct Args {
pub docker_in_docker: bool,
}

pub fn parse(target_list: &TargetList) -> Args {
// Fix for issue #581. target_dir must be absolute.
fn absolute_path(path: PathBuf) -> Result<PathBuf> {
Ok(if path.is_absolute() {
path
} else {
env::current_dir()?.join(path)
})
}

pub fn parse(target_list: &TargetList) -> Result<Args> {
let mut channel = None;
let mut target = None;
let mut target_dir = None;
Expand Down Expand Up @@ -44,12 +54,12 @@ pub fn parse(target_list: &TargetList) -> Args {
} else if arg == "--target-dir" {
all.push(arg);
if let Some(td) = args.next() {
target_dir = Some(PathBuf::from(&td));
target_dir = Some(absolute_path(PathBuf::from(&td))?);
all.push("/target".to_string());
}
} else if arg.starts_with("--target-dir=") {
if let Some((_, td)) = arg.split_once('=') {
target_dir = Some(PathBuf::from(&td));
target_dir = Some(absolute_path(PathBuf::from(&td))?);
all.push("--target-dir=/target".into());
}
} else {
Expand All @@ -66,12 +76,12 @@ pub fn parse(target_list: &TargetList) -> Args {
.map(|s| bool::from_str(&s).unwrap_or_default())
.unwrap_or_default();

Args {
Ok(Args {
all,
subcommand: sc,
channel,
target,
target_dir,
docker_in_docker,
}
})
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub fn main() -> Result<()> {

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

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

0 comments on commit 0adbce2

Please sign in to comment.