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 ;
6- use std:: path:: Path ;
7+ use std:: path:: { Path , PathBuf } ;
78
89use build_helper:: ci:: CiEnv ;
910use cargo_metadata:: semver:: Version ;
@@ -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 > ] = & [
@@ -248,19 +270,6 @@ const EXCEPTIONS_BOOTSTRAP: ExceptionList = &[];
248270
249271const EXCEPTIONS_UEFI_QEMU_TEST : ExceptionList = & [ ] ;
250272
251- #[ derive( Clone , Copy ) ]
252- struct ListLocation {
253- path : & ' static str ,
254- line : u32 ,
255- }
256-
257- /// Creates a [`ListLocation`] for the current location (with an additional offset to the actual list start);
258- macro_rules! location {
259- ( + $offset: literal) => {
260- ListLocation { path: file!( ) , line: line!( ) + $offset }
261- } ;
262- }
263-
264273const PERMITTED_RUSTC_DEPS_LOCATION : ListLocation = location ! ( +6 ) ;
265274
266275/// Crates rustc is allowed to depend on. Avoid adding to the list if possible.
@@ -646,6 +655,11 @@ pub fn check(root: &Path, cargo: &Path, tidy_ctx: TidyCtx) {
646655 . other_options ( vec ! [ "--locked" . to_owned( ) ] ) ;
647656 let metadata = t ! ( cmd. exec( ) ) ;
648657
658+ // Check for packages which have been moved into a different workspace and not updated
659+ let canonicalized_root = t ! ( PathBuf :: from( path) . canonicalize( ) ) ;
660+ if metadata. workspace_root != canonicalized_root {
661+ check. error ( format ! ( "{path} is part of another workspace, remove from `WORKSPACES` ({WORKSPACE_LOCATION})" ) ) ;
662+ }
649663 check_license_exceptions ( & metadata, path, exceptions, & mut check) ;
650664 if let Some ( ( crates, permitted_deps, location) ) = crates_and_deps {
651665 let descr = crates. get ( 0 ) . unwrap_or ( & path) ;
0 commit comments