aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan R Abrahams <ajordanr@google.com>2021-12-28 22:22:49 +0000
committerCommit Bot <commit-bot@chromium.org>2022-01-08 00:36:49 +0000
commit6683e0e6b2152e8e92e7da9c4008913518e1fbd8 (patch)
treefeb20f56ba249f5b53e32dfc07bfd5ac3700259f
parentdbc8cb672a14f4a8bb136074817c71a22f743eaf (diff)
downloadtoolchain-utils-6683e0e6b2152e8e92e7da9c4008913518e1fbd8.tar.gz
patch_sync: Filter patches by platform
Because some patch collections may contain patches which don't apply to our given platform, we don't want to attempt to lookup their hashes. If we do, we may encounter a file-not-found error, as those patches haven't been ported to this platform. Also fixes a bug where no_commit was inverted. BUG=b:209493133 TEST=N/A Change-Id: I8b86133dfc6361919174f9f9b392d756b4304d2b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3364792 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/main.rs36
-rw-r--r--llvm_tools/patch_sync/src/patch_parsing.rs8
2 files changed, 35 insertions, 9 deletions
diff --git a/llvm_tools/patch_sync/src/main.rs b/llvm_tools/patch_sync/src/main.rs
index 081ce01a..f2d70edb 100644
--- a/llvm_tools/patch_sync/src/main.rs
+++ b/llvm_tools/patch_sync/src/main.rs
@@ -82,7 +82,8 @@ fn transpose_subcmd(args: TransposeOpt) -> Result<()> {
// Chromium OS Patches ----------------------------------------------------
let mut cur_cros_collection =
patch_parsing::PatchCollection::parse_from_file(&cros_patches_path)
- .context("parsing cros PATCHES.json")?;
+ .context("parsing cros PATCHES.json")?
+ .filter_patches(|p| p.platforms.contains("chromiumos"));
let new_cros_patches: patch_parsing::PatchCollection = {
let cros_old_patches_json = ctx.old_cros_patch_contents(&args.old_cros_ref)?;
let old_cros_collection = patch_parsing::PatchCollection::parse_from_str(
@@ -95,7 +96,8 @@ fn transpose_subcmd(args: TransposeOpt) -> Result<()> {
// Android Patches -------------------------------------------------------
let mut cur_android_collection =
patch_parsing::PatchCollection::parse_from_file(&android_patches_path)
- .context("parsing android PATCHES.json")?;
+ .context("parsing android PATCHES.json")?
+ .filter_patches(|p| p.platforms.contains("android"));
let new_android_patches: patch_parsing::PatchCollection = {
let android_old_patches_json = ctx.old_android_patch_contents(&args.old_android_ref)?;
let old_android_collection = patch_parsing::PatchCollection::parse_from_str(
@@ -105,18 +107,34 @@ fn transpose_subcmd(args: TransposeOpt) -> Result<()> {
cur_android_collection.subtract(&old_android_collection)?
};
+ if args.dry_run {
+ println!("--dry-run specified; skipping modifications");
+ return Ok(());
+ }
+
// Transpose Patches -----------------------------------------------------
- new_cros_patches.transpose_write(&mut cur_cros_collection)?;
- new_android_patches.transpose_write(&mut cur_android_collection)?;
+ if !new_cros_patches.is_empty() {
+ new_cros_patches.transpose_write(&mut cur_android_collection)?;
+ }
+ if !new_android_patches.is_empty() {
+ new_android_patches.transpose_write(&mut cur_cros_collection)?;
+ }
- if !args.no_commit {
+ if args.no_commit {
+ println!("--no-commit specified; not committing or uploading");
return Ok(());
}
// Commit and upload for review ------------------------------------------
- ctx.cros_repo_upload()
- .context("uploading chromiumos changes")?;
- ctx.android_repo_upload()
- .context("uploading android changes")?;
+ // Note we want to check if the android patches are empty for CrOS, and
+ // vice versa. This is a little counterintuitive.
+ if !new_android_patches.is_empty() {
+ ctx.cros_repo_upload()
+ .context("uploading chromiumos changes")?;
+ }
+ if !new_cros_patches.is_empty() {
+ ctx.android_repo_upload()
+ .context("uploading android changes")?;
+ }
Ok(())
}
diff --git a/llvm_tools/patch_sync/src/patch_parsing.rs b/llvm_tools/patch_sync/src/patch_parsing.rs
index 733451ae..befa6ccb 100644
--- a/llvm_tools/patch_sync/src/patch_parsing.rs
+++ b/llvm_tools/patch_sync/src/patch_parsing.rs
@@ -44,6 +44,14 @@ impl PatchCollection {
})
}
+ /// Copy this collection with patches filtered by given criterion.
+ pub fn filter_patches(&self, f: impl FnMut(&PatchDictSchema) -> bool) -> Self {
+ Self {
+ patches: self.patches.iter().cloned().filter(f).collect(),
+ workdir: self.workdir.clone(),
+ }
+ }
+
#[allow(dead_code)]
/// Return true if the collection is tracking any patches.
pub fn is_empty(&self) -> bool {