Unbundle the build system.
Change-Id: I88912d876c3972212e8871b3e5b3b8b6d2da34d0
diff --git a/core/base_rules.mk b/core/base_rules.mk
index f0cbdca..77135ae 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -190,7 +190,7 @@
LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION))
ifdef LOCAL_SDK_VERSION
ifneq ($(LOCAL_SDK_VERSION),current)
-aidl_preprocess_import := -p$(TOPDIR)prebuilt/sdk/$(LOCAL_SDK_VERSION)/framework.aidl
+aidl_preprocess_import := -p$(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_VERSION)/framework.aidl
endif # !current
endif # LOCAL_SDK_VERSION
$(aidl_java_sources): PRIVATE_AIDL_FLAGS := -b $(aidl_preprocess_import) -I$(LOCAL_PATH) -I$(LOCAL_PATH)/src $(addprefix -I,$(LOCAL_AIDL_INCLUDES))
diff --git a/core/config.mk b/core/config.mk
index a4d3154..2dcd876 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -314,22 +314,26 @@
# For use with the LOCAL_SDK_VERSION variable for include $(BUILD_PACKAGE)
# ###############################################################
-# The files that we can convert into android.jars are are in config/api/*.xml
-# The 'current' version is whatever this source tree is. Once the apicheck
-# tool can generate the stubs from the xml files, we'll use that to be
-# able to build back-versions. In the meantime, 'current' is the only
-# one supported.
+HISTORICAL_SDK_VERSIONS_ROOT := $(TOPDIR)prebuilt/sdk
+
+# Historical SDK version N is stored in $(HISTORICAL_SDK_VERSIONS_ROOT)/N.
+# The 'current' version is whatever this source tree is.
#
# sgrax is the opposite of xargs. It takes the list of args and puts them
# on each line for sort to process.
# sort -g is a numeric sort, so 1 2 3 10 instead of 1 10 2 3.
-TARGET_AVAILABLE_SDK_VERSIONS := current \
- $(shell function sgrax() { \
- while [ -n "$$1" ] ; do echo $$1 ; shift ; done \
- } ; \
- ( sgrax $(patsubst $(SRC_API_DIR)/%.xml,%, \
- $(filter-out $(SRC_API_DIR)/current.xml, \
- $(shell find $(SRC_API_DIR) -name "*.xml"))) | sort -g ) )
+# Numerically sort a list of numbers
+# $(1): the list of numbers to be sorted
+define numerically_sort
+$(shell function sgrax() { \
+ while [ -n "$$1" ] ; do echo $$1 ; shift ; done \
+ } ; \
+ ( sgrax $(1) | sort -g ) )
+endef
+
+TARGET_AVAILABLE_SDK_VERSIONS := current $(call numerically_sort,\
+ $(patsubst $(HISTORICAL_SDK_VERSIONS_ROOT)/%/android.jar,%, \
+ $(wildcard $(HISTORICAL_SDK_VERSIONS_ROOT)/*/android.jar)))
INTERNAL_PLATFORM_API_FILE := $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/public_api.xml
diff --git a/core/package.mk b/core/package.mk
index d5de77b..e7be05f 100644
--- a/core/package.mk
+++ b/core/package.mk
@@ -244,17 +244,24 @@
# Most packages should link against the resources defined by framework-res.
# Even if they don't have their own resources, they may use framework
# resources.
+ifneq ($(filter-out current,$(LOCAL_SDK_VERSION)),)
+# for released sdk versions, the platform resources were built into android.jar.
+framework_res_package_export := \
+ $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_VERSION)/android.jar
+framework_res_package_export_deps := $(framework_res_package_export)
+else # LOCAL_SDK_VERSION
framework_res_package_export := \
$(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
-$(LOCAL_INTERMEDIATE_TARGETS): \
- PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
# We can't depend directly on the export.apk file; it won't get its
# PRIVATE_ vars set up correctly if we do. Instead, depend on the
# corresponding R.stamp file, which lists the export.apk as a dependency.
framework_res_package_export_deps := \
$(dir $(framework_res_package_export))src/R.stamp
+endif # LOCAL_SDK_VERSION
$(R_file_stamp): $(framework_res_package_export_deps)
-endif
+$(LOCAL_INTERMEDIATE_TARGETS): \
+ PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
+endif # LOCAL_NO_STANDARD_LIBRARIES
ifneq ($(full_classes_jar),)
$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
diff --git a/core/tasks/apicheck.mk b/core/tasks/apicheck.mk
index 044e4af..740668c 100644
--- a/core/tasks/apicheck.mk
+++ b/core/tasks/apicheck.mk
@@ -41,13 +41,18 @@
# Run the checkapi rules by default.
droidcore: checkapi
+last_released_sdk_version := $(lastword $(call numerically_sort,\
+ $(patsubst $(SRC_API_DIR)/%.xml,%, \
+ $(filter-out $(SRC_API_DIR)/current.xml, \
+ $(wildcard $(SRC_API_DIR)/*.xml)))))
+
# INTERNAL_PLATFORM_API_FILE is the one build by droiddoc.
# Check that the API we're building hasn't broken the last-released
# SDK version.
$(eval $(call check-api, \
checkapi-last, \
- $(SRC_API_DIR)/$(lastword $(TARGET_AVAILABLE_SDK_VERSIONS)).xml, \
+ $(SRC_API_DIR)/$(last_released_sdk_version).xml, \
$(INTERNAL_PLATFORM_API_FILE), \
-hide 2 -hide 3 -hide 4 -hide 5 -hide 6 -hide 24 -hide 25 \
-error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 -error 15 \