Skip to content

Commit 94c3f6e

Browse files
committed
Try to fix macro path
1 parent c3015bc commit 94c3f6e

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tl-proto = "0.5.3"
3737
case = "1.0.0"
3838
proc-macro2 = "1.0"
3939
quote = "1.0"
40-
syn = { version = "2.0", features = ["visit", "parsing"] }
40+
syn = { version = "2.0", features = ["full"] }
4141

4242
tycho-executor = { git = "https://github.com/broxus/tycho-vm.git"}
4343
tycho-vm = { git = "https://github.com/broxus/tycho-vm.git" }

proc/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ proc-macro = true
1212

1313
[dependencies]
1414
case = {workspace = true}
15-
proc-macro2 = {workspace = true}
15+
proc-macro2 = {workspace = true, features = ["span-locations"]}
1616
quote = {workspace = true}
17-
syn = { workspace = true }
17+
syn = { workspace = true, features = ["full"] }
1818
serde_json = {workspace = true}
1919
everscale-types = {workspace = true}
2020

proc/src/lib.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use quote::quote;
66
use std::fs;
77
use std::path::Path;
88
use syn::parse::{Parse, ParseStream};
9-
use syn::Result;
9+
use syn::{LitStr, Result};
1010
use syn::{parse_macro_input, ItemMod};
1111

1212
use crate::generator::{FunctionDescriptionTokens, StructGenerator};
@@ -15,12 +15,12 @@ mod generator;
1515
mod properties;
1616

1717
struct ModuleParams {
18-
path: String,
18+
path: LitStr,
1919
}
2020

2121
impl Parse for ModuleParams {
2222
fn parse(input: ParseStream) -> Result<Self> {
23-
let path = input.parse::<syn::LitStr>()?.value();
23+
let path = input.parse::<LitStr>()?;
2424
Ok(ModuleParams { path })
2525
}
2626
}
@@ -32,17 +32,27 @@ pub fn abi(params: TokenStream, input: TokenStream) -> TokenStream {
3232
let mut generated_events: Vec<proc_macro2::TokenStream> = Vec::new();
3333

3434
let params = parse_macro_input!(params as ModuleParams);
35-
let root = Path::new(env!("CARGO_MANIFEST_DIR"))
35+
let path = std::env::var("CARGO_MANIFEST_DIR").unwrap();
36+
37+
let root = Path::new(&path)
3638
.parent()
3739
.expect("project root dir not found");
3840

3941
println!("macro root: {root:?}");
40-
let file_path = root.join(params.path);
42+
let file_path = root.join(&params.path.value());
4143
println!("file path: {file_path:?}");
42-
43-
let content = fs::read_to_string(file_path).unwrap();
44-
45-
let contract = serde_json::from_str::<Contract>(&content).unwrap();
44+
45+
46+
let content = match fs::read_to_string(&file_path) {
47+
Ok(content) => content,
48+
Err(e) => panic!("Failed to read file by specified path. Error: {e:?}")
49+
};
50+
51+
let contract = match serde_json::from_str::<Contract>(&content) {
52+
Ok(contract) => contract,
53+
Err(e) => panic!("Failed to load contract from json. Error: {e:?}"),
54+
};
55+
4656

4757
let input = parse_macro_input!(input as ItemMod);
4858
let mod_name = &input.ident;

0 commit comments

Comments
 (0)