Merge "Don't use the remote pool when using clang-tidy"
diff --git a/core/base_rules.mk b/core/base_rules.mk
index 3f93c2c..abe059b 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -77,6 +77,20 @@
 endif
 _path :=
 
+ifeq ($(LOCAL_HOST_MODULE),true)
+my_image_variant := host
+else ifeq ($(LOCAL_VENDOR_MODULE),true)
+my_image_variant := vendor
+else ifeq ($(LOCAL_OEM_MODULE),true)
+my_image_variant := vendor
+else ifeq ($(LOCAL_ODM_MODULE),true)
+my_image_variant := vendor
+else ifeq ($(LOCAL_PRODUCT_MODULE),true)
+my_image_variant := product
+else
+my_image_variant := core
+endif
+
 # TODO(b/135957588) Remove following workaround
 # LOCAL_PRODUCT_SERVICES_MODULE to LOCAL_PRODUCT_MODULE for all Android.mk
 ifndef LOCAL_PRODUCT_MODULE
diff --git a/core/binary.mk b/core/binary.mk
index 273605a..0b03f6a 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -156,6 +156,8 @@
 my_ndk_sysroot_lib :=
 my_api_level := 10000
 
+my_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
+
 ifneq ($(LOCAL_SDK_VERSION),)
   ifdef LOCAL_IS_HOST_MODULE
     $(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module)
@@ -164,7 +166,6 @@
   # Make sure we've built the NDK.
   my_additional_dependencies += $(SOONG_OUT_DIR)/ndk_base.timestamp
 
-  my_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
   ifneq (,$(filter arm64 x86_64,$(my_arch)))
     my_min_sdk_version := 21
   else
@@ -1114,37 +1115,39 @@
 endif
 
 ###################################################################
+## Convert to sanitized names where they exist.
+## These lists come from sanitizerStaticLibsMap; see
+## build/soong/cc/sanitize.go
+##
+## $(1): list of static dependencies
+## $(2): name of sanitizer (e.g. cfi, hwasan)
+##################################################################
+define use_soong_sanitized_static_libraries
+  $(foreach lib,$(1),$(if $(filter $(lib),\
+      $(SOONG_$(2)_$(my_image_variant)_$(my_arch)_STATIC_LIBRARIES)),\
+      $(lib).$(2),$(lib)))
+endef
+
+###################################################################
 ## When compiling a CFI enabled target, use the .cfi variant of any
 ## static dependencies (where they exist).
 ##################################################################
-define use_soong_cfi_static_libraries
-  $(foreach l,$(1),$(if $(filter $(l),$(SOONG_CFI_STATIC_LIBRARIES)),\
-      $(l).cfi,$(l)))
-endef
-
 ifneq ($(filter cfi,$(my_sanitize)),)
-  my_whole_static_libraries := $(call use_soong_cfi_static_libraries,\
-    $(my_whole_static_libraries))
-  my_static_libraries := $(call use_soong_cfi_static_libraries,\
-    $(my_static_libraries))
+  my_whole_static_libraries := $(call use_soong_sanitized_static_libraries,\
+    $(my_whole_static_libraries),cfi)
+  my_static_libraries := $(call use_soong_sanitized_static_libraries,\
+    $(my_static_libraries),cfi)
 endif
 
-ifneq ($(LOCAL_USE_VNDK),)
-  my_soong_hwasan_static_libraries := $(SOONG_HWASAN_VENDOR_STATIC_LIBRARIES)
-else
-  my_soong_hwasan_static_libraries = $(SOONG_HWASAN_STATIC_LIBRARIES)
-endif
-
-define use_soong_hwasan_static_libraries
-  $(foreach l,$(1),$(if $(filter $(l),$(my_soong_hwasan_static_libraries)),\
-      $(l).hwasan,$(l)))
-endef
-
+###################################################################
+## When compiling a hwasan enabled target, use the .hwasan variant
+## of any static dependencies (where they exist).
+##################################################################
 ifneq ($(filter hwaddress,$(my_sanitize)),)
-  my_whole_static_libraries := $(call use_soong_hwasan_static_libraries,\
-    $(my_whole_static_libraries))
-  my_static_libraries := $(call use_soong_hwasan_static_libraries,\
-    $(my_static_libraries))
+  my_whole_static_libraries := $(call use_soong_sanitized_static_libraries,\
+    $(my_whole_static_libraries),hwasan)
+  my_static_libraries := $(call use_soong_sanitized_static_libraries,\
+    $(my_static_libraries),hwasan)
 endif
 
 ###########################################################
diff --git a/core/board_config.mk b/core/board_config.mk
index d4fe618..43a34f9 100644
--- a/core/board_config.mk
+++ b/core/board_config.mk
@@ -91,6 +91,10 @@
 
 _board_strip_readonly_list += $(_dynamic_partitions_var_list)
 
+# Kernel related variables
+_board_strip_readonly_list += \
+  BOARD_KERNEL_BINARIES \
+
 _build_broken_var_list := \
   BUILD_BROKEN_DUP_RULES \
   BUILD_BROKEN_ELF_PREBUILT_PRODUCT_COPY_FILES \
diff --git a/target/product/gsi/Android.mk b/target/product/gsi/Android.mk
index c491d4a..6775131 100644
--- a/target/product/gsi/Android.mk
+++ b/target/product/gsi/Android.mk
@@ -211,3 +211,13 @@
 LOCAL_MODULE_RELATIVE_PATH := init
 
 include $(BUILD_PREBUILT)
+
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := init.vndk-nodef.rc
+LOCAL_SRC_FILES := $(LOCAL_MODULE)
+LOCAL_MODULE_CLASS := ETC
+LOCAL_SYSTEM_EXT_MODULE := true
+LOCAL_MODULE_RELATIVE_PATH := init
+
+include $(BUILD_PREBUILT)
diff --git a/target/product/gsi/init.gsi.rc b/target/product/gsi/init.gsi.rc
index c6faba7..f482843 100644
--- a/target/product/gsi/init.gsi.rc
+++ b/target/product/gsi/init.gsi.rc
@@ -1,3 +1,5 @@
 #
 # Android init script for GSI required initialization
 #
+
+import /system/system_ext/etc/init/init.vndk-${ro.vndk.version:-nodef}.rc
diff --git a/target/product/gsi/init.legacy-gsi.rc b/target/product/gsi/init.legacy-gsi.rc
deleted file mode 100644
index 00dd576..0000000
--- a/target/product/gsi/init.legacy-gsi.rc
+++ /dev/null
@@ -1,3 +0,0 @@
-# If ro.vndk.version is not defined, import init.vndk-27.rc.
-import /system/etc/init/gsi/init.vndk-${ro.vndk.version:-27}.rc
-
diff --git a/target/product/gsi/init.vndk-27.rc b/target/product/gsi/init.vndk-27.rc
deleted file mode 100644
index d464a2f..0000000
--- a/target/product/gsi/init.vndk-27.rc
+++ /dev/null
@@ -1,3 +0,0 @@
-on early-init
-    # Set ro.vndk.version to 27 so that O-MR1-VENDOR can run latest GSI.
-    setprop ro.vndk.version 27
diff --git a/target/product/gsi/init.vndk-nodef.rc b/target/product/gsi/init.vndk-nodef.rc
new file mode 100644
index 0000000..efeef11
--- /dev/null
+++ b/target/product/gsi/init.vndk-nodef.rc
@@ -0,0 +1,3 @@
+on early-init
+    # Must define BOARD_VNDK_VERSION
+    exec - root -- /system/bin/reboot bootloader
diff --git a/target/product/gsi_release.mk b/target/product/gsi_release.mk
index 5421ee0..46c956d 100644
--- a/target/product/gsi_release.mk
+++ b/target/product/gsi_release.mk
@@ -49,7 +49,8 @@
 # GSI specific tasks on boot
 PRODUCT_PACKAGES += \
     gsi_skip_mount.cfg \
-    init.gsi.rc
+    init.gsi.rc \
+    init.vndk-nodef.rc \
 
 # Support additional P and Q VNDK packages
 PRODUCT_EXTRA_VNDK_VERSIONS := 28 29
diff --git a/target/product/legacy_gsi_release.mk b/target/product/legacy_gsi_release.mk
index c1646bb..09b96fb 100644
--- a/target/product/legacy_gsi_release.mk
+++ b/target/product/legacy_gsi_release.mk
@@ -16,22 +16,8 @@
 
 include $(SRC_TARGET_DIR)/product/gsi_release.mk
 
-PRODUCT_ARTIFACT_PATH_REQUIREMENT_ALLOWED_LIST += \
-    system/etc/init/init.legacy-gsi.rc \
-    system/etc/init/gsi/init.vndk-27.rc \
-    system/etc/ld.config.vndk_lite.txt \
-
 # Legacy GSI support additional O-MR1 interface
 PRODUCT_EXTRA_VNDK_VERSIONS += 27
 
-# Support for the O-MR1 devices
-PRODUCT_COPY_FILES += \
-    build/make/target/product/gsi/init.legacy-gsi.rc:system/etc/init/init.legacy-gsi.rc \
-    build/make/target/product/gsi/init.vndk-27.rc:system/etc/init/gsi/init.vndk-27.rc
-
-# Namespace configuration file for non-enforcing VNDK
-PRODUCT_PACKAGES += \
-    ld.config.vndk_lite.txt
-
 # Legacy GSI relax the compatible property checking
 PRODUCT_COMPATIBLE_PROPERTY_OVERRIDE := false