Skip to content

Commit

Permalink
cli: Sync program ids on the initial build (coral-xyz#3023)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Jun 13, 2024
1 parent 8528092 commit cdf2559
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- lang: Support legacy IDLs with `declare_program!` ([#2997](https://github.com/coral-xyz/anchor/pull/2997)).
- cli: Add `idl convert` command ([#3009](https://github.com/coral-xyz/anchor/pull/3009)).
- cli: Add `idl type` command ([#3017](https://github.com/coral-xyz/anchor/pull/3017)).
- cli: Sync program ids on the initial build ([#3023](https://github.com/coral-xyz/anchor/pull/3023)).

### Fixes

Expand Down
13 changes: 11 additions & 2 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{get_keypair, is_hidden};
use crate::{get_keypair, is_hidden, keys_sync};
use anchor_client::Cluster;
use anchor_lang_idl::types::Idl;
use anyhow::{anyhow, bail, Context, Error, Result};
Expand Down Expand Up @@ -512,7 +512,16 @@ impl Config {
.path();
if let Some(filename) = p.file_name() {
if filename.to_str() == Some("Anchor.toml") {
let cfg = Config::from_path(&p)?;
// Make sure the program id is correct (only on the initial build)
let mut cfg = Config::from_path(&p)?;
let deploy_dir = p.parent().unwrap().join("target").join("deploy");
if !deploy_dir.exists() && !cfg.programs.contains_key(&Cluster::Localnet) {
println!("Updating program ids...");
fs::create_dir_all(deploy_dir)?;
keys_sync(&ConfigOverride::default(), None)?;
cfg = Config::from_path(&p)?;
}

return Ok(Some(WithPath::new(cfg, p)));
}
}
Expand Down

0 comments on commit cdf2559

Please sign in to comment.