11//! Checks the licenses of third-party dependencies.
22
33use std:: collections:: { HashMap , HashSet } ;
4+ use std:: fmt:: { Display , Formatter } ;
45use std:: fs:: { File , read_dir} ;
56use std:: io:: Write ;
67use std:: path:: Path ;
@@ -14,6 +15,25 @@ use crate::diagnostics::{RunningCheck, TidyCtx};
1415#[ path = "../../../bootstrap/src/utils/proc_macro_deps.rs" ]
1516mod proc_macro_deps;
1617
18+ #[ derive( Clone , Copy ) ]
19+ struct ListLocation {
20+ path : & ' static str ,
21+ line : u32 ,
22+ }
23+
24+ impl Display for ListLocation {
25+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
26+ write ! ( f, "{}:{}" , self . path, self . line)
27+ }
28+ }
29+
30+ /// Creates a [`ListLocation`] for the current location (with an additional offset to the actual list start);
31+ macro_rules! location {
32+ ( + $offset: literal) => {
33+ ListLocation { path: file!( ) , line: line!( ) + $offset }
34+ } ;
35+ }
36+
1737/// These are licenses that are allowed for all crates, including the runtime,
1838/// rustc, tools, etc.
1939#[ rustfmt:: skip]
@@ -87,6 +107,8 @@ pub(crate) struct WorkspaceInfo<'a> {
87107 pub ( crate ) submodules : & ' a [ & ' a str ] ,
88108}
89109
110+ const WORKSPACE_LOCATION : ListLocation = location ! ( +4 ) ;
111+
90112/// The workspaces to check for licensing and optionally permitted dependencies.
91113// FIXME auto detect all cargo workspaces
92114pub ( crate ) const WORKSPACES : & [ WorkspaceInfo < ' static > ] = & [
@@ -242,19 +264,6 @@ const EXCEPTIONS_BOOTSTRAP: ExceptionList = &[];
242264
243265const EXCEPTIONS_UEFI_QEMU_TEST : ExceptionList = & [ ] ;
244266
245- #[ derive( Clone , Copy ) ]
246- struct ListLocation {
247- path : & ' static str ,
248- line : u32 ,
249- }
250-
251- /// Creates a [`ListLocation`] for the current location (with an additional offset to the actual list start);
252- macro_rules! location {
253- ( + $offset: literal) => {
254- ListLocation { path: file!( ) , line: line!( ) + $offset }
255- } ;
256- }
257-
258267const PERMITTED_RUSTC_DEPS_LOCATION : ListLocation = location ! ( +6 ) ;
259268
260269/// Crates rustc is allowed to depend on. Avoid adding to the list if possible.
@@ -641,6 +650,13 @@ pub fn check(root: &Path, cargo: &Path, tidy_ctx: TidyCtx) {
641650 . other_options ( vec ! [ "--locked" . to_owned( ) ] ) ;
642651 let metadata = t ! ( cmd. exec( ) ) ;
643652
653+ // Check for packages which have been moved into a different workspace and not updated
654+ let canonicalized_root =
655+ if path == "." { root. to_path_buf ( ) } else { t ! ( root. join( path) . canonicalize( ) ) } ;
656+ let canonicalized_root_real = t ! ( metadata. workspace_root. canonicalize( ) ) ;
657+ if canonicalized_root_real != canonicalized_root {
658+ check. error ( format ! ( "{path} is part of another workspace ({}), remove from `WORKSPACES` ({WORKSPACE_LOCATION})" , canonicalized_root_real. display( ) ) ) ;
659+ }
644660 check_license_exceptions ( & metadata, path, exceptions, & mut check) ;
645661 if let Some ( ( crates, permitted_deps, location) ) = crates_and_deps {
646662 let descr = crates. get ( 0 ) . unwrap_or ( & path) ;
0 commit comments