From 3c6a5c58f96c60ff05fee5783da483acc3000f17 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Tue, 26 Apr 2022 03:29:40 -0700 Subject: [PATCH] Move basedir to config file Summary: This allows us to extend this more easily to server builds, too. Reviewed By: lblasa Differential Revision: D35901750 fbshipit-source-id: 7030846ad485d709cf4c2e95f0cad287f98b051b --- packer/src/main.rs | 33 +++++++++++++++------------------ packer/src/packlist.yaml | 3 +++ packer/src/types.rs | 20 +++----------------- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/packer/src/main.rs b/packer/src/main.rs index 98727e9c9..931836d6c 100644 --- a/packer/src/main.rs +++ b/packer/src/main.rs @@ -62,7 +62,7 @@ struct Args { no_compression: bool, /// Platform to build for - #[clap(value_name = "PLATFORM", arg_enum)] + #[clap(value_name = "PLATFORM")] platform: Platform, } @@ -71,6 +71,7 @@ type PackListPlatform = BTreeMap>; #[derive(Debug, serde::Deserialize)] struct PackListSpec { mode: PackMode, + basedir: path::PathBuf, files: PackListPlatform, } @@ -101,13 +102,12 @@ fn default_progress_bar(len: u64) -> indicatif::ProgressBar { } fn pack( - platform: Platform, + platform: &Platform, dist_dir: &std::path::Path, pack_list: &PackList, output_directory: &std::path::Path, ) -> Result> { let pb = default_progress_bar(pack_list.0.len() as u64 * 2 - 1); - let base_dir = platform_base_dir(dist_dir, platform); pb.set_prefix(&format!( "{:width$}", "Packing archives", @@ -115,8 +115,9 @@ fn pack( )); let packlist_spec = pack_list .0 - .get(&platform) - .ok_or(error::Error::MissingPlatformDefinition(platform))?; + .get(platform) + .ok_or_else(|| error::Error::MissingPlatformDefinition(platform.clone()))?; + let base_dir = path::Path::new(dist_dir).join(&packlist_spec.basedir); let files = &packlist_spec.files; let res = files .into_par_iter() @@ -148,16 +149,8 @@ fn pack( res } -fn platform_base_dir(dist_dir: &path::Path, platform: Platform) -> path::PathBuf { - match platform { - Platform::Mac => path::Path::new(dist_dir).join("mac"), - Platform::Linux => path::Path::new(dist_dir).join("linux-unpacked"), - Platform::Windows => path::Path::new(dist_dir).join("win-unpacked"), - } -} - fn pack_platform_glob( - platform: Platform, + platform: &Platform, base_dir: &path::Path, pack_files: &[String], pack_type: PackType, @@ -185,7 +178,9 @@ fn pack_platform_glob( let full_path = path::Path::new(&base_dir).join(&path); if !full_path.exists() { bail!(error::Error::MissingPackFile( - platform, pack_type, full_path, + platform.to_string(), + pack_type, + full_path, )); } if full_path.is_file() { @@ -199,7 +194,7 @@ fn pack_platform_glob( } fn pack_platform_exact( - platform: Platform, + platform: &Platform, base_dir: &path::Path, pack_files: &[String], pack_type: PackType, @@ -209,7 +204,9 @@ fn pack_platform_exact( let full_path = path::Path::new(&base_dir).join(f); if !full_path.exists() { bail!(error::Error::MissingPackFile( - platform, pack_type, full_path, + platform.to_string(), + pack_type, + full_path, )); } if full_path.is_file() { @@ -247,7 +244,7 @@ fn main() -> Result<(), anyhow::Error> { serde_yaml::from_str(&pack_list_str).expect("Failed to deserialize YAML packlist."); std::fs::create_dir_all(&args.output) .with_context(|| format!("Failed to create output directory '{:?}'.", &args.output))?; - let archive_paths = pack(args.platform, &args.dist, &pack_list, &args.output)?; + let archive_paths = pack(&args.platform, &args.dist, &pack_list, &args.output)?; let compressed_archive_paths = if args.no_compression { None } else { diff --git a/packer/src/packlist.yaml b/packer/src/packlist.yaml index 8aa2a3cee..48eac5766 100644 --- a/packer/src/packlist.yaml +++ b/packer/src/packlist.yaml @@ -1,5 +1,6 @@ mac: mode: exact + basedir: mac files: frameworks: - Flipper.app/Contents/Frameworks/ @@ -11,6 +12,7 @@ mac: linux: mode: glob + basedir: linux-unpacked files: frameworks: - '!resources/' @@ -20,6 +22,7 @@ linux: windows: mode: glob + basedir: win-unpacked files: frameworks: - '!resources/' diff --git a/packer/src/types.rs b/packer/src/types.rs index de69db41f..c88ca662b 100644 --- a/packer/src/types.rs +++ b/packer/src/types.rs @@ -6,24 +6,10 @@ */ use std::fmt::{self, Display}; +use std::str; -#[derive( - Debug, - Copy, - Clone, - PartialEq, - Eq, - PartialOrd, - Ord, - serde::Deserialize, - clap::ArgEnum -)] -#[serde(rename_all = "lowercase")] -pub enum Platform { - Mac, - Linux, - Windows, -} +// TODO: Make this a newtype. +pub type Platform = String; #[derive( Debug,