Skip to content

Commit

Permalink
cli: fix failing 'anchor build' if 'Test.toml' included a relative pa… (
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-schaaf authored Apr 12, 2022
1 parent fb149f9 commit 53ead60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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> {
Expand Down
12 changes: 9 additions & 3 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 53ead60

Please sign in to comment.