Skip to content

Commit c08840d

Browse files
committed
Auto merge of #53586 - eddyb:top-lock, r=alexcrichton
Move Cargo.{toml,lock} to the repository root directory. This should give us back `src/` in errors, panics and debuginfo, for free. r? @Mark-Simulacrum @alexcrichton cc @michaelwoerister
2 parents dae6c93 + 7c166f5 commit c08840d

File tree

11 files changed

+70
-52
lines changed

11 files changed

+70
-52
lines changed

CONTRIBUTING.md

+1-6
Original file line numberDiff line numberDiff line change
@@ -494,16 +494,11 @@ the version in `Cargo.lock`, so the build can no longer continue.
494494
To resolve this, we need to update `Cargo.lock`. Luckily, cargo provides a
495495
command to do this easily.
496496

497-
First, go into the `src/` directory since that is where `Cargo.toml` is in
498-
the rust repository. Then run, `cargo update -p rustfmt-nightly` to solve
499-
the problem.
500-
501497
```
502-
$ cd src
503498
$ cargo update -p rustfmt-nightly
504499
```
505500

506-
This should change the version listed in `src/Cargo.lock` to the new version you updated
501+
This should change the version listed in `Cargo.lock` to the new version you updated
507502
the submodule to. Running `./x.py build` should work now.
508503

509504
## Writing Documentation
File renamed without changes.
+30-30
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
[workspace]
22
members = [
3-
"bootstrap",
4-
"rustc",
5-
"libstd",
6-
"libtest",
7-
"librustc_codegen_llvm",
8-
"tools/cargotest",
9-
"tools/clippy",
10-
"tools/compiletest",
11-
"tools/error_index_generator",
12-
"tools/linkchecker",
13-
"tools/rustbook",
14-
"tools/unstable-book-gen",
15-
"tools/tidy",
16-
"tools/build-manifest",
17-
"tools/remote-test-client",
18-
"tools/remote-test-server",
19-
"tools/rust-installer",
20-
"tools/cargo",
21-
"tools/rustdoc",
22-
"tools/rls",
23-
"tools/rustfmt",
24-
"tools/miri",
25-
"tools/rustdoc-themes",
3+
"src/bootstrap",
4+
"src/rustc",
5+
"src/libstd",
6+
"src/libtest",
7+
"src/librustc_codegen_llvm",
8+
"src/tools/cargotest",
9+
"src/tools/clippy",
10+
"src/tools/compiletest",
11+
"src/tools/error_index_generator",
12+
"src/tools/linkchecker",
13+
"src/tools/rustbook",
14+
"src/tools/unstable-book-gen",
15+
"src/tools/tidy",
16+
"src/tools/build-manifest",
17+
"src/tools/remote-test-client",
18+
"src/tools/remote-test-server",
19+
"src/tools/rust-installer",
20+
"src/tools/cargo",
21+
"src/tools/rustdoc",
22+
"src/tools/rls",
23+
"src/tools/rustfmt",
24+
"src/tools/miri",
25+
"src/tools/rustdoc-themes",
2626
]
2727
exclude = [
28-
"tools/rls/test_data",
28+
"src/tools/rls/test_data",
2929
]
3030

3131
# Curiously, LLVM 7.0 will segfault if compiled with opt-level=3
@@ -50,18 +50,18 @@ debug-assertions = false
5050
# so we use a `[patch]` here to override the github repository with our local
5151
# vendored copy.
5252
[patch."https://github.com/rust-lang/cargo"]
53-
cargo = { path = "tools/cargo" }
53+
cargo = { path = "src/tools/cargo" }
5454

5555
[patch.crates-io]
5656
# Similar to Cargo above we want the RLS to use a vendored version of `rustfmt`
5757
# that we're shipping as well (to ensure that the rustfmt in RLS and the
5858
# `rustfmt` executable are the same exact version).
59-
rustfmt-nightly = { path = "tools/rustfmt" }
59+
rustfmt-nightly = { path = "src/tools/rustfmt" }
6060

61-
# See comments in `tools/rustc-workspace-hack/README.md` for what's going on
61+
# See comments in `src/tools/rustc-workspace-hack/README.md` for what's going on
6262
# here
63-
rustc-workspace-hack = { path = 'tools/rustc-workspace-hack' }
63+
rustc-workspace-hack = { path = 'src/tools/rustc-workspace-hack' }
6464

6565
[patch."https://github.com/rust-lang-nursery/rust-clippy"]
66-
clippy_lints = { path = "tools/clippy/clippy_lints" }
67-
rustc_tools_util = { path = "tools/clippy/rustc_tools_util" }
66+
clippy_lints = { path = "src/tools/clippy/clippy_lints" }
67+
rustc_tools_util = { path = "src/tools/clippy/rustc_tools_util" }

src/bootstrap/bootstrap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ def bootstrap(help_triggered):
801801
registry = 'https://example.com'
802802
803803
[source.vendored-sources]
804-
directory = '{}/src/vendor'
804+
directory = '{}/vendor'
805805
""".format(build.rust_root))
806806
else:
807807
if os.path.exists('.cargo'):

src/bootstrap/dist.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ impl Step for Src {
851851
t!(fs::create_dir_all(&dst_src));
852852

853853
let src_files = [
854-
"src/Cargo.lock",
854+
"Cargo.lock",
855855
];
856856
// This is the reduced set of paths which will become the rust-src component
857857
// (essentially libstd and all of its path dependencies)
@@ -949,6 +949,8 @@ impl Step for PlainSourceTarball {
949949
"configure",
950950
"x.py",
951951
"config.toml.example",
952+
"Cargo.toml",
953+
"Cargo.lock",
952954
];
953955
let src_dirs = [
954956
"src",
@@ -992,7 +994,7 @@ impl Step for PlainSourceTarball {
992994
// Vendor all Cargo dependencies
993995
let mut cmd = Command::new(&builder.initial_cargo);
994996
cmd.arg("vendor")
995-
.current_dir(&plain_dst_src.join("src"));
997+
.current_dir(&plain_dst_src);
996998
builder.run(&mut cmd);
997999
}
9981000

src/bootstrap/test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,7 @@ impl Step for Distcheck {
19341934
.arg("generate-lockfile")
19351935
.arg("--manifest-path")
19361936
.arg(&toml)
1937+
.env("__CARGO_TEST_ROOT", &dir)
19371938
.current_dir(&dir),
19381939
);
19391940
}

src/bootstrap/tool.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,13 @@ pub fn prepare_tool_cargo(
260260
}
261261

262262
macro_rules! tool {
263-
($($name:ident, $path:expr, $tool_name:expr, $mode:expr
264-
$(,llvm_tools = $llvm:expr)* $(,is_external_tool = $external:expr)*;)+) => {
263+
($(
264+
$name:ident, $path:expr, $tool_name:expr, $mode:expr
265+
$(,llvm_tools = $llvm:expr)*
266+
$(,is_external_tool = $external:expr)*
267+
$(,cargo_test_root = $cargo_test_root:expr)*
268+
;
269+
)+) => {
265270
#[derive(Copy, PartialEq, Eq, Clone)]
266271
pub enum Tool {
267272
$(
@@ -283,6 +288,15 @@ macro_rules! tool {
283288
$(Tool::$name => false $(|| $llvm)*,)+
284289
}
285290
}
291+
292+
/// Whether this tool requires may run Cargo for test crates,
293+
/// which currently needs setting the environment variable
294+
/// `__CARGO_TEST_ROOT` to separate it from the workspace.
295+
pub fn needs_cargo_test_root(&self) -> bool {
296+
match self {
297+
$(Tool::$name => false $(|| $cargo_test_root)*,)+
298+
}
299+
}
286300
}
287301

288302
impl<'a> Builder<'a> {
@@ -358,8 +372,9 @@ tool!(
358372
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen", Mode::ToolBootstrap;
359373
Tidy, "src/tools/tidy", "tidy", Mode::ToolBootstrap;
360374
Linkchecker, "src/tools/linkchecker", "linkchecker", Mode::ToolBootstrap;
361-
CargoTest, "src/tools/cargotest", "cargotest", Mode::ToolBootstrap;
362-
Compiletest, "src/tools/compiletest", "compiletest", Mode::ToolBootstrap, llvm_tools = true;
375+
CargoTest, "src/tools/cargotest", "cargotest", Mode::ToolBootstrap, cargo_test_root = true;
376+
Compiletest, "src/tools/compiletest", "compiletest", Mode::ToolBootstrap,
377+
llvm_tools = true, cargo_test_root = true;
363378
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::ToolBootstrap;
364379
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::ToolBootstrap;
365380
RustInstaller, "src/tools/rust-installer", "fabricate", Mode::ToolBootstrap,
@@ -678,6 +693,11 @@ impl<'a> Builder<'a> {
678693
}
679694
}
680695

696+
// Set `__CARGO_TEST_ROOT` to the build directory if needed.
697+
if tool.needs_cargo_test_root() {
698+
cmd.env("__CARGO_TEST_ROOT", &self.config.out);
699+
}
700+
681701
add_lib_path(lib_paths, cmd);
682702
}
683703

src/test/rustdoc-ui/failed-doctest-output.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error[E0425]: cannot find value `no` in this scope
1212
3 | no
1313
| ^^ not found in this scope
1414

15-
thread '$DIR/failed-doctest-output.rs - OtherStruct (line 27)' panicked at 'couldn't compile the test', librustdoc/test.rs:323:13
15+
thread '$DIR/failed-doctest-output.rs - OtherStruct (line 27)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:323:13
1616
note: Run with `RUST_BACKTRACE=1` for a backtrace.
1717

1818
---- $DIR/failed-doctest-output.rs - SomeStruct (line 21) stdout ----
@@ -21,7 +21,7 @@ thread '$DIR/failed-doctest-output.rs - SomeStruct (line 21)' panicked at 'test
2121
thread 'main' panicked at 'oh no', $DIR/failed-doctest-output.rs:3:1
2222
note: Run with `RUST_BACKTRACE=1` for a backtrace.
2323

24-
', librustdoc/test.rs:358:17
24+
', src/librustdoc/test.rs:358:17
2525

2626

2727
failures:

src/tools/tidy/src/deps.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Check license of third-party deps by inspecting src/vendor
11+
//! Check license of third-party deps by inspecting vendor
1212
1313
use std::collections::{BTreeSet, HashSet, HashMap};
1414
use std::fs::File;
@@ -203,7 +203,7 @@ impl<'a> From<CrateVersion<'a>> for Crate<'a> {
203203
/// Specifically, this checks that the license is correct.
204204
pub fn check(path: &Path, bad: &mut bool) {
205205
// Check licences
206-
let path = path.join("vendor");
206+
let path = path.join("../vendor");
207207
assert!(path.exists(), "vendor directory missing");
208208
let mut saw_dir = false;
209209
for dir in t!(path.read_dir()) {
@@ -215,7 +215,7 @@ pub fn check(path: &Path, bad: &mut bool) {
215215
dir.path()
216216
.to_str()
217217
.unwrap()
218-
.contains(&format!("src/vendor/{}", exception))
218+
.contains(&format!("vendor/{}", exception))
219219
});
220220
if is_exception {
221221
continue;
@@ -304,7 +304,7 @@ fn get_deps(path: &Path, cargo: &Path) -> Resolve {
304304
.arg("--format-version")
305305
.arg("1")
306306
.arg("--manifest-path")
307-
.arg(path.join("Cargo.toml"))
307+
.arg(path.join("../Cargo.toml"))
308308
.output()
309309
.expect("Unable to run `cargo metadata`")
310310
.stdout;

src/tools/tidy/src/extdeps.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const WHITELISTED_SOURCES: &[&str] = &[
2121

2222
/// check for external package sources
2323
pub fn check(path: &Path, bad: &mut bool) {
24-
// Cargo.lock of rust: src/Cargo.lock
25-
let path = path.join("Cargo.lock");
24+
// Cargo.lock of rust (tidy runs inside src/)
25+
let path = path.join("../Cargo.lock");
2626

2727
// open and read the whole file
2828
let mut cargo_lock = String::new();

src/tools/tidy/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ fn filter_dirs(path: &Path) -> bool {
6464
"src/librustc_data_structures/owning_ref",
6565
"src/compiler-rt",
6666
"src/liblibc",
67-
"src/vendor",
6867
"src/rt/hoedown",
6968
"src/tools/cargo",
7069
"src/tools/clang",
@@ -78,6 +77,7 @@ fn filter_dirs(path: &Path) -> bool {
7877
"src/target",
7978
"src/stdsimd",
8079
"target",
80+
"vendor",
8181
];
8282
skip.iter().any(|p| path.ends_with(p))
8383
}

0 commit comments

Comments
 (0)