Skip to content

Commit

Permalink
Add und-only baked testdata to repo and make cargo make quick quick…
Browse files Browse the repository at this point in the history
… again (#4486)

With some basic instructions on how to use it with VSCode.
  • Loading branch information
sffc authored Jan 30, 2024
1 parent aeef4f6 commit 15d8829
Show file tree
Hide file tree
Showing 293 changed files with 10,452 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ jobs:
with:
key: download-cache
path: /tmp/icu4x-source-cache
- name: Install rustfmt
run: rustup component add rustfmt

# Actual job
- name: Run `cargo make ci-job-testdata`
Expand Down
24 changes: 23 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Issues are open to everyone to discuss and can be used to jump-start Pull Reques

In most cases, the first step is to find or file a new issue related to your planned contribution, discuss it, and once you received a feedback indicating that the pull request would be welcomed you can start working on it.

## Installing dependencies
## Development Environment

### Installing dependencies

To build ICU4X, you will need the following dependencies:

Expand All @@ -20,6 +22,26 @@ To build ICU4X, you will need the following dependencies:

Certain tests may need further dependencies, these are documented below in the [Testing](#testing) section.

### IDE setup

ICU4X can be edited using any text editor capable of editing Rust code.

#### Visual Studio Code

Many ICU4X engineers use [Visual Studio Code](https://code.visualstudio.com/) with the [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) extension.

To build all code paths and improve build times in VSCode, we recommend the following settings. (Note: The second setting causes VSCode to build ICU4X with only the `und` locale, which reduces build times but also makes some tests fail; to run them normally, run `cargo test --all-features` on the command line.) To add these settings, choose "Preferences: Open Workspace Settings (JSON)" from the command palette (Ctrl+Shift+P):

```javascript
"settings": {
"rust-analyzer.cargo.features": "all",
"rust-analyzer.cargo.extraEnv": {
// Path relative to `provider/baked/*/src/lib.rs`
"ICU4X_DATA_DIR": "../../../../provider/datagen/tests/data/baked"
}
}
```

## Contributing a Pull Request

The first step is to fork the repository to your namespace and create a branch off of the `main` branch to work with.
Expand Down
7 changes: 3 additions & 4 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ ICU4X_BUILDING_WITH_FORCED_NIGHTLY = { value = "1", condition = { env_set = ["IC
[tasks.quick]
description = "Run quick version of all lints and builds (useful before pushing to GitHub)"
category = "ICU4X Development"
dependencies = [
env = { "ICU4X_DATA_DIR" = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/provider/datagen/tests/data/baked" }
run_task.name = [
"ci-job-fmt",
"ci-job-clippy",
"ci-job-nostd",
"check-no-features",
"check-tutorials-local",
"ci-job-tidy",
"depcheck",
"ci-job-doc",
]

Expand Down
1 change: 1 addition & 0 deletions components/calendar/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct Baked;
const _: () = {
pub mod icu {
pub use crate as calendar;
#[allow(unused_imports)] // baked data may or may not need this
pub use icu_locid_transform as locid_transform;
}
icu_calendar_data::make_provider!(Baked);
Expand Down
1 change: 1 addition & 0 deletions components/collator/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const _: () = {
pub mod icu {
pub use crate as collator;
pub use icu_collections as collections;
#[allow(unused_imports)] // baked data may or may not need this
pub use icu_locid_transform as locid_transform;
}
icu_collator_data::make_provider!(Baked);
Expand Down
1 change: 1 addition & 0 deletions components/datetime/src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct Baked;
const _: () = {
pub mod icu {
pub use crate as datetime;
#[allow(unused_imports)] // baked data may or may not need this
pub use icu_locid_transform as locid_transform;
}
icu_datetime_data::make_provider!(Baked);
Expand Down
1 change: 1 addition & 0 deletions components/decimal/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct Baked;
const _: () = {
pub mod icu {
pub use crate as decimal;
#[allow(unused_imports)] // baked data may or may not need this
pub use icu_locid_transform as locid_transform;
}
icu_decimal_data::make_provider!(Baked);
Expand Down
1 change: 1 addition & 0 deletions components/list/src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct Baked;
const _: () = {
pub mod icu {
pub use crate as list;
#[allow(unused_imports)] // baked data may or may not need this
pub use icu_locid_transform as locid_transform;
}
icu_list_data::make_provider!(Baked);
Expand Down
1 change: 1 addition & 0 deletions components/plurals/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct Baked;
const _: () = {
pub mod icu {
pub use crate as plurals;
#[allow(unused_imports)] // baked data may or may not need this
pub use icu_locid_transform as locid_transform;
}
icu_plurals_data::make_provider!(Baked);
Expand Down
1 change: 1 addition & 0 deletions components/properties/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const _: () = {
pub mod icu {
pub use crate as properties;
pub use icu_collections as collections;
#[allow(unused_imports)] // baked data may or may not need this
pub use icu_locid_transform as locid_transform;
}
icu_properties_data::make_provider!(Baked);
Expand Down
1 change: 1 addition & 0 deletions experimental/compactdecimal/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct Baked;
const _: () = {
pub mod icu {
pub use crate as compactdecimal;
#[allow(unused_imports)] // baked data may or may not need this
pub use icu_locid_transform as locid_transform;
}
icu_compactdecimal_data::make_provider!(Baked);
Expand Down
1 change: 1 addition & 0 deletions experimental/displaynames/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct Baked;
const _: () = {
pub mod icu {
pub use crate as displaynames;
#[allow(unused_imports)] // baked data may or may not need this
pub use icu_locid_transform as locid_transform;
}
icu_displaynames_data::make_provider!(Baked);
Expand Down
1 change: 1 addition & 0 deletions experimental/relativetime/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct Baked;
const _: () = {
pub mod icu {
pub use crate as relativetime;
#[allow(unused_imports)] // baked data may or may not need this
pub use icu_locid_transform as locid_transform;
}
icu_relativetime_data::make_provider!(Baked);
Expand Down
71 changes: 70 additions & 1 deletion provider/datagen/src/tests/make_testdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::baked_exporter;
use crate::prelude::*;
use crlify::BufWriterWithLineEndingFix;
use icu_provider::datagen::*;
Expand Down Expand Up @@ -46,6 +47,18 @@ fn generate_json_and_verify_postcard() {
),
});

let stubdata_out = Box::new(BakedStubdataExporter(
baked_exporter::BakedExporter::new(
"tests/data/baked".into(),
baked_exporter::Options {
overwrite: true,
pretty: true,
..Default::default()
},
)
.unwrap(),
));

DatagenDriver::new()
.with_keys(crate::all_keys())
.with_locales(LOCALES.iter().cloned())
Expand All @@ -55,11 +68,67 @@ fn generate_json_and_verify_postcard() {
])
.export(
&DatagenProvider::new_testing(),
MultiExporter::new(vec![json_out, postcard_out]),
MultiExporter::new(vec![json_out, postcard_out, stubdata_out]),
)
.unwrap();
}

/// Generates a stub data directory that can be used with `ICU4X_DATA_DIR`
/// for faster development and debugging. For example, put the following in
/// VSCode settings.json:
///
/// ```javascript
/// "rust-analyzer.cargo.extraEnv": {
/// // Relative to provider/baked/x/src
/// "ICU4X_DATA_DIR": "../../../datagen/tests/data/stub"
/// },
/// ```
struct BakedStubdataExporter(baked_exporter::BakedExporter);

impl DataExporter for BakedStubdataExporter {
fn put_payload(
&self,
key: DataKey,
locale: &DataLocale,
payload: &DataPayload<ExportMarker>,
) -> Result<(), DataError> {
// put `und-*` but not any other locales
if locale.is_langid_und() {
self.0.put_payload(key, locale, payload)
} else {
Ok(())
}
}

fn flush_singleton(
&self,
key: DataKey,
payload: &DataPayload<ExportMarker>,
) -> Result<(), DataError> {
self.0.flush_singleton(key, payload)
}

fn flush(&self, key: DataKey) -> Result<(), DataError> {
self.0.flush(key)
}

fn flush_with_built_in_fallback(
&self,
key: DataKey,
fallback_mode: BuiltInFallbackMode,
) -> Result<(), DataError> {
self.0.flush_with_built_in_fallback(key, fallback_mode)
}

fn close(&mut self) -> Result<(), DataError> {
self.0.close()
}

fn supports_built_in_fallback(&self) -> bool {
self.0.supports_built_in_fallback()
}
}

struct PostcardTestingExporter {
size_hash: Mutex<BTreeMap<(DataKey, String), (usize, u64)>>,
zero_copy_violations: Mutex<BTreeSet<DataKey>>,
Expand Down
2 changes: 2 additions & 0 deletions provider/datagen/tests/data/baked/any.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 15d8829

Please sign in to comment.