Skip to content

Commit 47a0291

Browse files
committed
Fix rustc/rustdoc config values to be config-relative paths.
1 parent 7b229bb commit 47a0291

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

src/cargo/util/config/mod.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ impl Config {
732732
})
733733
}
734734

735-
fn string_to_path(&self, value: String, definition: &Definition) -> PathBuf {
735+
fn string_to_path(&self, value: &str, definition: &Definition) -> PathBuf {
736736
let is_path = value.contains('/') || (cfg!(windows) && value.contains('\\'));
737737
if is_path {
738738
definition.root(self).join(value)
@@ -1391,7 +1391,11 @@ impl Config {
13911391

13921392
/// Looks for a path for `tool` in an environment variable or the given config, and returns
13931393
/// `None` if it's not present.
1394-
fn maybe_get_tool(&self, tool: &str, from_config: &Option<PathBuf>) -> Option<PathBuf> {
1394+
fn maybe_get_tool(
1395+
&self,
1396+
tool: &str,
1397+
from_config: &Option<ConfigRelativePath>,
1398+
) -> Option<PathBuf> {
13951399
let var = tool.to_uppercase();
13961400

13971401
match env::var_os(&var) {
@@ -1408,13 +1412,13 @@ impl Config {
14081412
Some(path)
14091413
}
14101414

1411-
None => from_config.clone(),
1415+
None => from_config.as_ref().map(|p| p.resolve_program(self)),
14121416
}
14131417
}
14141418

14151419
/// Looks for a path for `tool` in an environment variable or config path, defaulting to `tool`
14161420
/// as a path.
1417-
fn get_tool(&self, tool: &str, from_config: &Option<PathBuf>) -> PathBuf {
1421+
fn get_tool(&self, tool: &str, from_config: &Option<ConfigRelativePath>) -> PathBuf {
14181422
self.maybe_get_tool(tool, from_config)
14191423
.unwrap_or_else(|| PathBuf::from(tool))
14201424
}
@@ -2084,10 +2088,10 @@ pub struct CargoBuildConfig {
20842088
pub jobs: Option<u32>,
20852089
pub rustflags: Option<StringList>,
20862090
pub rustdocflags: Option<StringList>,
2087-
pub rustc_wrapper: Option<PathBuf>,
2088-
pub rustc_workspace_wrapper: Option<PathBuf>,
2089-
pub rustc: Option<PathBuf>,
2090-
pub rustdoc: Option<PathBuf>,
2091+
pub rustc_wrapper: Option<ConfigRelativePath>,
2092+
pub rustc_workspace_wrapper: Option<ConfigRelativePath>,
2093+
pub rustc: Option<ConfigRelativePath>,
2094+
pub rustdoc: Option<ConfigRelativePath>,
20912095
pub out_dir: Option<ConfigRelativePath>,
20922096
}
20932097

src/cargo/util/config/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ impl ConfigRelativePath {
3434
/// Values which don't look like a filesystem path (don't contain `/` or
3535
/// `\`) will be returned as-is, and everything else will fall through to an
3636
/// absolute path.
37-
pub fn resolve_program(self, config: &Config) -> PathBuf {
38-
config.string_to_path(self.0.val, &self.0.definition)
37+
pub fn resolve_program(&self, config: &Config) -> PathBuf {
38+
config.string_to_path(&self.0.val, &self.0.definition)
3939
}
4040
}
4141

tests/testsuite/build.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4075,7 +4075,21 @@ fn rustc_wrapper() {
40754075

40764076
#[cargo_test]
40774077
fn rustc_wrapper_relative() {
4078-
let p = project().file("src/lib.rs", "").build();
4078+
Package::new("bar", "1.0.0").publish();
4079+
let p = project()
4080+
.file(
4081+
"Cargo.toml",
4082+
r#"
4083+
[package]
4084+
name = "foo"
4085+
version = "0.1.0"
4086+
4087+
[dependencies]
4088+
bar = "1.0"
4089+
"#,
4090+
)
4091+
.file("src/lib.rs", "")
4092+
.build();
40794093
let wrapper = tools::echo_wrapper();
40804094
let exe_name = wrapper.file_name().unwrap().to_str().unwrap();
40814095
let relative_path = format!("./{}", exe_name);
@@ -4090,6 +4104,17 @@ fn rustc_wrapper_relative() {
40904104
.env("RUSTC_WORKSPACE_WRAPPER", &relative_path)
40914105
.with_stderr_contains(&running)
40924106
.run();
4107+
p.build_dir().rm_rf();
4108+
p.change_file(
4109+
".cargo/config.toml",
4110+
&format!(
4111+
r#"
4112+
build.rustc-wrapper = "./{}"
4113+
"#,
4114+
exe_name
4115+
),
4116+
);
4117+
p.cargo("build -v").with_stderr_contains(&running).run();
40934118
}
40944119

40954120
#[cargo_test]

0 commit comments

Comments
 (0)