Skip to content

Commit

Permalink
detect gdb version & rust support in compiletest
Browse files Browse the repository at this point in the history
  • Loading branch information
TimNN committed Oct 31, 2016
1 parent 6554fb0 commit dce4600
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 89 deletions.
7 changes: 0 additions & 7 deletions configure
Expand Up @@ -862,13 +862,6 @@ then
fi
fi

if [ -n "$CFG_GDB" ]
then
# Store GDB's version
CFG_GDB_VERSION=$($CFG_GDB --version 2>/dev/null | head -1)
putvar CFG_GDB_VERSION
fi

if [ -n "$CFG_LLDB" ]
then
# Store LLDB's version
Expand Down
2 changes: 1 addition & 1 deletion mk/tests.mk
Expand Up @@ -648,7 +648,7 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) = \
--host $(3) \
--docck-python $$(CFG_PYTHON) \
--lldb-python $$(CFG_LLDB_PYTHON) \
--gdb-version="$(CFG_GDB_VERSION)" \
--gdb="$(CFG_GDB)" \
--lldb-version="$(CFG_LLDB_VERSION)" \
--llvm-version="$$(LLVM_VERSION_$(3))" \
--android-cross-path=$(CFG_ARM_LINUX_ANDROIDEABI_NDK) \
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/check.rs
Expand Up @@ -168,8 +168,8 @@ pub fn compiletest(build: &Build,
cmd.arg("--lldb-python").arg(python_default);
}

if let Some(ref vers) = build.gdb_version {
cmd.arg("--gdb-version").arg(vers);
if let Some(ref gdb) = build.config.gdb {
cmd.arg("--gdb").arg(gdb);
}
if let Some(ref vers) = build.lldb_version {
cmd.arg("--lldb-version").arg(vers);
Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/config.rs
Expand Up @@ -85,6 +85,7 @@ pub struct Config {
pub mandir: Option<String>,
pub codegen_tests: bool,
pub nodejs: Option<PathBuf>,
pub gdb: Option<PathBuf>,
}

/// Per-target configuration stored in the global configuration structure.
Expand Down Expand Up @@ -122,6 +123,7 @@ struct Build {
compiler_docs: Option<bool>,
docs: Option<bool>,
submodules: Option<bool>,
gdb: Option<String>,
}

/// TOML representation of how the LLVM build is configured.
Expand Down Expand Up @@ -226,6 +228,7 @@ impl Config {
}
config.rustc = build.rustc.map(PathBuf::from);
config.cargo = build.cargo.map(PathBuf::from);
config.gdb = build.gdb.map(PathBuf::from);
set(&mut config.compiler_docs, build.compiler_docs);
set(&mut config.docs, build.docs);
set(&mut config.submodules, build.submodules);
Expand Down Expand Up @@ -392,6 +395,9 @@ impl Config {
"CFG_DEFAULT_LINKER" if value.len() > 0 => {
self.rustc_default_linker = Some(value.to_string());
}
"CFG_GDB" if value.len() > 0 => {
self.gdb = Some(PathBuf::from(value));
}
"CFG_RELEASE_CHANNEL" => {
self.channel = value.to_string();
}
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/config.toml.example
Expand Up @@ -79,6 +79,9 @@
# Indicate whether submodules are managed and updated automatically.
#submodules = true

# The path to (or name of) the GDB executable to use
#gdb = "gdb"

# =============================================================================
# Options for compiling Rust code itself
# =============================================================================
Expand Down
2 changes: 0 additions & 2 deletions src/bootstrap/lib.rs
Expand Up @@ -123,7 +123,6 @@ pub struct Build {
bootstrap_key_stage0: String,

// Probed tools at runtime
gdb_version: Option<String>,
lldb_version: Option<String>,
lldb_python_dir: Option<String>,

Expand Down Expand Up @@ -196,7 +195,6 @@ impl Build {
package_vers: String::new(),
cc: HashMap::new(),
cxx: HashMap::new(),
gdb_version: None,
lldb_version: None,
lldb_python_dir: None,
}
Expand Down
7 changes: 6 additions & 1 deletion src/bootstrap/sanity.rs
Expand Up @@ -92,6 +92,12 @@ pub fn check(build: &mut Build) {
need_cmd(s.as_ref());
}

if let Some(ref gdb) = build.config.gdb {
need_cmd(gdb.as_ref());
} else {
build.config.gdb = have_cmd("gdb".as_ref());
}

// We're gonna build some custom C code here and there, host triples
// also build some C++ shims for LLVM so we need a C++ compiler.
for target in build.config.target.iter() {
Expand Down Expand Up @@ -198,7 +204,6 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
.to_string()
})
};
build.gdb_version = run(Command::new("gdb").arg("--version")).ok();
build.lldb_version = run(Command::new("lldb").arg("--version")).ok();
if build.lldb_version.is_some() {
build.lldb_python_dir = run(Command::new("lldb").arg("-P")).ok();
Expand Down
7 changes: 5 additions & 2 deletions src/tools/compiletest/src/common.rs
Expand Up @@ -146,8 +146,11 @@ pub struct Config {
// Host triple for the compiler being invoked
pub host: String,

// Version of GDB
pub gdb_version: Option<String>,
// Path to / name of the GDB executable
pub gdb: Option<String>,

// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch
pub gdb_version: Option<u32>,

// Whether GDB has native rust support
pub gdb_native_rust: bool,
Expand Down
23 changes: 4 additions & 19 deletions src/tools/compiletest/src/header.rs
Expand Up @@ -18,6 +18,8 @@ use common::Config;
use common;
use util;

use extract_gdb_version;

/// Properties which must be known very early, before actually running
/// the test.
pub struct EarlyProps {
Expand Down Expand Up @@ -75,15 +77,15 @@ impl EarlyProps {
return true;
}

if let Some(ref actual_version) = config.gdb_version {
if let Some(actual_version) = config.gdb_version {
if line.contains("min-gdb-version") {
let min_version = line.trim()
.split(' ')
.last()
.expect("Malformed GDB version directive");
// Ignore if actual version is smaller the minimum required
// version
gdb_version_to_int(actual_version) < gdb_version_to_int(min_version)
actual_version < extract_gdb_version(min_version).unwrap()
} else {
false
}
Expand Down Expand Up @@ -464,23 +466,6 @@ pub fn parse_name_value_directive(line: &str, directive: &str) -> Option<String>
}
}

pub fn gdb_version_to_int(version_string: &str) -> isize {
let error_string = format!("Encountered GDB version string with unexpected format: {}",
version_string);
let error_string = error_string;

let components: Vec<&str> = version_string.trim().split('.').collect();

if components.len() != 2 {
panic!("{}", error_string);
}

let major: isize = components[0].parse().ok().expect(&error_string);
let minor: isize = components[1].parse().ok().expect(&error_string);

return major * 1000 + minor;
}

pub fn lldb_version_to_int(version_string: &str) -> isize {
let error_string = format!("Encountered LLDB version string with unexpected format: {}",
version_string);
Expand Down

0 comments on commit dce4600

Please sign in to comment.