@@ -59,6 +59,7 @@ struct ProjectContext<'a> {
5959 build_outputs : HashMap < PackageId , BuildOutput > ,
6060 proc_macro_dylibs : Vec < ( String , Utf8PathBuf ) > ,
6161 sysroot : project_model:: Sysroot ,
62+ matcher : Box < dyn Fn ( & Package ) -> bool > ,
6263}
6364
6465impl < ' a > ProjectContext < ' a > {
@@ -99,13 +100,51 @@ impl<'a> ProjectContext<'a> {
99100
100101 let dependencies = get_indirect_dependencies ( metadata, & workspace_crates, args. depth ) ?;
101102
103+ let blocklist = args
104+ . blocklist
105+ . split ( ',' )
106+ . filter ( |s| !s. is_empty ( ) )
107+ . map ( glob:: Pattern :: new)
108+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
109+ let allowlist = args
110+ . allowlist
111+ . split ( ',' )
112+ . filter ( |s| !s. is_empty ( ) )
113+ . map ( glob:: Pattern :: new)
114+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
115+
116+ let matcher = Box :: new ( {
117+ let workspace_crates = workspace_crates. clone ( ) ;
118+
119+ move |pkg : & Package | {
120+ if workspace_crates. contains ( & pkg. id ) {
121+ return true ;
122+ }
123+
124+ for pat in & allowlist {
125+ if pat. matches ( & pkg. name ) {
126+ return true ;
127+ }
128+ }
129+
130+ for pat in & blocklist {
131+ if pat. matches ( & pkg. name ) {
132+ return false ;
133+ }
134+ }
135+
136+ true
137+ }
138+ } ) ;
139+
102140 Ok ( ProjectContext {
103141 metadata,
104142 workspace_crates,
105143 dependencies,
106144 build_outputs,
107145 proc_macro_dylibs,
108146 sysroot,
147+ matcher,
109148 } )
110149 }
111150
@@ -180,7 +219,7 @@ fn main() -> Result<()> {
180219
181220 let project_context = ProjectContext :: load ( & metadata, & args) ?;
182221
183- let resolved_crates = resolve_crates ( & project_context, & args ) ?;
222+ let resolved_crates = resolve_crates ( & project_context) ?;
184223
185224 let project_json = generate_project_json ( & project_context, & resolved_crates) ?;
186225
@@ -192,7 +231,6 @@ fn main() -> Result<()> {
192231/// Resolve all crates and their information based on project context
193232fn resolve_crates < ' a > (
194233 context : & ' a ProjectContext < ' a > ,
195- args : & Args ,
196234) -> Result < HashMap < & ' a PackageId , CrateInfo < ' a > > > {
197235 let mut crate_infos = HashMap :: new ( ) ;
198236
@@ -201,18 +239,7 @@ fn resolve_crates<'a>(
201239 continue ;
202240 } ;
203241
204- let is_blocked = args. blocklist . split ( ',' ) . any ( |blocked| {
205- !blocked. is_empty ( )
206- && !context. workspace_crates . contains ( pkg_id)
207- && pkg_id. repr . contains ( blocked)
208- } ) ;
209-
210- let is_allowed = args
211- . allowlist
212- . split ( ',' )
213- . any ( |allowed| !allowed. is_empty ( ) && pkg_id. repr . contains ( allowed) ) ;
214-
215- if is_blocked && !is_allowed {
242+ if !( context. matcher ) ( package) {
216243 continue ;
217244 }
218245
0 commit comments