coverage: Add a script to generate directories per board.

This script reads the latest relevant build per board and then reads the
output of the GetDepGraph step. It then reads all the installed files
and outputs the directories under platform and platform2 that are being
installed on each board. Later, this will output a file that will be
used in zero coverage calculations. This is meant to be run manually
until zero coverage can do this automatically.

Output from the script - http://go/paste/6585903727247360

BUG=b:223224702
TEST=ran manually ./boards.sh

Change-Id: Ifc3048bfd4d17c910dd462de1c0927faab7cc142
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crostestutils/+/3829998
Reviewed-by: Kshitij Pancholi <panchok@google.com>
Reviewed-by: Katherine Threlkeld <kathrelkeld@chromium.org>
Commit-Queue: Srinivas Hegde <srinivashegde@google.com>
Tested-by: Srinivas Hegde <srinivashegde@google.com>
diff --git a/provingground/coverage/boards.sh b/provingground/coverage/boards.sh
new file mode 100755
index 0000000..1875619
--- /dev/null
+++ b/provingground/coverage/boards.sh
@@ -0,0 +1,107 @@
+#!/bin/bash
+# Copyright 2022 The ChromiumOS Authors.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+declare -A platPaths
+declare -A plat2Paths
+boards=(
+"brya")
+
+###########################################################
+# Get the build number of the latest relevant build.
+# GLOBALS:
+#  board: Board to get the build number for.
+# ARGS: None
+###########################################################
+build_number() {
+    local ps="chromeos/postsubmit/${board}-postsubmit"
+    local tag="relevance:relevant"
+    echo "Querying ${ps} for last relevant successful build"
+    bNum=$(bb ls "${ps}" -1 -status success -t "${tag}" -json | jq '.number')
+    echo "Found build number: ${bNum}"
+
+    if [ -z "${bNum}" ]
+    then
+        echo "No build number found."
+        exit
+    fi
+}
+
+###########################################################
+# Get all the files under platform and platform2 dirs.
+# GLOBALS:
+#   platPaths: Dictionary containing different file paths.
+# ARGS:
+#   path: The file path to check for.
+###########################################################
+plat_files() {
+    path=$1
+    d=$(echo "${path}" | cut -d '/' -f 3)
+    if [[ ${path} == src/platform/* ]]
+    then
+        platPaths["${d}"]=1
+    elif [[ ${path} == src/platform2/* ]]
+    then
+        plat2Paths["${d}"]=1
+    fi
+}
+
+###########################################################
+# Gets all the CPP files installed on the board.
+# GLOBALS:
+#   board: Board to check the installed files for.
+#   bNum: Build number of board to check for.
+# ARGS: None
+###########################################################
+cpp_files() {
+    local bn="chromeos/postsubmit/${board}-postsubmit/${bNum}"
+    local api="chromite.api.DependencyService/GetBuildDependencyGraph"
+    local query="dependency graph calculation|call ${api}"
+    resp=$(bb log "${bn}" "${query}" response | jq '.')
+
+    echo "Dep graph section start"
+    local qp=".depGraph.packageDeps[].dependencySourcePaths[].path"
+    for path in $(echo "${resp}" | jq "${qp}")
+    do
+        # The path is of the form "src/platform2/f1.cc"
+        # Edit path to remove end quotes.
+        path=$(echo "${path}" | sed 's/.$//' | sed 's/^.//')
+        plat_files "${path}"
+    done
+    echo "Dep graph section done"
+
+    echo "SDK Dep graph section start"
+    qp=".sdkDepGraph.packageDeps[].dependencySourcePaths[].path"
+    for path in $(echo "${resp}" | jq "${qp}")
+    do
+        # The path is of the form "src/platform2/f1.cc"
+        # Edit path to remove end quotes.
+        path=$(echo "${path}" | sed 's/.$//' | sed 's/^.//')
+        plat_files "${path}"
+    done
+    echo "SDK Dep graph section done"
+}
+
+for board in "${boards[@]}"
+do
+    echo "Getting build number for ${board}"
+    build_number
+
+    echo "Finding CPP files for ${board}"
+    cpp_files
+
+    echo "All dirs in src/platform for ${board}"
+    for dir in "${!platPaths[@]}"
+    do
+        echo "src/platform/${dir}/"
+    done
+
+    echo "*************************************"
+    echo "All dirs in src/platform2 for ${board}"
+    for dir in "${!plat2Paths[@]}"
+    do
+        echo "src/platform2/${dir}"
+    done
+    echo "*************************************"
+done