Skip to content

Commit 4f81879

Browse files
committed
Auto merge of rust-lang#124564 - jieyouxu:rollup-kuf5wlq, r=jieyouxu
Rollup of 4 pull requests Successful merges: - rust-lang#124280 (Port repr128-dwarf run-make test to rmake) - rust-lang#124299 (Add test for issue 106269) - rust-lang#124553 (Write `git-commit-{sha,info}` for Cargo in source tarballs) - rust-lang#124561 (Add `normalize()` in run-make `Diff` type) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 20aa2d8 + 7350a7f commit 4f81879

File tree

12 files changed

+164
-26
lines changed

12 files changed

+164
-26
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3318,6 +3318,7 @@ dependencies = [
33183318
name = "run_make_support"
33193319
version = "0.0.0"
33203320
dependencies = [
3321+
"gimli",
33213322
"object 0.34.0",
33223323
"regex",
33233324
"similar",

src/bootstrap/src/core/build_steps/dist.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::core::build_steps::llvm;
2525
use crate::core::build_steps::tool::{self, Tool};
2626
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
2727
use crate::core::config::TargetSelection;
28-
use crate::utils::channel;
28+
use crate::utils::channel::{self, Info};
2929
use crate::utils::helpers::{exe, is_dylib, output, t, target_supports_cranelift_backend, timeit};
3030
use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball};
3131
use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};
@@ -991,10 +991,17 @@ impl Step for PlainSourceTarball {
991991

992992
// Create the version file
993993
builder.create(&plain_dst_src.join("version"), &builder.rust_version());
994-
if let Some(info) = builder.rust_info().info() {
995-
channel::write_commit_hash_file(plain_dst_src, &info.sha);
996-
channel::write_commit_info_file(plain_dst_src, info);
997-
}
994+
995+
// Create the files containing git info, to ensure --version outputs the same.
996+
let write_git_info = |info: Option<&Info>, path: &Path| {
997+
if let Some(info) = info {
998+
t!(std::fs::create_dir_all(path));
999+
channel::write_commit_hash_file(path, &info.sha);
1000+
channel::write_commit_info_file(path, info);
1001+
}
1002+
};
1003+
write_git_info(builder.rust_info().info(), plain_dst_src);
1004+
write_git_info(builder.cargo_info.info(), &plain_dst_src.join("./src/tools/cargo"));
9981005

9991006
// If we're building from git or tarball sources, we need to vendor
10001007
// a complete distribution.

src/tools/compiletest/src/runtest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3825,6 +3825,7 @@ impl<'test> TestCx<'test> {
38253825
.arg(format!("-Ldependency={}", &support_lib_deps_deps.to_string_lossy()))
38263826
.arg("--extern")
38273827
.arg(format!("run_make_support={}", &support_lib_path.to_string_lossy()))
3828+
.arg("--edition=2021")
38283829
.arg(&self.testpaths.file.join("rmake.rs"))
38293830
.env("TARGET", &self.config.target)
38303831
.env("PYTHON", &self.config.python)

src/tools/run-make-support/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ object = "0.34.0"
88
similar = "2.5.0"
99
wasmparser = "0.118.2"
1010
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
11+
gimli = "0.28.1"

src/tools/run-make-support/src/diff/mod.rs

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use regex::Regex;
12
use similar::TextDiff;
23
use std::path::Path;
34

@@ -14,12 +15,19 @@ pub struct Diff {
1415
expected_name: Option<String>,
1516
actual: Option<String>,
1617
actual_name: Option<String>,
18+
normalizers: Vec<(String, String)>,
1719
}
1820

1921
impl Diff {
2022
/// Construct a bare `diff` invocation.
2123
pub fn new() -> Self {
22-
Self { expected: None, expected_name: None, actual: None, actual_name: None }
24+
Self {
25+
expected: None,
26+
expected_name: None,
27+
actual: None,
28+
actual_name: None,
29+
normalizers: Vec::new(),
30+
}
2331
}
2432

2533
/// Specify the expected output for the diff from a file.
@@ -58,15 +66,29 @@ impl Diff {
5866
self
5967
}
6068

69+
/// Specify a regex that should replace text in the "actual" text that will be compared.
70+
pub fn normalize<R: Into<String>, I: Into<String>>(
71+
&mut self,
72+
regex: R,
73+
replacement: I,
74+
) -> &mut Self {
75+
self.normalizers.push((regex.into(), replacement.into()));
76+
self
77+
}
78+
6179
/// Executes the diff process, prints any differences to the standard error.
6280
#[track_caller]
6381
pub fn run(&self) {
6482
let expected = self.expected.as_ref().expect("expected text not set");
65-
let actual = self.actual.as_ref().expect("actual text not set");
83+
let mut actual = self.actual.as_ref().expect("actual text not set").to_string();
6684
let expected_name = self.expected_name.as_ref().unwrap();
6785
let actual_name = self.actual_name.as_ref().unwrap();
86+
for (regex, replacement) in &self.normalizers {
87+
let re = Regex::new(regex).expect("bad regex in custom normalization rule");
88+
actual = re.replace_all(&actual, replacement).into_owned();
89+
}
6890

69-
let output = TextDiff::from_lines(expected, actual)
91+
let output = TextDiff::from_lines(expected, &actual)
7092
.unified_diff()
7193
.header(expected_name, actual_name)
7294
.to_string();

src/tools/run-make-support/src/diff/tests.rs

+22
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,26 @@ test failed: `EXPECTED_TEXT` is different from `ACTUAL_TEXT`
3636

3737
assert_eq!(output.downcast_ref::<String>().unwrap(), expected_output);
3838
}
39+
40+
#[test]
41+
fn test_normalize() {
42+
let expected = "
43+
running 2 tests
44+
..
45+
46+
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
47+
";
48+
let actual = "
49+
running 2 tests
50+
..
51+
52+
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s
53+
";
54+
55+
diff()
56+
.expected_text("EXPECTED_TEXT", expected)
57+
.actual_text("ACTUAL_TEXT", actual)
58+
.normalize(r#"finished in \d+\.\d+s"#, "finished in $$TIME")
59+
.run();
60+
}
3961
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::env;
1515
use std::path::{Path, PathBuf};
1616
use std::process::{Command, Output};
1717

18+
pub use gimli;
1819
pub use object;
1920
pub use regex;
2021
pub use wasmparser;

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ run-make/relocation-model/Makefile
235235
run-make/relro-levels/Makefile
236236
run-make/remap-path-prefix-dwarf/Makefile
237237
run-make/remap-path-prefix/Makefile
238-
run-make/repr128-dwarf/Makefile
239238
run-make/reproducible-build-2/Makefile
240239
run-make/reproducible-build/Makefile
241240
run-make/resolve-rename/Makefile

tests/assembly/manual-eq-efficient.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Regression test for #106269
2+
//@ assembly-output: emit-asm
3+
//@ compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel
4+
//@ only-x86_64
5+
//@ ignore-sgx
6+
7+
pub struct S {
8+
a: u8,
9+
b: u8,
10+
c: u8,
11+
d: u8,
12+
}
13+
14+
// CHECK-LABEL: manual_eq:
15+
#[no_mangle]
16+
pub fn manual_eq(s1: &S, s2: &S) -> bool {
17+
// CHECK: mov [[REG:[a-z0-9]+]], dword ptr [{{[a-z0-9]+}}]
18+
// CHECK-NEXT: cmp [[REG]], dword ptr [{{[a-z0-9]+}}]
19+
// CHECK-NEXT: sete al
20+
// CHECK: ret
21+
s1.a == s2.a && s1.b == s2.b && s1.c == s2.c && s1.d == s2.d
22+
}

tests/run-make/repr128-dwarf/Makefile

-16
This file was deleted.

tests/run-make/repr128-dwarf/lib.rs renamed to tests/run-make/repr128-dwarf/main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![crate_type = "lib"]
21
#![feature(repr128)]
32

43
// Use .to_le() to ensure that the bytes are in the same order on both little- and big-endian
@@ -21,3 +20,7 @@ pub enum I128Enum {
2120
}
2221

2322
pub fn f(_: U128Enum, _: I128Enum) {}
23+
24+
fn main() {
25+
f(U128Enum::U128A, I128Enum::I128A);
26+
}

tests/run-make/repr128-dwarf/rmake.rs

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//@ ignore-windows
2+
// This test should be replaced with one in tests/debuginfo once GDB or LLDB support 128-bit enums.
3+
4+
extern crate run_make_support;
5+
6+
use gimli::{AttributeValue, Dwarf, EndianRcSlice, Reader, RunTimeEndian};
7+
use object::{Object, ObjectSection};
8+
use run_make_support::{gimli, object, rustc, tmp_dir};
9+
use std::borrow::Cow;
10+
use std::collections::HashMap;
11+
use std::rc::Rc;
12+
13+
fn main() {
14+
let output = tmp_dir().join("repr128");
15+
rustc().input("main.rs").arg("-o").arg(&output).arg("-Cdebuginfo=2").run();
16+
// Mach-O uses packed debug info
17+
let dsym_location = output
18+
.with_extension("dSYM")
19+
.join("Contents")
20+
.join("Resources")
21+
.join("DWARF")
22+
.join("repr128");
23+
let output =
24+
std::fs::read(if dsym_location.try_exists().unwrap() { dsym_location } else { output })
25+
.unwrap();
26+
let obj = object::File::parse(output.as_slice()).unwrap();
27+
let endian = if obj.is_little_endian() { RunTimeEndian::Little } else { RunTimeEndian::Big };
28+
let dwarf = gimli::Dwarf::load(|section| -> Result<_, ()> {
29+
let data = obj.section_by_name(section.name()).map(|s| s.uncompressed_data().unwrap());
30+
Ok(EndianRcSlice::new(Rc::from(data.unwrap_or_default().as_ref()), endian))
31+
})
32+
.unwrap();
33+
let mut iter = dwarf.units();
34+
let mut still_to_find = HashMap::from([
35+
("U128A", 0_u128),
36+
("U128B", 1_u128),
37+
("U128C", u64::MAX as u128 + 1),
38+
("U128D", u128::MAX),
39+
("I128A", 0_i128 as u128),
40+
("I128B", (-1_i128) as u128),
41+
("I128C", i128::MIN as u128),
42+
("I128D", i128::MAX as u128),
43+
]);
44+
while let Some(header) = iter.next().unwrap() {
45+
let unit = dwarf.unit(header).unwrap();
46+
let mut cursor = unit.entries();
47+
while let Some((_, entry)) = cursor.next_dfs().unwrap() {
48+
if entry.tag() == gimli::constants::DW_TAG_enumerator {
49+
let name = dwarf
50+
.attr_string(
51+
&unit,
52+
entry.attr(gimli::constants::DW_AT_name).unwrap().unwrap().value(),
53+
)
54+
.unwrap();
55+
let name = name.to_string().unwrap();
56+
if let Some(expected) = still_to_find.remove(name.as_ref()) {
57+
match entry.attr(gimli::constants::DW_AT_const_value).unwrap().unwrap().value()
58+
{
59+
AttributeValue::Block(value) => {
60+
assert_eq!(
61+
value.to_slice().unwrap(),
62+
expected.to_le_bytes().as_slice(),
63+
"{name}"
64+
);
65+
}
66+
value => panic!("{name}: unexpected DW_AT_const_value of {value:?}"),
67+
}
68+
}
69+
}
70+
}
71+
}
72+
if !still_to_find.is_empty() {
73+
panic!("Didn't find debug entries for {still_to_find:?}");
74+
}
75+
}

0 commit comments

Comments
 (0)