Forráskód Böngészése

cli: fix failing 'anchor build' if 'Test.toml' included a relative pa… (#1772)

Paul 3 éve
szülő
commit
53ead6077c
3 módosított fájl, 14 hozzáadás és 8 törlés
  1. 1 0
      CHANGELOG.md
  2. 4 5
      cli/src/config.rs
  3. 9 3
      cli/src/lib.rs

+ 1 - 0
CHANGELOG.md

@@ -12,6 +12,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 
 ### Fixes
 
+* lang: Fix `anchor build` failing if `Test.toml` included a relative path that didn't exist yet because it's created by `anchor build` ([#1772](https://github.com/project-serum/anchor/pull/1772)).
 * cli: Update js/ts template to use new `AnchorProvider` class ([#1770](https://github.com/project-serum/anchor/pull/1770)).
 
 ## [0.24.0] - 2022-04-12

+ 4 - 5
cli/src/config.rs

@@ -335,9 +335,9 @@ pub struct BuildConfig {
 }
 
 impl Config {
-    fn with_test_config(mut self, p: impl AsRef<Path>) -> Result<Self> {
-        self.test_config = TestConfig::discover(p)?;
-        Ok(self)
+    pub fn add_test_config(&mut self, root: impl AsRef<Path>) -> Result<()> {
+        self.test_config = TestConfig::discover(root)?;
+        Ok(())
     }
 
     pub fn docker(&self) -> String {
@@ -393,8 +393,7 @@ impl Config {
     fn from_path(p: impl AsRef<Path>) -> Result<Self> {
         fs::read_to_string(&p)
             .with_context(|| format!("Error reading the file with path: {}", p.as_ref().display()))?
-            .parse::<Self>()?
-            .with_test_config(p.as_ref().parent().unwrap())
+            .parse::<Self>()
     }
 
     pub fn wallet_kp(&self) -> Result<Keypair> {

+ 9 - 3
cli/src/lib.rs

@@ -1828,6 +1828,9 @@ fn test(
             )?;
         }
 
+        let root = cfg.path().parent().unwrap().to_owned();
+        cfg.add_test_config(root)?;
+
         // Run the deploy against the cluster in two cases:
         //
         // 1. The cluster is not localnet.
@@ -3050,14 +3053,17 @@ fn localnet(
 //
 // The closure passed into this function must never change the working directory
 // to be outside the workspace. Doing so will have undefined behavior.
-fn with_workspace<R>(cfg_override: &ConfigOverride, f: impl FnOnce(&WithPath<Config>) -> R) -> R {
+fn with_workspace<R>(
+    cfg_override: &ConfigOverride,
+    f: impl FnOnce(&mut WithPath<Config>) -> R,
+) -> R {
     set_workspace_dir_or_exit();
 
-    let cfg = Config::discover(cfg_override)
+    let mut cfg = Config::discover(cfg_override)
         .expect("Previously set the workspace dir")
         .expect("Anchor.toml must always exist");
 
-    let r = f(&cfg);
+    let r = f(&mut cfg);
 
     set_workspace_dir_or_exit();