Skip to content

Commit 917be27

Browse files
committed
Minor improvement to apply_patches
1 parent 87bbc2d commit 917be27

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

build_system/prepare.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::env;
22
use std::ffi::OsStr;
3-
use std::ffi::OsString;
43
use std::fs;
5-
use std::path::Path;
4+
use std::path::{Path, PathBuf};
65
use std::process::Command;
76

87
use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version};
@@ -156,26 +155,35 @@ fn init_git_repo(repo_dir: &Path) {
156155
spawn_and_wait(git_commit_cmd);
157156
}
158157

159-
fn get_patches(crate_name: &str) -> Vec<OsString> {
160-
let mut patches: Vec<_> = fs::read_dir("patches")
158+
fn get_patches(source_dir: &Path, crate_name: &str) -> Vec<PathBuf> {
159+
let mut patches: Vec<_> = fs::read_dir(source_dir.join("patches"))
161160
.unwrap()
162161
.map(|entry| entry.unwrap().path())
163162
.filter(|path| path.extension() == Some(OsStr::new("patch")))
164-
.map(|path| path.file_name().unwrap().to_owned())
165-
.filter(|file_name| {
166-
file_name.to_str().unwrap().split_once("-").unwrap().1.starts_with(crate_name)
163+
.filter(|path| {
164+
path.file_name()
165+
.unwrap()
166+
.to_str()
167+
.unwrap()
168+
.split_once("-")
169+
.unwrap()
170+
.1
171+
.starts_with(crate_name)
167172
})
168173
.collect();
169174
patches.sort();
170175
patches
171176
}
172177

173178
fn apply_patches(crate_name: &str, target_dir: &Path) {
174-
for patch in get_patches(crate_name) {
175-
eprintln!("[PATCH] {:?} <- {:?}", target_dir.file_name().unwrap(), patch);
176-
let patch_arg = env::current_dir().unwrap().join("patches").join(patch);
179+
for patch in get_patches(&std::env::current_dir().unwrap(), crate_name) {
180+
eprintln!(
181+
"[PATCH] {:?} <- {:?}",
182+
target_dir.file_name().unwrap(),
183+
patch.file_name().unwrap()
184+
);
177185
let mut apply_patch_cmd = Command::new("git");
178-
apply_patch_cmd.arg("am").arg(patch_arg).arg("-q").current_dir(target_dir);
186+
apply_patch_cmd.arg("am").arg(patch).arg("-q").current_dir(target_dir);
179187
spawn_and_wait(apply_patch_cmd);
180188
}
181189
}

0 commit comments

Comments
 (0)