aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2023-03-24 16:13:38 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-03-24 16:13:38 +0000
commit65467a85df11fe221e80c99c7259679133426686 (patch)
tree5527dfaa25123d7f41a971f7402fa597ffb68871
parent0c22754af4a6de5ac554243cedab0e314669322d (diff)
parent2ed3f60c57d709dea5b6179a79da86568483ea10 (diff)
downloadexternal_updater-65467a85df11fe221e80c99c7259679133426686.tar.gz
Support non //external projects. am: 98dfa743fe am: 4233a68b1c am: 046b2ead74 am: 2ed3f60c57
Original change: https://android-review.googlesource.com/c/platform/tools/external_updater/+/2506729 Change-Id: If70bbd2e81e19ca7e5333294304cc1d98ba3a1f3 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--external_updater.py8
-rw-r--r--fileutils.py8
-rw-r--r--git_updater.py32
3 files changed, 45 insertions, 3 deletions
diff --git a/external_updater.py b/external_updater.py
index 35a9456..68550fb 100644
--- a/external_updater.py
+++ b/external_updater.py
@@ -119,7 +119,13 @@ def _do_update(args: argparse.Namespace, updater: Updater,
if args.stop_after_merge:
return
- rel_proj_path = fileutils.get_relative_project_path(full_path)
+ try:
+ rel_proj_path = fileutils.get_relative_project_path(full_path)
+ except ValueError:
+ # Absolute paths to other trees will not be relative to our tree. There are
+ # not portable instructions for upgrading that project, since the path will
+ # differ between machines (or checkouts).
+ rel_proj_path = "<absolute path to project>"
msg = textwrap.dedent(f"""\
Upgrade {metadata.name} to {updater.latest_version}
diff --git a/fileutils.py b/fileutils.py
index 5d1a238..09aab37 100644
--- a/fileutils.py
+++ b/fileutils.py
@@ -110,7 +110,13 @@ def write_metadata(proj_path: Path, metadata: metadata_pb2.MetaData, keep_date:
date.year = now.year
date.month = now.month
date.day = now.day
- rel_proj_path = get_relative_project_path(proj_path)
+ try:
+ rel_proj_path = get_relative_project_path(proj_path)
+ except ValueError:
+ # Absolute paths to other trees will not be relative to our tree. There are
+ # not portable instructions for upgrading that project, since the path will
+ # differ between machines (or checkouts).
+ rel_proj_path = "<absolute path to project>"
usage_hint = textwrap.dedent(f"""\
# This project was upgraded with external_updater.
# Usage: tools/external_updater/updater.sh update {rel_proj_path}
diff --git a/git_updater.py b/git_updater.py
index 02e73c0..483f3fc 100644
--- a/git_updater.py
+++ b/git_updater.py
@@ -27,6 +27,36 @@ class GitUpdater(base_updater.Updater):
def is_supported_url(self) -> bool:
return git_utils.is_valid_url(self._proj_path, self._old_url.value)
+ @staticmethod
+ def _is_likely_android_remote(url: str) -> bool:
+ """Returns True if the URL is likely to be the project's Android remote."""
+ # There isn't a strict rule for finding the correct remote for upstream-master,
+ # so we have to guess. Be careful to filter out things that look almost right
+ # but aren't. Here's an example of a project that has a lot of false positives:
+ #
+ # aosp /usr/local/google/home/danalbert/src/mirrors/android/refs/aosp/toolchain/rr.git (fetch)
+ # aosp persistent-https://android.git.corp.google.com/toolchain/rr (push)
+ # origin https://github.com/DanAlbert/rr.git (fetch)
+ # origin https://github.com/DanAlbert/rr.git (push)
+ # unmirrored persistent-https://android.git.corp.google.com/toolchain/rr (fetch)
+ # unmirrored persistent-https://android.git.corp.google.com/toolchain/rr (push)
+ # update_origin https://github.com/rr-debugger/rr (fetch)
+ # update_origin https://github.com/rr-debugger/rr (push)
+ # upstream https://github.com/rr-debugger/rr.git (fetch)
+ # upstream https://github.com/rr-debugger/rr.git (push)
+ #
+ # unmirrored is the correct remote here. It's not a local path, and contains
+ # either /platform/external/ or /toolchain/ (the two common roots for third-
+ # party Android imports).
+ if '://' not in url:
+ # Skip anything that's likely a local GoB mirror.
+ return False
+ if '/platform/external/' in url:
+ return True
+ if '/toolchain/' in url:
+ return True
+ return False
+
def _setup_remote(self) -> None:
remotes = git_utils.list_remotes(self._proj_path)
current_remote_url = None
@@ -35,7 +65,7 @@ class GitUpdater(base_updater.Updater):
if name == self.UPSTREAM_REMOTE_NAME:
current_remote_url = url
- if '/platform/external/' in url:
+ if self._is_likely_android_remote(url):
android_remote_name = name
if android_remote_name is None: