Skip to content

Commit

Permalink
More assorted datagen renames (#4854)
Browse files Browse the repository at this point in the history
Part of #4629
  • Loading branch information
sffc authored May 2, 2024
1 parent d23ab3e commit 041c795
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion provider/blob/tests/test_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const BLOB_V2: &[u8] = include_bytes!("data/v2.postcard");
fn run_driver(exporter: BlobExporter) -> Result<(), DataError> {
DatagenDriver::new()
.with_keys([icu_provider::hello_world::HelloWorldV1Marker::KEY])
.with_locales_and_fallback([LocaleFamily::full()], Default::default())
.with_locales_and_fallback([LocaleFamily::FULL], Default::default())
.export(&icu_provider::hello_world::HelloWorldProvider, exporter)
}

Expand Down
8 changes: 4 additions & 4 deletions provider/datagen/src/bin/icu4x-datagen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ fn main() -> eyre::Result<()> {
let mut preprocessed_locales = if cli.locales.as_slice() == ["none"] {
Some(PreprocessedLocales::LanguageIdentifiers(vec![]))
} else if cli.locales.as_slice() == ["full"] || cli.all_locales {
Some(PreprocessedLocales::All)
Some(PreprocessedLocales::Full)
} else {
if cli.locales.as_slice() == ["all"] {
log::warn!(
Expand Down Expand Up @@ -490,13 +490,13 @@ fn main() -> eyre::Result<()> {

enum PreprocessedLocales {
LanguageIdentifiers(Vec<LanguageIdentifier>),
All,
Full,
}

if cli.without_fallback || matches!(cli.fallback, Fallback::Preresolved) {
driver = driver.with_locales_no_fallback(
match preprocessed_locales {
Some(PreprocessedLocales::All) => {
Some(PreprocessedLocales::Full) => {
eyre::bail!("--without-fallback needs an explicit locale list")
}
Some(PreprocessedLocales::LanguageIdentifiers(lids)) => lids,
Expand All @@ -510,7 +510,7 @@ fn main() -> eyre::Result<()> {
);
} else {
let locale_families = match preprocessed_locales {
Some(PreprocessedLocales::All) => vec![LocaleFamily::full()],
Some(PreprocessedLocales::Full) => vec![LocaleFamily::FULL],
Some(PreprocessedLocales::LanguageIdentifiers(lids)) => lids
.into_iter()
.map(LocaleFamily::with_descendants)
Expand Down
34 changes: 16 additions & 18 deletions provider/datagen/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,13 @@ impl LocaleFamily {
/// The family containing all locales.
///
/// Stylized on the CLI as: "full"
pub const fn full() -> Self {
Self {
langid: None,
annotations: LocaleFamilyAnnotations {
include_ancestors: false,
include_descendants: true,
},
}
}
pub const FULL: Self = Self {
langid: None,
annotations: LocaleFamilyAnnotations {
include_ancestors: false,
include_descendants: true,
},
};

pub(crate) fn into_parts(self) -> (Option<LanguageIdentifier>, LocaleFamilyAnnotations) {
(self.langid, self.annotations)
Expand Down Expand Up @@ -311,7 +309,7 @@ impl FromStr for LocaleFamily {
type Err = LocaleFamilyParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if s == "full" {
return Ok(Self::full());
return Ok(Self::FULL);
}
let (first, remainder) = s
.as_bytes()
Expand Down Expand Up @@ -637,7 +635,7 @@ impl DatagenDriver {
.map(LocaleFamily::with_descendants)
.map(LocaleFamily::into_parts)
.collect(),
None => [LocaleFamily::full()]
None => [LocaleFamily::FULL]
.into_iter()
.map(LocaleFamily::into_parts)
.collect(),
Expand Down Expand Up @@ -707,14 +705,14 @@ impl DatagenDriver {

let (uses_internal_fallback, deduplication_strategy) = match &locales_fallback {
LocalesWithOrWithoutFallback::WithoutFallback { langids } => {
let mut sorted_locales = langids
let mut sorted_locale_strs = langids
.iter()
.map(|x| x.write_to_string())
.collect::<Vec<_>>();
sorted_locales.sort_unstable();
sorted_locale_strs.sort_unstable();
log::info!(
"Datagen configured without fallback with these locales: {:?}",
sorted_locales
sorted_locale_strs
);
(false, DeduplicationStrategy::None)
}
Expand All @@ -735,12 +733,12 @@ impl DatagenDriver {
}
Some(x) => x,
};
let mut sorted_locales = families
let mut sorted_locale_strs = families
.iter()
.map(LocaleFamilyBorrowed::from_parts)
.map(|family| family.write_to_string().into_owned())
.collect::<Vec<_>>();
sorted_locales.sort_unstable();
sorted_locale_strs.sort_unstable();
log::info!(
"Datagen configured with {}, {}, and these locales: {:?}",
if uses_internal_fallback {
Expand All @@ -754,7 +752,7 @@ impl DatagenDriver {
"deduplication retaining base languages",
DeduplicationStrategy::None => "no deduplication",
},
sorted_locales
sorted_locale_strs
);
(uses_internal_fallback, deduplication_strategy)
}
Expand Down Expand Up @@ -1035,7 +1033,7 @@ fn select_locales_for_key(
}
} else {
// Full locale family: set the bit instead of adding to the set
debug_assert_eq!(annotations, &LocaleFamily::full().annotations);
debug_assert_eq!(annotations, &LocaleFamily::FULL.annotations);
include_full = true;
None
}
Expand Down
8 changes: 4 additions & 4 deletions provider/datagen/tests/test-options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ fn all_preferred() {
.with_fallback_mode(FallbackMode::PreferredForExporter),
DatagenDriver::new()
.with_keys([HelloWorldV1Marker::KEY])
.with_locales_and_fallback([LocaleFamily::full()], Default::default()),
.with_locales_and_fallback([LocaleFamily::FULL], Default::default()),
&TestingProvider::with_decimal_symbol_like_data(),
);

Expand Down Expand Up @@ -280,7 +280,7 @@ fn all_hybrid() {
.with_fallback_mode(FallbackMode::Hybrid),
DatagenDriver::new()
.with_keys([HelloWorldV1Marker::KEY])
.with_locales_and_fallback([LocaleFamily::full()], {
.with_locales_and_fallback([LocaleFamily::FULL], {
let mut options = FallbackOptions::default();
options.deduplication_strategy = Some(DeduplicationStrategy::None);
options
Expand Down Expand Up @@ -329,7 +329,7 @@ fn all_runtime() {
.with_fallback_mode(FallbackMode::RuntimeManual),
DatagenDriver::new()
.with_keys([HelloWorldV1Marker::KEY])
.with_locales_and_fallback([LocaleFamily::full()], {
.with_locales_and_fallback([LocaleFamily::FULL], {
let mut options = FallbackOptions::default();
options.deduplication_strategy = Some(DeduplicationStrategy::Maximal);
options
Expand Down Expand Up @@ -373,7 +373,7 @@ fn all_runtime_retain_base() {
let exported = export_to_map_1_5(
DatagenDriver::new()
.with_keys([HelloWorldV1Marker::KEY])
.with_locales_and_fallback([LocaleFamily::full()], {
.with_locales_and_fallback([LocaleFamily::FULL], {
let mut options = FallbackOptions::default();
options.deduplication_strategy = Some(DeduplicationStrategy::RetainBaseLanguages);
options
Expand Down

0 comments on commit 041c795

Please sign in to comment.