Skip to content

Commit

Permalink
don't change Display impl
Browse files Browse the repository at this point in the history
  • Loading branch information
lolbinarycat committed Jul 31, 2024
1 parent 2bb79fb commit 5f0b85a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
20 changes: 15 additions & 5 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,19 @@ impl TargetSelection {
pub fn is_windows(&self) -> bool {
self.contains("windows")
}
}

impl fmt::Display for TargetSelection {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(file) = self.file { write!(f, "{file}") } else { write!(f, "{}", self.triple) }
/// Path to the file defining the custom target, if any.
pub fn filepath(&self) -> Option<&Path> {
self.file.as_ref().map(Path::new)
/*if let Some(ref p) = self.file.as_ref {
Some(Path::new(p))
} else {
None
}*/
}
}

impl fmt::Debug for TargetSelection {
impl fmt::Display for TargetSelection {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.triple)?;
if let Some(file) = self.file {
Expand All @@ -530,6 +534,12 @@ impl fmt::Debug for TargetSelection {
}
}

impl fmt::Debug for TargetSelection {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{self}")
}
}

impl PartialEq<&str> for TargetSelection {
fn eq(&self, other: &&str) -> bool {
self.triple == *other
Expand Down
10 changes: 5 additions & 5 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::collections::HashMap;
#[cfg(not(feature = "bootstrap-self-test"))]
use std::collections::HashSet;
use std::ffi::{OsStr, OsString};
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::{env, fs};

#[cfg(not(feature = "bootstrap-self-test"))]
Expand Down Expand Up @@ -259,18 +259,18 @@ than building it.
has_target |= STAGE0_MISSING_TARGETS.contains(&target_str.as_str());

if !has_target {
// This might also be a custom target, so check the target file that could have been specified by the user.
if Path::new(&target_str).exists() {
// This might also be a custom target, so check the target file that could have been specified by the user.
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");

// Recursively traverse through nested directories.
let walker = walkdir::WalkDir::new(custom_target_path).into_iter();
for entry in walker.filter_map(|e| e.ok()) {
has_target |= entry.file_name() == target_filename;
has_target |= entry.file_name() == target_filename;
}
}
}
Expand Down

0 comments on commit 5f0b85a

Please sign in to comment.