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 Nov 9, 2017
1 parent f5d02ee commit 1f6ba25
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
18 changes: 18 additions & 0 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,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 @@ -161,13 +166,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 @@ -183,6 +183,7 @@ fn run() -> Result<ExitStatus> {
&root,
&rustflags,
&meta,
config.as_ref(),
&src,
&sysroot,
verbose,
Expand Down
25 changes: 18 additions & 7 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn build(
ctoml: &cargo::Toml,
home: &Home,
rustflags: &Rustflags,
config: Option<&cargo::Config>,
src: &Src,
hash: u64,
verbose: bool,
Expand All @@ -46,6 +47,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 @@ -112,13 +118,16 @@ version = "0.0.0"
}

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

// Create hash file
Expand Down Expand Up @@ -180,6 +189,7 @@ pub fn update(
root: &Root,
rustflags: &Rustflags,
meta: &VersionMeta,
config: Option<&cargo::Config>,
src: &Src,
sysroot: &Sysroot,
verbose: bool,
Expand All @@ -198,6 +208,7 @@ pub fn update(
&ctoml,
home,
rustflags,
config,
src,
hash,
verbose,
Expand Down

0 comments on commit 1f6ba25

Please sign in to comment.