|
1 | 1 | use std::env;
|
2 | 2 | use std::ffi::OsStr;
|
3 |
| -use std::ffi::OsString; |
4 | 3 | use std::fs;
|
5 |
| -use std::path::Path; |
| 4 | +use std::path::{Path, PathBuf}; |
6 | 5 | use std::process::Command;
|
7 | 6 |
|
8 | 7 | use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version};
|
@@ -156,26 +155,35 @@ fn init_git_repo(repo_dir: &Path) {
|
156 | 155 | spawn_and_wait(git_commit_cmd);
|
157 | 156 | }
|
158 | 157 |
|
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")) |
161 | 160 | .unwrap()
|
162 | 161 | .map(|entry| entry.unwrap().path())
|
163 | 162 | .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) |
167 | 172 | })
|
168 | 173 | .collect();
|
169 | 174 | patches.sort();
|
170 | 175 | patches
|
171 | 176 | }
|
172 | 177 |
|
173 | 178 | 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 | + ); |
177 | 185 | 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); |
179 | 187 | spawn_and_wait(apply_patch_cmd);
|
180 | 188 | }
|
181 | 189 | }
|
0 commit comments