Skip to content

Commit 62e9f2b

Browse files
committed
rustbuild: make libdir_relative a method
1 parent a1af698 commit 62e9f2b

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

src/bootstrap/builder.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,11 @@ impl<'a> Builder<'a> {
444444

445445
fn run(self, builder: &Builder) -> Interned<PathBuf> {
446446
let compiler = self.compiler;
447-
let lib = if compiler.stage >= 1 && builder.build.config.libdir_relative.is_some() {
448-
builder.build.config.libdir_relative.clone().unwrap()
447+
let config = &builder.build.config;
448+
let lib = if compiler.stage >= 1 && config.libdir_relative().is_some() {
449+
builder.build.config.libdir_relative().unwrap()
449450
} else {
450-
PathBuf::from("lib")
451+
Path::new("lib")
451452
};
452453
let sysroot = builder.sysroot(self.compiler).join(lib)
453454
.join("rustlib").join(self.target).join("lib");

src/bootstrap/compile.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,7 @@ fn rustc_cargo_env(build: &Build, cargo: &mut Command) {
516516
.env("CFG_VERSION", build.rust_version())
517517
.env("CFG_PREFIX", build.config.prefix.clone().unwrap_or_default());
518518

519-
let libdir_relative =
520-
build.config.libdir_relative.clone().unwrap_or(PathBuf::from("lib"));
519+
let libdir_relative = build.config.libdir_relative().unwrap_or(Path::new("lib"));
521520
cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);
522521

523522
// If we're not building a compiler with debugging information then remove

src/bootstrap/config.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::collections::{HashMap, HashSet};
1717
use std::env;
1818
use std::fs::File;
1919
use std::io::prelude::*;
20-
use std::path::PathBuf;
20+
use std::path::{Path, PathBuf};
2121
use std::process;
2222
use std::cmp;
2323

@@ -126,7 +126,6 @@ pub struct Config {
126126
pub docdir: Option<PathBuf>,
127127
pub bindir: Option<PathBuf>,
128128
pub libdir: Option<PathBuf>,
129-
pub libdir_relative: Option<PathBuf>,
130129
pub mandir: Option<PathBuf>,
131130
pub codegen_tests: bool,
132131
pub nodejs: Option<PathBuf>,
@@ -418,22 +417,6 @@ impl Config {
418417
config.mandir = install.mandir.clone().map(PathBuf::from);
419418
}
420419

421-
// Try to infer `libdir_relative` from `libdir`.
422-
if let Some(ref libdir) = config.libdir {
423-
let mut libdir = libdir.as_path();
424-
if !libdir.is_relative() {
425-
// Try to make it relative to the prefix.
426-
if let Some(ref prefix) = config.prefix {
427-
if let Ok(suffix) = libdir.strip_prefix(prefix) {
428-
libdir = suffix;
429-
}
430-
}
431-
}
432-
if libdir.is_relative() {
433-
config.libdir_relative = Some(libdir.to_path_buf());
434-
}
435-
}
436-
437420
// Store off these values as options because if they're not provided
438421
// we'll infer default values for them later
439422
let mut thinlto = None;
@@ -581,6 +564,17 @@ impl Config {
581564
config
582565
}
583566

567+
/// Try to find the relative path of `libdir`.
568+
pub fn libdir_relative(&self) -> Option<&Path> {
569+
let libdir = self.libdir.as_ref()?;
570+
if libdir.is_relative() {
571+
Some(libdir)
572+
} else {
573+
// Try to make it relative to the prefix.
574+
libdir.strip_prefix(self.prefix.as_ref()?).ok()
575+
}
576+
}
577+
584578
pub fn verbose(&self) -> bool {
585579
self.verbose > 0
586580
}

0 commit comments

Comments
 (0)