]>
git.proxmox.com Git - rustc.git/blob - vendor/compiletest_rs/src/common.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 pub use self::Mode
::*;
14 use std
::fs
::{read_dir, remove_file}
;
15 use std
::str::FromStr
;
16 use std
::path
::PathBuf
;
17 #[cfg(feature = "rustc")]
20 use test
::ColorConfig
;
21 use runtest
::dylib_env_var
;
23 #[derive(Clone, Copy, PartialEq, Debug)]
44 pub fn disambiguator(self) -> &'
static str {
45 // Run-pass and pretty run-pass tests could run concurrently, and if they do,
46 // they need to keep their output segregated. Same is true for debuginfo tests that
47 // can be run both on gdb and lldb.
50 DebugInfoGdb
=> ".gdb",
51 DebugInfoLldb
=> ".lldb",
57 impl FromStr
for Mode
{
59 fn from_str(s
: &str) -> Result
<Mode
, ()> {
61 "compile-fail" => Ok(CompileFail
),
62 "parse-fail" => Ok(ParseFail
),
63 "run-fail" => Ok(RunFail
),
64 "run-pass" => Ok(RunPass
),
65 "run-pass-valgrind" => Ok(RunPassValgrind
),
66 "pretty" => Ok(Pretty
),
67 "debuginfo-lldb" => Ok(DebugInfoLldb
),
68 "debuginfo-gdb" => Ok(DebugInfoGdb
),
69 "codegen" => Ok(Codegen
),
70 "rustdoc" => Ok(Rustdoc
),
71 "codegen-units" => Ok(CodegenUnits
),
72 "incremental" => Ok(Incremental
),
73 "run-make" => Ok(RunMake
),
75 "mir-opt" => Ok(MirOpt
),
76 "assembly" => Ok(Assembly
),
82 impl fmt
::Display
for Mode
{
83 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
84 fmt
::Display
::fmt(match *self {
85 CompileFail
=> "compile-fail",
86 ParseFail
=> "parse-fail",
87 RunFail
=> "run-fail",
88 RunPass
=> "run-pass",
89 RunPassValgrind
=> "run-pass-valgrind",
91 DebugInfoGdb
=> "debuginfo-gdb",
92 DebugInfoLldb
=> "debuginfo-lldb",
95 CodegenUnits
=> "codegen-units",
96 Incremental
=> "incremental",
97 RunMake
=> "run-make",
100 Assembly
=> "assembly",
108 /// `true` to overwrite stderr/stdout/fixed files instead of complaining about changes in output.
111 /// The library paths required for running the compiler
112 pub compile_lib_path
: PathBuf
,
114 /// The library paths required for running compiled programs
115 pub run_lib_path
: PathBuf
,
117 /// The rustc executable
118 pub rustc_path
: PathBuf
,
120 /// The rustdoc executable
121 pub rustdoc_path
: Option
<PathBuf
>,
123 /// The python executable to use for LLDB
124 pub lldb_python
: String
,
126 /// The python executable to use for htmldocck
127 pub docck_python
: String
,
129 /// The llvm FileCheck binary path
130 pub llvm_filecheck
: Option
<PathBuf
>,
132 /// The valgrind path
133 pub valgrind_path
: Option
<String
>,
135 /// Whether to fail if we can't run run-pass-valgrind tests under valgrind
136 /// (or, alternatively, to silently run them like regular run-pass tests).
137 pub force_valgrind
: bool
,
139 /// The directory containing the tests to run
140 pub src_base
: PathBuf
,
142 /// The directory where programs should be built
143 pub build_base
: PathBuf
,
145 /// The name of the stage being built (stage1, etc)
146 pub stage_id
: String
,
148 /// The test mode, compile-fail, run-fail, run-pass
151 /// Run ignored tests
152 pub run_ignored
: bool
,
154 /// Only run tests that match these filters
155 pub filters
: Vec
<String
>,
157 /// Exactly match the filter, rather than a substring
158 pub filter_exact
: bool
,
160 /// Write out a parseable log of tests that were run
161 pub logfile
: Option
<PathBuf
>,
163 /// A command line to prefix program execution with,
164 /// for running under valgrind
165 pub runtool
: Option
<String
>,
167 /// Flags to pass to the compiler when building for the host
168 pub host_rustcflags
: Option
<String
>,
170 /// Flags to pass to the compiler when building for the target
171 pub target_rustcflags
: Option
<String
>,
173 /// Target system to be tested
176 /// Host triple for the compiler being invoked
179 /// Path to / name of the GDB executable
180 pub gdb
: Option
<String
>,
182 /// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch
183 pub gdb_version
: Option
<u32>,
185 /// Whether GDB has native rust support
186 pub gdb_native_rust
: bool
,
189 pub lldb_version
: Option
<String
>,
192 pub llvm_version
: Option
<String
>,
194 /// Is LLVM a system LLVM
195 pub system_llvm
: bool
,
197 /// Path to the android tools
198 pub android_cross_path
: PathBuf
,
200 /// Extra parameter to run adb on arm-linux-androideabi
201 pub adb_path
: String
,
203 /// Extra parameter to run test suite on arm-linux-androideabi
204 pub adb_test_dir
: String
,
206 /// status whether android device available or not
207 pub adb_device_status
: bool
,
209 /// the path containing LLDB's Python module
210 pub lldb_python_dir
: Option
<String
>,
212 /// Explain what's going on
215 /// Print one character per test instead of one line
218 /// Whether to use colors in test.
219 pub color
: ColorConfig
,
221 /// where to find the remote test client process, if we're using it
222 pub remote_test_client
: Option
<PathBuf
>,
224 /// If true, this will generate a coverage file with UI test files that run `MachineApplicable`
225 /// diagnostics but are missing `run-rustfix` annotations. The generated coverage file is
226 /// created in `/<build_base>/rustfix_missing_coverage.txt`
227 pub rustfix_coverage
: bool
,
229 // Configuration for various run-make tests frobbing things like C compilers
230 // or querying about various LLVM component information.
235 pub linker
: Option
<String
>,
236 pub llvm_components
: String
,
237 pub llvm_cxxflags
: String
,
238 pub nodejs
: Option
<String
>,
242 pub struct TestPaths
{
243 pub file
: PathBuf
, // e.g., compile-test/foo/bar/baz.rs
244 pub base
: PathBuf
, // e.g., compile-test, auxiliary
245 pub relative_dir
: PathBuf
, // e.g., foo/bar
248 /// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
249 pub fn expected_output_path(
250 testpaths
: &TestPaths
,
251 revision
: Option
<&str>,
254 assert
!(UI_EXTENSIONS
.contains(&kind
));
255 let mut parts
= Vec
::new();
257 if let Some(x
) = revision
{
262 let extension
= parts
.join(".");
263 testpaths
.file
.with_extension(extension
)
266 pub const UI_EXTENSIONS
: &[&str] = &[UI_STDERR
, UI_STDOUT
, UI_FIXED
];
267 pub const UI_STDERR
: &str = "stderr";
268 pub const UI_STDOUT
: &str = "stdout";
269 pub const UI_FIXED
: &str = "fixed";
272 /// Add rustc flags to link with the crate's dependencies in addition to the crate itself
273 pub fn link_deps(&mut self) {
274 let varname
= dylib_env_var();
276 // Dependencies can be found in the environment variable. Throw everything there into the
278 let lib_paths
= env
::var(varname
).unwrap_or_else(|err
| match err
{
279 env
::VarError
::NotPresent
=> String
::new(),
280 err
=> panic
!("can't get {} environment variable: {}", varname
, err
),
283 // Append to current flags if any are set, otherwise make new String
284 let mut flags
= self.target_rustcflags
.take().unwrap_or_else(String
::new
);
285 if !lib_paths
.is_empty() {
286 for p
in env
::split_paths(&lib_paths
) {
288 flags
+= p
.to_str().unwrap(); // Can't fail. We already know this is unicode
292 self.target_rustcflags
= Some(flags
);
295 /// Remove rmeta files from target `deps` directory
297 /// These files are created by `cargo check`, and conflict with
298 /// `cargo build` rlib files, causing E0464 for tests which use
299 /// the parent crate.
300 pub fn clean_rmeta(&self) {
301 if self.target_rustcflags
.is_some() {
302 for directory
in self.target_rustcflags
306 .filter(|s
| s
.ends_with("/deps"))
308 if let Ok(mut entries
) = read_dir(directory
) {
309 while let Some(Ok(entry
)) = entries
.next() {
310 if entry
.file_name().to_string_lossy().ends_with(".rmeta") {
311 let _
= remove_file(entry
.path());
319 #[cfg(feature = "tmp")]
320 pub fn tempdir(mut self) -> ConfigWithTemp
{
321 let tmp
= tempfile
::Builder
::new().prefix("compiletest").tempdir()
322 .expect("failed to create temporary directory");
323 self.build_base
= tmp
.path().to_owned();
324 config_tempdir
::ConfigWithTemp
{
331 #[cfg(feature = "tmp")]
336 pub struct ConfigWithTemp
{
337 pub config
: super::Config
,
338 pub tempdir
: tempfile
::TempDir
,
341 impl ops
::Deref
for ConfigWithTemp
{
342 type Target
= super::Config
;
344 fn deref(&self) -> &Self::Target
{
349 impl ops
::DerefMut
for ConfigWithTemp
{
350 fn deref_mut(&mut self) -> &mut Self::Target
{
356 #[cfg(feature = "tmp")]
357 pub use self::config_tempdir
::ConfigWithTemp
;
360 impl Default
for Config
{
361 fn default() -> Config
{
362 #[cfg(feature = "rustc")]
363 let platform
= rustc_session
::config
::host_triple().to_string();
367 compile_lib_path
: PathBuf
::from(""),
368 run_lib_path
: PathBuf
::from(""),
369 rustc_path
: PathBuf
::from("rustc"),
371 lldb_python
: "python".to_owned(),
372 docck_python
: "docck-python".to_owned(),
374 force_valgrind
: false,
375 llvm_filecheck
: None
,
376 src_base
: PathBuf
::from("tests/run-pass"),
377 build_base
: env
::temp_dir(),
378 stage_id
: "stage-id".to_owned(),
385 host_rustcflags
: None
,
386 target_rustcflags
: None
,
387 #[cfg(feature = "rustc")]
388 target
: platform
.clone(),
389 #[cfg(not(feature = "rustc"))]
390 target
: env
!("TARGET").to_string(),
391 #[cfg(feature = "rustc")]
392 host
: platform
.clone(),
393 #[cfg(not(feature = "rustc"))]
394 host
: env
!("HOST").to_string(),
395 rustfix_coverage
: false,
398 gdb_native_rust
: false,
402 android_cross_path
: PathBuf
::from("android-cross-path"),
403 adb_path
: "adb-path".to_owned(),
404 adb_test_dir
: "adb-test-dir/target".to_owned(),
405 adb_device_status
: false,
406 lldb_python_dir
: None
,
409 color
: ColorConfig
::AutoColor
,
410 remote_test_client
: None
,
411 cc
: "cc".to_string(),
412 cxx
: "cxx".to_string(),
413 cflags
: "cflags".to_string(),
414 ar
: "ar".to_string(),
416 llvm_components
: "llvm-components".to_string(),
417 llvm_cxxflags
: "llvm-cxxflags".to_string(),