Skip to content

Commit

Permalink
Add blob2 to datagen CLI; regen test postcard
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Nov 1, 2023
1 parent 42cbfa3 commit 1fcd2cf
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4 deletions.
Binary file modified provider/adapters/tests/data/blob.postcard
Binary file not shown.
Binary file added provider/blob/tests/data/v1.postcard
Binary file not shown.
File renamed without changes.
10 changes: 9 additions & 1 deletion provider/datagen/src/bin/datagen/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::path::PathBuf;
enum Format {
Dir,
Blob,
Blob2,
Mod,
DeprecatedDefault,
}
Expand Down Expand Up @@ -212,7 +213,7 @@ pub struct Cli {
#[arg(
help = "Path to output directory or file. Must be empty or non-existent, unless \
--overwrite is present, in which case the directory is deleted first. \
For --format=blob, omit this option to dump to stdout. \
For --format={blob,blob2}, omit this option to dump to stdout. \
For --format={dir,mod} defaults to 'icu4x_data'."
)]
output: Option<PathBuf>,
Expand Down Expand Up @@ -410,6 +411,13 @@ impl Cli {
PathBuf::from("/stdout")
},
}),
Format::Blob2 => Ok(config::Export::Blob2 {
path: if let Some(path) = &self.output {
path.clone()
} else {
PathBuf::from("/stdout")
},
}),
Format::Mod => Ok(config::Export::Baked {
path: if let Some(mod_directory) = self.output.as_ref() {
mod_directory.clone()
Expand Down
3 changes: 3 additions & 0 deletions provider/datagen/src/bin/datagen/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ pub enum Export {
Blob {
path: PathBuf,
},
Blob2 {
path: PathBuf,
},
Baked {
path: PathBuf,
#[serde(default, skip_serializing_if = "is_default")]
Expand Down
9 changes: 7 additions & 2 deletions provider/datagen/src/bin/datagen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ fn main() -> eyre::Result<()> {
Ok(driver.export(&provider, exporter)?)
}
}
config::Export::Blob { ref path } => {
config::Export::Blob { ref path } | config::Export::Blob2 { ref path } => {
#[cfg(not(feature = "blob_exporter"))]
eyre::bail!("Exporting to a BlobProvider requires the `blob_exporter` Cargo feature");
#[cfg(feature = "blob_exporter")]
{
let exporter = icu_provider_blob::export::BlobExporter::new_with_sink(
let mut exporter = icu_provider_blob::export::BlobExporter::new_with_sink(
if path == std::path::Path::new("/stdout") {
Box::new(std::io::stdout())
} else if !config.overwrite && path.exists() {
Expand All @@ -170,6 +170,11 @@ fn main() -> eyre::Result<()> {
)
},
);
if matches!(config.export, config::Export::Blob { .. }) {
exporter.set_v1();
} else {
exporter.set_v2();
}
Ok(driver.export(&provider, exporter)?)
}
}
Expand Down
3 changes: 2 additions & 1 deletion tools/make/data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ exec --fail-on-error target/debug/icu4x-datagen --keys "core/helloworld@1" --loc
exec --fail-on-error target/debug/icu4x-datagen --keys "core/helloworld@1" --locales full --format dir --syntax bincode --out provider/fs/tests/data/bincode --overwrite
exec --fail-on-error target/debug/icu4x-datagen --keys "core/helloworld@1" --locales full --format dir --syntax postcard --out provider/fs/tests/data/postcard --overwrite
exec --fail-on-error target/debug/icu4x-datagen --keys "core/helloworld@1" --locales full --format blob --overwrite --out provider/blob/tests/data/hello_world.postcard
exec --fail-on-error target/debug/icu4x-datagen --keys "core/helloworld@1" --locales full --format blob --overwrite --out provider/blob/tests/data/v1.postcard
exec --fail-on-error target/debug/icu4x-datagen --keys "core/helloworld@1" --locales full --format blob2 --overwrite --out provider/blob/tests/data/v2.postcard
exec --fail-on-error target/debug/icu4x-datagen --keys "core/helloworld@1" "fallback/likelysubtags@1" "fallback/parents@1" "fallback/supplement/co@1" --locales full --format blob --out provider/adapters/tests/data/blob.postcard --overwrite
exec --fail-on-error target/debug/icu4x-datagen --keys "core/helloworld@1" --fallback preresolved --locales de --format dir --syntax json --out provider/adapters/tests/data/langtest/de --overwrite
Expand Down

0 comments on commit 1fcd2cf

Please sign in to comment.