about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-08-25 19:29:28 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-10-10 12:47:25 +0000
commit6baa14787e544e1f85b341e818aaff6d18a12238 (patch)
treec8f735f7f16f47a84d6210270a0f548f6fad6ab4
parent212f273dbc4c439afa955d748feb8e2a29866ac9 (diff)
downloadrust-6baa14787e544e1f85b341e818aaff6d18a12238.tar.gz
rust-6baa14787e544e1f85b341e818aaff6d18a12238.zip
Check for external package sources in all workspaces
-rw-r--r--src/tools/tidy/src/deps.rs22
-rw-r--r--src/tools/tidy/src/extdeps.rs42
2 files changed, 38 insertions, 26 deletions
diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs
index 552dfc00fe3..2212b228f1b 100644
--- a/src/tools/tidy/src/deps.rs
+++ b/src/tools/tidy/src/deps.rs
@@ -42,21 +42,21 @@ type ExceptionList = &'static [(&'static str, &'static str)];
 /// * Optionally a tuple of:
 ///     * A list of crates for which dependencies need to be explicitly allowed.
 ///     * The list of allowed dependencies.
-const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)] = &[
+pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)] = &[
     // The root workspace has to be first for check_rustfix to work.
-    ("Cargo.toml", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES))),
+    (".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES))),
     // Outside of the alphabetical section because rustfmt formats it using multiple lines.
     (
-        "compiler/rustc_codegen_cranelift/Cargo.toml",
+        "compiler/rustc_codegen_cranelift",
         EXCEPTIONS_CRANELIFT,
         Some((&["rustc_codegen_cranelift"], PERMITTED_CRANELIFT_DEPENDENCIES)),
     ),
     // tidy-alphabetical-start
-    ("compiler/rustc_codegen_gcc/Cargo.toml", EXCEPTIONS_GCC, None),
-    ("src/bootstrap/Cargo.toml", EXCEPTIONS_BOOTSTRAP, None),
-    ("src/tools/cargo/Cargo.toml", EXCEPTIONS_CARGO, None),
-    ("src/tools/rust-analyzer/Cargo.toml", EXCEPTIONS_RUST_ANALYZER, None),
-    ("src/tools/x/Cargo.toml", &[], None),
+    ("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None),
+    ("src/bootstrap", EXCEPTIONS_BOOTSTRAP, None),
+    ("src/tools/cargo", EXCEPTIONS_CARGO, None),
+    ("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None),
+    ("src/tools/x", &[], None),
     // tidy-alphabetical-end
 ];
 
@@ -438,7 +438,7 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
     for &(workspace, exceptions, permitted_deps) in WORKSPACES {
         let mut cmd = cargo_metadata::MetadataCommand::new();
         cmd.cargo_path(cargo)
-            .manifest_path(root.join(workspace))
+            .manifest_path(root.join(workspace).join("Cargo.toml"))
             .features(cargo_metadata::CargoOpt::AllFeatures);
         let metadata = t!(cmd.exec());
 
@@ -447,12 +447,12 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
             check_permitted_dependencies(&metadata, workspace, permitted_deps, crates, bad);
         }
 
-        if workspace == "Cargo.toml" {
+        if workspace == "." {
             let runtime_ids = compute_runtime_crates(&metadata);
             check_runtime_license_exceptions(&metadata, runtime_ids, bad);
             checked_runtime_licenses = true;
             rust_metadata = Some(metadata);
-        } else if workspace == "src/tools/cargo/Cargo.toml" {
+        } else if workspace == "src/tools/cargo" {
             check_rustfix(
                 rust_metadata
                     .as_ref()
diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs
index aad57cacbb4..2556b19a7d6 100644
--- a/src/tools/tidy/src/extdeps.rs
+++ b/src/tools/tidy/src/extdeps.rs
@@ -9,25 +9,37 @@ const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crat
 /// Checks for external package sources. `root` is the path to the directory that contains the
 /// workspace `Cargo.toml`.
 pub fn check(root: &Path, bad: &mut bool) {
-    // `Cargo.lock` of rust.
-    let path = root.join("Cargo.lock");
+    for &(workspace, _, _) in crate::deps::WORKSPACES {
+        // FIXME check other workspaces too
+        // `Cargo.lock` of rust.
+        let path = root.join(workspace).join("Cargo.lock");
 
-    // Open and read the whole file.
-    let cargo_lock = t!(fs::read_to_string(&path));
+        // Open and read the whole file.
+        let cargo_lock = t!(fs::read_to_string(&path));
 
-    // Process each line.
-    for line in cargo_lock.lines() {
-        // Consider only source entries.
-        if !line.starts_with("source = ") {
-            continue;
-        }
+        // Process each line.
+        for line in cargo_lock.lines() {
+            // Consider only source entries.
+            if !line.starts_with("source = ") {
+                continue;
+            }
+
+            // Extract source value.
+            let source = line.split_once('=').unwrap().1.trim();
 
-        // Extract source value.
-        let source = line.split_once('=').unwrap().1.trim();
+            // Ensure source is allowed.
+            if !ALLOWED_SOURCES.contains(&&*source) {
+                if workspace == "compiler/rustc_codegen_gcc" {
+                    // FIXME stop using git dependencies for rustc_codegen_gcc?
+                    if source
+                        == "\"git+https://github.com/antoyo/gccjit.rs#d6e52626cfc6f487094a5d5ac66302baf3439984\""
+                    {
+                        continue;
+                    }
+                }
 
-        // Ensure source is allowed.
-        if !ALLOWED_SOURCES.contains(&&*source) {
-            tidy_error!(bad, "invalid source: {}", source);
+                tidy_error!(bad, "invalid source: {}", source);
+            }
         }
     }
 }