Add qemu8 to host package. am: e677fdd856

Original change: https://android-review.googlesource.com/c/device/google/cuttlefish_vmm/+/2810815

Change-Id: I582cf65018d7058b8c22689217c369fc62355ec5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/Android.bp b/Android.bp
index 9f4fbf6..fb61904 100644
--- a/Android.bp
+++ b/Android.bp
@@ -165,3 +165,70 @@
   defaults: ["cuttlefish_host"],
   check_elf_files: false,
 }
+cc_prebuilt_binary {
+  name: "x86_64_linux_gnu_libc++.so.1_binary_for_qemu",
+  srcs: ["qemu/x86_64-linux-gnu/bin/libc++.so.1"],
+  stem: "libc++.so.1",
+  defaults: ["cuttlefish_host"],
+  check_elf_files: false,
+}
+cc_prebuilt_binary {
+  name: "x86_64_linux_gnu_libgfxstream_backend.so.0_binary_for_qemu",
+  srcs: ["qemu/x86_64-linux-gnu/bin/libgfxstream_backend.so.0"],
+  stem: "libgfxstream_backend.so.0",
+  defaults: ["cuttlefish_host"],
+  check_elf_files: false,
+}
+cc_prebuilt_binary {
+  name: "x86_64_linux_gnu_librutabaga_gfx_ffi.so.0_binary_for_qemu",
+  srcs: ["qemu/x86_64-linux-gnu/bin/librutabaga_gfx_ffi.so.0"],
+  stem: "librutabaga_gfx_ffi.so.0",
+  defaults: ["cuttlefish_host"],
+  check_elf_files: false,
+}
+cc_prebuilt_binary {
+  name: "x86_64_linux_gnu_libz.so.1_binary_for_qemu",
+  srcs: ["qemu/x86_64-linux-gnu/bin/libz.so.1"],
+  stem: "libz.so.1",
+  defaults: ["cuttlefish_host"],
+  check_elf_files: false,
+}
+cc_prebuilt_binary {
+  name: "x86_64_linux_gnu_qemu-system-aarch64_binary_for_qemu",
+  srcs: ["qemu/x86_64-linux-gnu/bin/qemu-system-aarch64"],
+  stem: "qemu-system-aarch64",
+  defaults: ["cuttlefish_host"],
+  check_elf_files: false,
+}
+cc_prebuilt_binary {
+  name: "x86_64_linux_gnu_qemu-system-riscv64_binary_for_qemu",
+  srcs: ["qemu/x86_64-linux-gnu/bin/qemu-system-riscv64"],
+  stem: "qemu-system-riscv64",
+  defaults: ["cuttlefish_host"],
+  check_elf_files: false,
+}
+cc_prebuilt_binary {
+  name: "x86_64_linux_gnu_qemu-system-x86_64_binary_for_qemu",
+  srcs: ["qemu/x86_64-linux-gnu/bin/qemu-system-x86_64"],
+  stem: "qemu-system-x86_64",
+  defaults: ["cuttlefish_host"],
+  check_elf_files: false,
+}
+prebuilt_usr_share_host {
+  name: "x86_64_efi-virtio.rom_resource_for_qemu",
+  src: "qemu/x86_64-linux-gnu/usr/share/qemu/efi-virtio.rom",
+  filename: "efi-virtio.rom",
+  sub_dir: "qemu",
+}
+prebuilt_usr_share_host {
+  name: "x86_64_en-us_resource_for_qemu",
+  src: "qemu/x86_64-linux-gnu/usr/share/qemu/keymaps/en-us",
+  filename: "en-us",
+  sub_dir: "qemu/keymaps",
+}
+prebuilt_usr_share_host {
+  name: "x86_64_opensbi-riscv64-generic-fw_dynamic.bin_resource_for_qemu",
+  src: "qemu/x86_64-linux-gnu/usr/share/qemu/opensbi-riscv64-generic-fw_dynamic.bin",
+  filename: "opensbi-riscv64-generic-fw_dynamic.bin",
+  sub_dir: "qemu",
+}
diff --git a/gen_android_bp.sh b/gen_android_bp.sh
index e80fd94..62ceeaf 100755
--- a/gen_android_bp.sh
+++ b/gen_android_bp.sh
@@ -10,6 +10,32 @@
 # under get_arch_dir() in cuttlefish_vmm, where is seccomp?
 readonly subdir="etc/seccomp"
 
+# Replaces the generated section with content read from stdin.
+#
+# Args:
+#   path to the file to edit in place
+#   tag uniquely identifying the generated section.
+#     The generated content is delimited by two lines ending with
+#     "Start of generated ${tag}" and "End of generated ${tag}"
+function update_generated_section {
+  local -r file="$1"
+  local -r tag="$2"
+  local -r lead="^.*Start of generated ${tag}$"
+  local -r tail="^.*End of generated ${tag}$"
+  egrep --silent "${lead}" "${file}"
+  egrep --silent "${tail}" "${file}"
+  sed -i -e "
+    /$lead/,/$tail/{
+      /$lead/{
+        p;
+        a \    // Generated by device/google/cuttlefish_vmm/gen_android_bp.sh
+        r /dev/stdin
+      };
+      /$tail/p;
+      d
+    }" "${file}"""
+}
+
 function remove_trailing_slash {
   if [[ $1 == "/" ]]; then
     echo $i
@@ -182,14 +208,55 @@
       --check_elf_files="false" | "${comment_or_noop}"
   done
 done
+
+  for binary_path in qemu/x86_64-linux-gnu/bin/*.so* qemu/x86_64-linux-gnu/bin/qemu-system*; do
+    gen_module "cc_prebuilt_binary" '  ' \
+      --name="\"x86_64_linux_gnu_$(basename "${binary_path}")_binary_for_qemu\"" \
+      --srcs="[\"${binary_path}\"]" \
+      --stem="\"$(basename "${binary_path}")"\" \
+      --defaults="[\"cuttlefish_host\"]" \
+      --check_elf_files="false"
+  done
+  resource_paths=(
+    qemu/efi-virtio.rom
+    qemu/keymaps/en-us
+    qemu/opensbi-riscv64-generic-fw_dynamic.bin
+  )
+
+  for resource_path in "${resource_paths[@]}"
+  do
+    local base_name="$(basename "${resource_path}")"
+    local arch='x86_64'
+    local arch_dir="$(get_arch_dir ${arch})"
+    local sub_dir="$(dirname "${resource_path}")"
+    gen_module "prebuilt_usr_share_host" '  ' \
+      --name="\"${arch}_${base_name}_resource_for_qemu\"" \
+      --src="\"qemu/x86_64-linux-gnu/usr/share/${resource_path}\"" \
+      --filename="\"${base_name}\"" \
+      --sub_dir="\"${sub_dir}\""
+  done
 }
 
+function generate_all_cuttlefish_host_package_android_bp() {
+  #TODO: Handle Crosvm prebuilts which are currently performed manually.
+  qemu_binaries="$(grep "_binary_for_qemu" Android.bp | sed 's/name: /  /g')"
+  qemu_resources="$(grep "_resource_for_qemu" Android.bp | sed 's/name: /  /g')"
+
+  local android_bp_file="../cuttlefish/build/Android.bp"
+  echo "${qemu_binaries}" | update_generated_section "${android_bp_file}" "qemu_x86_64_linux_gnu_binary"
+  echo "${qemu_resources}" | update_generated_section "${android_bp_file}" "qemu_x86_64_linux_gnu_resource"
+}
+
+
 # main
 
 # Set the current directory to the script location.
 cd "$(dirname "$0")"
 
 gen_main_android_bp > $(get_output_file .)
+generate_all_cuttlefish_host_package_android_bp
+
+
 for arch in ${seccomp_archs[@]}; do
   arch_dir=$(get_arch_dir ${arch})
   outfile="$(get_output_file ${arch_dir})"