aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkos Denke <akos.denke@linaro.org>2021-11-11 08:57:33 -0500
committerAkos Denke <akos.denke@linaro.org>2021-12-02 11:14:16 -0500
commit3e610119b40971643aed423cfcdc19f2c3cdf46a (patch)
tree4e1237fe190a37e2cddf8c26e29a1116144ab97f
parentb241e5d728535adf3c93fe0f9f3830d5a1f445a8 (diff)
downloadart-build-scripts-3e610119b40971643aed423cfcdc19f2c3cdf46a.tar.gz
Rework Gerrit patch application.
The Jenkins provides the Gerrit project name, and we have to find the corresponding repo manifest project to apply the patch on. Previously, the Gerrit project name was searched in the local manifest, which is not ideal from two perspectives. * It relies on a setup, which has a local manifest with the given name. This was solved by using the repo tool itself, to get the desired repo project information. * The Gerrit project can be a prefixed version of the repo project, as the repo concatenates the remote fetch URL with the project name, where the first can contain extra prefix in its end. Like: Gerrit project name: gerrit/prefix/repo/project repo remote fetch URL: http://<gerrit_base_url>/gerrit/prefix repo project name: repo/project This was solved by searching the repo project name by incrementally removing prefixes from the Gerrit project. The later one also means, that the local manifest does not have to override the project name to the Gerrit project on the CI, just to recognize it later. Change-Id: I91e5307e1e4d15be53dc2a4a55a8b5f3133efa82
-rwxr-xr-xjenkins/setup_android.sh36
1 files changed, 34 insertions, 2 deletions
diff --git a/jenkins/setup_android.sh b/jenkins/setup_android.sh
index 0b8e2f1c..790e6121 100755
--- a/jenkins/setup_android.sh
+++ b/jenkins/setup_android.sh
@@ -224,8 +224,40 @@ apply_gerrit_patches() {
touch "${gerrit_patches_file}"
if [[ -v GERRIT_PROJECT ]]; then
log I "Applying Gerrit patches."
- local patch_dir=$(grep "\"${GERRIT_PROJECT}\"" \
- .repo/local_manifests/linaro.xml | grep -Po 'path="\K[^"]*')
+ # Prepare for the case, the Gerrit project is a prefixed version of the
+ # repo manifest project as in the repo manifest, a prefix can be part of
+ # the remote fetch URL instead.
+
+ # Try to incrementally remove the leading '*/' part from the Gerrit project
+ # and try to find it in the list of repo projects.
+ # So, if the Gerrit project is `gerrit/prefix/repo/project`, it will search
+ # for the following exact matches:
+ # gerrit/prefix/repo/project
+ # prefix/repo/project
+ # repo/project
+ # project
+ # It will stop at the first match, which is `repo/project` in our case.
+ local -r repo_all_projects=$(repo list --name-only)
+ local prefix_removed_gerrit_project="${GERRIT_PROJECT}"
+ local repo_project=""
+ while true; do
+ if (grep -q --line-regexp "${prefix_removed_gerrit_project}" \
+ <<< "${repo_all_projects}"); then
+ repo_project="${prefix_removed_gerrit_project}"
+ break
+ fi
+ if [[ "${prefix_removed_gerrit_project}" != *"/"* ]]; then
+ break
+ fi
+ prefix_removed_gerrit_project="${prefix_removed_gerrit_project#*/}"
+ done
+
+ if [[ -z "${repo_project}" ]]; then
+ log E "Cannot find gerrit project (${GERRIT_PROJECT}) within the repo tree to apply the patch"
+ abort
+ fi
+
+ local -r patch_dir=$(repo list "${repo_project}" --path-only)
local -r gerrit_url="ssh://git@${GERRIT_HOST}/${GERRIT_PROJECT}"
safe pushd "${patch_dir}" >/dev/null
fetch_apply_gerrit_refspec "${gerrit_url}" "${GERRIT_REFSPEC}"