PageRenderTime 33ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/tools/cargotest/main.rs

https://gitlab.com/jianglu/rust
Rust | 175 lines | 146 code | 15 blank | 14 comment | 9 complexity | 6792f686cdbfe1227f19efe707727c34 MD5 | raw file
  1. // Copyright 2016 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.
  4. //
  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. use std::env;
  11. use std::process::Command;
  12. use std::path::{Path, PathBuf};
  13. use std::fs::File;
  14. use std::io::Write;
  15. struct Test {
  16. repo: &'static str,
  17. name: &'static str,
  18. sha: &'static str,
  19. lock: Option<&'static str>,
  20. packages: &'static [&'static str],
  21. }
  22. const TEST_REPOS: &'static [Test] = &[
  23. Test {
  24. name: "iron",
  25. repo: "https://github.com/iron/iron",
  26. sha: "21c7dae29c3c214c08533c2a55ac649b418f2fe3",
  27. lock: Some(include_str!("lockfiles/iron-Cargo.lock")),
  28. packages: &[],
  29. },
  30. Test {
  31. name: "ripgrep",
  32. repo: "https://github.com/BurntSushi/ripgrep",
  33. sha: "b65bb37b14655e1a89c7cd19c8b011ef3e312791",
  34. lock: None,
  35. packages: &[],
  36. },
  37. Test {
  38. name: "tokei",
  39. repo: "https://github.com/Aaronepower/tokei",
  40. sha: "5e11c4852fe4aa086b0e4fe5885822fbe57ba928",
  41. lock: None,
  42. packages: &[],
  43. },
  44. Test {
  45. name: "treeify",
  46. repo: "https://github.com/dzamlo/treeify",
  47. sha: "999001b223152441198f117a68fb81f57bc086dd",
  48. lock: None,
  49. packages: &[],
  50. },
  51. Test {
  52. name: "xsv",
  53. repo: "https://github.com/BurntSushi/xsv",
  54. sha: "66956b6bfd62d6ac767a6b6499c982eae20a2c9f",
  55. lock: None,
  56. packages: &[],
  57. },
  58. Test {
  59. name: "servo",
  60. repo: "https://github.com/servo/servo",
  61. sha: "17e97b9320fdb7cdb33bbc5f4d0fde0653bbf2e4",
  62. lock: None,
  63. // Only test Stylo a.k.a. Quantum CSS, the parts of Servo going into Firefox.
  64. // This takes much less time to build than all of Servo and supports stable Rust.
  65. packages: &["stylo_tests", "selectors"],
  66. },
  67. Test {
  68. name: "webrender",
  69. repo: "https://github.com/servo/webrender",
  70. sha: "57250b2b8fa63934f80e5376a29f7dcb3f759ad6",
  71. lock: None,
  72. packages: &[],
  73. },
  74. ];
  75. fn main() {
  76. let args = env::args().collect::<Vec<_>>();
  77. let ref cargo = args[1];
  78. let out_dir = Path::new(&args[2]);
  79. let ref cargo = Path::new(cargo);
  80. for test in TEST_REPOS.iter().rev() {
  81. test_repo(cargo, out_dir, test);
  82. }
  83. }
  84. fn test_repo(cargo: &Path, out_dir: &Path, test: &Test) {
  85. println!("testing {}", test.repo);
  86. let dir = clone_repo(test, out_dir);
  87. if let Some(lockfile) = test.lock {
  88. File::create(&dir.join("Cargo.lock"))
  89. .expect("")
  90. .write_all(lockfile.as_bytes())
  91. .expect("");
  92. }
  93. if !run_cargo_test(cargo, &dir, test.packages) {
  94. panic!("tests failed for {}", test.repo);
  95. }
  96. }
  97. fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf {
  98. let out_dir = out_dir.join(test.name);
  99. if !out_dir.join(".git").is_dir() {
  100. let status = Command::new("git")
  101. .arg("init")
  102. .arg(&out_dir)
  103. .status()
  104. .expect("");
  105. assert!(status.success());
  106. }
  107. // Try progressively deeper fetch depths to find the commit
  108. let mut found = false;
  109. for depth in &[0, 1, 10, 100, 1000, 100000] {
  110. if *depth > 0 {
  111. let status = Command::new("git")
  112. .arg("fetch")
  113. .arg(test.repo)
  114. .arg("master")
  115. .arg(&format!("--depth={}", depth))
  116. .current_dir(&out_dir)
  117. .status()
  118. .expect("");
  119. assert!(status.success());
  120. }
  121. let status = Command::new("git")
  122. .arg("reset")
  123. .arg(test.sha)
  124. .arg("--hard")
  125. .current_dir(&out_dir)
  126. .status()
  127. .expect("");
  128. if status.success() {
  129. found = true;
  130. break;
  131. }
  132. }
  133. if !found {
  134. panic!("unable to find commit {}", test.sha)
  135. }
  136. let status = Command::new("git")
  137. .arg("clean")
  138. .arg("-fdx")
  139. .current_dir(&out_dir)
  140. .status()
  141. .unwrap();
  142. assert!(status.success());
  143. out_dir
  144. }
  145. fn run_cargo_test(cargo_path: &Path, crate_path: &Path, packages: &[&str]) -> bool {
  146. let mut command = Command::new(cargo_path);
  147. command.arg("test");
  148. for name in packages {
  149. command.arg("-p").arg(name);
  150. }
  151. let status = command
  152. // Disable rust-lang/cargo's cross-compile tests
  153. .env("CFG_DISABLE_CROSS_TESTS", "1")
  154. // Relax #![deny(warnings)] in some crates
  155. .env("RUSTFLAGS", "--cap-lints warn")
  156. .current_dir(crate_path)
  157. .status()
  158. .expect("");
  159. status.success()
  160. }