From 0f051fd3277a2e1b8ce88eabd11c80b6b2294fcf Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Wed, 23 Nov 2016 21:30:01 +0100 Subject: [PATCH] fix: Specify the libgluon dependency explicitly in compiletest.rs Apparently cargo/rustc no longer removes .rlibs compiled with a different set of feature flags (or rustc are no longer capable of disambiguate between them). Since gluon are compiled with a combination of `test`, `nightly` and `skeptic` we end up with two libgluon-xxxxxxx.rlib in deps and I select just one of them in this PR which should hopefully be the correct one. --- tests/compiletest.rs | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 84d1a2fcb3..bcaf40a4a9 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -1,8 +1,34 @@ #![cfg(feature = "nightly")] extern crate compiletest_rs as compiletest; +extern crate env_logger; use std::env; -use std::path::PathBuf; +use std::fs; +use std::path::{Path, PathBuf}; + + +fn lib_dir(out_dir: &Path, lib_name: &str) -> PathBuf { + // Just loading gluon through -L dir does not work as we compile gluon with different sets of flags which + // gives ambiguity errors. + // Instead retrieve the latest compiled gluon library which should usually be the correct one + let mut gluon_rlibs: Vec<_> = fs::read_dir(out_dir.join("deps")) + .unwrap() + .filter_map(|entry| { + let entry = entry.expect("dir entry"); + if entry.path() + .to_str() + .map_or(false, |name| name.contains(lib_name)) { + Some(entry) + } else { + None + } + }) + .collect(); + gluon_rlibs.sort_by(|l, r| { + l.metadata().unwrap().modified().unwrap().cmp(&r.metadata().unwrap().modified().unwrap()) + }); + gluon_rlibs.last().expect("libgluon not found").path() +} fn run_mode(mode: &'static str) { // Retrieve the path where library dependencies are output @@ -11,7 +37,7 @@ fn run_mode(mode: &'static str) { match out_dir.file_name() { Some(name) => { match name.to_str() { - Some(name) if name == "deps" || name == "debug" => break, + Some(name) if name == "debug" => break, _ => (), } } @@ -19,19 +45,25 @@ fn run_mode(mode: &'static str) { } out_dir.pop(); } + let gluon_rlib = lib_dir(&out_dir, "libgluon-"); + let gluon_vm_rlib = lib_dir(&out_dir, "libgluon_vm-"); let mut config = compiletest::default_config(); let cfg_mode = mode.parse().ok().expect("Invalid mode"); + config.verbose = true; config.mode = cfg_mode; config.src_base = PathBuf::from(format!("tests/{}", mode)); - let dir = out_dir.to_str().unwrap(); - config.target_rustcflags = Some(format!("-L {} -L {}/deps", dir, dir)); - + config.target_rustcflags = Some(format!("-L {}/deps --extern gluon={} --extern gluon_vm={}", + out_dir.display(), + gluon_rlib.display(), + gluon_vm_rlib.display())); + println!("{}", config.target_rustcflags.as_ref().unwrap()); compiletest::run_tests(&config); } #[test] fn compile_test() { + let _ = env_logger::init(); run_mode("compile-fail"); }