|
| 1 | +diff --git a/sdk/cargo-build-bpf/src/main.rs b/sdk/cargo-build-bpf/src/main.rs |
| 2 | +index a602f6715f..a2451f3ce1 100644 |
| 3 | +--- a/sdk/cargo-build-bpf/src/main.rs |
| 4 | ++++ b/sdk/cargo-build-bpf/src/main.rs |
| 5 | +@@ -2,7 +2,6 @@ use { |
| 6 | + bzip2::bufread::BzDecoder, |
| 7 | + clap::{crate_description, crate_name, crate_version, Arg}, |
| 8 | + regex::Regex, |
| 9 | +- solana_download_utils::download_file, |
| 10 | + solana_sdk::signature::{write_keypair_file, Keypair}, |
| 11 | + std::{ |
| 12 | + collections::{HashMap, HashSet}, |
| 13 | +@@ -113,81 +112,12 @@ where |
| 14 | + |
| 15 | + // Check whether a package is installed and install it if missing. |
| 16 | + fn install_if_missing( |
| 17 | +- config: &Config, |
| 18 | +- package: &str, |
| 19 | +- url: &str, |
| 20 | +- download_file_name: &str, |
| 21 | +- target_path: &Path, |
| 22 | ++ _config: &Config, |
| 23 | ++ _package: &str, |
| 24 | ++ _url: &str, |
| 25 | ++ _download_file_name: &str, |
| 26 | ++ _target_path: &Path, |
| 27 | + ) -> Result<(), String> { |
| 28 | +- // Check whether the target path is an empty directory. This can |
| 29 | +- // happen if package download failed on previous run of |
| 30 | +- // cargo-build-bpf. Remove the target_path directory in this |
| 31 | +- // case. |
| 32 | +- if target_path.is_dir() |
| 33 | +- && target_path |
| 34 | +- .read_dir() |
| 35 | +- .map_err(|err| err.to_string())? |
| 36 | +- .next() |
| 37 | +- .is_none() |
| 38 | +- { |
| 39 | +- fs::remove_dir(&target_path).map_err(|err| err.to_string())?; |
| 40 | +- } |
| 41 | +- |
| 42 | +- // Check whether the package is already in ~/.cache/solana. |
| 43 | +- // Download it and place in the proper location if not found. |
| 44 | +- if !target_path.is_dir() |
| 45 | +- && !target_path |
| 46 | +- .symlink_metadata() |
| 47 | +- .map(|metadata| metadata.file_type().is_symlink()) |
| 48 | +- .unwrap_or(false) |
| 49 | +- { |
| 50 | +- if target_path.exists() { |
| 51 | +- fs::remove_file(&target_path).map_err(|err| err.to_string())?; |
| 52 | +- } |
| 53 | +- fs::create_dir_all(&target_path).map_err(|err| err.to_string())?; |
| 54 | +- let mut url = String::from(url); |
| 55 | +- url.push('/'); |
| 56 | +- url.push_str(config.bpf_tools_version); |
| 57 | +- url.push('/'); |
| 58 | +- url.push_str(download_file_name); |
| 59 | +- let download_file_path = target_path.join(download_file_name); |
| 60 | +- if download_file_path.exists() { |
| 61 | +- fs::remove_file(&download_file_path).map_err(|err| err.to_string())?; |
| 62 | +- } |
| 63 | +- download_file(url.as_str(), &download_file_path, true, &mut None)?; |
| 64 | +- let zip = File::open(&download_file_path).map_err(|err| err.to_string())?; |
| 65 | +- let tar = BzDecoder::new(BufReader::new(zip)); |
| 66 | +- let mut archive = Archive::new(tar); |
| 67 | +- archive |
| 68 | +- .unpack(&target_path) |
| 69 | +- .map_err(|err| err.to_string())?; |
| 70 | +- fs::remove_file(download_file_path).map_err(|err| err.to_string())?; |
| 71 | +- } |
| 72 | +- // Make a symbolic link source_path -> target_path in the |
| 73 | +- // sdk/bpf/dependencies directory if no valid link found. |
| 74 | +- let source_base = config.bpf_sdk.join("dependencies"); |
| 75 | +- if !source_base.exists() { |
| 76 | +- fs::create_dir_all(&source_base).map_err(|err| err.to_string())?; |
| 77 | +- } |
| 78 | +- let source_path = source_base.join(package); |
| 79 | +- // Check whether the correct symbolic link exists. |
| 80 | +- let invalid_link = if let Ok(link_target) = source_path.read_link() { |
| 81 | +- if link_target.ne(target_path) { |
| 82 | +- fs::remove_file(&source_path).map_err(|err| err.to_string())?; |
| 83 | +- true |
| 84 | +- } else { |
| 85 | +- false |
| 86 | +- } |
| 87 | +- } else { |
| 88 | +- true |
| 89 | +- }; |
| 90 | +- if invalid_link { |
| 91 | +- #[cfg(unix)] |
| 92 | +- std::os::unix::fs::symlink(target_path, source_path).map_err(|err| err.to_string())?; |
| 93 | +- #[cfg(windows)] |
| 94 | +- std::os::windows::fs::symlink_dir(target_path, source_path) |
| 95 | +- .map_err(|err| err.to_string())?; |
| 96 | +- } |
| 97 | + Ok(()) |
| 98 | + } |
| 99 | + |
0 commit comments