Add default -Wall -Werror or -Wall.

* Skip Android.bp, prebuilt, and HEADER_LIBRARIES targets.
* If neither -Wno-error nor -Werror is used, add default -Wall -Werror.
  However, if the build target is in a project
  under one of ANDROID_WARNING_ALLOWED_PROJECTS, add only -Wall.
* Dump name of modules using -Wno-error or added -Wall -Werror
  into file $(PRODUCT_OUT)/wall_werror.txt.

Bug: 66996870
Test: normal build
Change-Id: Ief8cf776e8613ed073a64dd271534688845d5c2c
diff --git a/core/Makefile b/core/Makefile
index 4ef0d89..2962bcd 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -517,6 +517,20 @@
 $(call dist-for-goals,droidcore,$(SOONG_TO_CONVERT))
 
 # -----------------------------------------------------------------
+# Modules use -Wno-error, or added default -Wall -Werror
+WALL_WERROR := $(PRODUCT_OUT)/wall_werror.txt
+$(WALL_WERROR):
+	@rm -f $@
+	echo "# Modules using -Wno-error" >> $@
+	for m in $(sort $(SOONG_MODULES_USING_WNO_ERROR) $(MODULES_USING_WNO_ERROR)); do echo $$m >> $@; done
+	echo "# Modules added default -Wall -Werror" >> $@
+	for m in $(sort $(SOONG_MODULES_ADDED_WERROR) $(MODULES_ADDED_WERROR)); do echo $$m >> $@; done
+	echo "# Modules added default -Wall" >> $@
+	for m in $(sort $(SOONG_MODULES_ADDED_WALL) $(MODULES_ADDED_WALL)); do echo $$m >> $@; done
+
+$(call dist-for-goals,droidcore,$(WALL_WERROR))
+
+# -----------------------------------------------------------------
 # The dev key is used to sign this package, and as the key required
 # for future OTA packages installed by this system.  Actual product
 # deliverables will be re-signed by hand.  We expect this file to