Skip to content

Commit

Permalink
Auto merge of rust-lang#126611 - jieyouxu:rollup-061kmhl, r=jieyouxu
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jun 17, 2024
2 parents 59e2c01 + 739577d commit cb74cba
Show file tree
Hide file tree
Showing 35 changed files with 560 additions and 265 deletions.
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 @@ -92,7 +84,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 @@ -137,20 +128,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

0 comments on commit cb74cba

Please sign in to comment.