diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2022-08-28 16:05:45 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2022-09-12 10:35:38 +0000 |
| commit | 917be273ab827c45e3b46e24157525339844e121 (patch) | |
| tree | c21937f353d692aa357f21a9ed6791c0c24b6a2a | |
| parent | 87bbc2d4135b0ee8c5fd5f33db7411029b5484e5 (diff) | |
| download | rust-917be273ab827c45e3b46e24157525339844e121.tar.gz rust-917be273ab827c45e3b46e24157525339844e121.zip | |
Minor improvement to apply_patches
| -rw-r--r-- | build_system/prepare.rs | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/build_system/prepare.rs b/build_system/prepare.rs index b7368e8ffab..9b89525395f 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -1,8 +1,7 @@ use std::env; use std::ffi::OsStr; -use std::ffi::OsString; use std::fs; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::Command; use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; @@ -156,14 +155,20 @@ fn init_git_repo(repo_dir: &Path) { spawn_and_wait(git_commit_cmd); } -fn get_patches(crate_name: &str) -> Vec<OsString> { - let mut patches: Vec<_> = fs::read_dir("patches") +fn get_patches(source_dir: &Path, crate_name: &str) -> Vec<PathBuf> { + let mut patches: Vec<_> = fs::read_dir(source_dir.join("patches")) .unwrap() .map(|entry| entry.unwrap().path()) .filter(|path| path.extension() == Some(OsStr::new("patch"))) - .map(|path| path.file_name().unwrap().to_owned()) - .filter(|file_name| { - file_name.to_str().unwrap().split_once("-").unwrap().1.starts_with(crate_name) + .filter(|path| { + path.file_name() + .unwrap() + .to_str() + .unwrap() + .split_once("-") + .unwrap() + .1 + .starts_with(crate_name) }) .collect(); patches.sort(); @@ -171,11 +176,14 @@ fn get_patches(crate_name: &str) -> Vec<OsString> { } fn apply_patches(crate_name: &str, target_dir: &Path) { - for patch in get_patches(crate_name) { - eprintln!("[PATCH] {:?} <- {:?}", target_dir.file_name().unwrap(), patch); - let patch_arg = env::current_dir().unwrap().join("patches").join(patch); + for patch in get_patches(&std::env::current_dir().unwrap(), crate_name) { + eprintln!( + "[PATCH] {:?} <- {:?}", + target_dir.file_name().unwrap(), + patch.file_name().unwrap() + ); let mut apply_patch_cmd = Command::new("git"); - apply_patch_cmd.arg("am").arg(patch_arg).arg("-q").current_dir(target_dir); + apply_patch_cmd.arg("am").arg(patch).arg("-q").current_dir(target_dir); spawn_and_wait(apply_patch_cmd); } } |
