|
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}; |
9 | | -use super::utils::{copy_dir_recursively, spawn_and_wait}; |
| 8 | +use super::utils::{cargo_command, copy_dir_recursively, spawn_and_wait}; |
10 | 9 |
|
11 | 10 | pub(crate) fn prepare() { |
12 | 11 | prepare_sysroot(); |
@@ -53,8 +52,7 @@ pub(crate) fn prepare() { |
53 | 52 | ); |
54 | 53 |
|
55 | 54 | eprintln!("[LLVM BUILD] simple-raytracer"); |
56 | | - let mut build_cmd = Command::new("cargo"); |
57 | | - build_cmd.arg("build").env_remove("CARGO_TARGET_DIR").current_dir("simple-raytracer"); |
| 55 | + let build_cmd = cargo_command("cargo", "build", None, Path::new("simple-raytracer")); |
58 | 56 | spawn_and_wait(build_cmd); |
59 | 57 | fs::copy( |
60 | 58 | Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")), |
@@ -156,26 +154,35 @@ fn init_git_repo(repo_dir: &Path) { |
156 | 154 | spawn_and_wait(git_commit_cmd); |
157 | 155 | } |
158 | 156 |
|
159 | | -fn get_patches(crate_name: &str) -> Vec<OsString> { |
160 | | - let mut patches: Vec<_> = fs::read_dir("patches") |
| 157 | +fn get_patches(source_dir: &Path, crate_name: &str) -> Vec<PathBuf> { |
| 158 | + let mut patches: Vec<_> = fs::read_dir(source_dir.join("patches")) |
161 | 159 | .unwrap() |
162 | 160 | .map(|entry| entry.unwrap().path()) |
163 | 161 | .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) |
| 162 | + .filter(|path| { |
| 163 | + path.file_name() |
| 164 | + .unwrap() |
| 165 | + .to_str() |
| 166 | + .unwrap() |
| 167 | + .split_once("-") |
| 168 | + .unwrap() |
| 169 | + .1 |
| 170 | + .starts_with(crate_name) |
167 | 171 | }) |
168 | 172 | .collect(); |
169 | 173 | patches.sort(); |
170 | 174 | patches |
171 | 175 | } |
172 | 176 |
|
173 | 177 | 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); |
| 178 | + for patch in get_patches(&std::env::current_dir().unwrap(), crate_name) { |
| 179 | + eprintln!( |
| 180 | + "[PATCH] {:?} <- {:?}", |
| 181 | + target_dir.file_name().unwrap(), |
| 182 | + patch.file_name().unwrap() |
| 183 | + ); |
177 | 184 | let mut apply_patch_cmd = Command::new("git"); |
178 | | - apply_patch_cmd.arg("am").arg(patch_arg).arg("-q").current_dir(target_dir); |
| 185 | + apply_patch_cmd.arg("am").arg(patch).arg("-q").current_dir(target_dir); |
179 | 186 | spawn_and_wait(apply_patch_cmd); |
180 | 187 | } |
181 | 188 | } |
0 commit comments