From 8174c0d65932dd6d7845af9b715090f57417b641 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 19 Feb 2018 16:08:36 -0800 Subject: [PATCH] rustbuild: make libdir_relative a method --- src/bootstrap/builder.rs | 7 ++++--- src/bootstrap/compile.rs | 3 +-- src/bootstrap/config.rs | 30 ++++++++++++------------------ 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 05aa6283ee579..fcb78c479fa27 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -444,10 +444,11 @@ impl<'a> Builder<'a> { fn run(self, builder: &Builder) -> Interned { let compiler = self.compiler; - let lib = if compiler.stage >= 1 && builder.build.config.libdir_relative.is_some() { - builder.build.config.libdir_relative.clone().unwrap() + let config = &builder.build.config; + let lib = if compiler.stage >= 1 && config.libdir_relative().is_some() { + builder.build.config.libdir_relative().unwrap() } else { - PathBuf::from("lib") + Path::new("lib") }; let sysroot = builder.sysroot(self.compiler).join(lib) .join("rustlib").join(self.target).join("lib"); diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index e6389f27785b5..c85b04ddc0245 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -516,8 +516,7 @@ fn rustc_cargo_env(build: &Build, cargo: &mut Command) { .env("CFG_VERSION", build.rust_version()) .env("CFG_PREFIX", build.config.prefix.clone().unwrap_or_default()); - let libdir_relative = - build.config.libdir_relative.clone().unwrap_or(PathBuf::from("lib")); + let libdir_relative = build.config.libdir_relative().unwrap_or(Path::new("lib")); cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative); // If we're not building a compiler with debugging information then remove diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 6d98153e233ba..3cf8f36df25ee 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -17,7 +17,7 @@ use std::collections::{HashMap, HashSet}; use std::env; use std::fs::File; use std::io::prelude::*; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process; use std::cmp; @@ -126,7 +126,6 @@ pub struct Config { pub docdir: Option, pub bindir: Option, pub libdir: Option, - pub libdir_relative: Option, pub mandir: Option, pub codegen_tests: bool, pub nodejs: Option, @@ -418,22 +417,6 @@ impl Config { config.mandir = install.mandir.clone().map(PathBuf::from); } - // Try to infer `libdir_relative` from `libdir`. - if let Some(ref libdir) = config.libdir { - let mut libdir = libdir.as_path(); - if !libdir.is_relative() { - // Try to make it relative to the prefix. - if let Some(ref prefix) = config.prefix { - if let Ok(suffix) = libdir.strip_prefix(prefix) { - libdir = suffix; - } - } - } - if libdir.is_relative() { - config.libdir_relative = Some(libdir.to_path_buf()); - } - } - // Store off these values as options because if they're not provided // we'll infer default values for them later let mut thinlto = None; @@ -581,6 +564,17 @@ impl Config { config } + /// Try to find the relative path of `libdir`. + pub fn libdir_relative(&self) -> Option<&Path> { + let libdir = self.libdir.as_ref()?; + if libdir.is_relative() { + Some(libdir) + } else { + // Try to make it relative to the prefix. + libdir.strip_prefix(self.prefix.as_ref()?).ok() + } + } + pub fn verbose(&self) -> bool { self.verbose > 0 }