Skip to content

Commit c0fb8c5

Browse files
committed
chore(project-selector): allow glob patterns
1 parent 612a6e0 commit c0fb8c5

4 files changed

Lines changed: 47 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

justfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ fmt:
2020
cargo fmt
2121

2222
select crates="" depth="2":
23-
cargo r -p project-selector -- {{crates}} -b cumulus,snowbridge,parachain,xcm,pallet,fp,metadata-hash,bp,bridge,fc,polkadot-runtime,polkadot-core,polkadot-ckb,polkadot-primitives -a pallet-balances -d {{depth}} > rust-project.json
23+
SKIP_WASM_BUILD=1 cargo r -p project-selector -- {{crates}} \
24+
-b "*polkadot*,*cumulus*,*snowbridge*,*parachain*,*xcm*,pallet*,fp*,*metadata-hash*,bp*,bridge*,fc*,substrate*build*" \
25+
-a "polkadot-sdk*,pallet*api" \
26+
-d {{depth}} > rust-project.json
2427

2528
run-localnode profile="--alice":
2629
cargo xtask run local {{profile}}

project-selector/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ serde_json = { version = "1", features = ["std"] }
1414
itertools = "0.14.0"
1515
clap.workspace = true
1616
anyhow = "1.0.98"
17+
glob = "0.3.2"

project-selector/src/main.rs

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6465
impl<'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(|s| glob::Pattern::new(s))
108+
.collect::<Result<Vec<_>, _>>()?;
109+
let allowlist = args
110+
.allowlist
111+
.split(',')
112+
.filter(|s| !s.is_empty())
113+
.map(|s| glob::Pattern::new(s))
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
193232
fn 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

Comments
 (0)