Skip to content
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

Fix x test src/tools/error_index_generator --stage {0,1} #95440

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,18 @@ impl<'a> Builder<'a> {
}
}

pub fn rustc_lib_paths(&self, compiler: Compiler) -> Vec<PathBuf> {
let mut dylib_dirs = vec![self.rustc_libdir(compiler)];

// Ensure that the downloaded LLVM libraries can be found.
if self.config.llvm_from_ci {
let ci_llvm_lib = self.out.join(&*compiler.host.triple).join("ci-llvm").join("lib");
dylib_dirs.push(ci_llvm_lib);
}

dylib_dirs
}

/// Adds the compiler's directory of dynamic libraries to `cmd`'s dynamic
/// library lookup path.
pub fn add_rustc_lib_path(&self, compiler: Compiler, cmd: &mut Command) {
Expand All @@ -845,15 +857,7 @@ impl<'a> Builder<'a> {
return;
}

let mut dylib_dirs = vec![self.rustc_libdir(compiler)];

// Ensure that the downloaded LLVM libraries can be found.
if self.config.llvm_from_ci {
let ci_llvm_lib = self.out.join(&*compiler.host.triple).join("ci-llvm").join("lib");
dylib_dirs.push(ci_llvm_lib);
}

add_dylib_path(dylib_dirs, cmd);
add_dylib_path(self.rustc_lib_paths(compiler), cmd);
}

/// Gets a path to the compiler specified.
Expand Down
22 changes: 7 additions & 15 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,22 +379,14 @@ pub struct ErrorIndex {

impl ErrorIndex {
pub fn command(builder: &Builder<'_>) -> Command {
// This uses stage-1 to match the behavior of building rustdoc.
// Error-index-generator links with the rustdoc library, so we want to
// use the same librustdoc to avoid building rustdoc twice (and to
// avoid building the compiler an extra time). This uses
// saturating_sub to deal with building with stage 0. (Using stage 0
// isn't recommended, since it will fail if any new error index tests
// use new syntax, but it should work otherwise.)
let compiler = builder.compiler(builder.top_stage.saturating_sub(1), builder.config.build);
// Error-index-generator links with the rustdoc library, so we need to add `rustc_lib_paths`
// for rustc_private and libLLVM.so, and `sysroot_lib` for libstd, etc.
let host = builder.config.build;
let compiler = builder.compiler_for(builder.top_stage, host, host);
let mut cmd = Command::new(builder.ensure(ErrorIndex { compiler }));
add_dylib_path(
vec![
PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host)),
builder.rustc_libdir(compiler),
],
&mut cmd,
);
let mut dylib_paths = builder.rustc_lib_paths(compiler);
dylib_paths.push(PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host)));
add_dylib_path(dylib_paths, &mut cmd);
cmd
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn libdir(target: TargetSelection) -> &'static str {
}

/// Adds a list of lookup paths to `cmd`'s dynamic library lookup path.
/// If The dylib_path_par is already set for this cmd, the old value will be overwritten!
/// If the dylib_path_var is already set for this cmd, the old value will be overwritten!
pub fn add_dylib_path(path: Vec<PathBuf>, cmd: &mut Command) {
let mut list = dylib_path();
for path in path {
Expand Down
32 changes: 0 additions & 32 deletions src/tools/error_index_generator/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ fn main() {
// Note that we could skip one of the .. but this ensures we at least loosely find the right
// directory.
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let dest = out_dir.join("error_codes.rs");

let error_codes_path = "../../../compiler/rustc_error_codes/src/error_codes.rs";

Expand All @@ -29,35 +28,4 @@ fn main() {
let md_content = fs::read_to_string(entry.path()).unwrap();
fs::write(&out_dir.join(entry.file_name()), &md_content).unwrap();
}

let mut all = String::new();
all.push_str(
r###"
fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new();
macro_rules! register_diagnostics {
($($ecode:ident: $message:expr,)*) => (
register_diagnostics!{$($ecode:$message,)* ;}
);
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
$(
{long_codes.extend([
(stringify!($ecode), Some($message)),
].iter());}
)*
$(
{long_codes.extend([
stringify!($code),
].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());}
)*
)
}
"###,
);
all.push_str(r#"include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));"#);
all.push_str("\nlong_codes\n");
all.push_str("}\n");

fs::write(&dest, all).unwrap();
}
24 changes: 23 additions & 1 deletion src/tools/error_index_generator/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,26 @@ fn main() {
}
}

include!(concat!(env!("OUT_DIR"), "/error_codes.rs"));
fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new();
macro_rules! register_diagnostics {
($($ecode:ident: $message:expr,)*) => (
register_diagnostics!{$($ecode:$message,)* ;}
);

($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
$(
{long_codes.extend([
(stringify!($ecode), Some($message)),
].iter());}
)*
$(
{long_codes.extend([
stringify!($code),
].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());}
)*
)
}
include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));
long_codes
}