Allow arbitrary packs
Summary: The limitation to two types is arbitrary and limiting. Instead, we want to be able to create as many cache artifacts as is sensible to improve the caching behaviour. A lot of unnecessary cloning in here. I might optimise this a bit in the future but it's not really perf critical as this is highly I/O bound. Reviewed By: lblasa Differential Revision: D38155922 fbshipit-source-id: 78b86ebff54269c5049e59197f1c25fedfad0111
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d73387d80b
commit
6913d6f653
@@ -130,7 +130,7 @@ fn pack(
|
|||||||
let files = &packlist_spec.files;
|
let files = &packlist_spec.files;
|
||||||
let res = files
|
let res = files
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.map(|(&pack_type, pack_files)| {
|
.map(|(pack_type, pack_files)| {
|
||||||
let output_path = path::Path::new(output_directory).join(format!("{}.tar", 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).with_context(|| {
|
let mut tar = tar::Builder::new(File::create(&output_path).with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
@@ -150,7 +150,9 @@ fn pack(
|
|||||||
tar.finish()?;
|
tar.finish()?;
|
||||||
pb.inc(1);
|
pb.inc(1);
|
||||||
|
|
||||||
Ok((pack_type, output_path))
|
// TODO: Consider borrowing and changing all return types instead
|
||||||
|
// of the unnecessary clone.
|
||||||
|
Ok((pack_type.clone(), output_path))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -162,7 +164,7 @@ fn pack_platform_glob(
|
|||||||
platform: &Platform,
|
platform: &Platform,
|
||||||
base_dir: &path::Path,
|
base_dir: &path::Path,
|
||||||
pack_files: &[String],
|
pack_files: &[String],
|
||||||
pack_type: PackType,
|
pack_type: &PackType,
|
||||||
tar_builder: &mut tar::Builder<File>,
|
tar_builder: &mut tar::Builder<File>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut ov = ignore::overrides::OverrideBuilder::new(base_dir);
|
let mut ov = ignore::overrides::OverrideBuilder::new(base_dir);
|
||||||
@@ -188,7 +190,7 @@ fn pack_platform_glob(
|
|||||||
if !full_path.exists() {
|
if !full_path.exists() {
|
||||||
bail!(error::Error::MissingPackFile(
|
bail!(error::Error::MissingPackFile(
|
||||||
platform.clone(),
|
platform.clone(),
|
||||||
pack_type,
|
pack_type.clone(),
|
||||||
full_path,
|
full_path,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -206,7 +208,7 @@ fn pack_platform_exact(
|
|||||||
platform: &Platform,
|
platform: &Platform,
|
||||||
base_dir: &path::Path,
|
base_dir: &path::Path,
|
||||||
pack_files: &[String],
|
pack_files: &[String],
|
||||||
pack_type: PackType,
|
pack_type: &PackType,
|
||||||
tar_builder: &mut tar::Builder<File>,
|
tar_builder: &mut tar::Builder<File>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for f in pack_files {
|
for f in pack_files {
|
||||||
@@ -214,7 +216,7 @@ fn pack_platform_exact(
|
|||||||
if !full_path.exists() {
|
if !full_path.exists() {
|
||||||
bail!(error::Error::MissingPackFile(
|
bail!(error::Error::MissingPackFile(
|
||||||
platform.clone(),
|
platform.clone(),
|
||||||
pack_type,
|
pack_type.clone(),
|
||||||
full_path,
|
full_path,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -296,7 +298,7 @@ fn compress_paths(
|
|||||||
let mut encoder = xz2::write::XzEncoder::new(writer, 9);
|
let mut encoder = xz2::write::XzEncoder::new(writer, 9);
|
||||||
std::io::copy(&mut reader, &mut encoder)?;
|
std::io::copy(&mut reader, &mut encoder)?;
|
||||||
pb.inc(1);
|
pb.inc(1);
|
||||||
Ok((*pack_type, output_path))
|
Ok((pack_type.clone(), output_path))
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<(PackType, path::PathBuf)>>>()?;
|
.collect::<Result<Vec<(PackType, path::PathBuf)>>>()?;
|
||||||
pb.finish();
|
pb.finish();
|
||||||
@@ -370,7 +372,7 @@ fn gen_manifest_files(
|
|||||||
let extrinsic_checksum = sha256_digest(&mut BufReader::new(File::open(path)?))?;
|
let extrinsic_checksum = sha256_digest(&mut BufReader::new(File::open(path)?))?;
|
||||||
pb.inc(1);
|
pb.inc(1);
|
||||||
Ok((
|
Ok((
|
||||||
*pack_type,
|
pack_type,
|
||||||
PackFile {
|
PackFile {
|
||||||
file_name: path
|
file_name: path
|
||||||
.file_name()
|
.file_name()
|
||||||
@@ -387,7 +389,7 @@ fn gen_manifest_files(
|
|||||||
.fold(
|
.fold(
|
||||||
BTreeMap::new(),
|
BTreeMap::new(),
|
||||||
|mut acc: BTreeMap<_, _>, (pack_type, pack_file)| {
|
|mut acc: BTreeMap<_, _>, (pack_type, pack_file)| {
|
||||||
acc.insert(pack_type, pack_file);
|
acc.insert(pack_type.clone(), pack_file);
|
||||||
acc
|
acc
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -414,7 +416,7 @@ mod test {
|
|||||||
.join("archive_a.tar");
|
.join("archive_a.tar");
|
||||||
let tmp_dir = tempdir::TempDir::new("manifest_test")?;
|
let tmp_dir = tempdir::TempDir::new("manifest_test")?;
|
||||||
|
|
||||||
let archive_paths = &[(PackType::Core, artifact_path)];
|
let archive_paths = &[(PackType::new("core"), artifact_path)];
|
||||||
let path = manifest(archive_paths, &None, tmp_dir.path())?;
|
let path = manifest(archive_paths, &None, tmp_dir.path())?;
|
||||||
|
|
||||||
let manifest_content = std::fs::read_to_string(&path)?;
|
let manifest_content = std::fs::read_to_string(&path)?;
|
||||||
|
|||||||
@@ -50,3 +50,7 @@ server-linux:
|
|||||||
- node
|
- node
|
||||||
core:
|
core:
|
||||||
- '!node'
|
- '!node'
|
||||||
|
- '!static'
|
||||||
|
static:
|
||||||
|
- '!*'
|
||||||
|
- static
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ impl Display for Platform {
|
|||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
Clone,
|
Clone,
|
||||||
Copy,
|
|
||||||
PartialEq,
|
PartialEq,
|
||||||
Eq,
|
Eq,
|
||||||
PartialOrd,
|
PartialOrd,
|
||||||
@@ -38,9 +37,13 @@ impl Display for Platform {
|
|||||||
serde::Serialize
|
serde::Serialize
|
||||||
)]
|
)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
pub enum PackType {
|
pub struct PackType(String);
|
||||||
Frameworks,
|
|
||||||
Core,
|
#[cfg(test)]
|
||||||
|
impl PackType {
|
||||||
|
pub fn new(s: &str) -> Self {
|
||||||
|
Self(s.to_string())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
@@ -65,10 +68,7 @@ pub enum PackMode {
|
|||||||
|
|
||||||
impl Display for PackType {
|
impl Display for PackType {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
write!(f, "{}", self.0)
|
||||||
Self::Frameworks => write!(f, "frameworks"),
|
|
||||||
Self::Core => write!(f, "core"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user