Refactor build flags handling and add tool alias management

- Introduced a new method `apply_default_string` to streamline the application of default values for string fields in build flags.
- Enhanced `apply_flags_table` to utilize the new method for setting various build flags, improving code readability and maintainability.
- Added support for additional build flags: `fuse_ld`, `ranlib`, `strip`, `nm`, `objcopy`, `objdump`, and `readelf`.
- Implemented a new command `set` to manage tool aliases for compilers, linkers, and shells, allowing users to set preferred tools in the build environment.
- Improved error handling and validation for tool alias configuration, ensuring that existing non-symlink files are not replaced.
- Added tests to verify the correct behavior of tool alias management and build flag application.
This commit is contained in:
2026-05-27 14:39:01 -05:00
parent 1833a2c42d
commit 5c33a36100
23 changed files with 1895 additions and 170 deletions
+23
View File
@@ -491,6 +491,18 @@ fn generate_lib32_meson_cross_file(
let ld = meson_binary_value(&command_words(&flags.ld), "linker")?;
content.push_str(&format!("ld = {ld}\n"));
}
for (name, command, label) in [
("strip", flags.strip.as_str(), "strip"),
("nm", flags.nm.as_str(), "nm"),
("objcopy", flags.objcopy.as_str(), "objcopy"),
("objdump", flags.objdump.as_str(), "objdump"),
("readelf", flags.readelf.as_str(), "readelf"),
] {
if !command.trim().is_empty() {
let value = meson_binary_value(&command_words(command), label)?;
content.push_str(&format!("{name} = {value}\n"));
}
}
content.push_str(&format!(
"\n[host_machine]\nsystem = 'linux'\ncpu_family = '{cpu_family}'\ncpu = '{arch}'\nendian = 'little'\n"
));
@@ -961,7 +973,12 @@ mod tests {
cc: "clang -m32".to_string(),
cxx: "clang++ -m32".to_string(),
ar: "llvm-ar".to_string(),
strip: "llvm-strip".to_string(),
ld: "ld.lld".to_string(),
nm: "llvm-nm".to_string(),
objcopy: "llvm-objcopy".to_string(),
objdump: "llvm-objdump".to_string(),
readelf: "llvm-readelf".to_string(),
..BuildFlags::default()
};
@@ -970,6 +987,12 @@ mod tests {
assert!(content.contains("Generated by depot for target: i686-sfg-linux-gnu"));
assert!(content.contains("c = ['clang', '-m32', '--target=i686-sfg-linux-gnu']"));
assert!(content.contains("cpp = ['clang++', '-m32', '--target=i686-sfg-linux-gnu']"));
assert!(content.contains("strip = 'llvm-strip'"));
assert!(content.contains("ld = 'ld.lld'"));
assert!(content.contains("nm = 'llvm-nm'"));
assert!(content.contains("objcopy = 'llvm-objcopy'"));
assert!(content.contains("objdump = 'llvm-objdump'"));
assert!(content.contains("readelf = 'llvm-readelf'"));
assert!(content.contains("cpu_family = 'x86'"));
assert!(content.contains("cpu = 'i686'"));
Ok(())