1+ mod  attributes; 
12mod  name; 
2- mod  raw; 
33
4- use  std:: collections:: BTreeMap ; 
54use  std:: env; 
65use  std:: fs:: File ; 
76use  std:: io:: { BufWriter ,  Write } ; 
@@ -12,40 +11,22 @@ use walkdir::WalkDir;
1211const  ATTRIBUTE_DIR :  & str  = "sentry-conventions/model/attributes" ; 
1312const  NAME_DIR :  & str  = "sentry-conventions/model/name" ; 
1413
15- #[ derive( Default ) ]  
16- struct  RawNode  { 
17-     children :  BTreeMap < String ,  RawNode > , 
18-     info :  Option < String > , 
19- } 
14+ fn  main ( )  { 
15+     let  crate_dir:  PathBuf  = env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) . into ( ) ; 
2016
21- impl  RawNode  { 
22-     fn  build ( & self ,  w :  & mut  impl  std:: io:: Write )  -> Result < ( ) ,  std:: io:: Error >  { 
23-         let  Self  {  children,  info }  = self ; 
24-         write ! ( w,  "Node {{ info: " ) ?; 
25-         match  info { 
26-             Some ( info)  => write ! ( w,  "Some({})" ,  info) ?, 
27-             None  => write ! ( w,  "None" ) ?, 
28-         } ; 
29-         write ! ( w,  ", children: ::phf::phf_map!{{" , ) ?; 
30-         for  ( segment,  child)  in  children { 
31-             write ! ( w,  "\" {segment}\"  => " ) ?; 
32-             child. build ( w) ?; 
33-             write ! ( w,  "," ) ?; 
34-         } 
35-         write ! ( w,  "}} }}" ) 
36-     } 
37- } 
17+     write_attribute_rs ( & crate_dir) ; 
18+     write_name_rs ( & crate_dir) ; 
19+ 
20+     // Ideally this would only run when compiling for tests, but #[cfg(test)] doesn't seem to work 
21+     // here. 
22+     write_test_name_rs ( ) ; 
3823
39- /// Parse a path-like attribute key into individual segments. 
40- /// 
41- /// NOTE: This does not yet support escaped segments, e.g. `"foo.'my.thing'.bar"` will split into 
42- /// `["foo.'my", "thing'.bar"]`. 
43- fn  parse_segments ( key :  & str )  -> impl  Iterator < Item  = & str >  { 
44-     key. split ( '.' ) 
24+     println ! ( "cargo::rerun-if-changed=." ) ; 
4525} 
4626
47- fn  main ( )  { 
48-     let  crate_dir:  PathBuf  = env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) . into ( ) ; 
27+ fn  write_attribute_rs ( crate_dir :  & Path )  { 
28+     use  attributes:: { Attribute ,  RawNode ,  format_attribute_info,  parse_segments} ; 
29+ 
4930    let  mut  root = RawNode :: default ( ) ; 
5031
5132    for  file in  WalkDir :: new ( crate_dir. join ( ATTRIBUTE_DIR ) )  { 
@@ -55,8 +36,8 @@ fn main() {
5536            && ext. to_str ( )  == Some ( "json" ) 
5637        { 
5738            let  contents = std:: fs:: read_to_string ( file. path ( ) ) . unwrap ( ) ; 
58-             let  attr:  raw :: Attribute  = serde_json:: from_str ( & contents) . unwrap ( ) ; 
59-             let  ( key,  value)  = raw :: format_attribute_info ( attr) ; 
39+             let  attr:  Attribute  = serde_json:: from_str ( & contents) . unwrap ( ) ; 
40+             let  ( key,  value)  = format_attribute_info ( attr) ; 
6041
6142            let  mut  node = & mut  root; 
6243            let  mut  parts = parse_segments ( & key) . peekable ( ) ; 
@@ -79,14 +60,6 @@ fn main() {
7960    write ! ( & mut  out_file,  "static ATTRIBUTES: Node<AttributeInfo> = " , ) . unwrap ( ) ; 
8061    root. build ( & mut  out_file) . unwrap ( ) ; 
8162    write ! ( & mut  out_file,  ";" ) . unwrap ( ) ; 
82- 
83-     write_name_rs ( & crate_dir) ; 
84- 
85-     // Ideally this would only run when compiling for tests, but #[cfg(test)] doesn't seem to work 
86-     // here. 
87-     write_test_name_rs ( ) ; 
88- 
89-     println ! ( "cargo::rerun-if-changed=." ) ; 
9063} 
9164
9265fn  write_name_rs ( crate_dir :  & Path )  { 
0 commit comments