]> git.proxmox.com Git - cargo.git/commitdiff
Fix rustc/rustdoc config values to be config-relative paths.
authorEric Huss <eric@huss.org>
Thu, 10 Jun 2021 00:46:18 +0000 (17:46 -0700)
committerEric Huss <eric@huss.org>
Thu, 10 Jun 2021 00:46:18 +0000 (17:46 -0700)
src/cargo/util/config/mod.rs
src/cargo/util/config/path.rs
tests/testsuite/build.rs

index 71bbf78b456b0cd91d2a61e12a0753175a4b9c33..1d865d4f1362d97a1fdee85548b07f48ee32091e 100644 (file)
@@ -732,7 +732,7 @@ impl Config {
         })
     }
 
-    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)
@@ -1391,7 +1391,11 @@ impl Config {
 
     /// 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) {
@@ -1408,13 +1412,13 @@ impl Config {
                 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))
     }
@@ -2084,10 +2088,10 @@ pub struct CargoBuildConfig {
     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>,
 }
 
index 6180d0f3f1347020a64ff799d5675de6615fb5a0..a90cab2b2680c40d8a5f36e8d110f3afa58c7460 100644 (file)
@@ -34,8 +34,8 @@ impl 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)
     }
 }
 
index f703454e517ec6974ddb784f514506f3c678a469..5b2f3786bd57676a6531c6e43f097b09a8ef1cfa 100644 (file)
@@ -4075,7 +4075,21 @@ fn rustc_wrapper() {
 
 #[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);
@@ -4090,6 +4104,17 @@ fn rustc_wrapper_relative() {
         .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]