diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d86ea3ce..d71bee238 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cli/src/config.rs b/cli/src/config.rs index 0358dc0e5..7500efa3c 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -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}; @@ -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))); } }