Skip to content

Commit

Permalink
Update shank idl dependency (#61)
Browse files Browse the repository at this point in the history
* Update cargo toml dependency

* Fix clippy warnings
  • Loading branch information
febo authored Oct 31, 2023
1 parent a010cca commit 92b09da
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 46 deletions.
8 changes: 5 additions & 3 deletions shank-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn try_resolve_path(p: Option<String>, label: &str) -> Result<PathBuf> {
}?;

let p = if p.is_absolute() {
Ok(p.to_path_buf())
Ok(p)
} else {
debug!("{} is relative, resolving from current dir", label);
std::env::current_dir().map(|x| x.join(p))
Expand Down Expand Up @@ -98,8 +98,10 @@ pub fn idl(
lib_full_path_str.to_str().ok_or(anyhow!("Invalid Path"))?;

// Extract IDL and convert to JSON
let mut opts = ParseIdlOpts::default();
opts.program_address_override = program_id;
let opts = ParseIdlOpts {
program_address_override: program_id,
..ParseIdlOpts::default()
};
let idl = extract_idl(lib_full_path, opts)?
.ok_or(anyhow!("No IDL could be extracted"))?;
let idl_json = idl.try_into_json()?;
Expand Down
2 changes: 1 addition & 1 deletion shank-idl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ shank_macro_impl = { version = "0.2.1", path = "../shank-macro-impl" }
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.72"
anyhow = "1.0.48"
cargo_toml = "0.10.1"
cargo_toml = "0.17"
heck = "0.3.3"
2 changes: 1 addition & 1 deletion shank-idl/src/idl_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl From<InstructionAccount> for IdlAccountItem {
}

fn is_false(x: &bool) -> bool {
return !x;
!x
}
// -----------------
// IdlAccount
Expand Down
1 change: 0 additions & 1 deletion shank-idl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use anyhow::{anyhow, Result};
use idl::Idl;
use manifest::Manifest;
use shank_macro_impl::custom_type::DetectCustomTypeConfig;
use shellexpand;

use std::path::PathBuf;

Expand Down
8 changes: 2 additions & 6 deletions shank-idl/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ impl Manifest {
}

pub fn lib_rel_path(&self) -> Option<String> {
self.lib
.as_ref()
.map(|x| x.path.clone())
.flatten()
.to_owned()
self.lib.as_ref().and_then(|x| x.path.clone())
}

pub fn lib_name(&self) -> Result<String> {
Expand All @@ -96,7 +92,7 @@ impl Manifest {

pub fn version(&self) -> String {
match &self.package {
Some(package) => package.version.to_string(),
Some(package) => package.version.get().unwrap().clone(),
_ => "0.0.0".to_string(),
}
}
Expand Down
6 changes: 3 additions & 3 deletions shank-idl/tests/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn check_or_update_idl(idl: &Idl, json_path: &str) {
#[test]
fn account_from_single_file() {
let file = fixtures_dir().join("single_file").join("account.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -48,7 +48,7 @@ fn account_from_single_file() {
#[test]
fn account_from_single_file_complex_types() {
let file = fixtures_dir().join("single_file").join("complex_types.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -59,7 +59,7 @@ fn account_from_single_file_complex_types() {
#[test]
fn account_from_single_file_padding() {
let file = fixtures_dir().join("single_file").join("padding.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand Down
4 changes: 2 additions & 2 deletions shank-idl/tests/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn fixtures_dir() -> PathBuf {
#[test]
fn errors_this_error() {
let file = fixtures_dir().join("this_error.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -26,7 +26,7 @@ fn errors_this_error() {
#[test]
fn errors_this_error_custom_codes() {
let file = fixtures_dir().join("this_error_custom_codes.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand Down
20 changes: 10 additions & 10 deletions shank-idl/tests/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn instruction_from_single_file_no_args() {
let file = fixtures_dir()
.join("single_file")
.join("instruction_no_args.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -31,7 +31,7 @@ fn instruction_from_single_file_with_args() {
let file = fixtures_dir()
.join("single_file")
.join("instruction_with_args.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -48,7 +48,7 @@ fn instruction_from_single_file_with_struct_args() {
let file = fixtures_dir()
.join("single_file")
.join("instruction_with_struct_args.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -65,7 +65,7 @@ fn instruction_from_single_file_with_multiple_args() {
let file = fixtures_dir()
.join("single_file")
.join("instruction_with_multiple_args.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -82,7 +82,7 @@ fn instruction_from_single_file_with_optional_account() {
let file = fixtures_dir()
.join("single_file")
.join("instruction_with_optional_account.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -99,7 +99,7 @@ fn instruction_from_single_file_with_optional_account_defaulting() {
let file = fixtures_dir()
.join("single_file")
.join("instruction_with_optional_account_defaulting.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -116,7 +116,7 @@ fn instruction_from_single_file_invalid_attr() {
let file = fixtures_dir()
.join("single_file")
.join("instruction_invalid_attr.rs");
let res = parse_file(&file, &ParseIdlConfig::optional_program_address());
let res = parse_file(file, &ParseIdlConfig::optional_program_address());

let err = res.unwrap_err();
let source_string = err.source().unwrap().to_string();
Expand All @@ -129,7 +129,7 @@ fn instruction_from_single_file_invalid_discriminant() {
let file = fixtures_dir()
.join("single_file")
.join("instruction_invalid_discriminant.rs");
let res = parse_file(&file, &ParseIdlConfig::optional_program_address());
let res = parse_file(file, &ParseIdlConfig::optional_program_address());

let err = res.unwrap_err().to_string();
assert!(err.contains("discriminants have to be <= u8::MAX"));
Expand All @@ -141,7 +141,7 @@ fn instruction_from_single_file_with_optional_signer_account() {
let file = fixtures_dir()
.join("single_file")
.join("instruction_with_optional_signer_account.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -158,7 +158,7 @@ fn instruction_from_single_file_with_docs() {
let file = fixtures_dir()
.join("single_file")
.join("instruction_with_docs.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand Down
6 changes: 3 additions & 3 deletions shank-idl/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn fixtures_dir() -> PathBuf {
#[test]
fn macro_valid_program_id() {
let file = fixtures_dir().join("program_id_valid.rs");
let idl = parse_file(&file, &ParseIdlConfig::default())
let idl = parse_file(file, &ParseIdlConfig::default())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -25,7 +25,7 @@ fn macro_valid_program_id() {
#[test]
fn macro_missing_program_id() {
let file = fixtures_dir().join("program_id_missing.rs");
let err = parse_file(&file, &ParseIdlConfig::default())
let err = parse_file(file, &ParseIdlConfig::default())
.expect_err("Should fail")
.to_string();
assert!(err.contains("Could not find"));
Expand All @@ -35,7 +35,7 @@ fn macro_missing_program_id() {
#[test]
fn macro_missing_program_id_not_required() {
let file = fixtures_dir().join("program_id_missing.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand Down
20 changes: 10 additions & 10 deletions shank-idl/tests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn fixtures_dir() -> PathBuf {
#[test]
fn type_valid_single_struct() {
let file = fixtures_dir().join("valid_single_struct.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -25,7 +25,7 @@ fn type_valid_single_struct() {
#[test]
fn type_valid_single_emum() {
let file = fixtures_dir().join("valid_single_enum.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -40,7 +40,7 @@ fn type_valid_single_emum() {
#[test]
fn type_valid_single_data_emum() {
let file = fixtures_dir().join("valid_single_data_enum.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -55,7 +55,7 @@ fn type_valid_single_data_emum() {
#[test]
fn type_valid_multiple() {
let file = fixtures_dir().join("valid_multiple.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");
// eprintln!("{}", serde_json::to_string_pretty(&idl).unwrap());
Expand All @@ -72,14 +72,14 @@ fn type_valid_multiple() {
fn type_invalid_single() {
let file = fixtures_dir().join("invalid_single.rs");
assert!(
parse_file(&file, &ParseIdlConfig::optional_program_address()).is_err()
parse_file(file, &ParseIdlConfig::optional_program_address()).is_err()
)
}

#[test]
fn type_valid_maps() {
let file = fixtures_dir().join("valid_multiple_maps.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");
// eprintln!("{}", serde_json::to_string_pretty(&idl).unwrap());
Expand All @@ -95,7 +95,7 @@ fn type_valid_maps() {
#[test]
fn type_valid_sets() {
let file = fixtures_dir().join("valid_multiple_sets.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");
// eprintln!("{}", serde_json::to_string_pretty(&idl).unwrap());
Expand All @@ -111,7 +111,7 @@ fn type_valid_sets() {
#[test]
fn type_valid_tuples() {
let file = fixtures_dir().join("valid_multiple_tuples.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");
// eprintln!("{}", serde_json::to_string_pretty(&idl).unwrap());
Expand All @@ -127,7 +127,7 @@ fn type_valid_tuples() {
#[test]
fn type_valid_single_struct_shank_type() {
let file = fixtures_dir().join("valid_single_struct_shank_type.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");
// eprintln!("{}", serde_json::to_string_pretty(&idl).unwrap());
Expand All @@ -143,7 +143,7 @@ fn type_valid_single_struct_shank_type() {
#[test]
fn type_valid_single_enum_shank_type() {
let file = fixtures_dir().join("valid_single_enum_shank_type.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");
// eprintln!("{}", serde_json::to_string_pretty(&idl).unwrap());
Expand Down
4 changes: 1 addition & 3 deletions shank-macro-impl/src/krate/crate_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ impl CrateContext {
}

pub fn modules(&self) -> impl Iterator<Item = ModuleContext> {
self.modules
.iter()
.map(move |(_, detail)| ModuleContext { detail })
self.modules.values().map(|detail| ModuleContext { detail })
}

pub fn root_module(&self) -> ModuleContext {
Expand Down
2 changes: 1 addition & 1 deletion shank-macro-impl/src/parsed_macro/parsed_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl From<&ItemMacro> for ParsedMacro {
.iter()
.map(|ident| ident.to_string())
.reduce(|acc, ident| format!("{}::{}", acc, ident))
.unwrap_or_else(|| "".to_string());
.unwrap_or_default();

let literal = syn::parse2::<Literal>(item_macro.mac.tokens.clone())
.map_or(None, |lit| {
Expand Down
4 changes: 2 additions & 2 deletions shank-macro-impl/src/parsers/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ pub fn attr_is_derive(attr: &&Attribute, derive: &str) -> bool {
}
}

pub fn get_derive_attr<'a, 'b>(
pub fn get_derive_attr<'a>(
attrs: &'a [Attribute],
derive: &'b str,
derive: &str,
) -> Option<&'a Attribute> {
attrs.iter().find(|attr| attr_is_derive(attr, derive))
}

0 comments on commit 92b09da

Please sign in to comment.