This is an automated email from the ASF dual-hosted git repository. PsiACE pushed a commit to branch chore/xtask-download-serde-data in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git
commit 65c95a00a2f45eb0c9881b681cdcbad5acd9af59 Author: Chojan Shang <[email protected]> AuthorDate: Tue Jul 28 16:19:30 2026 +0800 build: move test data preparation into xtask --- .github/workflows/ci.yml | 2 +- CONTRIBUTING.md | 29 +- Cargo.lock | 683 ++++++++++++++++++++++++++++++++++++- Cargo.toml | 7 + datasketches/tests/serde_tests.rs | 7 +- tools/download_serde_tests_data.py | 115 ------- xtask/Cargo.toml | 3 + xtask/src/main.rs | 7 + xtask/src/test_data.rs | 207 +++++++++++ 9 files changed, 917 insertions(+), 143 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13c665e..7cff831 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,7 +93,7 @@ jobs: cache-bin: "false" - name: Prepare test data shell: bash - run: ./tools/download_serde_tests_data.py + run: cargo x test-data - name: Run unit tests shell: bash run: cargo x test diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f2d5e15..5ae90fd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,6 +42,12 @@ Build: cargo build --workspace ``` +Prepare the cross-language serialization test data: + +```shell +cargo x test-data +``` + Test: ```shell @@ -110,26 +116,17 @@ cargo install taplo-cli typos-cli hawkeye ## Serialization snapshots -Some tests depend on snapshot files under `datasketches/tests/serde_tests`. If they are missing, tests will fail. Download them with: - -```shell -python3 ./tools/download_serde_tests_data.py --all -``` - -The script downloads the latest snapshots from the `main` branch of -[`apache/datasketches-tck`](https://github.com/apache/datasketches-tck) and writes them to: +Serialization compatibility tests use Java and C++ snapshots from a pinned +revision of [`apache/datasketches-tck`](https://github.com/apache/datasketches-tck). +The `cargo x test-data` command downloads the TCK archive and synchronizes its +snapshots into: - `datasketches/tests/serde_tests/java_generated_files` - `datasketches/tests/serde_tests/cpp_generated_files` -You can download them separately: - -```shell -python3 ./tools/download_serde_tests_data.py --java -python3 ./tools/download_serde_tests_data.py --cpp -``` - -The script requires Python 3 and network access. +These directories are not stored in Git. Run the command before the first test +run and again whenever the pinned TCK revision changes. It requires network +access and removes stale `.sk` files when synchronizing the snapshots. ## Code of Conduct diff --git a/Cargo.lock b/Cargo.lock index 011194d..966fe50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + [[package]] name = "aho-corasick" version = "1.1.4" @@ -47,7 +53,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -58,7 +64,16 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" +dependencies = [ + "derive_arbitrary", ] [[package]] @@ -67,12 +82,30 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "2.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da" +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "camino" version = "1.2.4" @@ -105,6 +138,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cc" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5add81bb678e6cb321aff7fa0dc7689ad82b112dbc032cea19f91d6b8e3582b9" +dependencies = [ + "find-msvc-tools", + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.4" @@ -165,9 +208,24 @@ checksum = "4fe5f465a4f6fee88fad41b85d990f84c835335e85b5d9e6e63e0d06d28cba7c" dependencies = [ "encode_unicode", "libc", - "windows-sys", + "windows-sys 0.61.2", ] +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61803da095bee82a81bb1a452ecc25d3b2f1416d1897eb86430c6159ef717c17" + [[package]] name = "datasketches" version = "0.3.0" @@ -176,12 +234,40 @@ dependencies = [ "insta", ] +[[package]] +name = "derive_arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "displaydoc" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ac70aa55017e108007fbaf5aa0f54b021c98f92ff8af59d42eda9da96e3dd4f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "encode_unicode" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "errno" version = "0.3.14" @@ -189,7 +275,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -198,6 +284,42 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "flate2" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "getrandom" version = "0.4.3" @@ -232,12 +354,131 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + [[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "icu_collections" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" + +[[package]] +name = "icu_properties" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" + +[[package]] +name = "icu_provider" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "insta" version = "1.48.0" @@ -274,12 +515,34 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" +[[package]] +name = "litemap" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" + +[[package]] +name = "log" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" + [[package]] name = "memchr" version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -301,6 +564,21 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "potential_utf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +dependencies = [ + "zerovec", +] + [[package]] name = "proc-macro2" version = "1.0.107" @@ -354,6 +632,20 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rustix" version = "1.1.4" @@ -364,7 +656,42 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c54fcab019b409d04215d3a17cb438fd7fbf192ee61461f20f4fe18704bc138" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", ] [[package]] @@ -426,18 +753,59 @@ dependencies = [ "zmij", ] +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + [[package]] name = "similar" version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" +[[package]] +name = "smallvec" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" + +[[package]] +name = "socks" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c3dbbd9ae980613c6dd8e28a9407b50509d3803b57624d5dfe8315218cd58b" +dependencies = [ + "byteorder", + "libc", + "winapi", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "2.0.119" @@ -460,6 +828,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "tempfile" version = "3.27.0" @@ -467,10 +846,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom", + "getrandom 0.4.3", "once_cell", "rustix", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -493,18 +872,92 @@ dependencies = [ "syn 3.0.3", ] +[[package]] +name = "tinystr" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "unicode-ident" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" +dependencies = [ + "base64", + "log", + "once_cell", + "rustls", + "rustls-pki-types", + "socks", + "url", + "webpki-roots 0.26.11", +] + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "webpki-roots" +version = "0.26.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.9", +] + +[[package]] +name = "webpki-roots" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "which" version = "8.0.5" @@ -514,12 +967,43 @@ dependencies = [ "libc", ] +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -529,13 +1013,186 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "writeable" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" + [[package]] name = "x" version = "0.0.0" dependencies = [ "cargo_metadata", "clap", + "tempfile", + "ureq", "which", + "zip", +] + +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + +[[package]] +name = "zerotrie" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zip" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabe6324e908f85a1c52063ce7aa26b68dcb7eb6dbc83a2d148403c9bc3eba50" +dependencies = [ + "arbitrary", + "crc32fast", + "crossbeam-utils", + "displaydoc", + "flate2", + "indexmap", + "memchr", + "thiserror", + "zopfli", ] [[package]] @@ -543,3 +1200,15 @@ name = "zmij" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" + +[[package]] +name = "zopfli" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249" +dependencies = [ + "bumpalo", + "crc32fast", + "log", + "simd-adler32", +] diff --git a/Cargo.toml b/Cargo.toml index 82d7702..f998ce0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,13 @@ insta = { version = "1.46.1" } googletest = { version = "0.14.2" } cargo_metadata = { version = "0.23.1" } which = { version = "8.0.0" } +tempfile = { version = "3.27.0" } +ureq = { version = "2.12.1", default-features = false, features = [ + "proxy-from-env", + "socks-proxy", + "tls", +] } +zip = { version = "2.4.2", default-features = false, features = ["deflate"] } [workspace.lints.rust] unknown_lints = "deny" diff --git a/datasketches/tests/serde_tests.rs b/datasketches/tests/serde_tests.rs index 92cdc42..0039913 100644 --- a/datasketches/tests/serde_tests.rs +++ b/datasketches/tests/serde_tests.rs @@ -29,11 +29,10 @@ pub fn serialization_test_data(sub_dir: &str, name: &str) -> PathBuf { panic!( r#"serialization test data file not found: {} - Please ensure test data files are present in the repository. Generally, you can - run the following commands from the project root to download the test data files - if they are missing: + Run the following command from the project root to download the missing + serialization test data: - $ ./tools/download_serde_tests_data.py + $ cargo x test-data "#, path.display(), ); diff --git a/tools/download_serde_tests_data.py b/tools/download_serde_tests_data.py deleted file mode 100755 index a659611..0000000 --- a/tools/download_serde_tests_data.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env python3 - -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -import argparse -import shutil -import sys -import tempfile -import urllib.error -import urllib.request -import zipfile -from pathlib import Path, PurePosixPath - - -def download_archive(destination): - archive_url = "https://github.com/apache/datasketches-tck/archive/0016a517/main.zip" - print(f"Downloading serialization snapshots from {archive_url}", flush=True) - request = urllib.request.Request(archive_url) - with urllib.request.urlopen(request, timeout=60) as response: - with destination.open("wb") as output: - shutil.copyfileobj(response, output) - - -def extract_snapshots(archive, destination, language): - source_parts = ("serialization", language, "snapshots") - members = [] - for member in archive.infolist(): - path = PurePosixPath(member.filename) - if ( - not member.is_dir() - and path.suffix == ".sk" - and path.parent.parts[-3:] == source_parts - ): - members.append((path.name, member)) - if not members: - raise RuntimeError(f"no {language} snapshots found in the TCK archive") - - if destination.parent.is_symlink() or destination.is_symlink(): - raise RuntimeError(f"snapshot output path cannot be a symbolic link: {destination}") - destination.mkdir(parents=True, exist_ok=True) - - expected_files = {name for name, _ in members} - for existing_file in destination.glob("*.sk"): - if existing_file.name not in expected_files: - existing_file.unlink() - - for name, member in members: - temp_path = None - try: - with tempfile.NamedTemporaryFile( - dir=destination, - prefix=f".{name}.", - delete=False, - ) as output: - temp_path = Path(output.name) - source = archive.open(member) - with source: - shutil.copyfileobj(source, output) - temp_path.replace(destination / name) - finally: - if temp_path is not None and temp_path.exists(): - temp_path.unlink() - - print(f"Extracted {len(members)} {language} snapshots into {destination}") - - -def main(): - parser = argparse.ArgumentParser( - description="Download serialization test data from apache/datasketches-tck." - ) - parser.add_argument("--java", action="store_true", help="Download Java test data") - parser.add_argument("--cpp", action="store_true", help="Download C++ test data") - parser.add_argument("--all", action="store_true", help="Download all test data") - args = parser.parse_args() - - repository_root = Path(__file__).resolve().parents[1] - serde_tests = repository_root / "datasketches" / "tests" / "serde_tests" - generated_targets = { - "cpp": serde_tests / "cpp_generated_files", - "java": serde_tests / "java_generated_files", - } - - languages = [] - if args.java or args.all: - languages.append("java") - if args.cpp or args.all: - languages.append("cpp") - if not languages: - languages = list(generated_targets) - - with tempfile.TemporaryDirectory(prefix="datasketches-tck-") as temp_dir: - archive_path = Path(temp_dir) / "datasketches-tck.zip" - download_archive(archive_path) - with zipfile.ZipFile(archive_path) as archive: - for language in languages: - extract_snapshots(archive, generated_targets[language], language) - - -if __name__ == "__main__": - main() diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 080aa8a..0299955 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -32,7 +32,10 @@ release = false [dependencies] clap = { workspace = true } cargo_metadata = { workspace = true } +tempfile = { workspace = true } +ureq = { workspace = true } which = { workspace = true } +zip = { workspace = true } [lints] workspace = true diff --git a/xtask/src/main.rs b/xtask/src/main.rs index da33cd0..edbc4fc 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -21,6 +21,10 @@ use std::process::Command as StdCommand; use clap::Parser; use clap::Subcommand; +mod test_data; + +use test_data::CommandTestData; + #[derive(Parser)] struct Command { #[clap(subcommand)] @@ -34,6 +38,7 @@ impl Command { SubCommand::Docs(cmd) => cmd.run(), SubCommand::Lint(cmd) => cmd.run(), SubCommand::Test(cmd) => cmd.run(), + SubCommand::TestData(cmd) => cmd.run(), } } } @@ -48,6 +53,8 @@ enum SubCommand { Lint(CommandLint), #[clap(about = "Run unit tests.")] Test(CommandTest), + #[clap(about = "Prepare serialization compatibility test data.")] + TestData(CommandTestData), } #[derive(Parser)] diff --git a/xtask/src/test_data.rs b/xtask/src/test_data.rs new file mode 100644 index 0000000..ea5e0f7 --- /dev/null +++ b/xtask/src/test_data.rs @@ -0,0 +1,207 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::collections::BTreeSet; +use std::error::Error; +use std::fs; +use std::io; +use std::io::Read; +use std::io::Seek; +use std::path::Path; +use std::time::Duration; + +use clap::Parser; +use tempfile::NamedTempFile; +use zip::ZipArchive; + +const ARCHIVE_URL: &str = "https://github.com/apache/datasketches-tck/archive/0016a517/main.zip"; + +type Result<T> = std::result::Result<T, Box<dyn Error>>; + +#[derive(Parser)] +#[clap(name = "test-data")] +pub(crate) struct CommandTestData {} + +impl CommandTestData { + pub(crate) fn run(self) { + if let Err(error) = self.prepare() { + eprintln!("failed to prepare serialization test data: {error}"); + std::process::exit(1); + } + } + + fn prepare(self) -> Result<()> { + let repository_root = Path::new(env!("CARGO_WORKSPACE_DIR")); + let serde_tests = repository_root.join("datasketches/tests/serde_tests"); + + println!("Downloading serialization snapshots from {ARCHIVE_URL}"); + let agent = ureq::AgentBuilder::new() + .timeout_connect(Duration::from_secs(60)) + .timeout_read(Duration::from_secs(60)) + .build(); + let response = agent.get(ARCHIVE_URL).call()?; + let mut reader = response.into_reader(); + + let archive_file = NamedTempFile::new()?; + io::copy(&mut reader, &mut archive_file.as_file())?; + + let mut archive = ZipArchive::new(archive_file.reopen()?)?; + for language in ["cpp", "java"] { + let destination = serde_tests.join(format!("{language}_generated_files")); + extract_snapshots(&mut archive, &destination, language)?; + } + + Ok(()) + } +} + +fn extract_snapshots<R: Read + Seek>( + archive: &mut ZipArchive<R>, + destination: &Path, + language: &str, +) -> Result<()> { + let source_suffix = ["serialization", language, "snapshots"]; + let mut members = Vec::new(); + let mut expected_files = BTreeSet::new(); + + for index in 0..archive.len() { + let member = archive.by_index(index)?; + let path = Path::new(member.name()); + let parent_matches = path + .parent() + .map(|parent| { + parent + .iter() + .rev() + .take(source_suffix.len()) + .zip(source_suffix.iter().rev()) + .all(|(actual, expected)| actual == *expected) + && parent.iter().count() >= source_suffix.len() + }) + .unwrap_or(false); + + if !member.is_dir() + && path.extension().is_some_and(|extension| extension == "sk") + && parent_matches + { + let Some(name) = path.file_name().map(ToOwned::to_owned) else { + continue; + }; + if !expected_files.insert(name.clone()) { + return Err(format!( + "duplicate {language} snapshot in archive: {}", + Path::new(&name).display() + ) + .into()); + } + members.push((index, name)); + } + } + + if members.is_empty() { + return Err(format!("no {language} snapshots found in the TCK archive").into()); + } + + ensure_not_symlink(destination)?; + if let Some(parent) = destination.parent() { + ensure_not_symlink(parent)?; + } + fs::create_dir_all(destination)?; + + for entry in fs::read_dir(destination)? { + let path = entry?.path(); + if path.extension().is_some_and(|extension| extension == "sk") + && path + .file_name() + .is_some_and(|name| !expected_files.contains(name)) + { + fs::remove_file(path)?; + } + } + + for (index, name) in members { + let mut source = archive.by_index(index)?; + let mut output = NamedTempFile::new_in(destination)?; + io::copy(&mut source, &mut output)?; + output.persist(destination.join(&name))?; + } + + println!( + "Extracted {} {language} snapshots into {}", + expected_files.len(), + destination.display() + ); + Ok(()) +} + +fn ensure_not_symlink(path: &Path) -> Result<()> { + if fs::symlink_metadata(path).is_ok_and(|metadata| metadata.file_type().is_symlink()) { + return Err(format!( + "snapshot output path cannot be a symbolic link: {}", + path.display() + ) + .into()); + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use std::fs; + use std::io::Cursor; + use std::io::Write; + + use tempfile::tempdir; + use zip::ZipWriter; + use zip::write::SimpleFileOptions; + + use super::extract_snapshots; + + #[test] + fn extracts_only_selected_snapshots_and_removes_stale_files() { + let temp_dir = tempdir().unwrap(); + let destination = temp_dir.path().join("java_generated_files"); + fs::create_dir(&destination).unwrap(); + fs::write(destination.join("stale.sk"), b"stale").unwrap(); + fs::write(destination.join("keep.txt"), b"keep").unwrap(); + + let mut writer = ZipWriter::new(Cursor::new(Vec::new())); + let options = SimpleFileOptions::default(); + writer + .start_file("tck/serialization/java/snapshots/java.sk", options) + .unwrap(); + writer.write_all(b"java").unwrap(); + writer + .start_file("tck/serialization/cpp/snapshots/cpp.sk", options) + .unwrap(); + writer.write_all(b"cpp").unwrap(); + writer + .start_file("tck/serialization/java/other/ignored.sk", options) + .unwrap(); + writer.write_all(b"ignored").unwrap(); + let archive = writer.finish().unwrap().into_inner(); + + let mut archive = zip::ZipArchive::new(Cursor::new(archive)).unwrap(); + extract_snapshots(&mut archive, &destination, "java").unwrap(); + + assert_eq!(fs::read(destination.join("java.sk")).unwrap(), b"java"); + assert_eq!(fs::read(destination.join("keep.txt")).unwrap(), b"keep"); + assert!(!destination.join("cpp.sk").exists()); + assert!(!destination.join("ignored.sk").exists()); + assert!(!destination.join("stale.sk").exists()); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
