@@ -387,8 +387,11 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
387
387
. manifest_path ( root. join ( "Cargo.toml" ) )
388
388
. features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
389
389
let metadata = t ! ( cmd. exec( ) ) ;
390
+
390
391
let runtime_ids = compute_runtime_crates ( & metadata) ;
391
- check_license_exceptions ( & metadata, EXCEPTIONS , runtime_ids, bad) ;
392
+ check_runtime_license_exceptions ( & metadata, runtime_ids, bad) ;
393
+
394
+ check_license_exceptions ( & metadata, EXCEPTIONS , bad) ;
392
395
check_permitted_dependencies (
393
396
& metadata,
394
397
"rustc" ,
@@ -403,8 +406,7 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
403
406
. manifest_path ( root. join ( "src/tools/cargo/Cargo.toml" ) )
404
407
. features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
405
408
let cargo_metadata = t ! ( cmd. exec( ) ) ;
406
- let runtime_ids = HashSet :: new ( ) ;
407
- check_license_exceptions ( & cargo_metadata, EXCEPTIONS_CARGO , runtime_ids, bad) ;
409
+ check_license_exceptions ( & cargo_metadata, EXCEPTIONS_CARGO , bad) ;
408
410
check_rustfix ( & metadata, & cargo_metadata, bad) ;
409
411
410
412
// Check rustc_codegen_cranelift independently as it has it's own workspace.
@@ -413,8 +415,7 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
413
415
. manifest_path ( root. join ( "compiler/rustc_codegen_cranelift/Cargo.toml" ) )
414
416
. features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
415
417
let metadata = t ! ( cmd. exec( ) ) ;
416
- let runtime_ids = HashSet :: new ( ) ;
417
- check_license_exceptions ( & metadata, EXCEPTIONS_CRANELIFT , runtime_ids, bad) ;
418
+ check_license_exceptions ( & metadata, EXCEPTIONS_CRANELIFT , bad) ;
418
419
check_permitted_dependencies (
419
420
& metadata,
420
421
"cranelift" ,
@@ -428,19 +429,54 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
428
429
. manifest_path ( root. join ( "src/bootstrap/Cargo.toml" ) )
429
430
. features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
430
431
let metadata = t ! ( cmd. exec( ) ) ;
431
- let runtime_ids = HashSet :: new ( ) ;
432
- check_license_exceptions ( & metadata, EXCEPTIONS_BOOTSTRAP , runtime_ids, bad) ;
432
+ check_license_exceptions ( & metadata, EXCEPTIONS_BOOTSTRAP , bad) ;
433
433
}
434
434
435
- /// Check that all licenses are in the valid list in `LICENSES`.
435
+ /// Check that all licenses of runtime dependencies are in the valid list in `LICENSES`.
436
436
///
437
- /// Packages listed in `exceptions` are allowed for tools.
438
- fn check_license_exceptions (
437
+ /// Unlike for tools we don't allow exceptions to the `LICENSES` list for the runtime with the sole
438
+ /// exception of `fortanix-sgx-abi` which is only used on x86_64-fortanix-unknown-sgx.
439
+ fn check_runtime_license_exceptions (
439
440
metadata : & Metadata ,
440
- exceptions : & [ ( & str , & str ) ] ,
441
441
runtime_ids : HashSet < & PackageId > ,
442
442
bad : & mut bool ,
443
443
) {
444
+ for pkg in & metadata. packages {
445
+ if !runtime_ids. contains ( & pkg. id ) {
446
+ // Only checking dependencies of runtime libraries here.
447
+ continue ;
448
+ }
449
+ if pkg. source . is_none ( ) {
450
+ // No need to check local packages.
451
+ continue ;
452
+ }
453
+ let license = match & pkg. license {
454
+ Some ( license) => license,
455
+ None => {
456
+ tidy_error ! ( bad, "dependency `{}` does not define a license expression" , pkg. id) ;
457
+ continue ;
458
+ }
459
+ } ;
460
+ if !LICENSES . contains ( & license. as_str ( ) ) {
461
+ if pkg. name == "fortanix-sgx-abi" {
462
+ // This is a specific exception because SGX is considered
463
+ // "third party". See
464
+ // https://github.com/rust-lang/rust/issues/62620 for more. In
465
+ // general, these should never be added.
466
+ if pkg. license . as_deref ( ) != Some ( "MPL-2.0" ) {
467
+ tidy_error ! ( bad, "invalid license `{}` in `{}`" , license, pkg. id) ;
468
+ }
469
+ continue ;
470
+ }
471
+ tidy_error ! ( bad, "invalid license `{}` in `{}`" , license, pkg. id) ;
472
+ }
473
+ }
474
+ }
475
+
476
+ /// Check that all licenses of tool dependencies are in the valid list in `LICENSES`.
477
+ ///
478
+ /// Packages listed in `exceptions` are allowed for tools.
479
+ fn check_license_exceptions ( metadata : & Metadata , exceptions : & [ ( & str , & str ) ] , bad : & mut bool ) {
444
480
// Validate the EXCEPTIONS list hasn't changed.
445
481
for ( name, license) in exceptions {
446
482
// Check that the package actually exists.
@@ -482,7 +518,7 @@ fn check_license_exceptions(
482
518
// No need to check local packages.
483
519
continue ;
484
520
}
485
- if !runtime_ids . contains ( & pkg . id ) && exception_names. contains ( & pkg. name . as_str ( ) ) {
521
+ if exception_names. contains ( & pkg. name . as_str ( ) ) {
486
522
continue ;
487
523
}
488
524
let license = match & pkg. license {
@@ -493,13 +529,6 @@ fn check_license_exceptions(
493
529
}
494
530
} ;
495
531
if !LICENSES . contains ( & license. as_str ( ) ) {
496
- if pkg. name == "fortanix-sgx-abi" {
497
- // This is a specific exception because SGX is considered
498
- // "third party". See
499
- // https://github.com/rust-lang/rust/issues/62620 for more. In
500
- // general, these should never be added.
501
- continue ;
502
- }
503
532
tidy_error ! ( bad, "invalid license `{}` in `{}`" , license, pkg. id) ;
504
533
}
505
534
}
0 commit comments