Search for the binary file for a function or extension inside the target directory. If the binary file exists, it creates the zip archive and extracts its architecture by reading the binary. If the zip file already exists, use it as the deployment archive. If none of them exist, return an error.
(
metadata: Option<&CargoMetadata>,
base_dir: &Option<P>,
data: &BinaryData,
include: Option<Vec<String>>,
)
| 172 | /// If the zip file already exists, use it as the deployment archive. |
| 173 | /// If none of them exist, return an error. |
| 174 | pub fn create_binary_archive<P>( |
| 175 | metadata: Option<&CargoMetadata>, |
| 176 | base_dir: &Option<P>, |
| 177 | data: &BinaryData, |
| 178 | include: Option<Vec<String>>, |
| 179 | ) -> Result<BinaryArchive> |
| 180 | where |
| 181 | P: AsRef<Path>, |
| 182 | { |
| 183 | let bootstrap_dir = if let Some(dir) = base_dir { |
| 184 | dir.as_ref().join(data.binary_location()) |
| 185 | } else { |
| 186 | let target_dir = metadata |
| 187 | .and_then(|m| target_dir_from_metadata(m).ok()) |
| 188 | .unwrap_or_else(|| PathBuf::from("target")); |
| 189 | |
| 190 | target_dir.join("lambda").join(data.binary_location()) |
| 191 | }; |
| 192 | |
| 193 | let binary_path = bootstrap_dir.join(data.binary_name()); |
| 194 | if binary_path.exists() { |
| 195 | return zip_binary(binary_path, bootstrap_dir, data, include); |
| 196 | } else { |
| 197 | let zip_path = bootstrap_dir.join(data.zip_name()); |
| 198 | |
| 199 | if zip_path.exists() { |
| 200 | return use_zip_in_place(zip_path, data, include); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | Err(BuildError::BinaryMissing(data.binary_name().into(), data.build_help().into()).into()) |
| 205 | } |
| 206 | |
| 207 | fn use_zip_in_place( |
| 208 | zip_path: PathBuf, |