Skip to content

Commit e596211

Browse files
committed
Rollup merge of rust-lang#33404 - gsquire:cargo-lock, r=alexcrichton
Cargo lock tidy check A rebased PR for rust-lang#32901
2 parents a5557c5 + b3de042 commit e596211

File tree

3 files changed

+51
-27
lines changed

3 files changed

+51
-27
lines changed

src/rustc/Cargo.lock

+6-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/tidy/src/cargo_lock.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2016 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+
use std::path::Path;
12+
13+
const CARGO_LOCK: &'static str = "Cargo.lock";
14+
15+
pub fn check(path: &Path, bad: &mut bool) {
16+
use std::process::Command;
17+
18+
super::walk(path,
19+
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
20+
&mut |file| {
21+
let name = file.file_name().unwrap().to_string_lossy();
22+
if name == CARGO_LOCK {
23+
let rel_path = file.strip_prefix(path).unwrap();
24+
let ret_code = Command::new("git")
25+
.arg("diff-index")
26+
.arg("--quiet")
27+
.arg("HEAD")
28+
.arg(rel_path)
29+
.current_dir(path)
30+
.status()
31+
.unwrap_or_else(|e| {
32+
panic!("could not run git diff-index: {}", e);
33+
});
34+
if !ret_code.success() {
35+
let parent_path = file.parent().unwrap().join("Cargo.toml");
36+
print!("dirty lock file found at {} ", rel_path.display());
37+
println!("please commit your changes or update the lock file by running:");
38+
println!("\n\tcargo update --manifest-path {}", parent_path.display());
39+
*bad = true;
40+
}
41+
}
42+
});
43+
}

src/tools/tidy/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ mod style;
3535
mod errors;
3636
mod features;
3737
mod cargo;
38+
mod cargo_lock;
3839

3940
fn main() {
4041
let path = env::args_os().skip(1).next().expect("need an argument");
@@ -46,6 +47,7 @@ fn main() {
4647
errors::check(&path, &mut bad);
4748
cargo::check(&path, &mut bad);
4849
features::check(&path, &mut bad);
50+
cargo_lock::check(&path, &mut bad);
4951

5052
if bad {
5153
panic!("some tidy checks failed");

0 commit comments

Comments
 (0)