Merge "Switch signapk to apksigner-core."
diff --git a/core/Makefile b/core/Makefile
index 83a008c..79a0dc3 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -921,6 +921,11 @@
 else
 recovery_fstab := $(strip $(wildcard $(TARGET_DEVICE_DIR)/recovery.fstab))
 endif
+ifdef TARGET_RECOVERY_BRICK
+recovery_brick := $(TARGET_RECOVERY_BRICK)
+else
+recovery_brick :=
+endif
 
 # Prior to A/B update, we used to have:
 #   boot.img + recovery-from-boot.p + recovery-resource.dat = recovery.img.
@@ -1006,6 +1011,8 @@
     cp -rf $(item) $(TARGET_RECOVERY_ROOT_OUT)/$(newline))
   $(hide) $(foreach item,$(recovery_fstab), \
     cp -f $(item) $(TARGET_RECOVERY_ROOT_OUT)/etc/recovery.fstab)
+  $(if $(strip $(recovery_brick)), \
+    $(hide) cp -f $(recovery_brick) $(TARGET_RECOVERY_ROOT_OUT)/etc/recovery.brick)
   $(hide) cp $(RECOVERY_INSTALL_OTA_KEYS) $(TARGET_RECOVERY_ROOT_OUT)/res/keys
   $(hide) cat $(INSTALLED_DEFAULT_PROP_TARGET) $(recovery_build_prop) \
           > $(TARGET_RECOVERY_ROOT_OUT)/default.prop
diff --git a/core/base_rules.mk b/core/base_rules.mk
index c4fbe11..30b6c1c 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -261,7 +261,7 @@
 ## logtags: Add .logtags files to global list
 ###########################################################
 
-logtags_sources := $(filter %.logtags,$(LOCAL_SRC_FILES))
+logtags_sources := $(filter %.logtags,$(LOCAL_SRC_FILES)) $(LOCAL_LOGTAGS_FILES)
 
 ifneq ($(strip $(logtags_sources)),)
 event_log_tags := $(addprefix $(LOCAL_PATH)/,$(logtags_sources))
diff --git a/core/binary.mk b/core/binary.mk
index 614b8aa..493bed8 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -1228,6 +1228,11 @@
   my_c_includes += $(JNI_H_INCLUDE)
 endif
 
+my_outside_includes := $(filter-out $(OUT_DIR)/%,$(filter /%,$(my_c_includes)))
+ifneq ($(my_outside_includes),)
+$(error $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): C_INCLUDES must be under the source or output directories: $(my_outside_includes))
+endif
+
 # all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES;
 # use normal_objects here to avoid creating circular dependencies. This assumes
 # that custom build rules which generate .o files don't consume other generated
@@ -1419,6 +1424,10 @@
     ifneq ($(LOCAL_TIDY_FLAGS),)
       my_tidy_flags := $(LOCAL_TIDY_FLAGS)
     endif
+    # If tidy flags are not specified, default to check all header files.
+    ifeq ($(my_tidy_flags),)
+      my_tidy_flags := -header-filter=.*
+    endif
   endif
 endif
 
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index bc1eefb..9ca880b 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -197,6 +197,7 @@
 # to avoid installing the presigned apks with classes.dex unstripped.
 LOCAL_REPLACE_PREBUILT_APK_INSTALLED:=
 LOCAL_NDK_VERSION:=current
+LOCAL_LOGTAGS_FILES:=
 
 # arch specific variables
 LOCAL_SRC_FILES_$(TARGET_ARCH):=
diff --git a/core/definitions.mk b/core/definitions.mk
index 7409e37..7572070 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -137,17 +137,33 @@
  )
 endef
 
+
+define _filter-soong-makefile
+$(if $(wildcard $(patsubst %/Android.mk,%/Android.bp,$(1))),\
+  $(info skipping $(1) ...)\
+    $(call _filter-soong-bpfile $(patsubst %/Android.mk,%/Android.bp,$(1))),\
+  $(1))
+endef
+
+define _filter-soong-bpfile
+$(if $(wildcard $(patsubst %/Android.bp,%/Android.soong.mk,$(1))),\
+  $(patsubst %/Android.bp,%/Android.soong.mk,$(1)))
+endef
+
 ###########################################################
 ## Remove any makefiles that are being handled by soong
+##
+## If passed an Android.mk file, returns the Android.mk file
+## if no Android.bp file exists and the same path.  If an
+## Android.bp file exists, or if passed an Android.bp file,
+## returns the Android.soong.mk file at the same path if it
+## exists, or nothing if it does not.
 ###########################################################
 define filter-soong-makefiles
-$(foreach mk,$(1),\
-  $(if $(wildcard $(patsubst %/Android.mk,%/Android.bp,$(mk))),\
-    $(if $(wildcard $(patsubst %/Android.mk,%/Android.soong.mk,$(mk))),\
-      $(info skipping $(mk), but including Android.soong.mk ...)\
-        $(patsubst %/Android.mk,%/Android.soong.mk,$(mk)),\
-      $(info skipping $(mk) ...)),\
-    $(mk)))
+$(sort $(foreach mk,$(1),\
+  $(if $(filter %/Android.bp,$(mk)),\
+    $(call _filter-soong-bpfile,$(mk)),\
+    $(call _filter-soong-makefile,$(mk)))))
 endef
 
 ###########################################################
@@ -155,7 +171,7 @@
 ###########################################################
 
 define all-makefiles-under
-$(sort $(call filter-soong-makefiles,$(wildcard $(1)/*/Android.mk)))
+$(call filter-soong-makefiles,$(wildcard $(1)/*/Android.mk $(1)/*/Android.bp))
 endef
 
 ###########################################################
@@ -168,7 +184,7 @@
 define first-makefiles-under
 $(call filter-soong-makefiles,\
   $(shell build/tools/findleaves.py $(FIND_LEAVES_EXCLUDES) \
-        --mindepth=2 $(1) Android.mk))
+        --mindepth=2 $(addprefix --dir=,$(1)) Android.bp Android.mk))
 endef
 
 ###########################################################
@@ -188,8 +204,9 @@
 
 # $(1): List of directories to look for under this directory
 define all-named-subdir-makefiles
-$(sort $(call filter-soong-makefiles,\
-  $(wildcard $(addsuffix /Android.mk, $(addprefix $(call my-dir)/,$(1))))))
+$(call filter-soong-makefiles,\
+  $(wildcard $(addsuffix /Android.mk, $(addprefix $(call my-dir)/,$(1))))\
+  $(wildcard $(addsuffix /Android.bp, $(addprefix $(call my-dir)/,$(1)))))
 endef
 
 ###########################################################
diff --git a/core/dumpvar.mk b/core/dumpvar.mk
index 1bd4777..4b3486a 100644
--- a/core/dumpvar.mk
+++ b/core/dumpvar.mk
@@ -35,10 +35,15 @@
 # what to add to the path given the config we have chosen.
 ifeq ($(CALLED_FROM_SETUP),true)
 
-ifneq ($(filter /%,$(HOST_OUT_EXECUTABLES)),)
-ABP:=$(HOST_OUT_EXECUTABLES)
+ifneq ($(filter /%,$(SOONG_HOST_OUT_EXECUTABLES)),)
+ABP := $(SOONG_HOST_OUT_EXECUTABLES)
 else
-ABP:=$(PWD)/$(HOST_OUT_EXECUTABLES)
+ABP := $(PWD)/$(SOONG_HOST_OUT_EXECUTABLES)
+endif
+ifneq ($(filter /%,$(HOST_OUT_EXECUTABLES)),)
+ABP := $(ABP):$(HOST_OUT_EXECUTABLES)
+else
+ABP := $(ABP):$(PWD)/$(HOST_OUT_EXECUTABLES)
 endif
 
 ANDROID_BUILD_PATHS := $(ABP)
diff --git a/core/envsetup.mk b/core/envsetup.mk
index f1c37c8..4b48b27 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -204,6 +204,8 @@
 endif
 endif
 
+SOONG_OUT_DIR := $(OUT_DIR)/soong
+
 DEBUG_OUT_DIR := $(OUT_DIR)/debug
 
 # Move the host or target under the debug/ directory
@@ -220,6 +222,7 @@
 HOST_OUT_release := $(HOST_OUT_ROOT_release)/$(HOST_OS)-$(HOST_PREBUILT_ARCH)
 HOST_OUT_debug := $(HOST_OUT_ROOT_debug)/$(HOST_OS)-$(HOST_PREBUILT_ARCH)
 HOST_OUT := $(HOST_OUT_$(HOST_BUILD_TYPE))
+SOONG_HOST_OUT := $(SOONG_OUT_DIR)/host/$(HOST_OS)-$(HOST_PREBUILT_ARCH)
 # TODO: remove
 BUILD_OUT := $(HOST_OUT)
 
@@ -237,6 +240,7 @@
 OUT_DOCS := $(TARGET_COMMON_OUT_ROOT)/docs
 
 BUILD_OUT_EXECUTABLES := $(BUILD_OUT)/bin
+SOONG_HOST_OUT_EXECUTABLES := $(SOONG_HOST_OUT)/bin
 
 HOST_OUT_EXECUTABLES := $(HOST_OUT)/bin
 HOST_OUT_SHARED_LIBRARIES := $(HOST_OUT)/lib64
diff --git a/core/main.mk b/core/main.mk
index 9866dff..2c97fcf 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -376,6 +376,7 @@
 ifneq (,$(user_variant))
   # Target is secure in user builds.
   ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
+  ADDITIONAL_DEFAULT_PROPERTIES += security.perf_harden=1
 
   ifeq ($(user_variant),user)
     ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=1
@@ -501,7 +502,6 @@
 #
 # Typical build; include any Android.mk files we can find.
 #
-subdirs := $(TOP)
 
 FULL_BUILD := true
 
@@ -542,14 +542,9 @@
 # Include all of the makefiles in the system
 #
 
-# Can't use first-makefiles-under here because
-# --mindepth=2 makes the prunes not work.
-subdir_makefiles := \
-	$(shell build/tools/findleaves.py $(FIND_LEAVES_EXCLUDES) $(subdirs) Android.mk)
+subdir_makefiles := $(SOONG_ANDROID_MK) $(call first-makefiles-under,$(TOP))
 
-subdir_makefiles := $(SOONG_ANDROID_MK) $(call filter-soong-makefiles,$(subdir_makefiles))
-
-$(foreach mk, $(subdir_makefiles),$(info including $(mk) ...)$(eval include $(mk)))
+$(foreach mk,$(subdir_makefiles),$(info including $(mk) ...)$(eval include $(mk)))
 
 ifdef PDK_FUSION_PLATFORM_ZIP
 # Bring in the PDK platform.zip modules.
diff --git a/core/ninja.mk b/core/ninja.mk
index 589affe..bbd5863 100644
--- a/core/ninja.mk
+++ b/core/ninja.mk
@@ -101,7 +101,7 @@
 endif
 
 ifeq (,$(NINJA_STATUS))
-NINJA_STATUS := [%p %s/%t]$(space)
+NINJA_STATUS := [%p %f/%t]$(space)
 endif
 
 NINJA_EXTRA_ARGS :=
diff --git a/core/prebuilt.mk b/core/prebuilt.mk
index f1edc8a..7b83467 100644
--- a/core/prebuilt.mk
+++ b/core/prebuilt.mk
@@ -13,7 +13,10 @@
   my_prefix := TARGET_
 
   ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true)
-    LOCAL_MULTILIB := first
+    # Only support prebuilt shared and static libraries for translated arch
+    ifeq ($(filter SHARED_LIBRARIES STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)),)
+      LOCAL_MULTILIB := first
+    endif
   endif
 endif
 
diff --git a/core/soong.mk b/core/soong.mk
index 2f36be9..c2c9e6c 100644
--- a/core/soong.mk
+++ b/core/soong.mk
@@ -1,4 +1,3 @@
-SOONG_OUT_DIR := $(OUT_DIR)/soong
 SOONG := $(SOONG_OUT_DIR)/soong
 SOONG_BOOTSTRAP := $(SOONG_OUT_DIR)/.soong.bootstrap
 SOONG_BUILD_NINJA := $(SOONG_OUT_DIR)/build.ninja
diff --git a/tools/findleaves.py b/tools/findleaves.py
index 3a9e508..72cc024 100755
--- a/tools/findleaves.py
+++ b/tools/findleaves.py
@@ -23,7 +23,7 @@
 import os
 import sys
 
-def perform_find(mindepth, prune, dirlist, filename):
+def perform_find(mindepth, prune, dirlist, filenames):
   result = []
   pruneleaves = set(map(lambda x: os.path.split(x)[1], prune))
   for rootdir in dirlist:
@@ -48,19 +48,24 @@
         if depth < mindepth:
           continue
       # match
-      if filename in files:
-        result.append(os.path.join(root, filename))
-        del dirs[:]
+      for filename in filenames:
+        if filename in files:
+          result.append(os.path.join(root, filename))
+          del dirs[:]
   return result
 
 def usage():
-  sys.stderr.write("""Usage: %(progName)s [<options>] <dirlist> <filename>
+  sys.stderr.write("""Usage: %(progName)s [<options>] [--dir=<dir>] <filenames>
 Options:
    --mindepth=<mindepth>
        Both behave in the same way as their find(1) equivalents.
    --prune=<dirname>
        Avoids returning results from inside any directory called <dirname>
        (e.g., "*/out/*"). May be used multiple times.
+   --dir=<dir>
+       Add a directory to search.  May be repeated multiple times.  For backwards
+       compatibility, if no --dir argument is provided then all but the last entry
+       in <filenames> are treated as directories.
 """ % {
       "progName": os.path.split(sys.argv[0])[1],
     })
@@ -69,6 +74,7 @@
 def main(argv):
   mindepth = -1
   prune = []
+  dirlist = []
   i=1
   while i<len(argv) and len(argv[i])>2 and argv[i][0:2] == "--":
     arg = argv[i]
@@ -82,14 +88,24 @@
       if len(p) == 0:
         usage()
       prune.append(p)
+    elif arg.startswith("--dir="):
+      d = arg[len("--dir="):]
+      if len(p) == 0:
+        usage()
+      dirlist.append(d)
     else:
       usage()
     i += 1
-  if len(argv)-i < 2: # need both <dirlist> and <filename>
-    usage()
-  dirlist = argv[i:-1]
-  filename = argv[-1]
-  results = list(set(perform_find(mindepth, prune, dirlist, filename)))
+  if len(dirlist) == 0: # backwards compatibility
+    if len(argv)-i < 2: # need both <dirlist> and <filename>
+      usage()
+    dirlist = argv[i:-1]
+    filenames = [argv[-1]]
+  else:
+    if len(argv)-i < 1: # need <filename>
+      usage()
+    filenames = argv[i:]
+  results = list(set(perform_find(mindepth, prune, dirlist, filenames)))
   results.sort()
   for r in results:
     print r