nnapi: update to latest dependencies, improve docs

This CL brings all the NNAPI dependencies up to latest as of 2021-01-11.
It also updates the documentation to explain how to do this
step-by-step, as well as adding the script to make the uprev easier.

BUG=b:177048246 b:161954169
TEST=cq passes

Change-Id: I3b349efd352dd48cd969eb1ab9e9d307466b9663
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/chromiumos-overlay/+/2620965
Commit-Queue: Jim Pollock <jmpollock@chromium.org>
Tested-by: Jim Pollock <jmpollock@chromium.org>
Reviewed-by: Michael Pishchagin <mblsha@google.com>
Auto-Submit: Jim Pollock <jmpollock@chromium.org>
diff --git a/chromeos-base/nnapi/README.md b/chromeos-base/nnapi/README.md
index 79238c7..cc46054 100644
--- a/chromeos-base/nnapi/README.md
+++ b/chromeos-base/nnapi/README.md
@@ -1,4 +1,9 @@
-# NNAPI Dependency Updating Instructions
+# NNAPI Updating Instructions
+
+## Quick Note
+
+If you're just updating code within `platform2/nnapi`, skip down to
+[Uprev the ebuild](#uprev-the-ebuild).
 
 ## Background
 
@@ -82,27 +87,56 @@
 repo upload --cbr . --no-verify
 ```
 
-### Update the Copybara repo
+### Update the aosp/system/core repo
 
 As described earlier, `aosp/system/core/libcutils` and
 `aosp/system/core/libutils` are updated by merging upstream into the master
-of `aosp/platform/system/core`. Given the amount of changes in this repo,
-it is best to ask the git admins to do this.
+of `aosp/platform/system/core`. This is a bit more involved than the previous
+cases, since this repo isn't mapped into the ChromeOS tree. It's quite
+similar though...
 
-#### Raise a bug for Git admins
+Steps:
 
-Use http://go/git-admin-bug to raise an Infra-Git ticket template
-with the following details:
+1.  Check out the core repo.
+1.  Create a merge branch from `origin/master`.
+1.  Do a non-ff git merge from `origin/upstream`.
+1.  Upload to gerrit.
+1.  Force submit / 'chump' the change since CQ won't process it.
+1.  Within a few minutes, copybara should update `libcutils` and `libutils`.
+1.  Check the [Copybara dashboard](https://copybara.corp.google.com/list-jobs?piperConfigPath=%2F%2Fdepot%2Fgoogle3%2Fthird_party%2Fcopybara-gsubtreed%2Faosp%2Fcopy.bara.sky).
 
-> Summary: "Please fast-forward master to upstream for aosp/system/core".
+```bash
+cd /tmp
+git clone https://chromium.googlesource.com/aosp/platform/system/core
+# Set up the commit hooks
+cd core
+f=`git rev-parse --git-dir`/hooks/commit-msg
+mkdir -p $(dirname $f)
+curl -Lo $f https://gerrit-review.googlesource.com/tools/hooks/commit-msg
+chmod +x $f
+# Done setting up the repo
+git checkout -b merge
+git merge origin/upstream --no-ff
+# This will ask for an appropriate commit msg
+git commit
+# This will upload to gerrit
+git push origin HEAD:refs/for/master
+```
 
-> * googlesource host (e.g. chromium, chrome-internal): chromium
-> * name of the repo: https://chromium.googlesource.com/aosp/platform/system/core
-> * permissions: default
->
-> Please fast-forward master to the tip of upstream, thank you!
+### Uprev the ebuild
 
-### Update the commit id and tree id in the ebuild
+Once you have any code changes and dependencies submitted via CQ, do a
+`repo sync` and you'll be able to uprev the ebuild. This is important, since
+you will not be able to get the git commit id's you need until this is done.
 
-TODO once I have the CROS_WORKON_MANUAL_UPREV change committed and can actually
-do this and get the steps exactly right.
+There is a script in this directory, `get_git_ids.sh` that will print out the
+two lines you need to replace.
+
+Steps:
+
+1.  Run `get_git_ids.sh`.
+1.  Rename `nnapi-0.0.2-r<N>.ebuild` to `nnapi-0.0.2-r<N+1>.ebuild`.
+1.  Replace CROS_WORKON_COMMIT and CROS_WORKON_TREE in that ebuild with the
+    output of the `get_gid_ids.sh` script.
+1.  Fix any build issues by creating ebuild patches (see the `files` dir).
+1.  Upload to gerrit and review as normal.
diff --git a/chromeos-base/nnapi/files/00009-libutils-timer-cast.patch b/chromeos-base/nnapi/files/00009-libutils-timer-cast.patch
new file mode 100644
index 0000000..488adfa
--- /dev/null
+++ b/chromeos-base/nnapi/files/00009-libutils-timer-cast.patch
@@ -0,0 +1,15 @@
+Fix signed / unsigned comparison warning as error.
+
+diff --git a/platform2/aosp/system/core/libutils/Timers.cpp b/platform2/aosp/system/core/libutils/Timers.cpp
+index fd3f4a9..7a98896 100644
+--- a/Timers.cpp
++++ b/Timers.cpp
+@@ -28,7 +28,7 @@
+ static constexpr size_t clock_id_max = 5;
+
+ static void checkClockId(int clock) {
+-    if (clock < 0 || clock >= clock_id_max) abort();
++    if (clock < 0 || clock >= static_cast<int>(clock_id_max)) abort();
+ }
+
+ #if defined(__linux__)
\ No newline at end of file
diff --git a/chromeos-base/nnapi/get_git_ids.sh b/chromeos-base/nnapi/get_git_ids.sh
new file mode 100755
index 0000000..ce6c405
--- /dev/null
+++ b/chromeos-base/nnapi/get_git_ids.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This is a little helper script to print out the CROS_WORKON_COMMIT and
+# CROS_WORKON_TREE values for the nnapi ebuild that represent the latest
+# commits in the various dependent repositories. This is useful when
+# uprev'ing the ebuild, since chromeos-base/nnapi is set to
+# CROS_WORKON_MANUAL_UPREV
+
+readonly EBUILD_FILE="nnapi-9999.ebuild"
+
+if [[ ! -f "${EBUILD_FILE}" ]]; then
+    echo "Please run this script from the dir containing ${EBUILD_FILE}"
+    exit 1
+fi
+
+# Source to get the variables we need
+# shellcheck source=nnapi-9999.ebuild
+source "${EBUILD_FILE}" 2> /dev/null
+
+# Get to src root
+cd ../../../../ || exit 1
+
+tree_ids=""
+commits=""
+
+# Loop through the directories
+subtree_ctr=0
+for i in "${CROS_WORKON_LOCALNAME[@]}"; do
+  cd "${i}" || exit 1
+
+  # Append git commit for current dir
+  commit_id=$(git rev-parse HEAD)
+  if [[ -n "${commits}" ]]; then
+    commits="${commits} \"${commit_id}\""
+  else
+    commits="\"${commit_id}\""
+  fi
+
+  # Append tree id for each subtree.
+  subtree=${CROS_WORKON_SUBTREE[${subtree_ctr}]}
+  if [[ -n "${subtree}" ]]; then
+    for tree in ${subtree}; do
+      tree_id=$(git rev-parse HEAD:"${tree}")
+      if [[ -n "${tree_ids}" ]]; then
+        tree_ids="${tree_ids} \"${tree_id}\""
+      else
+        tree_ids="\"${tree_id}\""
+      fi
+    done
+  else
+    tree_id=$(git rev-parse HEAD:./)
+    tree_ids="${tree_ids} \"${tree_id}\""
+  fi
+
+  cd - > /dev/null || exit 1
+  subtree_ctr=$((subtree_ctr+1))
+done
+
+echo "CROS_WORKON_COMMIT=(${commits})"
+echo "CROS_WORKON_TREE=(${tree_ids})"
\ No newline at end of file
diff --git a/chromeos-base/nnapi/nnapi-0.0.2-r1.ebuild b/chromeos-base/nnapi/nnapi-0.0.2-r2.ebuild
similarity index 84%
rename from chromeos-base/nnapi/nnapi-0.0.2-r1.ebuild
rename to chromeos-base/nnapi/nnapi-0.0.2-r2.ebuild
index ea0ae32..8d0c4394 100644
--- a/chromeos-base/nnapi/nnapi-0.0.2-r1.ebuild
+++ b/chromeos-base/nnapi/nnapi-0.0.2-r2.ebuild
@@ -3,8 +3,8 @@
 
 EAPI=7
 
-CROS_WORKON_COMMIT=("b05e4a6b92b2cfe608b6cd8d5d37168680fc080e" "e9ef20b988f629406f6a8d7fe22ae5f006abdbd2" "c1e30221aa92e7979cf0a0ee65914849db8b2dcb" "e2ccff249b3be3583ffb0e9be35db7be54715ec9" "08495901b78c7c3d9a1a81e541897c2ec114fe34" "f0356097d584b884e24b67c789b4800ec6895bd2" "83caf7c58917b971de049e882ec9b23816f12ca1" "59f317632862d15b59278a0235eb901270c2889d")
-CROS_WORKON_TREE=("52a8a8b6d3bbca5e90d4761aa308a5541d52b1bb" "febb5c918e5047e2dd8a2bd416944894f76e41b3" "e7dba8c91c1f3257c34d4a7ffff0ea2537aeb6bb" "53a4656104a89df4072d3101327f51fcf6c9cbb2" "b4147760c8f1da9f6749f61748d2cacf89237717" "078088f837cd0a9b1c3123b5d93904f4ec2f2af6" "cbb1596cd3157db5ffe44d03d24c30cc9ed53e38" "6d3d9da9942b38f318bc49866e0dca5ffefd99c8" "95bef85dda5cf0836566c16c6b0651ae91cca7e2" "2ea48bccbe24f13f304b13776b86028ca6022818")
+CROS_WORKON_COMMIT=("85109a843d7310588ec7feea6775ace121125882" "23e2bf511667b4fa5859812a4e7945c8638f6603" "ab4ff9c1ded692a3529e9c03ea6943fe094df0f9" "a14d63edf6f0058f6c478093b8e90e35fa3314ec" "b7f8cf0f0beab62bc5a391226ebd835c2fe377dc" "8e369832671de86e05cbbd3eeb7ddfe7df95f1ec" "6b79fa280312109216ce8b3a4893f266775cddc2" "e386a40d816e794c12040936608d252ab96077a7")
+CROS_WORKON_TREE=("52a8a8b6d3bbca5e90d4761aa308a5541d52b1bb" "febb5c918e5047e2dd8a2bd416944894f76e41b3" "e7dba8c91c1f3257c34d4a7ffff0ea2537aeb6bb" "d0c498cd8aacda36a50685194a4f11a5538c36ec" "f3727b50e53c0a9f165bce6d96002698678ebe1b" "97c692ea262a87836db5893fc63567ed30eadea6" "4007f79bbd89b30be582cb0cdb1292ce377f34e1" "077dba53acf2e9a7a56288ee75d515afa7541b94" "bcea173391bb1aa3b0978ecc33a27d447e59eb18" "6a8c1be1913e7a9ccf5141a072ad595a1e9d3add")
 inherit cros-constants
 
 CROS_WORKON_MANUAL_UPREV="1"
@@ -87,6 +87,7 @@
 	"${FILESDIR}/00006-libhidl-cast-interface.patch"
 	"${FILESDIR}/00007-libbase-get-property-from-envvar.patch"
 	"${FILESDIR}/00008-libutils-memory-leak.patch"
+	"${FILESDIR}/00009-libutils-timer-cast.patch"
 )
 
 src_prepare() {
@@ -101,6 +102,7 @@
 	eapply -p2 "${FILESDIR}/00006-libhidl-cast-interface.patch"
 	eapply -p2 "${FILESDIR}/00007-libbase-get-property-from-envvar.patch"
 	eapply -p2 "${FILESDIR}/00008-libutils-memory-leak.patch"
+	eapply -p2 "${FILESDIR}/00009-libutils-timer-cast.patch"
 	popd || exit
 
 	eapply_user
@@ -150,8 +152,9 @@
 		# AddressSanitizer: requested allocation size 0xfffffffffffffffe
 		# We can't use allocator_may_return_null=1 as it prints a warning that the
 		# toolchain considers an error.
-		gtest_excl_filter+="SharedBufferTest.TestAlloc:"
-		gtest_excl_filter+="SharedBufferTest.TestEditResize:"
+		gtest_excl_filter+="SharedBufferTest.alloc_null:"
+		gtest_excl_filter+="SharedBufferTest.editResize_null:"
+		gtest_excl_filter+="SharedBufferTest.editResize_death:"
 
 		# ForkSafe leaves some threads running which results in warning printed:
 		# ==26==Running thread 23 was not suspended. False leaks are possible.
diff --git a/chromeos-base/nnapi/nnapi-9999.ebuild b/chromeos-base/nnapi/nnapi-9999.ebuild
index 16958e8..e7c150f 100644
--- a/chromeos-base/nnapi/nnapi-9999.ebuild
+++ b/chromeos-base/nnapi/nnapi-9999.ebuild
@@ -85,6 +85,7 @@
 	"${FILESDIR}/00006-libhidl-cast-interface.patch"
 	"${FILESDIR}/00007-libbase-get-property-from-envvar.patch"
 	"${FILESDIR}/00008-libutils-memory-leak.patch"
+	"${FILESDIR}/00009-libutils-timer-cast.patch"
 )
 
 src_prepare() {
@@ -99,6 +100,7 @@
 	eapply -p2 "${FILESDIR}/00006-libhidl-cast-interface.patch"
 	eapply -p2 "${FILESDIR}/00007-libbase-get-property-from-envvar.patch"
 	eapply -p2 "${FILESDIR}/00008-libutils-memory-leak.patch"
+	eapply -p2 "${FILESDIR}/00009-libutils-timer-cast.patch"
 	popd || exit
 
 	eapply_user
@@ -148,8 +150,9 @@
 		# AddressSanitizer: requested allocation size 0xfffffffffffffffe
 		# We can't use allocator_may_return_null=1 as it prints a warning that the
 		# toolchain considers an error.
-		gtest_excl_filter+="SharedBufferTest.TestAlloc:"
-		gtest_excl_filter+="SharedBufferTest.TestEditResize:"
+		gtest_excl_filter+="SharedBufferTest.alloc_null:"
+		gtest_excl_filter+="SharedBufferTest.editResize_null:"
+		gtest_excl_filter+="SharedBufferTest.editResize_death:"
 
 		# ForkSafe leaves some threads running which results in warning printed:
 		# ==26==Running thread 23 was not suspended. False leaks are possible.