Rollup merge of #128283 - lolbinarycat:bootstrap-custom-target, r=albertlarsan68

bootstrap: fix bug preventing the use of custom targets

the bug was caused by two factors:
1. only checking the RUST_TARGET_PATH form, not the full filepath form
2. indirectly trying to use the Debug presentation to get the file path
This commit is contained in:
Matthias Krüger 2024-08-03 20:51:52 +02:00 committed by GitHub
commit 0afbe482f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 3 deletions

View File

@ -512,6 +512,11 @@ pub fn is_msvc(&self) -> bool {
pub fn is_windows(&self) -> bool {
self.contains("windows")
}
/// Path to the file defining the custom target, if any.
pub fn filepath(&self) -> Option<&Path> {
self.file.as_ref().map(Path::new)
}
}
impl fmt::Display for TargetSelection {

View File

@ -260,7 +260,9 @@ pub fn check(build: &mut Build) {
if !has_target {
// This might also be a custom target, so check the target file that could have been specified by the user.
if let Some(custom_target_path) = env::var_os("RUST_TARGET_PATH") {
if target.filepath().is_some_and(|p| p.exists()) {
has_target = true;
} else if let Some(custom_target_path) = env::var_os("RUST_TARGET_PATH") {
let mut target_filename = OsString::from(&target_str);
// Target filename ends with `.json`.
target_filename.push(".json");
@ -275,8 +277,12 @@ pub fn check(build: &mut Build) {
if !has_target {
panic!(
"No such target exists in the target list,
specify a correct location of the JSON specification file for custom targets!"
"No such target exists in the target list,\n\
make sure to correctly specify the location \
of the JSON specification file \
for custom targets!\n\
Use BOOTSTRAP_SKIP_TARGET_SANITY=1 to \
bypass this check."
);
}
}