SDK: source.properties templates.

This adds support for "templates" source.properties files that can
inherit the platform version/codename/api level from the build.

The purpose is for a given build to always generate SDK files that
match the platform generated in the same branch.

Change-Id: Id623bbef45a04d953da8eade7e8c34c77709f9c3
diff --git a/build/Android.mk b/build/Android.mk
index e4eeb0a..1cb0653 100644
--- a/build/Android.mk
+++ b/build/Android.mk
@@ -1,3 +1,27 @@
+# ===== SDK source.property files =====
+
+# Add all files to be generated from the source.prop templates to the SDK pre-requisites
+ALL_SDK_FILES += $(patsubst \
+                   $(TOPDIR)development/sdk/%_source.prop_template, \
+                   $(HOST_OUT)/development/sdk/%_source.properties, \
+                   $(wildcard $(TOPDIR)development/sdk/*_source.prop_template))
+
+# Rule to convert a source.prop template into the desired source.property
+# Rewritten variables:
+# - ${PLATFORM_VERSION}          e.g. "1.0"
+# - ${PLATFORM_SDK_VERSION}      e.g. "3", aka the API level
+# - ${PLATFORM_VERSION_CODENAME} e.g. "REL" (transformed into "") or "Cupcake"
+$(HOST_OUT)/development/sdk/%_source.properties : $(TOPDIR)development/sdk/%_source.prop_template
+	@echo Generate $@
+	$(hide) mkdir -p $(dir $@)
+	$(hide) sed -e 's/$${PLATFORM_VERSION}/$(PLATFORM_VERSION)/' \
+		 -e 's/$${PLATFORM_SDK_VERSION}/$(PLATFORM_SDK_VERSION)/' \
+		 -e 's/$${PLATFORM_VERSION_CODENAME}/$(subst REL,,$(PLATFORM_VERSION_CODENAME))/' \
+		 $< > $@
+
+
+# ===== Android Support/Compatibility Library =====
+
 LOCAL_PATH := $(call my-dir)
 
 # The source files for this library are _all_ generated, something we don't do
diff --git a/build/sdk-android-armeabi-v7a.atree b/build/sdk-android-armeabi-v7a.atree
index 8867bf7..e586945 100644
--- a/build/sdk-android-armeabi-v7a.atree
+++ b/build/sdk-android-armeabi-v7a.atree
@@ -18,4 +18,4 @@
 prebuilt/android-${TARGET_ARCH}/kernel/kernel-qemu-armv7 system-images/${PLATFORM_NAME}/${TARGET_CPU_ABI}/kernel-qemu
 
 # version files for the SDK updater, from development.git
-development/sdk/images_armeabi-v7a_source.properties   system-images/${PLATFORM_NAME}/${TARGET_CPU_ABI}/source.properties
+${HOST_OUT}/development/sdk/images_armeabi-v7a_source.properties system-images/${PLATFORM_NAME}/${TARGET_CPU_ABI}/source.properties
diff --git a/build/sdk-android-armeabi.atree b/build/sdk-android-armeabi.atree
index a31eca6..15f1f58 100644
--- a/build/sdk-android-armeabi.atree
+++ b/build/sdk-android-armeabi.atree
@@ -17,4 +17,4 @@
 prebuilt/android-${TARGET_ARCH}/kernel/kernel-qemu system-images/${PLATFORM_NAME}/${TARGET_CPU_ABI}/kernel-qemu
 
 # version files for the SDK updater, from development.git
-development/sdk/images_armeabi_source.properties   system-images/${PLATFORM_NAME}/${TARGET_CPU_ABI}/source.properties
+${HOST_OUT}/development/sdk/images_armeabi_source.properties system-images/${PLATFORM_NAME}/${TARGET_CPU_ABI}/source.properties
diff --git a/build/sdk-android-x86.atree b/build/sdk-android-x86.atree
index 748478a..a309149 100644
--- a/build/sdk-android-x86.atree
+++ b/build/sdk-android-x86.atree
@@ -17,4 +17,4 @@
 prebuilt/android-${TARGET_ARCH}/kernel/kernel-qemu system-images/${PLATFORM_NAME}/${TARGET_CPU_ABI}/kernel-qemu
 
 # version files for the SDK updater, from development.git
-development/sdk/images_x86_source.properties   system-images/${PLATFORM_NAME}/${TARGET_CPU_ABI}/source.properties
+${HOST_OUT}/development/sdk/images_x86_source.properties system-images/${PLATFORM_NAME}/${TARGET_CPU_ABI}/source.properties
diff --git a/build/sdk.atree b/build/sdk.atree
index 16c5184..afbffd8 100644
--- a/build/sdk.atree
+++ b/build/sdk.atree
@@ -61,7 +61,7 @@
 ##############################################################################
 
 # version files for the SDK updater, from development.git
-development/sdk/platform_source.properties    platforms/${PLATFORM_NAME}/source.properties
+${HOST_OUT}/development/sdk/platform_source.properties platforms/${PLATFORM_NAME}/source.properties
 
 # copy build prop from out/.../sdk/
 sdk/sdk-build.prop                            platforms/${PLATFORM_NAME}/build.prop
@@ -132,7 +132,7 @@
 ##############################################################################
 
 # version files for the SDK updater, from sdk.git
-development/sdk/doc_source.properties docs/source.properties
+${HOST_OUT}/development/sdk/doc_source.properties docs/source.properties
 
 # the docs
 docs/offline-sdk docs
diff --git a/build/tools/sdk_repo.mk b/build/tools/sdk_repo.mk
index de48e57..a0d93de 100644
--- a/build/tools/sdk_repo.mk
+++ b/build/tools/sdk_repo.mk
@@ -88,10 +88,10 @@
 # $3=package to create, must be "sources"
 #
 define mk-sdk-repo-sources
-$(call sdk-repo-pkg-zip,$(1),$(2),$(3)): $(2) $(TOPDIR)development/sdk/source_source.properties
+$(call sdk-repo-pkg-zip,$(1),$(2),$(3)): $(2) $(HOST_OUT)/development/sdk/source_source.properties
 	@echo "Building SDK sources package"
 	$(hide) $(TOPDIR)development/build/tools/mk_sources_zip.py \
-			$(TOPDIR)development/sdk/source_source.properties \
+			$(HOST_OUT)/development/sdk/source_source.properties \
 			$(call sdk-repo-pkg-zip,$(1),$(2),$(3)) \
 			$(TOPDIR).
 $(call dist-for-goals, sdk_repo, $(call sdk-repo-pkg-zip,$(1),$(2),$(3)))
diff --git a/sdk/doc_source.prop_template b/sdk/doc_source.prop_template
new file mode 100644
index 0000000..d3cdfd5
--- /dev/null
+++ b/sdk/doc_source.prop_template
@@ -0,0 +1,4 @@
+Pkg.UserSrc=false
+Pkg.Revision=1
+AndroidVersion.ApiLevel=${PLATFORM_SDK_VERSION}
+AndroidVersion.CodeName=${PLATFORM_VERSION_CODENAME}
diff --git a/sdk/doc_source.properties b/sdk/doc_source.properties
deleted file mode 100644
index 5b3dce6..0000000
--- a/sdk/doc_source.properties
+++ /dev/null
@@ -1,5 +0,0 @@
-Pkg.UserSrc=false
-Pkg.Revision=1
-AndroidVersion.ApiLevel=15
-#AndroidVersion.CodeName=
-
diff --git a/sdk/images_armeabi-v7a_source.prop_template b/sdk/images_armeabi-v7a_source.prop_template
new file mode 100644
index 0000000..ae67647
--- /dev/null
+++ b/sdk/images_armeabi-v7a_source.prop_template
@@ -0,0 +1,6 @@
+Pkg.Desc=Android SDK Platform ${PLATFORM_VERSION}
+Pkg.UserSrc=false
+Pkg.Revision=1
+AndroidVersion.ApiLevel=${PLATFORM_SDK_VERSION}
+AndroidVersion.CodeName=${PLATFORM_VERSION_CODENAME}
+SystemImage.Abi=armeabi-v7a
diff --git a/sdk/images_armeabi-v7a_source.properties b/sdk/images_armeabi-v7a_source.properties
deleted file mode 100644
index 9280fdd..0000000
--- a/sdk/images_armeabi-v7a_source.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-Pkg.Desc=Android SDK Platform 4.1
-Pkg.UserSrc=false
-Pkg.Revision=1
-AndroidVersion.ApiLevel=15
-#AndroidVersion.CodeName=
-SystemImage.Abi=armeabi-v7a
diff --git a/sdk/images_armeabi_source.prop_template b/sdk/images_armeabi_source.prop_template
new file mode 100644
index 0000000..b100e53
--- /dev/null
+++ b/sdk/images_armeabi_source.prop_template
@@ -0,0 +1,6 @@
+Pkg.Desc=Android SDK Platform ${PLATFORM_VERSION}
+Pkg.UserSrc=false
+Pkg.Revision=1
+AndroidVersion.ApiLevel=${PLATFORM_SDK_VERSION}
+AndroidVersion.CodeName=${PLATFORM_VERSION_CODENAME}
+SystemImage.Abi=armeabi
diff --git a/sdk/images_armeabi_source.properties b/sdk/images_armeabi_source.properties
deleted file mode 100644
index 63fc677..0000000
--- a/sdk/images_armeabi_source.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-Pkg.Desc=Android SDK Platform 4.1
-Pkg.UserSrc=false
-Pkg.Revision=1
-AndroidVersion.ApiLevel=15
-#AndroidVersion.CodeName=
-SystemImage.Abi=armeabi
diff --git a/sdk/images_x86_source.prop_template b/sdk/images_x86_source.prop_template
new file mode 100644
index 0000000..62e2e0d
--- /dev/null
+++ b/sdk/images_x86_source.prop_template
@@ -0,0 +1,6 @@
+Pkg.Desc=Android SDK Platform ${PLATFORM_VERSION}
+Pkg.UserSrc=false
+Pkg.Revision=1
+AndroidVersion.ApiLevel=${PLATFORM_SDK_VERSION}
+AndroidVersion.CodeName=${PLATFORM_VERSION_CODENAME}
+SystemImage.Abi=x86
diff --git a/sdk/images_x86_source.properties b/sdk/images_x86_source.properties
deleted file mode 100644
index bb82577..0000000
--- a/sdk/images_x86_source.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-Pkg.Desc=Android SDK Platform 4.1
-Pkg.UserSrc=false
-Pkg.Revision=1
-AndroidVersion.ApiLevel=15
-#AndroidVersion.CodeName=
-SystemImage.Abi=x86
diff --git a/sdk/platform_source.prop_template b/sdk/platform_source.prop_template
new file mode 100644
index 0000000..17a5e4e
--- /dev/null
+++ b/sdk/platform_source.prop_template
@@ -0,0 +1,9 @@
+Pkg.Desc=Android SDK Platform ${PLATFORM_VERSION}
+Pkg.UserSrc=false
+Platform.Version=${PLATFORM_VERSION}
+Pkg.Revision=1
+AndroidVersion.ApiLevel=${PLATFORM_SDK_VERSION}
+AndroidVersion.CodeName=${PLATFORM_VERSION_CODENAME}
+Layoutlib.Api=7
+Layoutlib.Revision=1
+Platform.MinToolsRev=15
diff --git a/sdk/platform_source.properties b/sdk/platform_source.properties
deleted file mode 100644
index 0e70356..0000000
--- a/sdk/platform_source.properties
+++ /dev/null
@@ -1,9 +0,0 @@
-Pkg.Desc=Android SDK Platform 4.1
-Pkg.UserSrc=false
-Platform.Version=4.1
-Pkg.Revision=1
-AndroidVersion.ApiLevel=15
-#AndroidVersion.CodeName=
-Layoutlib.Api=7
-Layoutlib.Revision=1
-Platform.MinToolsRev=15
diff --git a/sdk/source_source.prop_template b/sdk/source_source.prop_template
new file mode 100644
index 0000000..d3cdfd5
--- /dev/null
+++ b/sdk/source_source.prop_template
@@ -0,0 +1,4 @@
+Pkg.UserSrc=false
+Pkg.Revision=1
+AndroidVersion.ApiLevel=${PLATFORM_SDK_VERSION}
+AndroidVersion.CodeName=${PLATFORM_VERSION_CODENAME}
diff --git a/sdk/source_source.properties b/sdk/source_source.properties
deleted file mode 100644
index d0b390b..0000000
--- a/sdk/source_source.properties
+++ /dev/null
@@ -1,4 +0,0 @@
-Pkg.UserSrc=false
-Pkg.Revision=1
-AndroidVersion.ApiLevel=15
-#AndroidVersion.CodeName=
diff --git a/sdk/support_source.properties b/sdk/support_source.properties
index 16d5cd8..28d3579 100644
--- a/sdk/support_source.properties
+++ b/sdk/support_source.properties
@@ -3,4 +3,3 @@
 Extra.Vendor=android
 Extra.Path=support
 Extra.OldPaths=compatibility
-