Build all artifacts from packlist

Summary:
Instead of hardcoding the targets, it will now build all specified
types in the "packlist".

Reviewed By: jknoxville

Differential Revision: D21349762

fbshipit-source-id: 58f4a3bbf0b6ff4dd87eb44bbd7b200127da8017
This commit is contained in:
Pascal Hartig
2020-05-01 09:41:13 -07:00
committed by Facebook GitHub Bot
parent 2c20f016d4
commit 8818fbe375
3 changed files with 34 additions and 38 deletions

View File

@@ -12,7 +12,7 @@ use std::path::PathBuf;
#[derive(Debug)]
pub enum Error {
MissingPackFile(Platform, PackType, PathBuf),
MissingPackDefinition(Platform, PackType),
MissingPlatformDefinition(Platform),
}
impl std::error::Error for Error {}
@@ -27,10 +27,10 @@ impl fmt::Display for Error {
pack_type,
path.to_string_lossy()
),
Error::MissingPackDefinition(platform, pack_type) => write!(
Error::MissingPlatformDefinition(platform) => write!(
f,
"Missing packlist definition for platform {:?} and pack type {:?}.",
platform, pack_type,
"Platform {} is not defined in the given packlist.",
platform
),
}
}

View File

@@ -28,49 +28,34 @@ fn pack(
pack_list: &PackList,
output_directory: &std::path::PathBuf,
) -> Result<()> {
let mut frameworks_path = output_directory.clone();
frameworks_path.push("frameworks.tar");
let mut frameworks_tar = tar::Builder::new(File::create(frameworks_path)?);
let packtype_paths = pack_list
.0
.get(platform)
.ok_or_else(|| error::Error::MissingPlatformDefinition(platform.clone()))?;
for (pack_type, pack_files) in packtype_paths {
print!(
"Packing for platform {:?} type {:?} ...",
platform, pack_type
);
let output_path = path::Path::new(output_directory).join(format!("{}.tar", pack_type));
let mut tar = tar::Builder::new(File::create(output_path)?);
// MacOS uses symlinks for bundling multiple framework versions and pointing
// to the "Current" one.
frameworks_tar.follow_symlinks(false);
pack_platform(
platform,
dist_dir,
pack_list,
&PackType::Frameworks,
&mut frameworks_tar,
)?;
frameworks_tar.finish()?;
// TODO: Instead of hard-coding the two types, just iterate over the packlist.
let mut core_path = output_directory.clone();
core_path.push("core.tar");
let mut core_tar = tar::Builder::new(File::create(core_path)?);
pack_platform(
platform,
dist_dir,
pack_list,
&PackType::Core,
&mut core_tar,
)?;
eprintln!("Written.");
tar.follow_symlinks(false);
pack_platform(platform, dist_dir, pack_files, pack_type, &mut tar)?;
tar.finish()?;
println!(" done.");
}
Ok(())
}
fn pack_platform(
platform: &Platform,
dist_dir: &std::path::PathBuf,
pack_list: &PackList,
pack_files: &Vec<path::PathBuf>,
pack_type: &PackType,
tar_builder: &mut tar::Builder<File>,
) -> Result<()> {
let pack_files = pack_list
.0
.get(platform)
.and_then(|f| f.get(pack_type))
.ok_or_else(|| error::Error::MissingPackDefinition(platform.clone(), pack_type.clone()))?;
let base_dir = match platform {
Platform::Mac => path::Path::new(dist_dir).join("mac"),
// TODO: Verify this.

View File

@@ -6,6 +6,7 @@
*/
use clap::arg_enum;
use std::fmt::{self, Display};
arg_enum! {
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, serde::Deserialize)]
@@ -23,3 +24,13 @@ pub enum PackType {
Frameworks,
Core,
}
impl Display for PackType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use PackType::*;
match *self {
Frameworks => write!(f, "frameworks"),
Core => write!(f, "core"),
}
}
}