diff options
-rw-r--r-- | llvm_tools/patch_sync/src/android_utils.rs | 33 | ||||
-rw-r--r-- | llvm_tools/patch_sync/src/main.rs | 26 |
2 files changed, 59 insertions, 0 deletions
diff --git a/llvm_tools/patch_sync/src/android_utils.rs b/llvm_tools/patch_sync/src/android_utils.rs new file mode 100644 index 00000000..c6c1cd50 --- /dev/null +++ b/llvm_tools/patch_sync/src/android_utils.rs @@ -0,0 +1,33 @@ +use std::path::Path; +use std::process::Command; + +use anyhow::{bail, ensure, Result}; + +/// Return the Android checkout's current llvm version. +/// +/// This uses android_version.get_svn_revision_number, a python function +/// that can't be executed directly. We spawn a Python3 program +/// to run it and get the result from that. +pub fn get_android_llvm_version(android_checkout: &Path) -> Result<String> { + let mut command = Command::new("python3"); + let llvm_android_dir = android_checkout.join("toolchain/llvm_android"); + ensure!( + llvm_android_dir.is_dir(), + "can't get android llvm version; {} is not a directory", + llvm_android_dir.display() + ); + command.current_dir(llvm_android_dir); + command.args([ + "-c", + "import android_version; print(android_version.get_svn_revision_number(), end='')", + ]); + let output = command.output()?; + if !output.status.success() { + bail!( + "could not get android llvm version: {}", + String::from_utf8_lossy(&output.stderr) + ); + } + let out_string = String::from_utf8(output.stdout)?.trim().to_string(); + Ok(out_string) +} diff --git a/llvm_tools/patch_sync/src/main.rs b/llvm_tools/patch_sync/src/main.rs index bfcba584..9616716c 100644 --- a/llvm_tools/patch_sync/src/main.rs +++ b/llvm_tools/patch_sync/src/main.rs @@ -1,3 +1,4 @@ +mod android_utils; mod patch_parsing; mod version_control; @@ -103,6 +104,31 @@ fn transpose_subcmd(args: TransposeOpt) -> Result<()> { ) .context("finding new patches for android")?; + // Have to ignore patches that are already at the destination, even if + // the patches are new. + let new_cros_patches = new_cros_patches.subtract(&cur_android_collection)?; + let new_android_patches = new_android_patches.subtract(&cur_cros_collection)?; + + // Need to do an extra filtering step for Android, as AOSP doesn't + // want patches outside of the start/end bounds. + let android_llvm_version: u64 = { + let android_llvm_version_str = + android_utils::get_android_llvm_version(&ctx.android_checkout)?; + android_llvm_version_str.parse::<u64>().with_context(|| { + format!( + "converting llvm version to u64: '{}'", + android_llvm_version_str + ) + })? + }; + let new_android_patches = + new_android_patches.filter_patches(|p| match (p.start_version, p.end_version) { + (Some(start), Some(end)) => start <= android_llvm_version && android_llvm_version < end, + (Some(start), None) => start <= android_llvm_version, + (None, Some(end)) => android_llvm_version < end, + (None, None) => true, + }); + if args.verbose { display_patches("New patches from Chromium OS", &new_cros_patches); display_patches("New patches from Android", &new_android_patches); |