cli: Add "slop" when anchor build (#719)

This commit is contained in:
Pierre 2021-09-27 10:15:31 +10:00 committed by GitHub
parent 63eabc5b61
commit df97fd8d56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -15,6 +15,7 @@ incremented for features.
* lang: Add `--detach` flag to `anchor test` ([#770](https://github.com/project-serum/anchor/pull/770)).
* lang: Add `associated_token` keyword for initializing associated token accounts within `#[derive(Accounts)]` ([#790](https://github.com/project-serum/anchor/pull/790)).
* cli: Allow passing through cargo flags for build command ([#719](https://github.com/project-serum/anchor/pull/719)).
## [0.16.1] - 2021-09-17

View File

@ -74,6 +74,13 @@ pub enum Command {
/// only.
#[clap(short, long)]
solana_version: Option<String>,
#[clap(
required = false,
takes_value = true,
multiple_values = true,
last = true
)]
slop: Vec<String>,
},
/// Verifies the on-chain bytecode matches the locally compiled artifact.
/// Run this command inside a program subdirectory, i.e., in the dir
@ -261,6 +268,7 @@ pub fn entry(opts: Opts) -> Result<()> {
verifiable,
program_name,
solana_version,
slop,
} => build(
&opts.cfg_override,
idl,
@ -269,6 +277,7 @@ pub fn entry(opts: Opts) -> Result<()> {
solana_version,
None,
None,
Some(slop),
),
Command::Verify {
program_id,
@ -441,6 +450,7 @@ pub fn build(
solana_version: Option<String>,
stdout: Option<File>, // Used for the package registry server.
stderr: Option<File>, // Used for the package registry server.
slop: Option<Vec<String>>,
) -> Result<()> {
// Change to the workspace member directory, if needed.
if let Some(program_name) = program_name.as_ref() {
@ -477,6 +487,7 @@ pub fn build(
solana_version,
stdout,
stderr,
slop,
)?,
// If the Cargo.toml is at the root, build the entire workspace.
Some(cargo) if cargo.path().parent() == cfg.path().parent() => build_all(
@ -487,6 +498,7 @@ pub fn build(
solana_version,
stdout,
stderr,
slop,
)?,
// Cargo.toml represents a single package. Build it.
Some(cargo) => build_cwd(
@ -497,6 +509,7 @@ pub fn build(
solana_version,
stdout,
stderr,
slop,
)?,
}
@ -513,6 +526,7 @@ fn build_all(
solana_version: Option<String>,
stdout: Option<File>, // Used for the package registry server.
stderr: Option<File>, // Used for the package registry server.
slop: Option<Vec<String>>,
) -> Result<()> {
let cur_dir = std::env::current_dir()?;
let r = match cfg_path.parent() {
@ -527,6 +541,7 @@ fn build_all(
solana_version.clone(),
stdout.as_ref().map(|f| f.try_clone()).transpose()?,
stderr.as_ref().map(|f| f.try_clone()).transpose()?,
slop.clone(),
)?;
}
Ok(())
@ -545,13 +560,14 @@ fn build_cwd(
solana_version: Option<String>,
stdout: Option<File>,
stderr: Option<File>,
slop: Option<Vec<String>>,
) -> Result<()> {
match cargo_toml.parent() {
None => return Err(anyhow!("Unable to find parent")),
Some(p) => std::env::set_current_dir(&p)?,
};
match verifiable {
false => _build_cwd(idl_out),
false => _build_cwd(idl_out, slop),
true => build_cwd_verifiable(cfg, cargo_toml, solana_version, stdout, stderr),
}
}
@ -780,9 +796,10 @@ fn docker_build(
Ok(())
}
fn _build_cwd(idl_out: Option<PathBuf>) -> Result<()> {
fn _build_cwd(idl_out: Option<PathBuf>, slop: Option<Vec<String>>) -> Result<()> {
let exit = std::process::Command::new("cargo")
.arg("build-bpf")
.args(slop.unwrap_or(vec![]))
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
@ -832,6 +849,7 @@ fn verify(
},
None,
None,
None,
)?;
std::env::set_current_dir(&cur_dir)?;
@ -1322,7 +1340,7 @@ fn test(
with_workspace(cfg_override, |cfg| {
// Build if needed.
if !skip_build {
build(cfg_override, None, false, None, None, None, None)?;
build(cfg_override, None, false, None, None, None, None, None)?;
}
// Run the deploy against the cluster in two cases:
@ -2110,6 +2128,7 @@ fn publish(cfg_override: &ConfigOverride, program_name: String) -> Result<()> {
cfg.solana_version.clone(),
None,
None,
None,
)?;
// Success. Now we can finally upload to the server without worrying