Merge "Support for install multiple boot images."
diff --git a/core/Makefile b/core/Makefile
index 8e74dfe..3cc9831 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -181,10 +181,24 @@
 FINAL_VENDOR_DEFAULT_PROPERTIES += \
     $(call collapse-pairs, $(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))
 
+# Add cpu properties for bionic and ART.
 FINAL_VENDOR_DEFAULT_PROPERTIES += ro.bionic.arch=$(TARGET_ARCH)
-FINAL_VENDOR_DEFAULT_PROPERTIES += ro.bionic.cpu_variant=$(TARGET_CPU_VARIANT)
+FINAL_VENDOR_DEFAULT_PROPERTIES += ro.bionic.cpu_variant=$(TARGET_CPU_VARIANT_RUNTIME)
 FINAL_VENDOR_DEFAULT_PROPERTIES += ro.bionic.2nd_arch=$(TARGET_2ND_ARCH)
-FINAL_VENDOR_DEFAULT_PROPERTIES += ro.bionic.2nd_cpu_variant=$(TARGET_2ND_CPU_VARIANT)
+FINAL_VENDOR_DEFAULT_PROPERTIES += ro.bionic.2nd_cpu_variant=$(TARGET_2ND_CPU_VARIANT_RUNTIME)
+
+FINAL_VENDOR_DEFAULT_PROPERTIES += persist.sys.dalvik.vm.lib.2=libart.so
+FINAL_VENDOR_DEFAULT_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).variant=$(DEX2OAT_TARGET_CPU_VARIANT_RUNTIME)
+ifneq ($(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
+  FINAL_VENDOR_DEFAULT_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).features=$(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
+endif
+
+ifdef TARGET_2ND_ARCH
+  FINAL_VENDOR_DEFAULT_PROPERTIES += dalvik.vm.isa.$(TARGET_2ND_ARCH).variant=$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT_RUNTIME)
+  ifneq ($($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
+    FINAL_VENDOR_DEFAULT_PROPERTIES += dalvik.vm.isa.$(TARGET_2ND_ARCH).features=$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
+  endif
+endif
 
 # Although these variables are prefixed with TARGET_RECOVERY_, they are also needed under charger
 # mode (via libminui).
diff --git a/core/config.mk b/core/config.mk
index 518e138..5f08f2f 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -298,12 +298,24 @@
 $(call validate-kernel-headers,$(TARGET_PRODUCT_KERNEL_HEADERS))
 
 # Clean up/verify variables defined by the board config file.
+# TODO: Move this to right after the BoardConfig parsing.
 TARGET_BOOTLOADER_BOARD_NAME := $(strip $(TARGET_BOOTLOADER_BOARD_NAME))
 TARGET_CPU_ABI := $(strip $(TARGET_CPU_ABI))
 ifeq ($(TARGET_CPU_ABI),)
   $(error No TARGET_CPU_ABI defined by board config: $(board_config_mk))
 endif
 TARGET_CPU_ABI2 := $(strip $(TARGET_CPU_ABI2))
+TARGET_CPU_VARIANT := $(strip $(TARGET_CPU_VARIANT))
+TARGET_CPU_VARIANT_RUNTIME := $(strip $(TARGET_CPU_VARIANT_RUNTIME))
+
+TARGET_2ND_CPU_ABI := $(strip $(TARGET_2ND_CPU_ABI))
+TARGET_2ND_CPU_ABI2 := $(strip $(TARGET_2ND_CPU_ABI2))
+TARGET_2ND_CPU_VARIANT := $(strip $(TARGET_2ND_CPU_VARIANT))
+TARGET_2ND_CPU_VARIANT_RUNTIME := $(strip $(TARGET_2ND_CPU_VARIANT_RUNTIME))
+
+# Default *_CPU_VARIANT_RUNTIME to CPU_VARIANT if unspecified.
+TARGET_CPU_VARIANT_RUNTIME := $(or $(TARGET_CPU_VARIANT_RUNTIME),$(TARGET_CPU_VARIANT))
+TARGET_2ND_CPU_VARIANT_RUNTIME := $(or $(TARGET_2ND_CPU_VARIANT_RUNTIME),$(TARGET_2ND_CPU_VARIANT))
 
 BOARD_KERNEL_BASE := $(strip $(BOARD_KERNEL_BASE))
 BOARD_KERNEL_PAGESIZE := $(strip $(BOARD_KERNEL_PAGESIZE))
@@ -1135,11 +1147,13 @@
 first_non_empty_of_three = $(if $(1),$(1),$(if $(2),$(2),$(3)))
 DEX2OAT_TARGET_ARCH := $(TARGET_ARCH)
 DEX2OAT_TARGET_CPU_VARIANT := $(call first_non_empty_of_three,$(TARGET_CPU_VARIANT),$(TARGET_ARCH_VARIANT),default)
+DEX2OAT_TARGET_CPU_VARIANT_RUNTIME := $(call first_non_empty_of_three,$(TARGET_CPU_VARIANT_RUNTIME),$(TARGET_ARCH_VARIANT),default)
 DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES := default
 
 ifdef TARGET_2ND_ARCH
 $(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH := $(TARGET_2ND_ARCH)
 $(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT := $(call first_non_empty_of_three,$(TARGET_2ND_CPU_VARIANT),$(TARGET_2ND_ARCH_VARIANT),default)
+$(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT_RUNTIME := $(call first_non_empty_of_three,$(TARGET_2ND_CPU_VARIANT_RUNTIME),$(TARGET_2ND_ARCH_VARIANT),default)
 $(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES := default
 endif
 
diff --git a/core/main.mk b/core/main.mk
index f323aae..b63fd61 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -252,6 +252,11 @@
 ADDITIONAL_PRODUCT_PROPERTIES += ro.boot.dynamic_partitions_retrofit=true
 endif
 
+# Add the system server compiler filter if they are specified for the product.
+ifneq (,$(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER))
+ADDITIONAL_PRODUCT_PROPERTIES += dalvik.vm.systemservercompilerfilter=$(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER)
+endif
+
 # -----------------------------------------------------------------
 ###
 ### In this section we set up the things that are different
@@ -264,26 +269,6 @@
 is_sdk_build := true
 endif
 
-# Add build properties for ART. These define system properties used by installd
-# to pass flags to dex2oat.
-ADDITIONAL_BUILD_PROPERTIES += persist.sys.dalvik.vm.lib.2=libart.so
-ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).variant=$(DEX2OAT_TARGET_CPU_VARIANT)
-ifneq ($(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
-  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).features=$(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
-endif
-
-ifdef TARGET_2ND_ARCH
-  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_2ND_ARCH).variant=$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT)
-  ifneq ($($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
-    ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_2ND_ARCH).features=$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
-  endif
-endif
-
-# Add the system server compiler filter if they are specified for the product.
-ifneq (,$(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER))
-ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.systemservercompilerfilter=$(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER)
-endif
-
 ## user/userdebug ##
 
 user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT))
diff --git a/core/pdk_config.mk b/core/pdk_config.mk
index 383c11a..ce78ece 100644
--- a/core/pdk_config.mk
+++ b/core/pdk_config.mk
@@ -20,8 +20,6 @@
   target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates \
   target/common/obj/JAVA_LIBRARIES/core-oj_intermediates \
   target/common/obj/JAVA_LIBRARIES/core-libart_intermediates \
-  target/common/obj/JAVA_LIBRARIES/legacy-test_intermediates \
-  target/common/obj/JAVA_LIBRARIES/legacy-android-test_intermediates \
   target/common/obj/JAVA_LIBRARIES/ext_intermediates \
   target/common/obj/JAVA_LIBRARIES/framework_intermediates \
   target/common/obj/JAVA_LIBRARIES/hwbinder_intermediates \
diff --git a/core/product.mk b/core/product.mk
index 8a53982..efe029b 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -375,11 +375,13 @@
   TARGET_CPU_ABI \
   TARGET_CPU_ABI2 \
   TARGET_CPU_VARIANT \
+  TARGET_CPU_VARIANT_RUNTIME \
   TARGET_2ND_ARCH \
   TARGET_2ND_ARCH_VARIANT \
   TARGET_2ND_CPU_ABI \
   TARGET_2ND_CPU_ABI2 \
   TARGET_2ND_CPU_VARIANT \
+  TARGET_2ND_CPU_VARIANT_RUNTIME \
   TARGET_BOARD_PLATFORM \
   TARGET_BOARD_PLATFORM_GPU \
   TARGET_BOARD_KERNEL_HEADERS \
diff --git a/target/product/base_system.mk b/target/product/base_system.mk
index fe1954e..f8ff22f 100644
--- a/target/product/base_system.mk
+++ b/target/product/base_system.mk
@@ -114,6 +114,7 @@
     libandroidfw \
     libandroid_runtime \
     libandroid_servers \
+    libartpalette-system \
     libashmemd_client \
     libaudioeffect_jni \
     libaudioflinger \
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 8a60f7d..c685dd6 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -191,7 +191,7 @@
 
 
 def RunAndWait(args, verbose=None, **kwargs):
-  """Runs the given command and returns the exit code.
+  """Runs the given command waiting for it to complete.
 
   Args:
     args: The command represented as a list of strings.
@@ -201,12 +201,16 @@
         stdin, etc. stdout and stderr will default to subprocess.PIPE and
         subprocess.STDOUT respectively unless caller specifies any of them.
 
-  Returns:
-    The process return code.
+  Raises:
+    ExternalError: On non-zero exit from the command.
   """
   proc = Run(args, verbose=verbose, **kwargs)
   proc.wait()
-  return proc.returncode
+
+  if proc.returncode != 0:
+    raise ExternalError(
+        "Failed to run command '{}' (exit code {})".format(
+            args, proc.returncode))
 
 
 def RunAndCheckOutput(args, verbose=None, **kwargs):
diff --git a/tools/releasetools/merge_target_files.py b/tools/releasetools/merge_target_files.py
index 0a9933b..b2bb020 100755
--- a/tools/releasetools/merge_target_files.py
+++ b/tools/releasetools/merge_target_files.py
@@ -142,9 +142,6 @@
     will land.
 
     extract_item_list: A list of items to extract.
-
-  Returns:
-    On success, 0. Otherwise, a non-zero exit code from unzip.
   """
 
   logger.info('extracting from %s', target_files)
@@ -178,13 +175,7 @@
       target_files
   ] + filtered_extract_item_list
 
-  result = common.RunAndWait(command, verbose=True)
-
-  if result != 0:
-    logger.error('extract_items command %s failed %d', str(command), result)
-    return result
-
-  return 0
+  common.RunAndWait(command, verbose=True)
 
 
 def process_ab_partitions_txt(
@@ -305,9 +296,6 @@
     already contain plat_file_contexts and vendor_file_contexts (in the
     appropriate sub directories), and to which META/file_contexts.bin will be
     written.
-
-  Returns:
-    On success, 0. Otherwise, a non-zero exit code.
   """
 
   # To create a merged file_contexts.bin file, we use the system and vendor
@@ -352,12 +340,7 @@
 
   sorted_file_contexts_txt = os.path.join(temp_dir, 'sorted_file_contexts.txt')
   command = ['fc_sort', merged_file_contexts_txt, sorted_file_contexts_txt]
-
-  # TODO(b/124521133): Refector RunAndWait to raise exception on failure.
-  result = common.RunAndWait(command, verbose=True)
-
-  if result != 0:
-    return result
+  common.RunAndWait(command, verbose=True)
 
   # Finally, the compile step creates the final META/file_contexts.bin.
 
@@ -371,12 +354,7 @@
       sorted_file_contexts_txt,
   ]
 
-  result = common.RunAndWait(command, verbose=True)
-
-  if result != 0:
-    return result
-
-  return 0
+  common.RunAndWait(command, verbose=True)
 
 
 def process_special_cases(
@@ -402,9 +380,6 @@
     output_target_files_temp_dir: The name of a directory that will be used
     to create the output target files package after all the special cases
     are processed.
-
-  Returns:
-    On success, 0. Otherwise, a non-zero exit code.
   """
 
   process_ab_partitions_txt(
@@ -417,15 +392,10 @@
       other_target_files_temp_dir=other_target_files_temp_dir,
       output_target_files_temp_dir=output_target_files_temp_dir)
 
-  result = process_file_contexts_bin(
+  process_file_contexts_bin(
       temp_dir=temp_dir,
       output_target_files_temp_dir=output_target_files_temp_dir)
 
-  if result != 0:
-    return result
-
-  return 0
-
 
 def merge_target_files(
     temp_dir,
@@ -451,9 +421,6 @@
 
     output_target_files: The name of the output zip archive target files
     package created by merging system and other.
-
-  Returns:
-    On success, 0. Otherwise, a non-zero exit code.
   """
 
   # Create directory names that we'll use when we extract files from system,
@@ -467,64 +434,49 @@
   # We extract them directly into the output temporary directory since the
   # items do not need special case processing.
 
-  result = extract_items(
+  extract_items(
       target_files=system_target_files,
       target_files_temp_dir=output_target_files_temp_dir,
       extract_item_list=system_extract_as_is_item_list)
 
-  if result != 0:
-    return result
-
   # Extract "as is" items from the input other partial target files package. We
   # extract them directly into the output temporary directory since the items
   # do not need special case processing.
 
-  result = extract_items(
+  extract_items(
       target_files=other_target_files,
       target_files_temp_dir=output_target_files_temp_dir,
       extract_item_list=other_extract_as_is_item_list)
 
-  if result != 0:
-    return result
-
   # Extract "special" items from the input system partial target files package.
   # We extract these items to different directory since they require special
   # processing before they will end up in the output directory.
 
-  result = extract_items(
+  extract_items(
       target_files=system_target_files,
       target_files_temp_dir=system_target_files_temp_dir,
       extract_item_list=system_extract_special_item_list)
 
-  if result != 0:
-    return result
-
   # Extract "special" items from the input other partial target files package.
   # We extract these items to different directory since they require special
   # processing before they will end up in the output directory.
 
-  result = extract_items(
+  extract_items(
       target_files=other_target_files,
       target_files_temp_dir=other_target_files_temp_dir,
       extract_item_list=other_extract_special_item_list)
 
-  if result != 0:
-    return result
-
   # Now that the temporary directories contain all the extracted files, perform
   # special case processing on any items that need it. After this function
   # completes successfully, all the files we need to create the output target
   # files package are in place.
 
-  result = process_special_cases(
+  process_special_cases(
       temp_dir=temp_dir,
       system_target_files_temp_dir=system_target_files_temp_dir,
       other_target_files_temp_dir=other_target_files_temp_dir,
       output_target_files_temp_dir=output_target_files_temp_dir)
 
-  if result != 0:
-    return result
-
   # Regenerate IMAGES in the temporary directory.
 
   add_img_args = [
@@ -571,13 +523,7 @@
       '-l', output_target_files_list,
   ]
   logger.info('creating %s', output_target_files)
-  result = common.RunAndWait(command, verbose=True)
-
-  if result != 0:
-    logger.error('zip command %s failed %d', str(command), result)
-    return result
-
-  return 0
+  common.RunAndWait(command, verbose=True)
 
 
 def merge_target_files_with_temp_dir(
@@ -601,9 +547,6 @@
     package created by merging system and other.
 
     keep_tmp: Keep the temporary directory after processing is complete.
-
-  Returns:
-    On success, 0. Otherwise, a non-zero exit code.
   """
 
   # Create a temporary directory. This will serve as the parent of directories
@@ -619,7 +562,7 @@
   temp_dir = common.MakeTempDir(prefix='merge_target_files_')
 
   try:
-    return merge_target_files(
+    merge_target_files(
         temp_dir=temp_dir,
         system_target_files=system_target_files,
         other_target_files=other_target_files,
@@ -638,9 +581,6 @@
 
   Process command line arguments, then call merge_target_files_with_temp_dir to
   perform the heavy lifting.
-
-  Returns:
-    On success, 0. Otherwise, a non-zero exit code.
   """
 
   common.InitLogging()
@@ -668,14 +608,14 @@
       ],
       extra_option_handler=option_handler)
 
-  if (len(args) != 0 or 
+  if (len(args) != 0 or
       OPTIONS.system_target_files is None or
       OPTIONS.other_target_files is None or
       OPTIONS.output_target_files is None):
     common.Usage(__doc__)
-    return 1
+    sys.exit(1)
 
-  return merge_target_files_with_temp_dir(
+  merge_target_files_with_temp_dir(
       system_target_files=OPTIONS.system_target_files,
       other_target_files=OPTIONS.other_target_files,
       output_target_files=OPTIONS.output_target_files,
@@ -683,4 +623,4 @@
 
 
 if __name__ == '__main__':
-  sys.exit(main())
+  main()