Skip to content

Commit

Permalink
Added support for target-dir in config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils-TUD committed Sep 11, 2019
1 parent a6d1969 commit 941b5b7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
18 changes: 18 additions & 0 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,15 @@ pub fn run(args: &Args, verbose: bool) -> Result<ExitStatus> {
}

pub struct Config {
root: PathBuf,
table: Value,
}

impl Config {
pub fn root(&self) -> &PathBuf {
&self.root
}

pub fn target(&self) -> Result<Option<&str>> {
if let Some(v) = self.table.lookup("build.target") {
Ok(Some(v.as_str()
Expand All @@ -167,13 +172,26 @@ impl Config {
Ok(None)
}
}

pub fn target_dir(&self) -> Result<Option<&str>> {
if let Some(v) = self.table.lookup("build.target-dir") {
Ok(Some(
v.as_str().ok_or_else(
|| format!(".cargo/config: build.target-dir must be a string"),
)?,
))
} else {
Ok(None)
}
}
}

pub fn config() -> Result<Option<Config>> {
let cd = env::current_dir().chain_err(|| "couldn't get the current directory")?;

if let Some(p) = util::search(&cd, ".cargo/config") {
Ok(Some(Config {
root: p.to_path_buf(),
table: util::parse(&p.join(".cargo/config"))?,
}))
} else {
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ fn run() -> Result<ExitStatus> {
&root,
&rustflags,
&meta,
config.as_ref(),
&src,
&sysroot,
verbose,
Expand Down
19 changes: 14 additions & 5 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn build(
ctoml: &cargo::Toml,
home: &Home,
rustflags: &Rustflags,
config: Option<&cargo::Config>,
sysroot: &Sysroot,
hash: u64,
verbose: bool,
Expand All @@ -45,6 +46,11 @@ name = "sysroot"
version = "0.0.0"
"#;

let target_dir = match config {
Some(c) => c.target_dir()?,
None => None,
};

let rustlib = home.lock_rw(cmode.triple())?;
rustlib
.remove_siblings()
Expand Down Expand Up @@ -153,12 +159,13 @@ version = "0.0.0"
}

// Copy artifacts to Xargo sysroot
let base_dir = match target_dir {
Some(dir) => config.unwrap().root().join(dir),
None => td.join("target"),
};
util::cp_r(
&td.join("target")
.join(cmode.triple())
.join(profile())
.join("deps"),
&dst,
&base_dir.join(cmode.triple()).join(profile()).join("deps"),
&dst
)?;
}

Expand Down Expand Up @@ -221,6 +228,7 @@ pub fn update(
root: &Root,
rustflags: &Rustflags,
meta: &VersionMeta,
config: Option<&cargo::Config>,
src: &Src,
sysroot: &Sysroot,
verbose: bool,
Expand All @@ -239,6 +247,7 @@ pub fn update(
&ctoml,
home,
rustflags,
config,
sysroot,
hash,
verbose,
Expand Down

0 comments on commit 941b5b7

Please sign in to comment.