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

cli: add --skip-lint option #1482

Merged
merged 7 commits into from
Feb 21, 2022
Merged
Changes from 1 commit
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
65 changes: 56 additions & 9 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ pub enum Command {
/// Output directory for the IDL.
#[clap(short, long)]
idl: Option<String>,
/// True if the build should not fail even if there are
/// no "CHECK" comments where normally required
#[clap(long)]
skip_lint: bool,
/// Output directory for the TypeScript IDL.
#[clap(short = 't', long)]
idl_ts: Option<String>,
Expand Down Expand Up @@ -151,6 +155,10 @@ pub enum Command {
/// programs.
#[clap(long)]
skip_deploy: bool,
/// True if the build should not fail even if there are
/// no "CHECK" comments where normally required
#[clap(long)]
skip_lint: bool,
/// Flag to skip starting a local validator, if the configured cluster
/// url is a localnet.
#[clap(long)]
Expand Down Expand Up @@ -250,6 +258,10 @@ pub enum Command {
/// programs.
#[clap(long)]
skip_deploy: bool,
/// True if the build should not fail even if there are
/// no "CHECK" comments where normally required
#[clap(long)]
skip_lint: bool,
/// Arguments to pass to the underlying `cargo build-bpf` command.
#[clap(
required = false,
Expand Down Expand Up @@ -360,11 +372,13 @@ pub fn entry(opts: Opts) -> Result<()> {
docker_image,
bootstrap,
cargo_args,
skip_lint,
} => build(
&opts.cfg_override,
idl,
idl_ts,
verifiable,
skip_lint,
program_name,
solana_version,
docker_image,
Expand Down Expand Up @@ -407,11 +421,13 @@ pub fn entry(opts: Opts) -> Result<()> {
detach,
args,
cargo_args,
skip_lint,
} => test(
&opts.cfg_override,
skip_deploy,
skip_local_validator,
skip_build,
skip_lint,
detach,
args,
cargo_args,
Expand All @@ -430,8 +446,15 @@ pub fn entry(opts: Opts) -> Result<()> {
Command::Localnet {
skip_build,
skip_deploy,
skip_lint,
cargo_args,
} => localnet(
&opts.cfg_override,
skip_build,
skip_deploy,
skip_lint,
cargo_args,
} => localnet(&opts.cfg_override, skip_build, skip_deploy, cargo_args),
),
}
}

Expand Down Expand Up @@ -685,6 +708,7 @@ pub fn build(
idl: Option<String>,
idl_ts: Option<String>,
verifiable: bool,
skip_lint: bool,
program_name: Option<String>,
solana_version: Option<String>,
docker_image: Option<String>,
Expand Down Expand Up @@ -736,6 +760,7 @@ pub fn build(
stdout,
stderr,
cargo_args,
skip_lint,
)?,
// 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 @@ -747,6 +772,7 @@ pub fn build(
stdout,
stderr,
cargo_args,
skip_lint,
)?,
// Cargo.toml represents a single package. Build it.
Some(cargo) => build_cwd(
Expand All @@ -758,6 +784,7 @@ pub fn build(
stdout,
stderr,
cargo_args,
skip_lint,
)?,
}

Expand All @@ -776,6 +803,7 @@ fn build_all(
stdout: Option<File>, // Used for the package registry server.
stderr: Option<File>, // Used for the package registry server.
cargo_args: Vec<String>,
skip_lint: bool,
) -> Result<()> {
let cur_dir = std::env::current_dir()?;
let r = match cfg_path.parent() {
Expand All @@ -791,6 +819,7 @@ fn build_all(
stdout.as_ref().map(|f| f.try_clone()).transpose()?,
stderr.as_ref().map(|f| f.try_clone()).transpose()?,
cargo_args.clone(),
skip_lint,
)?;
}
Ok(())
Expand All @@ -811,14 +840,23 @@ fn build_cwd(
stdout: Option<File>,
stderr: Option<File>,
cargo_args: Vec<String>,
skip_lint: bool,
) -> Result<()> {
match cargo_toml.parent() {
None => return Err(anyhow!("Unable to find parent")),
Some(p) => std::env::set_current_dir(&p)?,
};
match build_config.verifiable {
false => _build_cwd(cfg, idl_out, idl_ts_out, cargo_args),
true => build_cwd_verifiable(cfg, cargo_toml, build_config, stdout, stderr, cargo_args),
false => _build_cwd(cfg, idl_out, idl_ts_out, skip_lint, cargo_args),
true => build_cwd_verifiable(
cfg,
cargo_toml,
build_config,
stdout,
stderr,
skip_lint,
cargo_args,
),
}
}

Expand All @@ -830,6 +868,7 @@ fn build_cwd_verifiable(
build_config: &BuildConfig,
stdout: Option<File>,
stderr: Option<File>,
skip_lint: bool,
cargo_args: Vec<String>,
) -> Result<()> {
// Create output dirs.
Expand Down Expand Up @@ -861,7 +900,7 @@ fn build_cwd_verifiable(
Ok(_) => {
// Build the idl.
println!("Extracting the IDL");
if let Ok(Some(idl)) = extract_idl(cfg, "src/lib.rs") {
if let Ok(Some(idl)) = extract_idl(cfg, "src/lib.rs", skip_lint) {
// Write out the JSON file.
println!("Writing the IDL file");
let out_file = workspace_dir.join(format!("target/idl/{}.json", idl.name));
Expand Down Expand Up @@ -1121,6 +1160,7 @@ fn _build_cwd(
cfg: &WithPath<Config>,
idl_out: Option<PathBuf>,
idl_ts_out: Option<PathBuf>,
skip_lint: bool,
cargo_args: Vec<String>,
) -> Result<()> {
let exit = std::process::Command::new("cargo")
Expand All @@ -1135,7 +1175,7 @@ fn _build_cwd(
}

// Always assume idl is located at src/lib.rs.
if let Some(idl) = extract_idl(cfg, "src/lib.rs")? {
if let Some(idl) = extract_idl(cfg, "src/lib.rs", skip_lint)? {
// JSON out path.
let out = match idl_out {
None => PathBuf::from(".").join(&idl.name).with_extension("json"),
Expand Down Expand Up @@ -1192,6 +1232,7 @@ fn verify(
None, // idl
None, // idl ts
true, // verifiable
true, // skip lint
None, // program name
solana_version.or_else(|| cfg.solana_version.clone()), // solana version
docker_image, // docker image
Expand Down Expand Up @@ -1219,7 +1260,7 @@ fn verify(
}

// Verify IDL (only if it's not a buffer account).
if let Some(local_idl) = extract_idl(&cfg, "src/lib.rs")? {
if let Some(local_idl) = extract_idl(&cfg, "src/lib.rs", true)? {
if bin_ver.state != BinVerificationState::Buffer {
let deployed_idl = fetch_idl(cfg_override, program_id)?;
if local_idl != deployed_idl {
Expand Down Expand Up @@ -1383,7 +1424,7 @@ fn fetch_idl(cfg_override: &ConfigOverride, idl_addr: Pubkey) -> Result<Idl> {
serde_json::from_slice(&s[..]).map_err(Into::into)
}

fn extract_idl(cfg: &WithPath<Config>, file: &str) -> Result<Option<Idl>> {
fn extract_idl(cfg: &WithPath<Config>, file: &str, skip_lint: bool) -> Result<Option<Idl>> {
let file = shellexpand::tilde(file);
let manifest_from_path = std::env::current_dir()?.join(PathBuf::from(&*file).parent().unwrap());
let cargo = Manifest::discover_from_path(manifest_from_path)?
Expand All @@ -1392,7 +1433,7 @@ fn extract_idl(cfg: &WithPath<Config>, file: &str) -> Result<Option<Idl>> {
&*file,
cargo.version(),
cfg.features.seeds,
cfg.features.safety_checks,
!skip_lint && cfg.features.safety_checks,
paul-schaaf marked this conversation as resolved.
Show resolved Hide resolved
)
}

Expand Down Expand Up @@ -1686,7 +1727,7 @@ fn idl_parse(
out_ts: Option<String>,
) -> Result<()> {
let cfg = Config::discover(cfg_override)?.expect("Not in workspace.");
let idl = extract_idl(&cfg, &file)?.ok_or_else(|| anyhow!("IDL not parsed"))?;
let idl = extract_idl(&cfg, &file, true)?.ok_or_else(|| anyhow!("IDL not parsed"))?;
let out = match out {
None => OutFile::Stdout,
Some(out) => OutFile::File(PathBuf::from(out)),
Expand Down Expand Up @@ -1726,11 +1767,13 @@ enum OutFile {
}

// Builds, deploys, and tests all workspace programs in a single command.
#[allow(clippy::too_many_arguments)]
fn test(
cfg_override: &ConfigOverride,
skip_deploy: bool,
skip_local_validator: bool,
skip_build: bool,
skip_lint: bool,
detach: bool,
extra_args: Vec<String>,
cargo_args: Vec<String>,
Expand All @@ -1743,6 +1786,7 @@ fn test(
None,
None,
false,
skip_lint,
None,
None,
None,
Expand Down Expand Up @@ -2667,6 +2711,7 @@ fn publish(
None,
None,
true,
false,
Some(program_name),
None,
None,
Expand Down Expand Up @@ -2754,6 +2799,7 @@ fn localnet(
cfg_override: &ConfigOverride,
skip_build: bool,
skip_deploy: bool,
skip_lint: bool,
cargo_args: Vec<String>,
) -> Result<()> {
with_workspace(cfg_override, |cfg| {
Expand All @@ -2764,6 +2810,7 @@ fn localnet(
None,
None,
false,
skip_lint,
None,
None,
None,
Expand Down