3 use std::io::prelude::*;
4 use std::io::BufReader;
5 use std::path::{Path, PathBuf};
9 use crate::common::{self, CompareMode, Config, Mode};
12 use crate::extract_gdb_version;
14 /// Whether to ignore the test.
15 #[derive(Clone, Copy, PartialEq, Debug)]
19 /// Ignore it totally.
21 /// Ignore only the gdb test, but run the lldb test.
23 /// Ignore only the lldb test, but run the gdb test.
28 pub fn can_run_gdb(&self) -> bool {
29 *self == Ignore::Run || *self == Ignore::IgnoreLldb
32 pub fn can_run_lldb(&self) -> bool {
33 *self == Ignore::Run || *self == Ignore::IgnoreGdb
36 pub fn no_gdb(&self) -> Ignore {
38 Ignore::Run => Ignore::IgnoreGdb,
39 Ignore::IgnoreGdb => Ignore::IgnoreGdb,
44 pub fn no_lldb(&self) -> Ignore {
46 Ignore::Run => Ignore::IgnoreLldb,
47 Ignore::IgnoreLldb => Ignore::IgnoreLldb,
53 /// The result of parse_cfg_name_directive.
54 #[derive(Clone, Copy, PartialEq, Debug)]
55 enum ParsedNameDirective {
60 /// Mode was DebugInfoGdbLldb and this matched gdb.
62 /// Mode was DebugInfoGdbLldb and this matched lldb.
66 /// Properties which must be known very early, before actually running
68 pub struct EarlyProps {
70 pub should_fail: bool,
72 pub revisions: Vec<String>,
76 pub fn from_file(config: &Config, testfile: &Path) -> Self {
77 let mut props = EarlyProps {
84 if config.mode == common::DebugInfoGdbLldb {
85 if config.lldb_python_dir.is_none() {
86 props.ignore = props.ignore.no_lldb();
88 if config.gdb_version.is_none() {
89 props.ignore = props.ignore.no_gdb();
91 } else if config.mode == common::DebugInfoCdb {
92 if config.cdb.is_none() {
93 props.ignore = Ignore::Ignore;
97 let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some();
98 let rustc_has_sanitizer_support = env::var_os("RUSTC_SANITIZER_SUPPORT").is_some();
100 iter_header(testfile, None, &mut |ln| {
101 // we should check if any only-<platform> exists and if it exists
102 // and does not matches the current platform, skip the test
103 if props.ignore != Ignore::Ignore {
104 props.ignore = match config.parse_cfg_name_directive(ln, "ignore") {
105 ParsedNameDirective::Match => Ignore::Ignore,
106 ParsedNameDirective::NoMatch => props.ignore,
107 ParsedNameDirective::MatchGdb => props.ignore.no_gdb(),
108 ParsedNameDirective::MatchLldb => props.ignore.no_lldb(),
111 if config.has_cfg_prefix(ln, "only") {
112 props.ignore = match config.parse_cfg_name_directive(ln, "only") {
113 ParsedNameDirective::Match => props.ignore,
114 ParsedNameDirective::NoMatch => Ignore::Ignore,
115 ParsedNameDirective::MatchLldb => props.ignore.no_gdb(),
116 ParsedNameDirective::MatchGdb => props.ignore.no_lldb(),
120 if ignore_llvm(config, ln) {
121 props.ignore = Ignore::Ignore;
124 if config.run_clang_based_tests_with.is_none() &&
125 config.parse_needs_matching_clang(ln) {
126 props.ignore = Ignore::Ignore;
129 if !rustc_has_profiler_support &&
130 config.parse_needs_profiler_support(ln) {
131 props.ignore = Ignore::Ignore;
134 if !rustc_has_sanitizer_support &&
135 config.parse_needs_sanitizer_support(ln) {
136 props.ignore = Ignore::Ignore;
140 if (config.mode == common::DebugInfoGdb || config.mode == common::DebugInfoGdbLldb) &&
141 props.ignore.can_run_gdb() && ignore_gdb(config, ln) {
142 props.ignore = props.ignore.no_gdb();
145 if (config.mode == common::DebugInfoLldb || config.mode == common::DebugInfoGdbLldb) &&
146 props.ignore.can_run_lldb() && ignore_lldb(config, ln) {
147 props.ignore = props.ignore.no_lldb();
150 if let Some(s) = config.parse_aux_build(ln) {
154 if let Some(r) = config.parse_revisions(ln) {
155 props.revisions.extend(r);
158 props.should_fail = props.should_fail || config.parse_name_directive(ln, "should-fail");
163 fn ignore_gdb(config: &Config, line: &str) -> bool {
164 if let Some(actual_version) = config.gdb_version {
165 if line.starts_with("min-gdb-version") {
166 let (start_ver, end_ver) = extract_gdb_version_range(line);
168 if start_ver != end_ver {
169 panic!("Expected single GDB version")
171 // Ignore if actual version is smaller the minimum required
173 actual_version < start_ver
174 } else if line.starts_with("ignore-gdb-version") {
175 let (min_version, max_version) = extract_gdb_version_range(line);
177 if max_version < min_version {
178 panic!("Malformed GDB version range: max < min")
181 actual_version >= min_version && actual_version <= max_version
190 // Takes a directive of the form "ignore-gdb-version <version1> [- <version2>]",
191 // returns the numeric representation of <version1> and <version2> as
192 // tuple: (<version1> as u32, <version2> as u32)
193 // If the <version2> part is omitted, the second component of the tuple
194 // is the same as <version1>.
195 fn extract_gdb_version_range(line: &str) -> (u32, u32) {
196 const ERROR_MESSAGE: &'static str = "Malformed GDB version directive";
198 let range_components = line.split(&[' ', '-'][..])
199 .filter(|word| !word.is_empty())
200 .map(extract_gdb_version)
201 .skip_while(Option::is_none)
202 .take(3) // 3 or more = invalid, so take at most 3.
203 .collect::<Vec<Option<u32>>>();
205 match range_components.len() {
207 let v = range_components[0].unwrap();
211 let v_min = range_components[0].unwrap();
212 let v_max = range_components[1].expect(ERROR_MESSAGE);
215 _ => panic!(ERROR_MESSAGE),
219 fn ignore_lldb(config: &Config, line: &str) -> bool {
220 if let Some(ref actual_version) = config.lldb_version {
221 if line.starts_with("min-lldb-version") {
222 let min_version = line.trim_end()
225 .expect("Malformed lldb version directive");
226 // Ignore if actual version is smaller the minimum required
228 lldb_version_to_int(actual_version) < lldb_version_to_int(min_version)
229 } else if line.starts_with("rust-lldb") && !config.lldb_native_rust {
239 fn ignore_llvm(config: &Config, line: &str) -> bool {
240 if config.system_llvm && line.starts_with("no-system-llvm") {
243 if let Some(ref actual_version) = config.llvm_version {
244 if line.starts_with("min-llvm-version") {
245 let min_version = line.trim_end()
248 .expect("Malformed llvm version directive");
249 // Ignore if actual version is smaller the minimum required
251 &actual_version[..] < min_version
252 } else if line.starts_with("min-system-llvm-version") {
253 let min_version = line.trim_end()
256 .expect("Malformed llvm version directive");
257 // Ignore if using system LLVM and actual version
258 // is smaller the minimum required version
259 config.system_llvm && &actual_version[..] < min_version
260 } else if line.starts_with("ignore-llvm-version") {
261 // Syntax is: "ignore-llvm-version <version1> [- <version2>]"
262 let range_components = line.split(' ')
263 .skip(1) // Skip the directive.
265 .filter(|word| !word.is_empty() && word != &"-")
266 .take(3) // 3 or more = invalid, so take at most 3.
267 .collect::<Vec<&str>>();
268 match range_components.len() {
270 &actual_version[..] == range_components[0]
273 let v_min = range_components[0];
274 let v_max = range_components[1];
276 panic!("Malformed LLVM version range: max < min")
278 // Ignore if version lies inside of range.
279 &actual_version[..] >= v_min && &actual_version[..] <= v_max
281 _ => panic!("Malformed LLVM version directive"),
293 #[derive(Clone, Debug)]
294 pub struct TestProps {
295 // Lines that should be expected, in order, on standard out
296 pub error_patterns: Vec<String>,
297 // Extra flags to pass to the compiler
298 pub compile_flags: Vec<String>,
299 // Extra flags to pass when the compiled code is run (such as --bench)
300 pub run_flags: Option<String>,
301 // If present, the name of a file that this test should match when
303 pub pp_exact: Option<PathBuf>,
304 // Other crates that should be compiled (typically from the same
305 // directory as the test, but for backwards compatibility reasons
306 // we also check the auxiliary directory)
307 pub aux_builds: Vec<String>,
308 // A list of crates to pass '--extern-private name:PATH' flags for
309 // This should be a subset of 'aux_build'
310 // FIXME: Replace this with a better solution: https://github.com/rust-lang/rust/pull/54020
311 pub extern_private: Vec<String>,
312 // Environment settings to use for compiling
313 pub rustc_env: Vec<(String, String)>,
314 // Environment variables to unset prior to compiling.
315 // Variables are unset before applying 'rustc_env'.
316 pub unset_rustc_env: Vec<String>,
317 // Environment settings to use during execution
318 pub exec_env: Vec<(String, String)>,
319 // Lines to check if they appear in the expected debugger output
320 pub check_lines: Vec<String>,
321 // Build documentation for all specified aux-builds as well
322 pub build_aux_docs: bool,
323 // Flag to force a crate to be built with the host architecture
324 pub force_host: bool,
325 // Check stdout for error-pattern output as well as stderr
326 pub check_stdout: bool,
327 // For UI tests, allows compiler to generate arbitrary output to stdout
328 pub dont_check_compiler_stdout: bool,
329 // For UI tests, allows compiler to generate arbitrary output to stderr
330 pub dont_check_compiler_stderr: bool,
331 // Don't force a --crate-type=dylib flag on the command line
333 // Set this for example if you have an auxiliary test file that contains
334 // a proc-macro and needs `#![crate_type = "proc-macro"]`. This ensures
335 // that the aux file is compiled as a `proc-macro` and not as a `dylib`.
336 pub no_prefer_dynamic: bool,
337 // Run --pretty expanded when running pretty printing tests
338 pub pretty_expanded: bool,
339 // Which pretty mode are we testing with, default to 'normal'
340 pub pretty_mode: String,
341 // Only compare pretty output and don't try compiling
342 pub pretty_compare_only: bool,
343 // Patterns which must not appear in the output of a cfail test.
344 pub forbid_output: Vec<String>,
345 // Revisions to test for incremental compilation.
346 pub revisions: Vec<String>,
347 // Directory (if any) to use for incremental compilation. This is
348 // not set by end-users; rather it is set by the incremental
349 // testing harness and used when generating compilation
350 // arguments. (In particular, it propagates to the aux-builds.)
351 pub incremental_dir: Option<PathBuf>,
352 // Specifies that a test must actually compile without errors.
353 pub compile_pass: bool,
354 // rustdoc will test the output of the `--test` option
355 pub check_test_line_numbers_match: bool,
356 // The test must be compiled and run successfully. Only used in UI tests for now.
358 // Skip any codegen step and running the executable. Only for run-pass.
359 pub skip_codegen: bool,
360 // Do not pass `-Z ui-testing` to UI tests
361 pub disable_ui_testing_normalization: bool,
362 // customized normalization rules
363 pub normalize_stdout: Vec<(String, String)>,
364 pub normalize_stderr: Vec<(String, String)>,
365 pub failure_status: i32,
366 // Whether or not `rustfix` should apply the `CodeSuggestion`s of this test and compile the
367 // resulting Rust code.
368 pub run_rustfix: bool,
369 // If true, `rustfix` will only apply `MachineApplicable` suggestions.
370 pub rustfix_only_machine_applicable: bool,
371 pub assembly_output: Option<String>,
375 pub fn new() -> Self {
377 error_patterns: vec![],
378 compile_flags: vec![],
382 extern_private: vec![],
385 unset_rustc_env: vec![],
388 build_aux_docs: false,
391 dont_check_compiler_stdout: false,
392 dont_check_compiler_stderr: false,
393 no_prefer_dynamic: false,
394 pretty_expanded: false,
395 pretty_mode: "normal".to_string(),
396 pretty_compare_only: false,
397 forbid_output: vec![],
398 incremental_dir: None,
400 check_test_line_numbers_match: false,
403 disable_ui_testing_normalization: false,
404 normalize_stdout: vec![],
405 normalize_stderr: vec![],
408 rustfix_only_machine_applicable: false,
409 assembly_output: None,
413 pub fn from_aux_file(&self, testfile: &Path, cfg: Option<&str>, config: &Config) -> Self {
414 let mut props = TestProps::new();
416 // copy over select properties to the aux build:
417 props.incremental_dir = self.incremental_dir.clone();
418 props.load_from(testfile, cfg, config);
423 pub fn from_file(testfile: &Path, cfg: Option<&str>, config: &Config) -> Self {
424 let mut props = TestProps::new();
425 props.load_from(testfile, cfg, config);
429 /// Loads properties from `testfile` into `props`. If a property is
430 /// tied to a particular revision `foo` (indicated by writing
431 /// `//[foo]`), then the property is ignored unless `cfg` is
433 fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
434 iter_header(testfile, cfg, &mut |ln| {
435 if let Some(ep) = config.parse_error_pattern(ln) {
436 self.error_patterns.push(ep);
439 if let Some(flags) = config.parse_compile_flags(ln) {
441 .extend(flags.split_whitespace().map(|s| s.to_owned()));
444 if let Some(edition) = config.parse_edition(ln) {
445 self.compile_flags.push(format!("--edition={}", edition));
448 if let Some(r) = config.parse_revisions(ln) {
449 self.revisions.extend(r);
452 if self.run_flags.is_none() {
453 self.run_flags = config.parse_run_flags(ln);
456 if self.pp_exact.is_none() {
457 self.pp_exact = config.parse_pp_exact(ln, testfile);
460 if !self.build_aux_docs {
461 self.build_aux_docs = config.parse_build_aux_docs(ln);
464 if !self.force_host {
465 self.force_host = config.parse_force_host(ln);
468 if !self.check_stdout {
469 self.check_stdout = config.parse_check_stdout(ln);
472 if !self.dont_check_compiler_stdout {
473 self.dont_check_compiler_stdout = config.parse_dont_check_compiler_stdout(ln);
476 if !self.dont_check_compiler_stderr {
477 self.dont_check_compiler_stderr = config.parse_dont_check_compiler_stderr(ln);
480 if !self.no_prefer_dynamic {
481 self.no_prefer_dynamic = config.parse_no_prefer_dynamic(ln);
484 if !self.pretty_expanded {
485 self.pretty_expanded = config.parse_pretty_expanded(ln);
488 if let Some(m) = config.parse_pretty_mode(ln) {
489 self.pretty_mode = m;
492 if !self.pretty_compare_only {
493 self.pretty_compare_only = config.parse_pretty_compare_only(ln);
496 if let Some(ab) = config.parse_aux_build(ln) {
497 self.aux_builds.push(ab);
500 if let Some(ep) = config.parse_extern_private(ln) {
501 self.extern_private.push(ep);
504 if let Some(ee) = config.parse_env(ln, "exec-env") {
505 self.exec_env.push(ee);
508 if let Some(ee) = config.parse_env(ln, "rustc-env") {
509 self.rustc_env.push(ee);
512 if let Some(ev) = config.parse_name_value_directive(ln, "unset-rustc-env") {
513 self.unset_rustc_env.push(ev);
516 if let Some(cl) = config.parse_check_line(ln) {
517 self.check_lines.push(cl);
520 if let Some(of) = config.parse_forbid_output(ln) {
521 self.forbid_output.push(of);
524 if !self.check_test_line_numbers_match {
525 self.check_test_line_numbers_match = config.parse_check_test_line_numbers_match(ln);
529 self.run_pass = config.parse_run_pass(ln);
532 if !self.compile_pass {
533 // run-pass implies compile_pass
534 self.compile_pass = config.parse_compile_pass(ln) || self.run_pass;
537 if !self.skip_codegen {
538 self.skip_codegen = config.parse_skip_codegen(ln);
541 if !self.disable_ui_testing_normalization {
542 self.disable_ui_testing_normalization =
543 config.parse_disable_ui_testing_normalization(ln);
546 if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stdout") {
547 self.normalize_stdout.push(rule);
549 if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stderr") {
550 self.normalize_stderr.push(rule);
553 if let Some(code) = config.parse_failure_status(ln) {
554 self.failure_status = code;
557 if !self.run_rustfix {
558 self.run_rustfix = config.parse_run_rustfix(ln);
561 if !self.rustfix_only_machine_applicable {
562 self.rustfix_only_machine_applicable =
563 config.parse_rustfix_only_machine_applicable(ln);
566 if self.assembly_output.is_none() {
567 self.assembly_output = config.parse_assembly_output(ln);
571 if self.failure_status == -1 {
572 self.failure_status = match config.mode {
573 Mode::RunFail => 101,
578 for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
579 if let Ok(val) = env::var(key) {
580 if self.exec_env.iter().find(|&&(ref x, _)| x == key).is_none() {
581 self.exec_env.push(((*key).to_owned(), val))
588 fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
589 if testfile.is_dir() {
593 let comment = if testfile.to_string_lossy().ends_with(".rs") {
599 // FIXME: would be nice to allow some whitespace between comment and brace :)
600 // It took me like 2 days to debug why compile-flags weren’t taken into account for my test :)
601 let comment_with_brace = comment.to_string() + "[";
603 let rdr = BufReader::new(File::open(testfile).unwrap());
604 for ln in rdr.lines() {
605 // Assume that any directives will be found before the first
606 // module or function. This doesn't seem to be an optimization
607 // with a warm page cache. Maybe with a cold one.
608 let ln = ln.unwrap();
610 if ln.starts_with("fn") || ln.starts_with("mod") {
612 } else if ln.starts_with(&comment_with_brace) {
613 // A comment like `//[foo]` is specific to revision `foo`
614 if let Some(close_brace) = ln.find(']') {
615 let open_brace = ln.find('[').unwrap();
616 let lncfg = &ln[open_brace + 1 .. close_brace];
617 let matches = match cfg {
618 Some(s) => s == &lncfg[..],
622 it(ln[(close_brace + 1)..].trim_start());
625 panic!("malformed condition directive: expected `{}foo]`, found `{}`",
626 comment_with_brace, ln)
628 } else if ln.starts_with(comment) {
629 it(ln[comment.len() ..].trim_start());
636 fn parse_error_pattern(&self, line: &str) -> Option<String> {
637 self.parse_name_value_directive(line, "error-pattern")
640 fn parse_forbid_output(&self, line: &str) -> Option<String> {
641 self.parse_name_value_directive(line, "forbid-output")
644 fn parse_aux_build(&self, line: &str) -> Option<String> {
645 self.parse_name_value_directive(line, "aux-build")
646 .map(|r| r.trim().to_string())
649 fn parse_extern_private(&self, line: &str) -> Option<String> {
650 self.parse_name_value_directive(line, "extern-private")
653 fn parse_compile_flags(&self, line: &str) -> Option<String> {
654 self.parse_name_value_directive(line, "compile-flags")
657 fn parse_revisions(&self, line: &str) -> Option<Vec<String>> {
658 self.parse_name_value_directive(line, "revisions")
659 .map(|r| r.split_whitespace().map(|t| t.to_string()).collect())
662 fn parse_run_flags(&self, line: &str) -> Option<String> {
663 self.parse_name_value_directive(line, "run-flags")
666 fn parse_check_line(&self, line: &str) -> Option<String> {
667 self.parse_name_value_directive(line, "check")
670 fn parse_force_host(&self, line: &str) -> bool {
671 self.parse_name_directive(line, "force-host")
674 fn parse_build_aux_docs(&self, line: &str) -> bool {
675 self.parse_name_directive(line, "build-aux-docs")
678 fn parse_check_stdout(&self, line: &str) -> bool {
679 self.parse_name_directive(line, "check-stdout")
682 fn parse_dont_check_compiler_stdout(&self, line: &str) -> bool {
683 self.parse_name_directive(line, "dont-check-compiler-stdout")
686 fn parse_dont_check_compiler_stderr(&self, line: &str) -> bool {
687 self.parse_name_directive(line, "dont-check-compiler-stderr")
690 fn parse_no_prefer_dynamic(&self, line: &str) -> bool {
691 self.parse_name_directive(line, "no-prefer-dynamic")
694 fn parse_pretty_expanded(&self, line: &str) -> bool {
695 self.parse_name_directive(line, "pretty-expanded")
698 fn parse_pretty_mode(&self, line: &str) -> Option<String> {
699 self.parse_name_value_directive(line, "pretty-mode")
702 fn parse_pretty_compare_only(&self, line: &str) -> bool {
703 self.parse_name_directive(line, "pretty-compare-only")
706 fn parse_failure_status(&self, line: &str) -> Option<i32> {
707 match self.parse_name_value_directive(line, "failure-status") {
708 Some(code) => code.trim().parse::<i32>().ok(),
713 fn parse_compile_pass(&self, line: &str) -> bool {
714 self.parse_name_directive(line, "compile-pass")
717 fn parse_disable_ui_testing_normalization(&self, line: &str) -> bool {
718 self.parse_name_directive(line, "disable-ui-testing-normalization")
721 fn parse_check_test_line_numbers_match(&self, line: &str) -> bool {
722 self.parse_name_directive(line, "check-test-line-numbers-match")
725 fn parse_run_pass(&self, line: &str) -> bool {
726 self.parse_name_directive(line, "run-pass")
729 fn parse_skip_codegen(&self, line: &str) -> bool {
730 self.parse_name_directive(line, "skip-codegen")
733 fn parse_assembly_output(&self, line: &str) -> Option<String> {
734 self.parse_name_value_directive(line, "assembly-output")
735 .map(|r| r.trim().to_string())
738 fn parse_env(&self, line: &str, name: &str) -> Option<(String, String)> {
739 self.parse_name_value_directive(line, name).map(|nv| {
740 // nv is either FOO or FOO=BAR
741 let mut strs: Vec<String> = nv.splitn(2, '=').map(str::to_owned).collect();
744 1 => (strs.pop().unwrap(), String::new()),
746 let end = strs.pop().unwrap();
747 (strs.pop().unwrap(), end)
749 n => panic!("Expected 1 or 2 strings, not {}", n),
754 fn parse_pp_exact(&self, line: &str, testfile: &Path) -> Option<PathBuf> {
755 if let Some(s) = self.parse_name_value_directive(line, "pp-exact") {
756 Some(PathBuf::from(&s))
757 } else if self.parse_name_directive(line, "pp-exact") {
758 testfile.file_name().map(PathBuf::from)
764 fn parse_custom_normalization(&self, mut line: &str, prefix: &str) -> Option<(String, String)> {
765 if self.parse_cfg_name_directive(line, prefix) == ParsedNameDirective::Match {
766 let from = parse_normalization_string(&mut line)?;
767 let to = parse_normalization_string(&mut line)?;
774 fn parse_needs_matching_clang(&self, line: &str) -> bool {
775 self.parse_name_directive(line, "needs-matching-clang")
778 fn parse_needs_profiler_support(&self, line: &str) -> bool {
779 self.parse_name_directive(line, "needs-profiler-support")
782 fn parse_needs_sanitizer_support(&self, line: &str) -> bool {
783 self.parse_name_directive(line, "needs-sanitizer-support")
786 /// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
787 /// or `normalize-stderr-32bit`.
788 fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> ParsedNameDirective {
789 if line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-') {
790 let name = line[prefix.len() + 1..]
791 .split(&[':', ' '][..])
796 util::matches_os(&self.target, name) || // target
797 name == util::get_arch(&self.target) || // architecture
798 name == util::get_pointer_width(&self.target) || // pointer width
799 name == self.stage_id.split('-').next().unwrap() || // stage
800 Some(name) == util::get_env(&self.target) || // env
801 (self.target != self.host && name == "cross-compile") ||
802 match self.compare_mode {
803 Some(CompareMode::Nll) => name == "compare-mode-nll",
804 Some(CompareMode::Polonius) => name == "compare-mode-polonius",
807 (cfg!(debug_assertions) && name == "debug") {
808 ParsedNameDirective::Match
811 common::DebugInfoGdbLldb => {
813 ParsedNameDirective::MatchGdb
814 } else if name == "lldb" {
815 ParsedNameDirective::MatchLldb
817 ParsedNameDirective::NoMatch
820 common::DebugInfoCdb => if name == "cdb" {
821 ParsedNameDirective::Match
823 ParsedNameDirective::NoMatch
825 common::DebugInfoGdb => if name == "gdb" {
826 ParsedNameDirective::Match
828 ParsedNameDirective::NoMatch
830 common::DebugInfoLldb => if name == "lldb" {
831 ParsedNameDirective::Match
833 ParsedNameDirective::NoMatch
835 common::Pretty => if name == "pretty" {
836 ParsedNameDirective::Match
838 ParsedNameDirective::NoMatch
840 _ => ParsedNameDirective::NoMatch,
844 ParsedNameDirective::NoMatch
848 fn has_cfg_prefix(&self, line: &str, prefix: &str) -> bool {
849 // returns whether this line contains this prefix or not. For prefix
850 // "ignore", returns true if line says "ignore-x86_64", "ignore-arch",
851 // "ignore-android" etc.
852 line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-')
855 fn parse_name_directive(&self, line: &str, directive: &str) -> bool {
856 // Ensure the directive is a whole word. Do not match "ignore-x86" when
857 // the line says "ignore-x86_64".
858 line.starts_with(directive) && match line.as_bytes().get(directive.len()) {
859 None | Some(&b' ') | Some(&b':') => true,
864 pub fn parse_name_value_directive(&self, line: &str, directive: &str) -> Option<String> {
865 let colon = directive.len();
866 if line.starts_with(directive) && line.as_bytes().get(colon) == Some(&b':') {
867 let value = line[(colon + 1)..].to_owned();
868 debug!("{}: {}", directive, value);
869 Some(expand_variables(value, self))
875 pub fn find_rust_src_root(&self) -> Option<PathBuf> {
876 let mut path = self.src_base.clone();
877 let path_postfix = Path::new("src/etc/lldb_batchmode.py");
880 if path.join(&path_postfix).is_file() {
888 fn parse_run_rustfix(&self, line: &str) -> bool {
889 self.parse_name_directive(line, "run-rustfix")
892 fn parse_rustfix_only_machine_applicable(&self, line: &str) -> bool {
893 self.parse_name_directive(line, "rustfix-only-machine-applicable")
896 fn parse_edition(&self, line: &str) -> Option<String> {
897 self.parse_name_value_directive(line, "edition")
901 pub fn lldb_version_to_int(version_string: &str) -> isize {
902 let error_string = format!(
903 "Encountered LLDB version string with unexpected format: {}",
906 version_string.parse().expect(&error_string)
909 fn expand_variables(mut value: String, config: &Config) -> String {
910 const CWD: &'static str = "{{cwd}}";
911 const SRC_BASE: &'static str = "{{src-base}}";
912 const BUILD_BASE: &'static str = "{{build-base}}";
914 if value.contains(CWD) {
915 let cwd = env::current_dir().unwrap();
916 value = value.replace(CWD, &cwd.to_string_lossy());
919 if value.contains(SRC_BASE) {
920 value = value.replace(SRC_BASE, &config.src_base.to_string_lossy());
923 if value.contains(BUILD_BASE) {
924 value = value.replace(BUILD_BASE, &config.build_base.to_string_lossy());
930 /// Finds the next quoted string `"..."` in `line`, and extract the content from it. Move the `line`
931 /// variable after the end of the quoted string.
936 /// let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\".";
937 /// let first = parse_normalization_string(&mut s);
938 /// assert_eq!(first, Some("something (32 bits)".to_owned()));
939 /// assert_eq!(s, " -> \"something ($WORD bits)\".");
941 fn parse_normalization_string(line: &mut &str) -> Option<String> {
942 // FIXME support escapes in strings.
943 let begin = line.find('"')? + 1;
944 let end = line[begin..].find('"')? + begin;
945 let result = line[begin..end].to_owned();
946 *line = &line[end + 1..];
951 fn test_parse_normalization_string() {
952 let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\".";
953 let first = parse_normalization_string(&mut s);
954 assert_eq!(first, Some("something (32 bits)".to_owned()));
955 assert_eq!(s, " -> \"something ($WORD bits)\".");
957 // Nothing to normalize (No quotes)
958 let mut s = "normalize-stderr-32bit: something (32 bits) -> something ($WORD bits).";
959 let first = parse_normalization_string(&mut s);
960 assert_eq!(first, None);
961 assert_eq!(s, r#"normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)."#);
963 // Nothing to normalize (Only a single quote)
964 let mut s = "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits).";
965 let first = parse_normalization_string(&mut s);
966 assert_eq!(first, None);
967 assert_eq!(s, "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits).");
969 // Nothing to normalize (Three quotes)
970 let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits).";
971 let first = parse_normalization_string(&mut s);
972 assert_eq!(first, Some("something (32 bits)".to_owned()));
973 assert_eq!(s, " -> \"something ($WORD bits).");