/// root and all member packages. It will then validate the workspace
/// before returning it, so `Ok` is only returned for valid workspaces.
pub fn new(manifest_path: &Path, config: &'cfg Config) -> CargoResult<Workspace<'cfg>> {
- let target_dir = config.target_dir()?;
+ let target_dir = config.target_dir();
let mut ws = Workspace {
config,
ws.target_dir = if let Some(dir) = target_dir {
Some(dir)
} else {
- ws.config.target_dir()?
+ ws.config.target_dir()
};
ws.members.push(ws.current_manifest.clone());
ws.default_members.push(ws.current_manifest.clone());
cache_rustc_info: bool,
/// Creation time of this config, used to output the total build time
creation_time: Instant,
- /// Target Directory via resolved Cli parameter
- cli_target_dir: Option<Filesystem>,
+ /// Target Directory via resolved Cli parameter
+ target_dir: Option<Filesystem>,
}
impl Config {
crates_io_source_id: LazyCell::new(),
cache_rustc_info,
creation_time: Instant::now(),
- cli_target_dir: None,
+ target_dir: None,
}
}
&self.cwd
}
- pub fn target_dir(&self) -> CargoResult<Option<Filesystem>> {
- if let Some(ref dir) = self.cli_target_dir {
- Ok(Some(dir.clone()))
- } else if let Some(dir) = env::var_os("CARGO_TARGET_DIR") {
- Ok(Some(Filesystem::new(self.cwd.join(dir))))
- } else if let Some(val) = self.get_path("build.target-dir")? {
- let val = self.cwd.join(val.val);
- Ok(Some(Filesystem::new(val)))
- } else {
- Ok(None)
- }
+ pub fn target_dir(&self) -> Option<Filesystem> {
+ self.target_dir.clone()
}
fn get(&self, key: &str) -> CargoResult<Option<ConfigValue>> {
| (None, None, None) => Verbosity::Normal,
};
- let cli_target_dir = match target_dir.as_ref() {
- Some(dir) => Some(Filesystem::new(dir.clone())),
- None => None,
+ let target_dir = if let Some(dir) = target_dir.as_ref() {
+ Some(Filesystem::new(self.cwd.join(dir)))
+ } else if let Some(dir) = env::var_os("CARGO_TARGET_DIR") {
+ Some(Filesystem::new(self.cwd.join(dir)))
+ } else if let Ok(Some(val)) = self.get_path("build.target-dir") {
+ let val = self.cwd.join(val.val);
+ Some(Filesystem::new(val))
+ } else {
+ None
};
self.shell().set_verbosity(verbosity);
self.extra_verbose = extra_verbose;
self.frozen = frozen;
self.locked = locked;
- self.cli_target_dir = cli_target_dir;
+ self.target_dir = target_dir;
self.cli_flags.parse(unstable_flags)?;
Ok(())
let exe_name = format!("foo{}", env::consts::EXE_SUFFIX);
assert_that(
- p.cargo("build").arg("--target-dir").arg("foo/target"),
+ p.cargo("build --target-dir foo/target"),
execs().with_status(0),
);
assert_that(
)
.unwrap();
assert_that(
- p.cargo("build").arg("--target-dir").arg("bar/target"),
+ p.cargo("build --target-dir bar/target"),
execs().with_status(0),
);
assert_that(
);
assert_that(
- p.cargo("build")
- .arg("--target-dir")
- .arg("foobar/target")
+ p.cargo("build --target-dir foobar/target")
.env("CARGO_TARGET_DIR", "bar/target"),
execs().with_status(0),
);