about summary refs log tree commit diff
path: root/src/tools/compiletest
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-07-06 11:25:29 +0800
committerkennytm <kennytm@gmail.com>2017-07-11 16:15:59 +0800
commit18712e6edf685855ce0e0470730192165e56e0b1 (patch)
treeb0a89537cddedd3b84ce7a410f8888e021a23207 /src/tools/compiletest
parent1999bfaa9f961ce2e0c82e97f9bc152d5ce5ed72 (diff)
downloadrust-18712e6edf685855ce0e0470730192165e56e0b1.tar.gz
rust-18712e6edf685855ce0e0470730192165e56e0b1.zip
compiletest: Refactor: Move the `ignore-{}` logic into its own method.
Prepare for `normalize-std???` which will share the same logic.
Added `ignore-32bit` and `ignore-64bit`.
Diffstat (limited to 'src/tools/compiletest')
-rw-r--r--src/tools/compiletest/src/header.rs56
-rw-r--r--src/tools/compiletest/src/util.rs8
2 files changed, 34 insertions, 30 deletions
diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs
index 5ac60d8f2c8..59d08ceae21 100644
--- a/src/tools/compiletest/src/header.rs
+++ b/src/tools/compiletest/src/header.rs
@@ -40,15 +40,8 @@ impl EarlyProps {
                     None,
                     &mut |ln| {
             props.ignore =
-                props.ignore || config.parse_name_directive(ln, "ignore-test") ||
-                config.parse_name_directive(ln, &ignore_target(config)) ||
-                config.parse_name_directive(ln, &ignore_architecture(config)) ||
-                config.parse_name_directive(ln, &ignore_stage(config)) ||
-                config.parse_name_directive(ln, &ignore_env(config)) ||
-                (config.mode == common::Pretty &&
-                 config.parse_name_directive(ln, "ignore-pretty")) ||
-                (config.target != config.host &&
-                 config.parse_name_directive(ln, "ignore-cross-compile")) ||
+                props.ignore ||
+                config.parse_cfg_name_directive(ln, "ignore") ||
                 ignore_gdb(config, ln) ||
                 ignore_lldb(config, ln) ||
                 ignore_llvm(config, ln);
@@ -62,28 +55,11 @@ impl EarlyProps {
 
         return props;
 
-        fn ignore_target(config: &Config) -> String {
-            format!("ignore-{}", util::get_os(&config.target))
-        }
-        fn ignore_architecture(config: &Config) -> String {
-            format!("ignore-{}", util::get_arch(&config.target))
-        }
-        fn ignore_stage(config: &Config) -> String {
-            format!("ignore-{}", config.stage_id.split('-').next().unwrap())
-        }
-        fn ignore_env(config: &Config) -> String {
-            format!("ignore-{}",
-                    util::get_env(&config.target).unwrap_or("<unknown>"))
-        }
         fn ignore_gdb(config: &Config, line: &str) -> bool {
             if config.mode != common::DebugInfoGdb {
                 return false;
             }
 
-            if config.parse_name_directive(line, "ignore-gdb") {
-                return true;
-            }
-
             if let Some(actual_version) = config.gdb_version {
                 if line.starts_with("min-gdb-version") {
                     let (start_ver, end_ver) = extract_gdb_version_range(line);
@@ -144,10 +120,6 @@ impl EarlyProps {
                 return false;
             }
 
-            if config.parse_name_directive(line, "ignore-lldb") {
-                return true;
-            }
-
             if let Some(ref actual_version) = config.lldb_version {
                 if line.starts_with("min-lldb-version") {
                     let min_version = line.trim_right()
@@ -525,6 +497,30 @@ impl Config {
         }
     }
 
+    /// Parses a name-value directive which contains config-specific information, e.g. `ignore-x86`
+    /// or `normalize-stderr-32bit`. Returns `true` if the line matches it.
+    fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> bool {
+        if line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-') {
+            let name = line[prefix.len()+1 ..].split(&[':', ' '][..]).next().unwrap();
+
+            name == "test" ||
+                name == util::get_os(&self.target) ||               // target
+                name == util::get_arch(&self.target) ||             // architecture
+                name == util::get_pointer_width(&self.target) ||    // pointer width
+                name == self.stage_id.split('-').next().unwrap() || // stage
+                Some(name) == util::get_env(&self.target) ||        // env
+                match self.mode {
+                    common::DebugInfoGdb => name == "gdb",
+                    common::DebugInfoLldb => name == "lldb",
+                    common::Pretty => name == "pretty",
+                    _ => false,
+                } ||
+                (self.target != self.host && name == "cross-compile")
+        } else {
+            false
+        }
+    }
+
     fn parse_name_directive(&self, line: &str, directive: &str) -> bool {
         // Ensure the directive is a whole word. Do not match "ignore-x86" when
         // the line says "ignore-x86_64".
diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs
index 4202356bd97..85fa38bbd3b 100644
--- a/src/tools/compiletest/src/util.rs
+++ b/src/tools/compiletest/src/util.rs
@@ -72,6 +72,14 @@ pub fn get_env(triple: &str) -> Option<&str> {
     triple.split('-').nth(3)
 }
 
+pub fn get_pointer_width(triple: &str) -> &'static str {
+    if triple.contains("64") || triple.starts_with("s390x") {
+        "64bit"
+    } else {
+        "32bit"
+    }
+}
+
 pub fn make_new_path(path: &str) -> String {
     assert!(cfg!(windows));
     // Windows just uses PATH as the library search path, so we have to