Run test build: Create special HiddenApi shard.

Very few tests depend on hiddenapi so build them in their own shard.

This removes the hiddenapi dependency from all other shards,
which in turn removes the dependency on ART headers and C++ code.

Bug: 213297521
Test: ./art/test.py -b -r --host
Test: ./art/test.py -b -r --host -t 674-hiddenapi
Change-Id: I5d18d49b70bdaf9c3492ff4a82d32f7e9ba96873
diff --git a/test/run_test_build.py b/test/run_test_build.py
index b7381dd..64d0eb0 100755
--- a/test/run_test_build.py
+++ b/test/run_test_build.py
@@ -69,7 +69,7 @@
 
     self.bootclasspath = args.bootclasspath.absolute()
     self.d8 = args.d8.absolute()
-    self.hiddenapi = args.hiddenapi.absolute()
+    self.hiddenapi = args.hiddenapi.absolute() if args.hiddenapi else None
     self.jasmin = args.jasmin.absolute()
     self.smali = args.smali.absolute()
     self.soong_zip = args.soong_zip.absolute()
@@ -484,10 +484,15 @@
   ziproot = args.out.absolute().parent / "zip"
   srcdirs = set(s.parents[-4].absolute() for s in args.srcs)
 
+  # Special hidden-api shard: If the --hiddenapi flag is provided, build only
+  # hiddenapi tests. Otherwise exclude all hiddenapi tests from normal shards.
+  def filter_by_hiddenapi(srcdir: Path) -> bool:
+    return (args.hiddenapi != None) == ("hiddenapi" in srcdir.name)
+
   # Initialize the test objects.
   # We need to do this before we change the working directory below.
   tests: List[BuildTestContext] = []
-  for srcdir in srcdirs:
+  for srcdir in filter(filter_by_hiddenapi, srcdirs):
     dstdir = ziproot / args.mode / srcdir.name
     copytree(srcdir, dstdir)
     tests.append(BuildTestContext(args, android_build_top, dstdir))