From 80970e6953faaba886215d8abd34e70f1d510103 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 19 Feb 2018 14:05:21 -0800 Subject: [PATCH 1/2] rustbuild: Restore Config.libdir_relative This re-introduces a `Config.libdir_relative` field, now derived from `libdir` and made relative to `prefix` if necessary. This fixes a regression from #46592 when `--libdir` is given an absolute path. `Builder::sysroot_libdir` should always use a relative path so its callers don't clobber system locations, and `librustc` also asserts that `CFG_LIBDIR_RELATIVE` is really relative. --- src/bootstrap/builder.rs | 4 ++-- src/bootstrap/compile.rs | 2 +- src/bootstrap/config.rs | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 66a1c97246200..05aa6283ee579 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -444,8 +444,8 @@ impl<'a> Builder<'a> { fn run(self, builder: &Builder) -> Interned { let compiler = self.compiler; - let lib = if compiler.stage >= 1 && builder.build.config.libdir.is_some() { - builder.build.config.libdir.clone().unwrap() + let lib = if compiler.stage >= 1 && builder.build.config.libdir_relative.is_some() { + builder.build.config.libdir_relative.clone().unwrap() } else { PathBuf::from("lib") }; diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 2dcc0e0e7cd9f..e6389f27785b5 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -517,7 +517,7 @@ fn rustc_cargo_env(build: &Build, cargo: &mut Command) { .env("CFG_PREFIX", build.config.prefix.clone().unwrap_or_default()); let libdir_relative = - build.config.libdir.clone().unwrap_or(PathBuf::from("lib")); + build.config.libdir_relative.clone().unwrap_or(PathBuf::from("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 812ca6d64fb6a..6d98153e233ba 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -126,6 +126,7 @@ 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, @@ -417,6 +418,22 @@ 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; From 8174c0d65932dd6d7845af9b715090f57417b641 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 19 Feb 2018 16:08:36 -0800 Subject: [PATCH 2/2] 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 }