Skip to content

Commit 6b05753

Browse files
committed
Run the tests of popular crates in the CI
1 parent 8235b26 commit 6b05753

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
"--extended-regex-tests",
3333
"--test-successful-rustc --nb-parts 2 --current-part 0",
3434
"--test-successful-rustc --nb-parts 2 --current-part 1",
35+
"--projects",
3536
]
3637

3738
steps:

build_system/src/prepare.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn clone_and_setup<F>(repo_url: &str, checkout_commit: &str, extra: Option<F>) -
152152
where
153153
F: Fn(&Path) -> Result<(), String>,
154154
{
155-
let clone_result = git_clone(repo_url, None)?;
155+
let clone_result = git_clone(repo_url, None, false)?;
156156
if !clone_result.ran_clone {
157157
println!("`{}` has already been cloned", clone_result.repo_name);
158158
}

build_system/src/test.rs

+54-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use crate::build;
22
use crate::config::{Channel, ConfigInfo};
33
use crate::utils::{
4-
get_gcc_path, get_toolchain, remove_file, run_command, run_command_with_env,
4+
get_gcc_path, get_toolchain, git_clone, remove_file, run_command, run_command_with_env,
55
run_command_with_output_and_env, rustc_version_info, split_args, walk_dir,
66
};
77

88
use std::collections::{BTreeSet, HashMap};
99
use std::ffi::OsStr;
10-
use std::fs::{remove_dir_all, File};
10+
use std::fs::{create_dir_all, remove_dir_all, File};
1111
use std::io::{BufRead, BufReader};
1212
use std::path::{Path, PathBuf};
1313
use std::str::FromStr;
@@ -31,6 +31,7 @@ fn get_runners() -> Runners {
3131
"--test-failing-rustc",
3232
("Run failing rustc tests", test_failing_rustc),
3333
);
34+
runners.insert("--projects", ("Run the tests of popular crates", test_projects));
3435
runners.insert("--test-libcore", ("Run libcore tests", test_libcore));
3536
runners.insert("--clean", ("Empty cargo target directory", clean));
3637
runners.insert("--build-sysroot", ("Build sysroot", build_sysroot));
@@ -679,6 +680,57 @@ where
679680
// echo "[BUILD] sysroot in release mode"
680681
// ./build_sysroot/build_sysroot.sh --release
681682

683+
fn test_projects(env: &Env, args: &TestArg) -> Result<(), String> {
684+
let projects = [
685+
//"https://gitlab.gnome.org/GNOME/librsvg", // FIXME: doesn't compile in the CI since the
686+
// version of cairo and other libraries is too old.
687+
"https://github.com/rust-random/getrandom",
688+
"https://github.com/BurntSushi/memchr",
689+
"https://github.com/dtolnay/itoa",
690+
"https://github.com/rust-lang/cfg-if",
691+
"https://github.com/rust-lang-nursery/lazy-static.rs",
692+
//"https://github.com/marshallpierce/rust-base64", // FIXME: one test is OOM-killed.
693+
// TODO: ignore the base64 test that is OOM-killed.
694+
"https://github.com/time-rs/time",
695+
"https://github.com/rust-lang/log",
696+
"https://github.com/bitflags/bitflags",
697+
//"https://github.com/serde-rs/serde", // FIXME: one test fails.
698+
//"https://github.com/rayon-rs/rayon", // TODO: very slow, only run on master?
699+
//"https://github.com/rust-lang/cargo", // TODO: very slow, only run on master?
700+
];
701+
702+
let run_tests = |projects_path, iter: &mut dyn Iterator<Item=&&str>| -> Result<(), String> {
703+
for project in iter {
704+
let clone_result = git_clone(project, Some(projects_path), true)?;
705+
let repo_path = Path::new(&clone_result.repo_dir);
706+
run_cargo_command(&[&"build", &"--release"], Some(repo_path), env, args)?;
707+
run_cargo_command(&[&"test"], Some(repo_path), env, args)?;
708+
}
709+
710+
Ok(())
711+
};
712+
713+
let projects_path = Path::new("projects");
714+
create_dir_all(projects_path)
715+
.map_err(|err| format!("Failed to create directory `projects`: {}", err))?;
716+
717+
let nb_parts = args.nb_parts.unwrap_or(0);
718+
if nb_parts > 0 {
719+
// We increment the number of tests by one because if this is an odd number, we would skip
720+
// one test.
721+
let count = projects.len() / nb_parts + 1;
722+
let current_part = args.current_part.unwrap();
723+
let start = current_part * count;
724+
// We remove the projects we don't want to test.
725+
run_tests(projects_path, &mut projects.iter().skip(start).take(count))?;
726+
}
727+
else {
728+
run_tests(projects_path, &mut projects.iter())?;
729+
}
730+
731+
Ok(())
732+
}
733+
682734
fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> {
683735
// FIXME: create a function "display_if_not_quiet" or something along the line.
684736
println!("[TEST] libcore");

build_system/src/utils.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,10 @@ pub fn get_gcc_path() -> Result<String, String> {
283283
pub struct CloneResult {
284284
pub ran_clone: bool,
285285
pub repo_name: String,
286+
pub repo_dir: String,
286287
}
287288

288-
pub fn git_clone(to_clone: &str, dest: Option<&Path>) -> Result<CloneResult, String> {
289+
pub fn git_clone(to_clone: &str, dest: Option<&Path>, shallow_clone: bool) -> Result<CloneResult, String> {
289290
let repo_name = to_clone.split('/').last().unwrap();
290291
let repo_name = match repo_name.strip_suffix(".git") {
291292
Some(n) => n.to_string(),
@@ -299,13 +300,20 @@ pub fn git_clone(to_clone: &str, dest: Option<&Path>) -> Result<CloneResult, Str
299300
return Ok(CloneResult {
300301
ran_clone: false,
301302
repo_name,
303+
repo_dir: dest.display().to_string(),
302304
});
303305
}
304306

305-
run_command_with_output(&[&"git", &"clone", &to_clone, &dest], None)?;
307+
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"git", &"clone", &to_clone, &dest];
308+
if shallow_clone {
309+
command.push(&"--depth");
310+
command.push(&"1");
311+
}
312+
run_command_with_output(&command, None)?;
306313
Ok(CloneResult {
307314
ran_clone: true,
308315
repo_name,
316+
repo_dir: dest.display().to_string(),
309317
})
310318
}
311319

0 commit comments

Comments
 (0)