Merge "zipalign: use getopt"
diff --git a/core/Makefile b/core/Makefile
index 8420891..5a387e0 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -4235,25 +4235,16 @@
   ifeq ($(TARGET_PRODUCT),sdk)
     build_ota_package := false
   endif
-  # A target without a kernel or recovery fstab may be one of the following:
-  # - A generic target. In this case, the OTA package usually isn't built.
-  #   PRODUCT_BUILD_GENERIC_OTA_PACKAGE may be set to true to force OTA package
-  #   generation.
-  # - A real device target, with TARGET_NO_KERNEL set to true and
-  #   BOARD_PREBUILT_BOOTIMAGE set. In this case, it is valid to generate
-  #   an OTA package.
   ifneq ($(PRODUCT_BUILD_GENERIC_OTA_PACKAGE),true)
     ifneq ($(filter generic%,$(TARGET_DEVICE)),)
       build_ota_package := false
     endif
-    ifeq ($(INSTALLED_BOOTIMAGE_TARGET),)
-      ifeq ($(TARGET_NO_KERNEL),true)
-        build_ota_package := false
-      endif
-      ifeq ($(recovery_fstab),)
-        build_ota_package := false
-      endif
-    endif # INSTALLED_BOOTIMAGE_TARGET == ""
+    ifeq ($(TARGET_NO_KERNEL),true)
+      build_ota_package := false
+    endif
+    ifeq ($(recovery_fstab),)
+      build_ota_package := false
+    endif
   endif # PRODUCT_BUILD_GENERIC_OTA_PACKAGE
 
   # Set build_otatools_package, and allow opt-out below.
diff --git a/tools/releasetools/merge_target_files.py b/tools/releasetools/merge_target_files.py
index c1fa9e7..7086f21 100755
--- a/tools/releasetools/merge_target_files.py
+++ b/tools/releasetools/merge_target_files.py
@@ -1000,8 +1000,15 @@
   # Copy the combined SEPolicy file and framework hashes to the image that is
   # being rebuilt.
   def copy_selinux_file(input_path, output_filename):
+    input_filename = os.path.join(target_files_dir, input_path)
+    if not os.path.exists(input_filename):
+      input_filename = input_filename.replace('SYSTEM_EXT/', 'SYSTEM/system_ext/') \
+          .replace('PRODUCT/', 'SYSTEM/product/')
+      if not os.path.exists(input_filename):
+        logger.info('Skipping copy_selinux_file for %s', input_filename)
+        return
     shutil.copy(
-        os.path.join(target_files_dir, input_path),
+        input_filename,
         os.path.join(target_files_dir, partition.upper(), 'etc/selinux',
                      output_filename))
 
@@ -1041,7 +1048,8 @@
     shutil.rmtree(os.path.join(vendor_target_files_dir, partition.upper()))
     shutil.copytree(
         os.path.join(target_files_dir, partition.upper()),
-        os.path.join(vendor_target_files_dir, partition.upper()))
+        os.path.join(vendor_target_files_dir, partition.upper()),
+        symlinks=True)
 
     # Delete then rebuild the partition.
     os.remove(os.path.join(vendor_target_files_dir, 'IMAGES', partition_img))
@@ -1056,6 +1064,8 @@
     common.RunAndCheckOutput(rebuild_partition_command, verbose=True)
 
     # Move the newly-created image to the merged target files dir.
+    if not os.path.exists(os.path.join(target_files_dir, 'IMAGES')):
+      os.makedirs(os.path.join(target_files_dir, 'IMAGES'))
     shutil.move(
         os.path.join(vendor_target_files_dir, 'IMAGES', partition_img),
         os.path.join(target_files_dir, 'IMAGES', partition_img))