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

This commit is contained in:
Paul 2022-04-12 15:27:03 -04:00 committed by GitHub
parent fb149f96a1
commit 53ead6077c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View File

@ -12,6 +12,7 @@ The minor version will be incremented upon a breaking change and the patch versi
### Fixes ### 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)). * 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 ## [0.24.0] - 2022-04-12

View File

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

View File

@ -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: // Run the deploy against the cluster in two cases:
// //
// 1. The cluster is not localnet. // 1. The cluster is not localnet.
@ -3050,14 +3053,17 @@ fn localnet(
// //
// The closure passed into this function must never change the working directory // The closure passed into this function must never change the working directory
// to be outside the workspace. Doing so will have undefined behavior. // 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(); 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("Previously set the workspace dir")
.expect("Anchor.toml must always exist"); .expect("Anchor.toml must always exist");
let r = f(&cfg); let r = f(&mut cfg);
set_workspace_dir_or_exit(); set_workspace_dir_or_exit();