Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "slop" when anchor build #719

Merged
merged 3 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 22 additions & 3 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -261,6 +268,7 @@ pub fn entry(opts: Opts) -> Result<()> {
verifiable,
program_name,
solana_version,
slop,
} => build(
&opts.cfg_override,
idl,
Expand All @@ -269,6 +277,7 @@ pub fn entry(opts: Opts) -> Result<()> {
solana_version,
None,
None,
Some(slop),
),
Command::Verify {
program_id,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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(
Expand 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(
Expand All @@ -497,6 +509,7 @@ pub fn build(
solana_version,
stdout,
stderr,
slop,
)?,
}

Expand All @@ -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() {
Expand All @@ -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(())
Expand All @@ -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),
}
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -832,6 +849,7 @@ fn verify(
},
None,
None,
None,
)?;
std::env::set_current_dir(&cur_dir)?;

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down