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 anchor-debug feature to optionally inject log statements #253

Merged
merged 3 commits into from
May 7, 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 @@ -14,6 +14,7 @@ incremented for features.
## Features

* client: Adds support for state instructions ([#248](https://github.com/project-serum/anchor/pull/248)).
* lang: Add `anchor-debug` feature flag for logging ([#253](https://github.com/project-serum/anchor/pull/253)).
* ts: Add support for u16 ([#255](https://github.com/project-serum/anchor/pull/255)).

## Breaking
Expand Down
11 changes: 11 additions & 0 deletions lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ description = "Solana Sealevel eDSL"
[features]
derive = []
default = []
anchor-debug = [
"anchor-attribute-access-control/anchor-debug",
"anchor-attribute-account/anchor-debug",
"anchor-attribute-error/anchor-debug",
"anchor-attribute-event/anchor-debug",
"anchor-attribute-interface/anchor-debug",
"anchor-attribute-program/anchor-debug",
"anchor-attribute-program/anchor-debug",
"anchor-attribute-state/anchor-debug",
"anchor-derive-accounts/anchor-debug"
]

[dependencies]
anchor-attribute-access-control = { path = "./attribute/access-control", version = "0.4.5" }
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/access-control/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true

[features]
anchor-debug = ["anchor-syn/anchor-debug"]

[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true

[features]
anchor-debug = ["anchor-syn/anchor-debug"]

[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true

[features]
anchor-debug = ["anchor-syn/anchor-debug"]

[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/event/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true

[features]
anchor-debug = ["anchor-syn/anchor-debug"]

[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true

[features]
anchor-debug = ["anchor-syn/anchor-debug"]

[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true

[features]
anchor-debug = ["anchor-syn/anchor-debug"]

[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true

[features]
anchor-debug = ["anchor-syn/anchor-debug"]

[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
4 changes: 4 additions & 0 deletions lang/derive/accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ edition = "2018"
[lib]
proc-macro = true

[features]
default = []
anchor-debug = ["anchor-syn/anchor-debug"]

[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
1 change: 1 addition & 0 deletions lang/syn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ edition = "2018"
idl = []
hash = []
default = []
anchor-debug = []

[dependencies]
proc-macro2 = "1.0"
Expand Down
6 changes: 3 additions & 3 deletions lang/syn/src/codegen/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn generate(accs: AccountsStruct) -> proc_macro2::TokenStream {
let name = &s.ident;
let ty = &s.raw_field.ty;
quote! {
#[cfg(feature = "debug-log")]
#[cfg(feature = "anchor-debug")]
::solana_program::log::sol_log(stringify!(#name));
let #name: #ty = anchor_lang::Accounts::try_accounts(program_id, accounts)?;
}
Expand All @@ -40,12 +40,12 @@ pub fn generate(accs: AccountsStruct) -> proc_macro2::TokenStream {
let name = &f.typed_ident();
match f.is_init {
false => quote! {
#[cfg(feature = "debug-log")]
#[cfg(feature = "anchor-debug")]
::solana_program::log::sol_log(stringify!(#name));
let #name = anchor_lang::Accounts::try_accounts(program_id, accounts)?;
},
true => quote! {
#[cfg(feature = "debug-log")]
#[cfg(feature = "anchor-debug")]
::solana_program::log::sol_log(stringify!(#name));
let #name = anchor_lang::AccountsInit::try_accounts_init(program_id, accounts)?;
},
Expand Down
4 changes: 4 additions & 0 deletions lang/syn/src/codegen/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ pub fn generate(program: Program) -> proc_macro2::TokenStream {
/// program, where execution begins.
#[cfg(not(feature = "no-entrypoint"))]
fn entry(program_id: &Pubkey, accounts: &[AccountInfo], ix_data: &[u8]) -> ProgramResult {
#[cfg(feature = "anchor-debug")]
{
msg!("anchor-debug is active");
}
if ix_data.len() < 8 {
return Err(ProgramError::Custom(99));
}
Expand Down