PageRenderTime 56ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/tools/cargotest/main.rs

https://bitbucket.org/sailfish009/rust
Rust | 139 lines | 120 code | 14 blank | 5 comment | 9 complexity | 8a2fe863c00b9d385b451cd4369e17d9 MD5 | raw file
Possible License(s): Apache-2.0, 0BSD, JSON, MIT
  1. use std::env;
  2. use std::fs;
  3. use std::path::{Path, PathBuf};
  4. use std::process::Command;
  5. struct Test {
  6. repo: &'static str,
  7. name: &'static str,
  8. sha: &'static str,
  9. lock: Option<&'static str>,
  10. packages: &'static [&'static str],
  11. }
  12. const TEST_REPOS: &[Test] = &[
  13. Test {
  14. name: "iron",
  15. repo: "https://github.com/iron/iron",
  16. sha: "cf056ea5e8052c1feea6141e40ab0306715a2c33",
  17. lock: None,
  18. packages: &[],
  19. },
  20. Test {
  21. name: "ripgrep",
  22. repo: "https://github.com/BurntSushi/ripgrep",
  23. sha: "ad9befbc1d3b5c695e7f6b6734ee1b8e683edd41",
  24. lock: None,
  25. packages: &[],
  26. },
  27. Test {
  28. name: "tokei",
  29. repo: "https://github.com/XAMPPRocky/tokei",
  30. sha: "a950ff128d5a435a8083b1c7577c0431f98360ca",
  31. lock: None,
  32. packages: &[],
  33. },
  34. Test {
  35. name: "xsv",
  36. repo: "https://github.com/BurntSushi/xsv",
  37. sha: "66956b6bfd62d6ac767a6b6499c982eae20a2c9f",
  38. lock: None,
  39. packages: &[],
  40. },
  41. Test {
  42. name: "servo",
  43. repo: "https://github.com/servo/servo",
  44. sha: "caac107ae8145ef2fd20365e2b8fadaf09c2eb3b",
  45. lock: None,
  46. // Only test Stylo a.k.a. Quantum CSS, the parts of Servo going into Firefox.
  47. // This takes much less time to build than all of Servo and supports stable Rust.
  48. packages: &["selectors"],
  49. },
  50. ];
  51. fn main() {
  52. let args = env::args().collect::<Vec<_>>();
  53. let cargo = &args[1];
  54. let out_dir = Path::new(&args[2]);
  55. let cargo = &Path::new(cargo);
  56. for test in TEST_REPOS.iter().rev() {
  57. test_repo(cargo, out_dir, test);
  58. }
  59. }
  60. fn test_repo(cargo: &Path, out_dir: &Path, test: &Test) {
  61. println!("testing {}", test.repo);
  62. let dir = clone_repo(test, out_dir);
  63. if let Some(lockfile) = test.lock {
  64. fs::write(&dir.join("Cargo.lock"), lockfile).unwrap();
  65. }
  66. if !run_cargo_test(cargo, &dir, test.packages) {
  67. panic!("tests failed for {}", test.repo);
  68. }
  69. }
  70. fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf {
  71. let out_dir = out_dir.join(test.name);
  72. if !out_dir.join(".git").is_dir() {
  73. let status = Command::new("git").arg("init").arg(&out_dir).status().unwrap();
  74. assert!(status.success());
  75. }
  76. // Try progressively deeper fetch depths to find the commit
  77. let mut found = false;
  78. for depth in &[0, 1, 10, 100, 1000, 100000] {
  79. if *depth > 0 {
  80. let status = Command::new("git")
  81. .arg("fetch")
  82. .arg(test.repo)
  83. .arg("master")
  84. .arg(&format!("--depth={}", depth))
  85. .current_dir(&out_dir)
  86. .status()
  87. .unwrap();
  88. assert!(status.success());
  89. }
  90. let status = Command::new("git")
  91. .arg("reset")
  92. .arg(test.sha)
  93. .arg("--hard")
  94. .current_dir(&out_dir)
  95. .status()
  96. .unwrap();
  97. if status.success() {
  98. found = true;
  99. break;
  100. }
  101. }
  102. if !found {
  103. panic!("unable to find commit {}", test.sha)
  104. }
  105. let status =
  106. Command::new("git").arg("clean").arg("-fdx").current_dir(&out_dir).status().unwrap();
  107. assert!(status.success());
  108. out_dir
  109. }
  110. fn run_cargo_test(cargo_path: &Path, crate_path: &Path, packages: &[&str]) -> bool {
  111. let mut command = Command::new(cargo_path);
  112. command.arg("test");
  113. for name in packages {
  114. command.arg("-p").arg(name);
  115. }
  116. let status = command
  117. // Disable rust-lang/cargo's cross-compile tests
  118. .env("CFG_DISABLE_CROSS_TESTS", "1")
  119. // Relax #![deny(warnings)] in some crates
  120. .env("RUSTFLAGS", "--cap-lints warn")
  121. .current_dir(crate_path)
  122. .status()
  123. .unwrap();
  124. status.success()
  125. }