Skip to content

Rollup of 5 pull requests #126611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d226890
rewrite and rename issue-10971-temps-dir to rmake format
Oneirical Jun 11, 2024
03982da
rewrite inaccessible-temp-dir to rmake format
Oneirical Jun 11, 2024
7c2b3b5
rewrite output-with-hyphens to rmake format
Oneirical Jun 11, 2024
ff82e43
rewrite and rename issue-64153 to rmake.rs
Oneirical Jun 13, 2024
cabc982
rewrite invalid-staticlib to rmake
Oneirical Jun 13, 2024
a3b7c29
rewrite extern-flag-fun to rmake
Oneirical Jun 14, 2024
ab71510
rewrite incremental-debugger-visualiser to rmake
Oneirical Jun 14, 2024
e9ff47f
rewrite error-found-staticlib-instead-crate to rmake
Oneirical Jun 14, 2024
e088edd
rewrite output-filename-conflicts-with-directory to rmake
Oneirical Jun 14, 2024
8ece5ce
rewrite output-filename-overwrites-input to rmake
Oneirical Jun 14, 2024
5f2b47f
rewrite native-link-modifier-verbatim-rustc to rmake
Oneirical Jun 14, 2024
c349d08
Add `readelf` support to `run-make-support`
Rejyr Jun 16, 2024
e601c8d
Migrate `run-make/comment-section` to `rmake.rs`
Rejyr Jun 16, 2024
cdfcc94
rewrite incremental-session-fail to rmake
Oneirical Jun 14, 2024
03f19d6
Add new test_while_readonly helper function to run-make-support
Oneirical Jun 11, 2024
6fffe84
rewrite native-link-modifier-linker to rmake
Oneirical Jun 14, 2024
df6d873
rewrite no-builtins-lto to rmake
Oneirical Jun 13, 2024
d54f8ee
Rollup merge of #126279 - Oneirical:you-can-run-make-but-cannot-hide,…
jieyouxu Jun 17, 2024
d4ca72e
Rollup merge of #126437 - Oneirical:test-we-forget, r=jieyouxu
jieyouxu Jun 17, 2024
6dd6ad5
Rollup merge of #126490 - Oneirical:testicide, r=jieyouxu
jieyouxu Jun 17, 2024
7f5442e
Rollup merge of #126500 - Oneirical:test-for-the-holy-grail, r=jieyouxu
jieyouxu Jun 17, 2024
739577d
Rollup merge of #126534 - Rejyr:comment-section-migration, r=jieyouxu
jieyouxu Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
pub use clang::{clang, Clang};
pub use diff::{diff, Diff};
pub use llvm::{
llvm_filecheck, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmProfdata, LlvmReadobj,
llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmObjdump,
LlvmProfdata, LlvmReadobj,
};
pub use run::{cmd, run, run_fail, run_with_args};
pub use rustc::{aux_build, rustc, Rustc};
Expand Down Expand Up @@ -214,6 +215,38 @@ pub fn cwd() -> PathBuf {
env::current_dir().unwrap()
}

// FIXME(Oneirical): This will no longer be required after compiletest receives the ability
// to manipulate read-only files. See https://github.com/rust-lang/rust/issues/126334
/// Ensure that the path P is read-only while the test runs, and restore original permissions
/// at the end so compiletest can clean up.
/// This will panic on Windows if the path is a directory (as it would otherwise do nothing)
#[track_caller]
pub fn test_while_readonly<P: AsRef<Path>, F: FnOnce() + std::panic::UnwindSafe>(
path: P,
closure: F,
) {
let path = path.as_ref();
if is_windows() && path.is_dir() {
eprintln!("This helper function cannot be used on Windows to make directories readonly.");
eprintln!(
"See the official documentation:
https://doc.rust-lang.org/std/fs/struct.Permissions.html#method.set_readonly"
);
panic!("`test_while_readonly` on directory detected while on Windows.");
}
let metadata = fs_wrapper::metadata(&path);
let original_perms = metadata.permissions();

let mut new_perms = original_perms.clone();
new_perms.set_readonly(true);
fs_wrapper::set_permissions(&path, new_perms);

let success = std::panic::catch_unwind(closure);

fs_wrapper::set_permissions(&path, original_perms);
success.unwrap();
}

/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
/// available on the platform!
#[track_caller]
Expand Down Expand Up @@ -271,6 +304,34 @@ pub fn set_host_rpath(cmd: &mut Command) {
});
}

/// Read the contents of a file that cannot simply be read by
/// read_to_string, due to invalid utf8 data, then assert that it contains `expected`.
#[track_caller]
pub fn invalid_utf8_contains<P: AsRef<Path>>(path: P, expected: &str) {
let buffer = fs_wrapper::read(path.as_ref());
if !String::from_utf8_lossy(&buffer).contains(expected) {
eprintln!("=== FILE CONTENTS (LOSSY) ===");
eprintln!("{}", String::from_utf8_lossy(&buffer));
eprintln!("=== SPECIFIED TEXT ===");
eprintln!("{}", expected);
panic!("specified text was not found in file");
}
}

/// Read the contents of a file that cannot simply be read by
/// read_to_string, due to invalid utf8 data, then assert that it does not contain `expected`.
#[track_caller]
pub fn invalid_utf8_not_contains<P: AsRef<Path>>(path: P, expected: &str) {
let buffer = fs_wrapper::read(path.as_ref());
if String::from_utf8_lossy(&buffer).contains(expected) {
eprintln!("=== FILE CONTENTS (LOSSY) ===");
eprintln!("{}", String::from_utf8_lossy(&buffer));
eprintln!("=== SPECIFIED TEXT ===");
eprintln!("{}", expected);
panic!("specified text was unexpectedly found in file");
}
}

/// Copy a directory into another.
pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
fn copy_dir_all_inner(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
Expand Down
58 changes: 53 additions & 5 deletions src/tools/run-make-support/src/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::path::{Path, PathBuf};

use crate::{env_var, Command};

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

/// Construct a new `llvm-objdump` invocation. This assumes that `llvm-objdump` is available
/// at `$LLVM_BIN_DIR/llvm-objdump`.
pub fn llvm_objdump() -> LlvmObjdump {
LlvmObjdump::new()
}

/// A `llvm-readobj` invocation builder.
#[derive(Debug)]
#[must_use]
Expand All @@ -44,9 +50,17 @@ pub struct LlvmFilecheck {
cmd: Command,
}

/// A `llvm-objdump` invocation builder.
#[derive(Debug)]
#[must_use]
pub struct LlvmObjdump {
cmd: Command,
}

crate::impl_common_helpers!(LlvmReadobj);
crate::impl_common_helpers!(LlvmProfdata);
crate::impl_common_helpers!(LlvmFilecheck);
crate::impl_common_helpers!(LlvmObjdump);

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

impl LlvmReadobj {
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
/// at `$LLVM_BIN_DIR/llvm-readobj`.
/// Construct a new `llvm-readobj` invocation with the `GNU` output style.
/// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`.
#[track_caller]
pub fn new() -> Self {
let llvm_readobj = llvm_bin_dir().join("llvm-readobj");
let cmd = Command::new(llvm_readobj);
Self { cmd }
let mut readobj = Self { cmd };
readobj.elf_output_style("GNU");
readobj
}

/// Specify the format of the ELF information.
///
/// Valid options are `LLVM` (default), `GNU`, and `JSON`.
pub fn elf_output_style(&mut self, style: &str) -> &mut Self {
self.cmd.arg("--elf-output-style");
self.cmd.arg(style);
self
}

/// Provide an input file.
Expand All @@ -76,6 +101,13 @@ impl LlvmReadobj {
self.cmd.arg("--file-header");
self
}

/// Specify the section to display.
pub fn section(&mut self, section: &str) -> &mut Self {
self.cmd.arg("--string-dump");
self.cmd.arg(section);
self
}
}

impl LlvmProfdata {
Expand Down Expand Up @@ -131,3 +163,19 @@ impl LlvmFilecheck {
self
}
}

impl LlvmObjdump {
/// Construct a new `llvm-objdump` invocation. This assumes that `llvm-objdump` is available
/// at `$LLVM_BIN_DIR/llvm-objdump`.
pub fn new() -> Self {
let llvm_objdump = llvm_bin_dir().join("llvm-objdump");
let cmd = Command::new(llvm_objdump);
Self { cmd }
}

/// Provide an input file.
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(path.as_ref());
self
}
}
15 changes: 0 additions & 15 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ run-make/c-unwind-abi-catch-panic/Makefile
run-make/cat-and-grep-sanity-check/Makefile
run-make/cdylib-dylib-linkage/Makefile
run-make/cdylib-fewer-symbols/Makefile
run-make/comment-section/Makefile
run-make/compiler-lookup-paths-2/Makefile
run-make/compiler-lookup-paths/Makefile
run-make/compiler-rt-works-on-mingw/Makefile
Expand All @@ -35,12 +34,10 @@ run-make/emit-shared-files/Makefile
run-make/emit-stack-sizes/Makefile
run-make/emit-to-stdout/Makefile
run-make/env-dep-info/Makefile
run-make/error-found-staticlib-instead-crate/Makefile
run-make/error-writing-dependencies/Makefile
run-make/export-executable-symbols/Makefile
run-make/extern-diff-internal-name/Makefile
run-make/extern-flag-disambiguates/Makefile
run-make/extern-flag-fun/Makefile
run-make/extern-flag-pathless/Makefile
run-make/extern-flag-rename-transitive/Makefile
run-make/extern-fn-explicit-align/Makefile
Expand All @@ -61,20 +58,15 @@ run-make/foreign-double-unwind/Makefile
run-make/foreign-exceptions/Makefile
run-make/foreign-rust-exceptions/Makefile
run-make/glibc-staticlib-args/Makefile
run-make/inaccessible-temp-dir/Makefile
run-make/include_bytes_deps/Makefile
run-make/incr-add-rust-src-component/Makefile
run-make/incr-foreign-head-span/Makefile
run-make/incremental-debugger-visualizer/Makefile
run-make/incremental-session-fail/Makefile
run-make/inline-always-many-cgu/Makefile
run-make/interdependent-c-libraries/Makefile
run-make/intrinsic-unreachable/Makefile
run-make/invalid-library/Makefile
run-make/invalid-so/Makefile
run-make/invalid-staticlib/Makefile
run-make/issue-107094/Makefile
run-make/issue-10971-temps-dir/Makefile
run-make/issue-109934-lto-debuginfo/Makefile
run-make/issue-14698/Makefile
run-make/issue-15460/Makefile
Expand All @@ -93,7 +85,6 @@ run-make/issue-40535/Makefile
run-make/issue-47384/Makefile
run-make/issue-47551/Makefile
run-make/issue-51671/Makefile
run-make/issue-64153/Makefile
run-make/issue-68794-textrel-on-minimal-lib/Makefile
run-make/issue-69368/Makefile
run-make/issue-83045/Makefile
Expand Down Expand Up @@ -140,20 +131,14 @@ run-make/missing-crate-dependency/Makefile
run-make/mixing-libs/Makefile
run-make/msvc-opt-minsize/Makefile
run-make/native-link-modifier-bundle/Makefile
run-make/native-link-modifier-verbatim-linker/Makefile
run-make/native-link-modifier-verbatim-rustc/Makefile
run-make/native-link-modifier-whole-archive/Makefile
run-make/no-alloc-shim/Makefile
run-make/no-builtins-attribute/Makefile
run-make/no-builtins-lto/Makefile
run-make/no-duplicate-libs/Makefile
run-make/obey-crate-type-flag/Makefile
run-make/optimization-remarks-dir-pgo/Makefile
run-make/optimization-remarks-dir/Makefile
run-make/output-filename-conflicts-with-directory/Makefile
run-make/output-filename-overwrites-input/Makefile
run-make/output-type-permutations/Makefile
run-make/output-with-hyphens/Makefile
run-make/override-aliased-flags/Makefile
run-make/overwrite-input/Makefile
run-make/panic-abort-eh_frame/Makefile
Expand Down
18 changes: 0 additions & 18 deletions tests/run-make/comment-section/Makefile

This file was deleted.

45 changes: 45 additions & 0 deletions tests/run-make/comment-section/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Both GCC and Clang write by default a `.comment` section with compiler information.
// Rustc received a similar .comment section, so this tests checks that this section
// properly appears.
// See https://github.com/rust-lang/rust/commit/74b8d324eb77a8f337b35dc68ac91b0c2c06debc

//@ only-linux

use std::path::PathBuf;

use run_make_support::llvm_readobj;
use run_make_support::rustc;
use run_make_support::{cwd, env_var, read_dir, run_in_tmpdir};

fn main() {
let target = env_var("TARGET");

rustc()
.arg("-")
.stdin("fn main() {}")
.emit("link,obj")
.arg("-Csave-temps")
.target(&target)
.run();

// Check linked output has a `.comment` section with the expected content.
llvm_readobj()
.section(".comment")
.input("rust_out")
.run()
.assert_stdout_contains("rustc version 1.");

// Check all object files (including temporary outputs) have a `.comment`
// section with the expected content.
read_dir(cwd(), |f| {
if !f.extension().is_some_and(|ext| ext == "o") {
return;
}

llvm_readobj()
.section(".comment")
.input(&f)
.run()
.assert_stdout_contains("rustc version 1.");
});
}
5 changes: 0 additions & 5 deletions tests/run-make/error-found-staticlib-instead-crate/Makefile

This file was deleted.

11 changes: 11 additions & 0 deletions tests/run-make/error-found-staticlib-instead-crate/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// When rustc is looking for a crate but is given a staticlib instead,
// the error message should be helpful and indicate precisely the cause
// of the compilation failure.
// See https://github.com/rust-lang/rust/pull/21978

use run_make_support::rustc;

fn main() {
rustc().input("foo.rs").crate_type("staticlib").run();
rustc().input("bar.rs").run_fail().assert_stderr_contains("found staticlib");
}
20 changes: 0 additions & 20 deletions tests/run-make/extern-flag-fun/Makefile

This file was deleted.

Loading
Loading