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
* 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

View File

@ -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> {

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:
//
// 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();