@@ -387,8 +387,11 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
387387 . manifest_path ( root. join ( "Cargo.toml" ) )
388388 . features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
389389 let metadata = t ! ( cmd. exec( ) ) ;
390+
390391 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) ;
392395 check_permitted_dependencies (
393396 & metadata,
394397 "rustc" ,
@@ -403,8 +406,7 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
403406 . manifest_path ( root. join ( "src/tools/cargo/Cargo.toml" ) )
404407 . features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
405408 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) ;
408410 check_rustfix ( & metadata, & cargo_metadata, bad) ;
409411
410412 // 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) {
413415 . manifest_path ( root. join ( "compiler/rustc_codegen_cranelift/Cargo.toml" ) )
414416 . features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
415417 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) ;
418419 check_permitted_dependencies (
419420 & metadata,
420421 "cranelift" ,
@@ -428,19 +429,54 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
428429 . manifest_path ( root. join ( "src/bootstrap/Cargo.toml" ) )
429430 . features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
430431 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) ;
433433}
434434
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`.
436436///
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 (
439440 metadata : & Metadata ,
440- exceptions : & [ ( & str , & str ) ] ,
441441 runtime_ids : HashSet < & PackageId > ,
442442 bad : & mut bool ,
443443) {
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 ) {
444480 // Validate the EXCEPTIONS list hasn't changed.
445481 for ( name, license) in exceptions {
446482 // Check that the package actually exists.
@@ -482,7 +518,7 @@ fn check_license_exceptions(
482518 // No need to check local packages.
483519 continue ;
484520 }
485- if !runtime_ids . contains ( & pkg . id ) && exception_names. contains ( & pkg. name . as_str ( ) ) {
521+ if exception_names. contains ( & pkg. name . as_str ( ) ) {
486522 continue ;
487523 }
488524 let license = match & pkg. license {
@@ -493,13 +529,6 @@ fn check_license_exceptions(
493529 }
494530 } ;
495531 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- }
503532 tidy_error ! ( bad, "invalid license `{}` in `{}`" , license, pkg. id) ;
504533 }
505534 }
0 commit comments