Skip to content

Commit 1aa0cf9

Browse files
committed
Unconditionally use git to download test repos
It no longer saves much download time while still complicating the code and requiring curl and tar to be installed.
1 parent 45be990 commit 1aa0cf9

File tree

3 files changed

+7
-73
lines changed

3 files changed

+7
-73
lines changed

build_system/prepare.rs

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use std::path::{Path, PathBuf};
55
use std::process::Command;
66

77
use crate::path::{Dirs, RelPath};
8-
use crate::utils::{
9-
copy_dir_recursively, remove_dir_if_exists, retry_spawn_and_wait, spawn_and_wait,
10-
};
8+
use crate::utils::{copy_dir_recursively, remove_dir_if_exists, spawn_and_wait};
119

1210
pub(crate) fn prepare(dirs: &Dirs) {
1311
RelPath::DOWNLOAD.ensure_exists(dirs);
@@ -110,7 +108,11 @@ impl GitRepo {
110108

111109
match self.url {
112110
GitRepoUrl::Github { user, repo } => {
113-
clone_repo_shallow_github(dirs, &download_dir, user, repo, self.rev);
111+
clone_repo(
112+
&download_dir,
113+
&format!("https://github.com/{}/{}.git", user, repo),
114+
self.rev,
115+
);
114116
}
115117
}
116118

@@ -145,7 +147,6 @@ impl GitRepo {
145147
}
146148
}
147149

148-
#[allow(dead_code)]
149150
fn clone_repo(download_dir: &Path, repo: &str, rev: &str) {
150151
eprintln!("[CLONE] {}", repo);
151152
// Ignore exit code as the repo may already have been checked out
@@ -162,55 +163,6 @@ fn clone_repo(download_dir: &Path, repo: &str, rev: &str) {
162163
std::fs::remove_dir_all(download_dir.join(".git")).unwrap();
163164
}
164165

165-
fn clone_repo_shallow_github(dirs: &Dirs, download_dir: &Path, user: &str, repo: &str, rev: &str) {
166-
if cfg!(windows) {
167-
// Older windows doesn't have tar or curl by default. Fall back to using git.
168-
clone_repo(download_dir, &format!("https://github.com/{}/{}.git", user, repo), rev);
169-
return;
170-
}
171-
172-
let archive_url = format!("https://github.com/{}/{}/archive/{}.tar.gz", user, repo, rev);
173-
let archive_file = RelPath::DOWNLOAD.to_path(dirs).join(format!("{}.tar.gz", rev));
174-
let archive_dir = RelPath::DOWNLOAD.to_path(dirs).join(format!("{}-{}", repo, rev));
175-
176-
eprintln!("[DOWNLOAD] {}/{} from {}", user, repo, archive_url);
177-
178-
// Remove previous results if they exists
179-
let _ = std::fs::remove_file(&archive_file);
180-
let _ = std::fs::remove_dir_all(&archive_dir);
181-
let _ = std::fs::remove_dir_all(&download_dir);
182-
183-
// Download zip archive
184-
let mut download_cmd = Command::new("curl");
185-
download_cmd
186-
.arg("--max-time")
187-
.arg("600")
188-
.arg("-y")
189-
.arg("30")
190-
.arg("-Y")
191-
.arg("10")
192-
.arg("--connect-timeout")
193-
.arg("30")
194-
.arg("--continue-at")
195-
.arg("-")
196-
.arg("--location")
197-
.arg("--output")
198-
.arg(&archive_file)
199-
.arg(archive_url);
200-
retry_spawn_and_wait(5, download_cmd);
201-
202-
// Unpack tar archive
203-
let mut unpack_cmd = Command::new("tar");
204-
unpack_cmd.arg("xf").arg(&archive_file).current_dir(RelPath::DOWNLOAD.to_path(dirs));
205-
spawn_and_wait(unpack_cmd);
206-
207-
// Rename unpacked dir to the expected name
208-
std::fs::rename(archive_dir, &download_dir).unwrap();
209-
210-
// Cleanup
211-
std::fs::remove_file(archive_file).unwrap();
212-
}
213-
214166
fn init_git_repo(repo_dir: &Path) {
215167
let mut git_init_cmd = git_command(repo_dir, "init");
216168
git_init_cmd.arg("-q");

build_system/usage.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,5 @@ REQUIREMENTS:
3939
* Rustup: By default rustup is used to install the right nightly version. If you don't want to
4040
use rustup, you can manually install the nightly version indicated by rust-toolchain.toml and
4141
point the CARGO, RUSTC and RUSTDOC env vars to the right executables.
42-
* Git: Git is used for applying patches and on Windows for downloading test repos.
43-
* Curl and tar (non-Windows only): Used by `./y.sh prepare` to download a single commit for
44-
repos. Git will be used to clone the whole repo when using Windows.
42+
* Git: Git is used for downloading test repos and applying patches.
4543
* [Hyperfine](https://github.com/sharkdp/hyperfine/): Used for benchmarking with `./y.sh bench`.

build_system/utils.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,6 @@ pub(crate) fn spawn_and_wait(mut cmd: Command) {
159159
}
160160
}
161161

162-
// Based on the retry function in rust's src/ci/shared.sh
163-
#[track_caller]
164-
pub(crate) fn retry_spawn_and_wait(tries: u64, mut cmd: Command) {
165-
for i in 1..tries + 1 {
166-
if i != 1 {
167-
eprintln!("Command failed. Attempt {i}/{tries}:");
168-
}
169-
if cmd.spawn().unwrap().wait().unwrap().success() {
170-
return;
171-
}
172-
std::thread::sleep(std::time::Duration::from_secs(i * 5));
173-
}
174-
eprintln!("The command has failed after {tries} attempts.");
175-
process::exit(1);
176-
}
177-
178162
pub(crate) fn remove_dir_if_exists(path: &Path) {
179163
match fs::remove_dir_all(&path) {
180164
Ok(()) => {}

0 commit comments

Comments
 (0)