am e442c136: Merge "Add NDK crtbegin_so.o and crtend_so.o if they exist."

* commit 'e442c1361a9066d7a394c080273d5f93d77979e4':
  Add NDK crtbegin_so.o and crtend_so.o if they exist.
diff --git a/core/Makefile b/core/Makefile
index e57ee73..9766336 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -15,15 +15,18 @@
 # <dest file> is relative to $(PRODUCT_OUT), so it should look like,
 # e.g., "system/etc/file.xml".
 # The filter part means "only eval the copy-one-file rule if this
-# src:dest pair is the first one to match %:dest"
+# src:dest pair is the first one to match the same dest"
+unique_product_copy_files_destinations := $(sort \
+    $(foreach cf,$(PRODUCT_COPY_FILES), $(call word-colon,2,$(cf))))
 $(foreach cf,$(PRODUCT_COPY_FILES), \
-  $(eval _src := $(call word-colon,1,$(cf))) \
-  $(eval _dest := $(call word-colon,2,$(cf))) \
-  $(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \
-  $(if $(filter $(_src):$(_dest),$(firstword $(filter %:$(_dest),$(PRODUCT_COPY_FILES)))), \
-    $(eval $(call copy-one-file,$(_src),$(_fulldest))),) \
-  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(_fulldest)) \
- )
+    $(eval _src := $(call word-colon,1,$(cf))) \
+    $(eval _dest := $(call word-colon,2,$(cf))) \
+    $(if $(filter $(unique_product_copy_files_destinations),$(_dest)), \
+        $(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \
+        $(eval $(call copy-one-file,$(_src),$(_fulldest))) \
+        $(eval ALL_DEFAULT_INSTALLED_MODULES += $(_fulldest)) \
+        $(eval unique_product_copy_files_destinations := $(filter-out $(_dest), \
+            $(unique_product_copy_files_destinations)))))
 
 # -----------------------------------------------------------------
 # docs/index.html
@@ -277,12 +280,15 @@
 
 event_log_tags_file := $(TARGET_OUT)/etc/event-log-tags
 
-# Include tags from all packages included in this product.
+# Include tags from all packages included in this product, plus all
+# tags that are part of the system (ie, not in a vendor/ or device/
+# directory).
 event_log_tags_src := \
     $(sort $(foreach m,\
       $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES) \
       $(call module-names-for-tag-list,user), \
-      $(ALL_MODULES.$(m).EVENT_LOG_TAGS)))
+      $(ALL_MODULES.$(m).EVENT_LOG_TAGS)) \
+      $(filter-out vendor/% device/% out/%,$(all_event_log_tags_src)))
 
 $(event_log_tags_file): PRIVATE_SRC_FILES := $(event_log_tags_src)
 $(event_log_tags_file): PRIVATE_MERGED_FILE := $(all_event_log_tags_file)
@@ -1067,6 +1073,7 @@
 ifneq ($(TARGET_PRODUCT),sdk)
 ifneq ($(TARGET_DEVICE),generic)
 ifneq ($(TARGET_NO_KERNEL),true)
+ifneq ($(recovery_fstab),)
 
 # -----------------------------------------------------------------
 # OTA update package
@@ -1119,6 +1126,7 @@
 .PHONY: updatepackage
 updatepackage: $(INTERNAL_UPDATE_PACKAGE_TARGET)
 
+endif    # recovery_fstab is defined
 endif    # TARGET_NO_KERNEL != true
 endif    # TARGET_DEVICE != generic
 endif    # TARGET_PRODUCT != sdk
diff --git a/core/java_library.mk b/core/java_library.mk
index abc4728..dbf6981 100644
--- a/core/java_library.mk
+++ b/core/java_library.mk
@@ -30,10 +30,12 @@
 LOCAL_INTERMEDIATE_TARGETS += $(common_javalib.jar)
 
 ifeq (true,$(WITH_DEXPREOPT))
+ifeq (,$(TARGET_BUILD_APPS))
 ifndef LOCAL_DEX_PREOPT
 LOCAL_DEX_PREOPT := true
 endif
 endif
+endif
 
 #################################
 include $(BUILD_SYSTEM)/java.mk
diff --git a/core/main.mk b/core/main.mk
index 858819b..bce1a9e 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -773,6 +773,7 @@
 $(call dist-for-goals,sdk win_sdk, \
 	$(ALL_SDK_TARGETS) \
 	$(SYMBOLS_ZIP) \
+	$(INSTALLED_BUILD_PROP_TARGET) \
  )
 endif
 
diff --git a/core/package.mk b/core/package.mk
index 6834995..34792d9 100644
--- a/core/package.mk
+++ b/core/package.mk
@@ -155,12 +155,14 @@
 LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
 
 ifeq (true,$(WITH_DEXPREOPT))
+ifeq (,$(TARGET_BUILD_APPS))
 ifneq (,$(LOCAL_SRC_FILES))
 ifndef LOCAL_DEX_PREOPT
 LOCAL_DEX_PREOPT := true
 endif
 endif
 endif
+endif
 
 # The dex files go in the package, so we don't
 # want to install them separately for this module.
diff --git a/core/prebuilt.mk b/core/prebuilt.mk
index b4717e0..f5eebc8 100644
--- a/core/prebuilt.mk
+++ b/core/prebuilt.mk
@@ -45,10 +45,20 @@
 ifeq ($(LOCAL_IS_HOST_MODULE)$(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
 # for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir,
 # while the deps should be in the common dir, so we make a copy in the common dir.
-common_library_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_MODULE),,COMMON)/$(notdir $(LOCAL_BUILT_MODULE))
-$(common_library_jar) : $(LOCAL_PATH)/$(LOCAL_SRC_FILES) | $(ACP)
+# For nonstatic library, $(common_javalib_jar) is the dependency file,
+# while $(common_classes_jar) is used to link.
+common_classes_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_MODULE),,COMMON)/classes.jar
+common_javalib_jar := $(dir $(common_classes_jar))javalib.jar
+
+$(common_classes_jar) : $(LOCAL_PATH)/$(LOCAL_SRC_FILES) | $(ACP)
 	$(transform-prebuilt-to-target)
-endif
+
+$(common_javalib_jar) : $(common_classes_jar) | $(ACP)
+	$(transform-prebuilt-to-target)
+
+# make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE)
+$(LOCAL_BUILT_MODULE) : $(common_javalib_jar)
+endif # TARGET JAVA_LIBRARIES
 
 ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
   # The magic string "EXTERNAL" means this package will be signed with
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index a236a12..52e7aed 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -18,6 +18,7 @@
 import getpass
 import imp
 import os
+import platform
 import re
 import sha
 import shutil
@@ -57,6 +58,22 @@
   return subprocess.Popen(args, **kwargs)
 
 
+def CloseInheritedPipes():
+  """ Gmake in MAC OS has file descriptor (PIPE) leak. We close those fds
+  before doing other work."""
+  if platform.system() != "Darwin":
+    return
+  for d in range(3, 1025):
+    try:
+      stat = os.fstat(d)
+      if stat is not None:
+        pipebit = stat[0] & 0x1000
+        if pipebit != 0:
+          os.close(d)
+    except OSError:
+      pass
+
+
 def LoadInfoDict(zip):
   """Read and parse the META/misc_info.txt key/value pairs from the
   input target files and return a dict."""
@@ -121,10 +138,6 @@
   makeint("boot_size")
 
   d["fstab"] = LoadRecoveryFSTab(zip)
-  if not d["fstab"]:
-    if "fs_type" not in d: d["fs_type"] = "yaffs2"
-    if "partition_type" not in d: d["partition_type"] = "MTD"
-
   return d
 
 def LoadRecoveryFSTab(zip):
@@ -134,9 +147,7 @@
   try:
     data = zip.read("RECOVERY/RAMDISK/etc/recovery.fstab")
   except KeyError:
-    # older target-files that doesn't have a recovery.fstab; fall back
-    # to the fs_type and partition_type keys.
-    return
+    raise ValueError("Could not find RECOVERY/RAMDISK/etc/recovery.fstab")
 
   d = {}
   for line in data.split("\n"):
@@ -350,9 +361,6 @@
     p = info_dict["fstab"][mount_point]
     fs_type = p.fs_type
     limit = info_dict.get(p.device + "_size", None)
-  else:
-    fs_type = info_dict.get("fs_type", None)
-    limit = info_dict.get(target + "_size", None)
   if not fs_type or not limit: return
 
   if fs_type == "yaffs2":
@@ -777,9 +785,4 @@
   if fstab:
     return PARTITION_TYPES[fstab[mount_point].fs_type], fstab[mount_point].device
   else:
-    devices = {"/boot": "boot",
-               "/recovery": "recovery",
-               "/radio": "radio",
-               "/data": "userdata",
-               "/cache": "cache"}
-    return info["partition_type"], info.get("partition_path", "") + devices[mount_point]
+    return None
diff --git a/tools/releasetools/edify_generator.py b/tools/releasetools/edify_generator.py
index 756d673..a7c8e32 100644
--- a/tools/releasetools/edify_generator.py
+++ b/tools/releasetools/edify_generator.py
@@ -140,13 +140,6 @@
                          (p.fs_type, common.PARTITION_TYPES[p.fs_type],
                           p.device, p.mount_point))
       self.mounts.add(p.mount_point)
-    else:
-      what = mount_point.lstrip("/")
-      what = self.info.get("partition_path", "") + what
-      self.script.append('mount("%s", "%s", "%s", "%s");' %
-                         (self.info["fs_type"], self.info["partition_type"],
-                          what, mount_point))
-      self.mounts.add(mount_point)
 
   def UnpackPackageDir(self, src, dst):
     """Unpack a given directory from the OTA package into the given
@@ -173,12 +166,6 @@
       p = fstab[partition]
       self.script.append('format("%s", "%s", "%s");' %
                          (p.fs_type, common.PARTITION_TYPES[p.fs_type], p.device))
-    else:
-      # older target-files without per-partition types
-      partition = self.info.get("partition_path", "") + partition
-      self.script.append('format("%s", "%s", "%s");' %
-                         (self.info["fs_type"], self.info["partition_type"],
-                          partition))
 
   def DeleteFiles(self, file_list):
     """Delete all files in file_list."""
@@ -231,23 +218,6 @@
             'package_extract_file("%(fn)s", "%(device)s");' % args)
       else:
         raise ValueError("don't know how to write \"%s\" partitions" % (p.fs_type,))
-    else:
-      # backward compatibility with older target-files that lack recovery.fstab
-      if self.info["partition_type"] == "MTD":
-        self.script.append(
-            ('assert(package_extract_file("%(fn)s", "/tmp/%(partition)s.img"),\n'
-             '       write_raw_image("/tmp/%(partition)s.img", "%(partition)s"),\n'
-             '       delete("/tmp/%(partition)s.img"));')
-            % {'partition': partition, 'fn': fn})
-      elif self.info["partition_type"] == "EMMC":
-        self.script.append(
-            ('package_extract_file("%(fn)s", "%(dir)s%(partition)s");')
-            % {'partition': partition, 'fn': fn,
-               'dir': self.info.get("partition_path", ""),
-               })
-      else:
-        raise ValueError("don't know how to write \"%s\" partitions" %
-                         (self.info["partition_type"],))
 
   def SetPermissions(self, fn, uid, gid, mode):
     """Set file ownership and permissions."""
diff --git a/tools/releasetools/img_from_target_files b/tools/releasetools/img_from_target_files
index 0139916..4a23ab4 100755
--- a/tools/releasetools/img_from_target_files
+++ b/tools/releasetools/img_from_target_files
@@ -188,6 +188,7 @@
 
 if __name__ == '__main__':
   try:
+    common.CloseInheritedPipes()
     main(sys.argv[1:])
   except common.ExternalError, e:
     print
diff --git a/tools/releasetools/ota_from_target_files b/tools/releasetools/ota_from_target_files
index aa691b4..cd10d7c 100755
--- a/tools/releasetools/ota_from_target_files
+++ b/tools/releasetools/ota_from_target_files
@@ -781,6 +781,7 @@
 
 if __name__ == '__main__':
   try:
+    common.CloseInheritedPipes()
     main(sys.argv[1:])
   except common.ExternalError, e:
     print