})
}
- fn string_to_path(&self, value: String, definition: &Definition) -> PathBuf {
+ fn string_to_path(&self, value: &str, definition: &Definition) -> PathBuf {
let is_path = value.contains('/') || (cfg!(windows) && value.contains('\\'));
if is_path {
definition.root(self).join(value)
/// Looks for a path for `tool` in an environment variable or the given config, and returns
/// `None` if it's not present.
- fn maybe_get_tool(&self, tool: &str, from_config: &Option<PathBuf>) -> Option<PathBuf> {
+ fn maybe_get_tool(
+ &self,
+ tool: &str,
+ from_config: &Option<ConfigRelativePath>,
+ ) -> Option<PathBuf> {
let var = tool.to_uppercase();
match env::var_os(&var) {
Some(path)
}
- None => from_config.clone(),
+ None => from_config.as_ref().map(|p| p.resolve_program(self)),
}
}
/// Looks for a path for `tool` in an environment variable or config path, defaulting to `tool`
/// as a path.
- fn get_tool(&self, tool: &str, from_config: &Option<PathBuf>) -> PathBuf {
+ fn get_tool(&self, tool: &str, from_config: &Option<ConfigRelativePath>) -> PathBuf {
self.maybe_get_tool(tool, from_config)
.unwrap_or_else(|| PathBuf::from(tool))
}
pub jobs: Option<u32>,
pub rustflags: Option<StringList>,
pub rustdocflags: Option<StringList>,
- pub rustc_wrapper: Option<PathBuf>,
- pub rustc_workspace_wrapper: Option<PathBuf>,
- pub rustc: Option<PathBuf>,
- pub rustdoc: Option<PathBuf>,
+ pub rustc_wrapper: Option<ConfigRelativePath>,
+ pub rustc_workspace_wrapper: Option<ConfigRelativePath>,
+ pub rustc: Option<ConfigRelativePath>,
+ pub rustdoc: Option<ConfigRelativePath>,
pub out_dir: Option<ConfigRelativePath>,
}
/// Values which don't look like a filesystem path (don't contain `/` or
/// `\`) will be returned as-is, and everything else will fall through to an
/// absolute path.
- pub fn resolve_program(self, config: &Config) -> PathBuf {
- config.string_to_path(self.0.val, &self.0.definition)
+ pub fn resolve_program(&self, config: &Config) -> PathBuf {
+ config.string_to_path(&self.0.val, &self.0.definition)
}
}
#[cargo_test]
fn rustc_wrapper_relative() {
- let p = project().file("src/lib.rs", "").build();
+ Package::new("bar", "1.0.0").publish();
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = "1.0"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
let wrapper = tools::echo_wrapper();
let exe_name = wrapper.file_name().unwrap().to_str().unwrap();
let relative_path = format!("./{}", exe_name);
.env("RUSTC_WORKSPACE_WRAPPER", &relative_path)
.with_stderr_contains(&running)
.run();
+ p.build_dir().rm_rf();
+ p.change_file(
+ ".cargo/config.toml",
+ &format!(
+ r#"
+ build.rustc-wrapper = "./{}"
+ "#,
+ exe_name
+ ),
+ );
+ p.cargo("build -v").with_stderr_contains(&running).run();
}
#[cargo_test]