cli: Sync program ids on the initial build (#3023)

This commit is contained in:
acheron 2024-06-13 13:25:08 +02:00 committed by GitHub
parent 8528092545
commit cdf25593b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

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

View File

@ -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)));
}
}