Skip to content

Commit cb74cba

Browse files
committed
Auto merge of rust-lang#126611 - jieyouxu:rollup-061kmhl, r=jieyouxu
Rollup of 5 pull requests Successful merges: - rust-lang#126279 (Migrate `inaccessible-temp-dir`, `output-with-hyphens` and `issue-10971-temps-dir` `run-make` tests to `rmake`) - rust-lang#126437 (Migrate `issue-64153`, `invalid-staticlib` and `no-builtins-lto` `run-make` tests to `rmake`) - rust-lang#126490 (Migrate `extern-flag-fun`, `incremental-debugger-visualiser` and `incremental-session-fail` `run-make` tests to `rmake.rs`) - rust-lang#126500 (Migrate `error-found-staticlib-instead-crate`, `output-filename-conflicts-with-directory`, `output-filename-overwrites-input`, `native-link-modifier-verbatim-rustc` and `native-link-verbatim-linker` `run-make` tests to `rmake.rs` format) - rust-lang#126534 (Migrate `run-make/comment-section` to `rmake.rs`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 59e2c01 + 739577d commit cb74cba

File tree

35 files changed

+560
-265
lines changed

35 files changed

+560
-265
lines changed

src/tools/run-make-support/src/lib.rs

+62-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
3030
pub use clang::{clang, Clang};
3131
pub use diff::{diff, Diff};
3232
pub use llvm::{
33-
llvm_filecheck, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmProfdata, LlvmReadobj,
33+
llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmObjdump,
34+
LlvmProfdata, LlvmReadobj,
3435
};
3536
pub use run::{cmd, run, run_fail, run_with_args};
3637
pub use rustc::{aux_build, rustc, Rustc};
@@ -214,6 +215,38 @@ pub fn cwd() -> PathBuf {
214215
env::current_dir().unwrap()
215216
}
216217

218+
// FIXME(Oneirical): This will no longer be required after compiletest receives the ability
219+
// to manipulate read-only files. See https://github.com/rust-lang/rust/issues/126334
220+
/// Ensure that the path P is read-only while the test runs, and restore original permissions
221+
/// at the end so compiletest can clean up.
222+
/// This will panic on Windows if the path is a directory (as it would otherwise do nothing)
223+
#[track_caller]
224+
pub fn test_while_readonly<P: AsRef<Path>, F: FnOnce() + std::panic::UnwindSafe>(
225+
path: P,
226+
closure: F,
227+
) {
228+
let path = path.as_ref();
229+
if is_windows() && path.is_dir() {
230+
eprintln!("This helper function cannot be used on Windows to make directories readonly.");
231+
eprintln!(
232+
"See the official documentation:
233+
https://doc.rust-lang.org/std/fs/struct.Permissions.html#method.set_readonly"
234+
);
235+
panic!("`test_while_readonly` on directory detected while on Windows.");
236+
}
237+
let metadata = fs_wrapper::metadata(&path);
238+
let original_perms = metadata.permissions();
239+
240+
let mut new_perms = original_perms.clone();
241+
new_perms.set_readonly(true);
242+
fs_wrapper::set_permissions(&path, new_perms);
243+
244+
let success = std::panic::catch_unwind(closure);
245+
246+
fs_wrapper::set_permissions(&path, original_perms);
247+
success.unwrap();
248+
}
249+
217250
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
218251
/// available on the platform!
219252
#[track_caller]
@@ -271,6 +304,34 @@ pub fn set_host_rpath(cmd: &mut Command) {
271304
});
272305
}
273306

307+
/// Read the contents of a file that cannot simply be read by
308+
/// read_to_string, due to invalid utf8 data, then assert that it contains `expected`.
309+
#[track_caller]
310+
pub fn invalid_utf8_contains<P: AsRef<Path>>(path: P, expected: &str) {
311+
let buffer = fs_wrapper::read(path.as_ref());
312+
if !String::from_utf8_lossy(&buffer).contains(expected) {
313+
eprintln!("=== FILE CONTENTS (LOSSY) ===");
314+
eprintln!("{}", String::from_utf8_lossy(&buffer));
315+
eprintln!("=== SPECIFIED TEXT ===");
316+
eprintln!("{}", expected);
317+
panic!("specified text was not found in file");
318+
}
319+
}
320+
321+
/// Read the contents of a file that cannot simply be read by
322+
/// read_to_string, due to invalid utf8 data, then assert that it does not contain `expected`.
323+
#[track_caller]
324+
pub fn invalid_utf8_not_contains<P: AsRef<Path>>(path: P, expected: &str) {
325+
let buffer = fs_wrapper::read(path.as_ref());
326+
if String::from_utf8_lossy(&buffer).contains(expected) {
327+
eprintln!("=== FILE CONTENTS (LOSSY) ===");
328+
eprintln!("{}", String::from_utf8_lossy(&buffer));
329+
eprintln!("=== SPECIFIED TEXT ===");
330+
eprintln!("{}", expected);
331+
panic!("specified text was unexpectedly found in file");
332+
}
333+
}
334+
274335
/// Copy a directory into another.
275336
pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
276337
fn copy_dir_all_inner(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {

src/tools/run-make-support/src/llvm.rs

+53-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::path::{Path, PathBuf};
22

33
use crate::{env_var, Command};
44

5-
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
6-
/// at `$LLVM_BIN_DIR/llvm-readobj`.
5+
/// Construct a new `llvm-readobj` invocation with the `GNU` output style.
6+
/// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`.
77
#[track_caller]
88
pub fn llvm_readobj() -> LlvmReadobj {
99
LlvmReadobj::new()
@@ -23,6 +23,12 @@ pub fn llvm_filecheck() -> LlvmFilecheck {
2323
LlvmFilecheck::new()
2424
}
2525

26+
/// Construct a new `llvm-objdump` invocation. This assumes that `llvm-objdump` is available
27+
/// at `$LLVM_BIN_DIR/llvm-objdump`.
28+
pub fn llvm_objdump() -> LlvmObjdump {
29+
LlvmObjdump::new()
30+
}
31+
2632
/// A `llvm-readobj` invocation builder.
2733
#[derive(Debug)]
2834
#[must_use]
@@ -44,9 +50,17 @@ pub struct LlvmFilecheck {
4450
cmd: Command,
4551
}
4652

53+
/// A `llvm-objdump` invocation builder.
54+
#[derive(Debug)]
55+
#[must_use]
56+
pub struct LlvmObjdump {
57+
cmd: Command,
58+
}
59+
4760
crate::impl_common_helpers!(LlvmReadobj);
4861
crate::impl_common_helpers!(LlvmProfdata);
4962
crate::impl_common_helpers!(LlvmFilecheck);
63+
crate::impl_common_helpers!(LlvmObjdump);
5064

5165
/// Generate the path to the bin directory of LLVM.
5266
#[must_use]
@@ -56,13 +70,24 @@ pub fn llvm_bin_dir() -> PathBuf {
5670
}
5771

5872
impl LlvmReadobj {
59-
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
60-
/// at `$LLVM_BIN_DIR/llvm-readobj`.
73+
/// Construct a new `llvm-readobj` invocation with the `GNU` output style.
74+
/// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`.
6175
#[track_caller]
6276
pub fn new() -> Self {
6377
let llvm_readobj = llvm_bin_dir().join("llvm-readobj");
6478
let cmd = Command::new(llvm_readobj);
65-
Self { cmd }
79+
let mut readobj = Self { cmd };
80+
readobj.elf_output_style("GNU");
81+
readobj
82+
}
83+
84+
/// Specify the format of the ELF information.
85+
///
86+
/// Valid options are `LLVM` (default), `GNU`, and `JSON`.
87+
pub fn elf_output_style(&mut self, style: &str) -> &mut Self {
88+
self.cmd.arg("--elf-output-style");
89+
self.cmd.arg(style);
90+
self
6691
}
6792

6893
/// Provide an input file.
@@ -76,6 +101,13 @@ impl LlvmReadobj {
76101
self.cmd.arg("--file-header");
77102
self
78103
}
104+
105+
/// Specify the section to display.
106+
pub fn section(&mut self, section: &str) -> &mut Self {
107+
self.cmd.arg("--string-dump");
108+
self.cmd.arg(section);
109+
self
110+
}
79111
}
80112

81113
impl LlvmProfdata {
@@ -131,3 +163,19 @@ impl LlvmFilecheck {
131163
self
132164
}
133165
}
166+
167+
impl LlvmObjdump {
168+
/// Construct a new `llvm-objdump` invocation. This assumes that `llvm-objdump` is available
169+
/// at `$LLVM_BIN_DIR/llvm-objdump`.
170+
pub fn new() -> Self {
171+
let llvm_objdump = llvm_bin_dir().join("llvm-objdump");
172+
let cmd = Command::new(llvm_objdump);
173+
Self { cmd }
174+
}
175+
176+
/// Provide an input file.
177+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
178+
self.cmd.arg(path.as_ref());
179+
self
180+
}
181+
}

src/tools/tidy/src/allowed_run_make_makefiles.txt

-15
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ run-make/c-unwind-abi-catch-panic/Makefile
1111
run-make/cat-and-grep-sanity-check/Makefile
1212
run-make/cdylib-dylib-linkage/Makefile
1313
run-make/cdylib-fewer-symbols/Makefile
14-
run-make/comment-section/Makefile
1514
run-make/compiler-lookup-paths-2/Makefile
1615
run-make/compiler-lookup-paths/Makefile
1716
run-make/compiler-rt-works-on-mingw/Makefile
@@ -35,12 +34,10 @@ run-make/emit-shared-files/Makefile
3534
run-make/emit-stack-sizes/Makefile
3635
run-make/emit-to-stdout/Makefile
3736
run-make/env-dep-info/Makefile
38-
run-make/error-found-staticlib-instead-crate/Makefile
3937
run-make/error-writing-dependencies/Makefile
4038
run-make/export-executable-symbols/Makefile
4139
run-make/extern-diff-internal-name/Makefile
4240
run-make/extern-flag-disambiguates/Makefile
43-
run-make/extern-flag-fun/Makefile
4441
run-make/extern-flag-pathless/Makefile
4542
run-make/extern-flag-rename-transitive/Makefile
4643
run-make/extern-fn-explicit-align/Makefile
@@ -61,20 +58,15 @@ run-make/foreign-double-unwind/Makefile
6158
run-make/foreign-exceptions/Makefile
6259
run-make/foreign-rust-exceptions/Makefile
6360
run-make/glibc-staticlib-args/Makefile
64-
run-make/inaccessible-temp-dir/Makefile
6561
run-make/include_bytes_deps/Makefile
6662
run-make/incr-add-rust-src-component/Makefile
6763
run-make/incr-foreign-head-span/Makefile
68-
run-make/incremental-debugger-visualizer/Makefile
69-
run-make/incremental-session-fail/Makefile
7064
run-make/inline-always-many-cgu/Makefile
7165
run-make/interdependent-c-libraries/Makefile
7266
run-make/intrinsic-unreachable/Makefile
7367
run-make/invalid-library/Makefile
7468
run-make/invalid-so/Makefile
75-
run-make/invalid-staticlib/Makefile
7669
run-make/issue-107094/Makefile
77-
run-make/issue-10971-temps-dir/Makefile
7870
run-make/issue-109934-lto-debuginfo/Makefile
7971
run-make/issue-14698/Makefile
8072
run-make/issue-15460/Makefile
@@ -92,7 +84,6 @@ run-make/issue-40535/Makefile
9284
run-make/issue-47384/Makefile
9385
run-make/issue-47551/Makefile
9486
run-make/issue-51671/Makefile
95-
run-make/issue-64153/Makefile
9687
run-make/issue-68794-textrel-on-minimal-lib/Makefile
9788
run-make/issue-69368/Makefile
9889
run-make/issue-83045/Makefile
@@ -137,20 +128,14 @@ run-make/missing-crate-dependency/Makefile
137128
run-make/mixing-libs/Makefile
138129
run-make/msvc-opt-minsize/Makefile
139130
run-make/native-link-modifier-bundle/Makefile
140-
run-make/native-link-modifier-verbatim-linker/Makefile
141-
run-make/native-link-modifier-verbatim-rustc/Makefile
142131
run-make/native-link-modifier-whole-archive/Makefile
143132
run-make/no-alloc-shim/Makefile
144133
run-make/no-builtins-attribute/Makefile
145-
run-make/no-builtins-lto/Makefile
146134
run-make/no-duplicate-libs/Makefile
147135
run-make/obey-crate-type-flag/Makefile
148136
run-make/optimization-remarks-dir-pgo/Makefile
149137
run-make/optimization-remarks-dir/Makefile
150-
run-make/output-filename-conflicts-with-directory/Makefile
151-
run-make/output-filename-overwrites-input/Makefile
152138
run-make/output-type-permutations/Makefile
153-
run-make/output-with-hyphens/Makefile
154139
run-make/override-aliased-flags/Makefile
155140
run-make/overwrite-input/Makefile
156141
run-make/panic-abort-eh_frame/Makefile

tests/run-make/comment-section/Makefile

-18
This file was deleted.
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Both GCC and Clang write by default a `.comment` section with compiler information.
2+
// Rustc received a similar .comment section, so this tests checks that this section
3+
// properly appears.
4+
// See https://github.com/rust-lang/rust/commit/74b8d324eb77a8f337b35dc68ac91b0c2c06debc
5+
6+
//@ only-linux
7+
8+
use std::path::PathBuf;
9+
10+
use run_make_support::llvm_readobj;
11+
use run_make_support::rustc;
12+
use run_make_support::{cwd, env_var, read_dir, run_in_tmpdir};
13+
14+
fn main() {
15+
let target = env_var("TARGET");
16+
17+
rustc()
18+
.arg("-")
19+
.stdin("fn main() {}")
20+
.emit("link,obj")
21+
.arg("-Csave-temps")
22+
.target(&target)
23+
.run();
24+
25+
// Check linked output has a `.comment` section with the expected content.
26+
llvm_readobj()
27+
.section(".comment")
28+
.input("rust_out")
29+
.run()
30+
.assert_stdout_contains("rustc version 1.");
31+
32+
// Check all object files (including temporary outputs) have a `.comment`
33+
// section with the expected content.
34+
read_dir(cwd(), |f| {
35+
if !f.extension().is_some_and(|ext| ext == "o") {
36+
return;
37+
}
38+
39+
llvm_readobj()
40+
.section(".comment")
41+
.input(&f)
42+
.run()
43+
.assert_stdout_contains("rustc version 1.");
44+
});
45+
}

tests/run-make/error-found-staticlib-instead-crate/Makefile

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// When rustc is looking for a crate but is given a staticlib instead,
2+
// the error message should be helpful and indicate precisely the cause
3+
// of the compilation failure.
4+
// See https://github.com/rust-lang/rust/pull/21978
5+
6+
use run_make_support::rustc;
7+
8+
fn main() {
9+
rustc().input("foo.rs").crate_type("staticlib").run();
10+
rustc().input("bar.rs").run_fail().assert_stderr_contains("found staticlib");
11+
}

tests/run-make/extern-flag-fun/Makefile

-20
This file was deleted.

0 commit comments

Comments
 (0)