Skip to content

Commit 100fb12

Browse files
committed
Auto merge of #52401 - semarie:tidy-extdeps, r=alexcrichton
tidy: add a new test for external dependencies ensure all packages in Cargo.lock will be vendored, and fail if the source packages isn't whitelisted. the purpose is to avoid such kind of issues: - #52029 Rustfmt isn't vendored correctly - #42719 building beta with vendor=true fail due to network dependencies as Rust comes with several external dependencies (clippy, miri, rustfmt, rls), it is important to have a way to catch some errors in the update of this submodules. The new check in tidy quickly reads `Cargo.lock` to search for the `source` of all packages. This attribute is present when the package comes from external source (like `crates.io-index` or some `git` repository). Some sources are whitelisted (like `crates.io-index`) as the crates are vendored. `Cargo.lock` extract with several cases (git, crates.io, and local). ``` [[package]] name = "rustfmt-nightly" version = "0.8.2" source = "git+https://github.com/rust-lang-nursery/rustfmt?rev=5e5992517d3591e2708d4ca6b155dfcbdf3344b9#5e5992517d3591e2708d4ca6b155dfcbdf3344b9" dependencies = [ ... ] [[package]] name = "same-file" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ ... ] [[package]] name = "rustdoc-themes" version = "0.1.0" ``` r? @alexcrichton
2 parents 31f1bc7 + a4ddda3 commit 100fb12

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/tools/tidy/src/extdeps.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ! Check for external package sources. Allow only vendorable packages.
12+
13+
use std::fs::File;
14+
use std::io::Read;
15+
use std::path::Path;
16+
17+
/// List of whitelisted sources for packages
18+
static WHITELISTED_SOURCES: &'static [&'static str] = &[
19+
"\"registry+https://github.com/rust-lang/crates.io-index\"",
20+
];
21+
22+
/// check for external package sources
23+
pub fn check(path: &Path, bad: &mut bool) {
24+
// Cargo.lock of rust: src/Cargo.lock
25+
let path = path.join("Cargo.lock");
26+
27+
// open and read the whole file
28+
let mut cargo_lock = String::new();
29+
t!(t!(File::open(path)).read_to_string(&mut cargo_lock));
30+
31+
// process each line
32+
let mut lines = cargo_lock.lines();
33+
while let Some(line) = lines.next() {
34+
35+
// consider only source entries
36+
if ! line.starts_with("source = ") {
37+
continue;
38+
}
39+
40+
// extract source value
41+
let parts: Vec<&str> = line.splitn(2, "=").collect();
42+
let source = parts[1].trim();
43+
44+
// ensure source is whitelisted
45+
if !WHITELISTED_SOURCES.contains(&&*source) {
46+
println!("invalid source: {}", source);
47+
*bad = true;
48+
}
49+
}
50+
}

src/tools/tidy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub mod features;
4949
pub mod cargo;
5050
pub mod pal;
5151
pub mod deps;
52+
pub mod extdeps;
5253
pub mod ui_tests;
5354
pub mod unstable_book;
5455
pub mod libcoretest;

src/tools/tidy/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fn main() {
4646
deps::check(&path, &mut bad);
4747
}
4848
deps::check_whitelist(&path, &cargo, &mut bad);
49+
extdeps::check(&path, &mut bad);
4950
ui_tests::check(&path, &mut bad);
5051

5152
if bad {

0 commit comments

Comments
 (0)