diff options
author | Jordan R Abrahams <ajordanr@google.com> | 2022-01-12 23:37:47 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2022-01-14 04:47:53 +0000 |
commit | 384bee7f9cdad4c183e7339985a26f3b9e9e31ee (patch) | |
tree | 12bbdd834e3529e98170c7766ef9c97a07002473 | |
parent | 500f764595891c07c8de9e6bfaa2b16d8628e561 (diff) | |
download | toolchain-utils-384bee7f9cdad4c183e7339985a26f3b9e9e31ee.tar.gz |
patch_sync: Fix PatchDictSchema fields
These were out of alphabetical order, and serde_json would write
them in the incorrect order to the PATCHES.json file.
Additionally, the `platforms` field may end up
being null after some discussion with the Android team.
This converts platforms to an Optional accordingly.
BUG=b:209493133
TEST=patch_sync transpose <...>
Change-Id: I7c0b2e984d713698a0ed53e7f36b38bef1a49d1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3379480
Reviewed-by: George Burgess <gbiv@chromium.org>
Tested-by: Jordan Abrahams-Whitehead <ajordanr@google.com>
Commit-Queue: Jordan Abrahams-Whitehead <ajordanr@google.com>
-rw-r--r-- | llvm_tools/patch_sync/src/patch_parsing.rs | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/llvm_tools/patch_sync/src/patch_parsing.rs b/llvm_tools/patch_sync/src/patch_parsing.rs index befa6ccb..c89d4eb2 100644 --- a/llvm_tools/patch_sync/src/patch_parsing.rs +++ b/llvm_tools/patch_sync/src/patch_parsing.rs @@ -10,11 +10,12 @@ use sha2::{Digest, Sha256}; /// JSON serde struct. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PatchDictSchema { - pub rel_patch_path: String, - pub start_version: Option<u64>, pub end_version: Option<u64>, - pub platforms: BTreeSet<String>, pub metadata: Option<BTreeMap<String, serde_json::Value>>, + #[serde(default, skip_serializing_if = "BTreeSet::is_empty")] + pub platforms: BTreeSet<String>, + pub rel_patch_path: String, + pub start_version: Option<u64>, } /// Struct to keep track of patches and their relative paths. @@ -59,7 +60,7 @@ impl PatchCollection { } /// Compute the set-set subtraction, returning a new `PatchCollection` which - /// keeps the minuend's wordir. + /// keeps the minuend's workdir. pub fn subtract(&self, subtrahend: &Self) -> Result<Self> { let mut new_patches = Vec::new(); // This is O(n^2) when it could be much faster, but n is always going to be less @@ -248,6 +249,7 @@ fn copy_create_parents(from: &Path, to: &Path) -> Result<()> { #[cfg(test)] mod test { + use super::*; /// Test we can extract the hash from patch files. @@ -318,4 +320,32 @@ mod test { vec!["x", "y"] ); } + + #[test] + fn test_union_empties() { + let patch1 = PatchDictSchema { + start_version: Some(0), + end_version: Some(1), + rel_patch_path: "a".into(), + metadata: None, + platforms: Default::default(), + }; + let collection1 = PatchCollection { + workdir: PathBuf::new(), + patches: vec![patch1.clone()], + }; + let collection2 = PatchCollection { + workdir: PathBuf::new(), + patches: vec![patch1], + }; + let union = collection1 + .union_helper( + &collection2, + |p| Ok(p.rel_patch_path.to_string()), + |p| Ok(p.rel_patch_path.to_string()), + ) + .expect("could not create union"); + assert_eq!(union.patches.len(), 1); + assert_eq!(union.patches[0].platforms.len(), 0); + } } |