@@ -2,14 +2,17 @@ use crate::codegen::dumper::Dumper;
2
2
use crate :: codegen:: ConfigDumpContent ;
3
3
use crate :: command_args;
4
4
use crate :: library:: commands:: command_runner:: execute_command;
5
+
5
6
use anyhow:: { bail, Context , Result } ;
6
7
use itertools:: Itertools ;
8
+ use lazy_static:: lazy_static;
7
9
use log:: { debug, info, warn} ;
8
10
use regex:: Regex ;
11
+
12
+ use std:: borrow:: Cow ;
9
13
use std:: collections:: hash_map:: Entry :: { Occupied , Vacant } ;
10
14
use std:: collections:: HashMap ;
11
15
use std:: path:: { Path , PathBuf } ;
12
- use std:: sync:: OnceLock ;
13
16
use std:: { env, fs} ;
14
17
15
18
#[ derive( Default ) ]
@@ -41,7 +44,10 @@ impl CachedCargoExpand {
41
44
42
45
let expanded = match self . cache . entry ( rust_crate_dir. to_owned ( ) ) {
43
46
Occupied ( entry) => entry. into_mut ( ) ,
44
- Vacant ( entry) => entry. insert ( run_cargo_expand ( rust_crate_dir, dumper, true ) ?) ,
47
+ Vacant ( entry) => entry. insert (
48
+ unwrap_frb_attrs_in_doc ( & run_cargo_expand ( rust_crate_dir, dumper, true ) ?)
49
+ . into_owned ( ) ,
50
+ ) ,
45
51
} ;
46
52
47
53
extract_module ( expanded, module)
@@ -93,7 +99,7 @@ fn run_cargo_expand(
93
99
"--theme=none" ,
94
100
"--ugly" ,
95
101
"--config" ,
96
- "build.rustflags=\ " --cfg frb_expand\" "
102
+ r# "build.rustflags="--cfg frb_expand""#
97
103
) ;
98
104
99
105
let output = execute_command ( "cargo" , & args, Some ( rust_crate_dir) , None )
@@ -114,20 +120,22 @@ fn run_cargo_expand(
114
120
// frb-coverage:ignore-end
115
121
}
116
122
117
- let mut stdout_lines = stdout. lines ( ) ;
118
- stdout_lines. next ( ) ;
119
- let ans = stdout_lines. join ( "\n " ) ;
120
- static PATTERN : OnceLock < Regex > = OnceLock :: new ( ) ;
121
- let pattern = PATTERN . get_or_init ( || {
122
- Regex :: new ( r####"#\[doc =[\s\n]*r###"frb_marker: ([\s\S]*?)"###]"#### ) . unwrap ( )
123
- } ) ;
124
- let ans = pattern. replace_all ( & ans, "$1" ) . into_owned ( ) ;
125
-
123
+ let ans = stdout. lines ( ) . skip ( 1 ) . join ( "\n " ) ;
126
124
dumper. dump_str ( ConfigDumpContent :: Source , "cargo_expand.rs" , & ans) ?;
127
-
128
125
Ok ( ans)
129
126
}
130
127
128
+ /// Turns `#[doc = "frb_marker: .."]` back into `#[frb(..)]`, usually produced
129
+ /// as a side-effect of cargo-expand.
130
+ // NOTE: The amount of pounds must match exactly with the implementation in frb_macros
131
+ fn unwrap_frb_attrs_in_doc ( code : & str ) -> Cow < str > {
132
+ lazy_static ! {
133
+ static ref PATTERN : Regex =
134
+ Regex :: new( r####"#\[doc =[\s\n]*r###"frb_marker: ([\s\S]*?)"###]"#### ) . unwrap( ) ;
135
+ }
136
+ PATTERN . replace_all ( code, "$1" )
137
+ }
138
+
131
139
fn install_cargo_expand ( ) -> Result < ( ) > {
132
140
execute_command (
133
141
"cargo" ,
0 commit comments