1
- //! Check license of third-party deps by inspecting vendor
1
+ //! Checks the licenses of third-party dependencies by inspecting vendors.
2
2
3
3
use std:: collections:: { BTreeSet , HashSet , HashMap } ;
4
4
use std:: fs;
@@ -21,7 +21,7 @@ const LICENSES: &[&str] = &[
21
21
/// These are exceptions to Rust's permissive licensing policy, and
22
22
/// should be considered bugs. Exceptions are only allowed in Rust
23
23
/// tooling. It is _crucial_ that no exception crates be dependencies
24
- /// of the Rust runtime (std / test).
24
+ /// of the Rust runtime (std/ test).
25
25
const EXCEPTIONS : & [ & str ] = & [
26
26
"mdbook" , // MPL2, mdbook
27
27
"openssl" , // BSD+advertising clause, cargo, mdbook
@@ -39,11 +39,11 @@ const EXCEPTIONS: &[&str] = &[
39
39
"colored" , // MPL-2.0, rustfmt
40
40
"ordslice" , // Apache-2.0, rls
41
41
"cloudabi" , // BSD-2-Clause, (rls -> crossbeam-channel 0.2 -> rand 0.5)
42
- "ryu" , // Apache-2.0, rls/cargo/... (b/c of serde)
42
+ "ryu" , // Apache-2.0, rls/cargo/... (because of serde)
43
43
"bytesize" , // Apache-2.0, cargo
44
44
"im-rc" , // MPL-2.0+, cargo
45
45
"adler32" , // BSD-3-Clause AND Zlib, cargo dep that isn't used
46
- "fortanix-sgx-abi" , // MPL-2.0+, libstd but only for sgx target
46
+ "fortanix-sgx-abi" , // MPL-2.0+, libstd but only for ` sgx` target
47
47
] ;
48
48
49
49
/// Which crates to check against the whitelist?
@@ -156,7 +156,7 @@ const WHITELIST: &[Crate] = &[
156
156
Crate ( "wincolor" ) ,
157
157
] ;
158
158
159
- // Some types for Serde to deserialize the output of `cargo metadata` to...
159
+ // Some types for Serde to deserialize the output of `cargo metadata` to.
160
160
161
161
#[ derive( Deserialize ) ]
162
162
struct Output {
@@ -174,9 +174,9 @@ struct ResolveNode {
174
174
dependencies : Vec < String > ,
175
175
}
176
176
177
- /// A unique identifier for a crate
177
+ /// A unique identifier for a crate.
178
178
#[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Debug , Hash ) ]
179
- struct Crate < ' a > ( & ' a str ) ; // (name, )
179
+ struct Crate < ' a > ( & ' a str ) ; // (name)
180
180
181
181
#[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Debug , Hash ) ]
182
182
struct CrateVersion < ' a > ( & ' a str , & ' a str ) ; // (name, version)
@@ -188,7 +188,7 @@ impl<'a> Crate<'a> {
188
188
}
189
189
190
190
impl < ' a > CrateVersion < ' a > {
191
- /// Returns the struct and whether or not the dep is in-tree
191
+ /// Returns the struct and whether or not the dependency is in-tree.
192
192
pub fn from_str ( s : & ' a str ) -> ( Self , bool ) {
193
193
let mut parts = s. split ( ' ' ) ;
194
194
let name = parts. next ( ) . unwrap ( ) ;
@@ -215,15 +215,15 @@ impl<'a> From<CrateVersion<'a>> for Crate<'a> {
215
215
///
216
216
/// Specifically, this checks that the license is correct.
217
217
pub fn check ( path : & Path , bad : & mut bool ) {
218
- // Check licences
218
+ // Check licences.
219
219
let path = path. join ( "../vendor" ) ;
220
220
assert ! ( path. exists( ) , "vendor directory missing" ) ;
221
221
let mut saw_dir = false ;
222
222
for dir in t ! ( path. read_dir( ) ) {
223
223
saw_dir = true ;
224
224
let dir = t ! ( dir) ;
225
225
226
- // skip our exceptions
226
+ // Skip our exceptions.
227
227
let is_exception = EXCEPTIONS . iter ( ) . any ( |exception| {
228
228
dir. path ( )
229
229
. to_str ( )
@@ -240,18 +240,18 @@ pub fn check(path: &Path, bad: &mut bool) {
240
240
assert ! ( saw_dir, "no vendored source" ) ;
241
241
}
242
242
243
- /// Checks the dependency of WHITELIST_CRATES at the given path. Changes `bad` to `true` if a check
244
- /// failed.
243
+ /// Checks the dependency of ` WHITELIST_CRATES` at the given path. Changes `bad` to `true` if a
244
+ /// check failed.
245
245
///
246
- /// Specifically, this checks that the dependencies are on the WHITELIST.
246
+ /// Specifically, this checks that the dependencies are on the ` WHITELIST` .
247
247
pub fn check_whitelist ( path : & Path , cargo : & Path , bad : & mut bool ) {
248
- // Get dependencies from cargo metadata
248
+ // Get dependencies from Cargo metadata.
249
249
let resolve = get_deps ( path, cargo) ;
250
250
251
- // Get the whitelist into a convenient form
251
+ // Get the whitelist in a convenient form.
252
252
let whitelist: HashSet < _ > = WHITELIST . iter ( ) . cloned ( ) . collect ( ) ;
253
253
254
- // Check dependencies
254
+ // Check dependencies.
255
255
let mut visited = BTreeSet :: new ( ) ;
256
256
let mut unapproved = BTreeSet :: new ( ) ;
257
257
for & krate in WHITELIST_CRATES . iter ( ) {
@@ -308,9 +308,9 @@ fn extract_license(line: &str) -> String {
308
308
}
309
309
}
310
310
311
- /// Get the dependencies of the crate at the given path using `cargo metadata`.
311
+ /// Gets the dependencies of the crate at the given path using `cargo metadata`.
312
312
fn get_deps ( path : & Path , cargo : & Path ) -> Resolve {
313
- // Run `cargo metadata` to get the set of dependencies
313
+ // Run `cargo metadata` to get the set of dependencies.
314
314
let output = Command :: new ( cargo)
315
315
. arg ( "metadata" )
316
316
. arg ( "--format-version" )
@@ -335,25 +335,25 @@ fn check_crate_whitelist<'a, 'b>(
335
335
krate : CrateVersion < ' a > ,
336
336
must_be_on_whitelist : bool ,
337
337
) -> BTreeSet < Crate < ' a > > {
338
- // Will contain bad deps
338
+ // This will contain bad deps.
339
339
let mut unapproved = BTreeSet :: new ( ) ;
340
340
341
- // Check if we have already visited this crate
341
+ // Check if we have already visited this crate.
342
342
if visited. contains ( & krate) {
343
343
return unapproved;
344
344
}
345
345
346
346
visited. insert ( krate) ;
347
347
348
- // If this path is in-tree, we don't require it to be on the whitelist
348
+ // If this path is in-tree, we don't require it to be on the whitelist.
349
349
if must_be_on_whitelist {
350
- // If this dependency is not on the WHITELIST, add to bad set
350
+ // If this dependency is not on ` WHITELIST` , add to bad set.
351
351
if !whitelist. contains ( & krate. into ( ) ) {
352
352
unapproved. insert ( krate. into ( ) ) ;
353
353
}
354
354
}
355
355
356
- // Do a DFS in the crate graph (it's a DAG, so we know we have no cycles!)
356
+ // Do a DFS in the crate graph (it's a DAG, so we know we have no cycles!).
357
357
let to_check = resolve
358
358
. nodes
359
359
. iter ( )
@@ -372,9 +372,10 @@ fn check_crate_whitelist<'a, 'b>(
372
372
373
373
fn check_crate_duplicate ( resolve : & Resolve , bad : & mut bool ) {
374
374
const FORBIDDEN_TO_HAVE_DUPLICATES : & [ & str ] = & [
375
- // These two crates take quite a long time to build, let's not let two
376
- // versions of them accidentally sneak into our dependency graph to
377
- // ensure we keep our CI times under control
375
+ // These two crates take quite a long time to build, so don't allow two versions of them
376
+ // to accidentally sneak into our dependency graph, in order to ensure we keep our CI times
377
+ // under control.
378
+
378
379
// "cargo", // FIXME(#53005)
379
380
"rustc-ap-syntax" ,
380
381
] ;
0 commit comments