Skip to content

Commit 6baa147

Browse files
committed
Check for external package sources in all workspaces
1 parent 212f273 commit 6baa147

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

src/tools/tidy/src/deps.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ type ExceptionList = &'static [(&'static str, &'static str)];
4242
/// * Optionally a tuple of:
4343
/// * A list of crates for which dependencies need to be explicitly allowed.
4444
/// * The list of allowed dependencies.
45-
const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)] = &[
45+
pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)] = &[
4646
// The root workspace has to be first for check_rustfix to work.
47-
("Cargo.toml", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES))),
47+
(".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES))),
4848
// Outside of the alphabetical section because rustfmt formats it using multiple lines.
4949
(
50-
"compiler/rustc_codegen_cranelift/Cargo.toml",
50+
"compiler/rustc_codegen_cranelift",
5151
EXCEPTIONS_CRANELIFT,
5252
Some((&["rustc_codegen_cranelift"], PERMITTED_CRANELIFT_DEPENDENCIES)),
5353
),
5454
// tidy-alphabetical-start
55-
("compiler/rustc_codegen_gcc/Cargo.toml", EXCEPTIONS_GCC, None),
56-
("src/bootstrap/Cargo.toml", EXCEPTIONS_BOOTSTRAP, None),
57-
("src/tools/cargo/Cargo.toml", EXCEPTIONS_CARGO, None),
58-
("src/tools/rust-analyzer/Cargo.toml", EXCEPTIONS_RUST_ANALYZER, None),
59-
("src/tools/x/Cargo.toml", &[], None),
55+
("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None),
56+
("src/bootstrap", EXCEPTIONS_BOOTSTRAP, None),
57+
("src/tools/cargo", EXCEPTIONS_CARGO, None),
58+
("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None),
59+
("src/tools/x", &[], None),
6060
// tidy-alphabetical-end
6161
];
6262

@@ -438,7 +438,7 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
438438
for &(workspace, exceptions, permitted_deps) in WORKSPACES {
439439
let mut cmd = cargo_metadata::MetadataCommand::new();
440440
cmd.cargo_path(cargo)
441-
.manifest_path(root.join(workspace))
441+
.manifest_path(root.join(workspace).join("Cargo.toml"))
442442
.features(cargo_metadata::CargoOpt::AllFeatures);
443443
let metadata = t!(cmd.exec());
444444

@@ -447,12 +447,12 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
447447
check_permitted_dependencies(&metadata, workspace, permitted_deps, crates, bad);
448448
}
449449

450-
if workspace == "Cargo.toml" {
450+
if workspace == "." {
451451
let runtime_ids = compute_runtime_crates(&metadata);
452452
check_runtime_license_exceptions(&metadata, runtime_ids, bad);
453453
checked_runtime_licenses = true;
454454
rust_metadata = Some(metadata);
455-
} else if workspace == "src/tools/cargo/Cargo.toml" {
455+
} else if workspace == "src/tools/cargo" {
456456
check_rustfix(
457457
rust_metadata
458458
.as_ref()

src/tools/tidy/src/extdeps.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,37 @@ const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crat
99
/// Checks for external package sources. `root` is the path to the directory that contains the
1010
/// workspace `Cargo.toml`.
1111
pub fn check(root: &Path, bad: &mut bool) {
12-
// `Cargo.lock` of rust.
13-
let path = root.join("Cargo.lock");
12+
for &(workspace, _, _) in crate::deps::WORKSPACES {
13+
// FIXME check other workspaces too
14+
// `Cargo.lock` of rust.
15+
let path = root.join(workspace).join("Cargo.lock");
1416

15-
// Open and read the whole file.
16-
let cargo_lock = t!(fs::read_to_string(&path));
17+
// Open and read the whole file.
18+
let cargo_lock = t!(fs::read_to_string(&path));
1719

18-
// Process each line.
19-
for line in cargo_lock.lines() {
20-
// Consider only source entries.
21-
if !line.starts_with("source = ") {
22-
continue;
23-
}
20+
// Process each line.
21+
for line in cargo_lock.lines() {
22+
// Consider only source entries.
23+
if !line.starts_with("source = ") {
24+
continue;
25+
}
26+
27+
// Extract source value.
28+
let source = line.split_once('=').unwrap().1.trim();
2429

25-
// Extract source value.
26-
let source = line.split_once('=').unwrap().1.trim();
30+
// Ensure source is allowed.
31+
if !ALLOWED_SOURCES.contains(&&*source) {
32+
if workspace == "compiler/rustc_codegen_gcc" {
33+
// FIXME stop using git dependencies for rustc_codegen_gcc?
34+
if source
35+
== "\"git+https://github.com/antoyo/gccjit.rs#d6e52626cfc6f487094a5d5ac66302baf3439984\""
36+
{
37+
continue;
38+
}
39+
}
2740

28-
// Ensure source is allowed.
29-
if !ALLOWED_SOURCES.contains(&&*source) {
30-
tidy_error!(bad, "invalid source: {}", source);
41+
tidy_error!(bad, "invalid source: {}", source);
42+
}
3143
}
3244
}
3345
}

0 commit comments

Comments
 (0)