-
Notifications
You must be signed in to change notification settings - Fork 13.5k
rustc_session: Add a structure for keeping both explicit and default sysroots #142799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1296,6 +1296,28 @@ bitflags::bitflags! { | |
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Sysroot { | ||
pub explicit: Option<PathBuf>, | ||
pub default: PathBuf, | ||
} | ||
|
||
impl Sysroot { | ||
pub fn new(explicit: Option<PathBuf>) -> Sysroot { | ||
Sysroot { explicit, default: filesearch::default_sysroot() } | ||
} | ||
|
||
/// Return explicit sysroot if it was passed with `--sysroot`, or default sysroot otherwise. | ||
pub fn path(&self) -> &Path { | ||
self.explicit.as_deref().unwrap_or(&self.default) | ||
} | ||
|
||
/// Returns both explicit sysroot if it was passed with `--sysroot` and the default sysroot. | ||
pub fn all_paths(&self) -> impl Iterator<Item = &Path> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How? Can't do that without changing the storage in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what you meant by "Right", so I changed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant that you are right about
I didn't think of that. Using collect for fluent_bundle is fine. |
||
self.explicit.as_deref().into_iter().chain(iter::once(&*self.default)) | ||
} | ||
} | ||
|
||
pub fn host_tuple() -> &'static str { | ||
// Get the host triple out of the build environment. This ensures that our | ||
// idea of the host triple is the same as for the set of libraries we've | ||
|
@@ -1342,7 +1364,7 @@ impl Default for Options { | |
describe_lints: false, | ||
output_types: OutputTypes(BTreeMap::new()), | ||
search_paths: vec![], | ||
sysroot: filesearch::materialize_sysroot(None), | ||
sysroot: Sysroot::new(None), | ||
target_triple: TargetTuple::from_tuple(host_tuple()), | ||
test: false, | ||
incremental: None, | ||
|
@@ -2673,7 +2695,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M | |
|
||
let cg = cg; | ||
|
||
let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::from(&m)); | ||
let target_triple = parse_target_triple(early_dcx, matches); | ||
let opt_level = parse_opt_level(early_dcx, matches, &cg); | ||
// The `-g` and `-C debuginfo` flags specify the same setting, so we want to be able | ||
|
@@ -2712,10 +2733,10 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M | |
|
||
let logical_env = parse_logical_env(early_dcx, matches); | ||
|
||
let sysroot = filesearch::materialize_sysroot(sysroot_opt); | ||
let sysroot = Sysroot::new(matches.opt_str("sysroot").map(PathBuf::from)); | ||
|
||
let real_source_base_dir = |suffix: &str, confirm: &str| { | ||
let mut candidate = sysroot.join(suffix); | ||
let mut candidate = sysroot.path().join(suffix); | ||
if let Ok(metadata) = candidate.symlink_metadata() { | ||
// Replace the symlink bootstrap creates, with its destination. | ||
// We could try to use `fs::canonicalize` instead, but that might | ||
|
@@ -2742,7 +2763,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M | |
let mut search_paths = vec![]; | ||
for s in &matches.opt_strs("L") { | ||
search_paths.push(SearchPath::from_cli_opt( | ||
&sysroot, | ||
sysroot.path(), | ||
&target_triple, | ||
early_dcx, | ||
s, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer necessary, right?