From 48023786cf63fc4ca90d0c3876d0d578c07d2f68 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 23 Feb 2011 16:46:42 -0800 Subject: [PATCH] Generate SDK Repository XML. When the "sdk_repo" modified is used during the SDK build, this also generates the repository.xml and addon.xml files for the new SDK repository packages and places them in the DIST_DIR. Example usage: make -j 16 PRODUCT-sdk-sdk showcommands sdk_repo dist DIST_DIR=/dist/sdk make -j 16 PRODUCT-google_sdk-sdk_addon showcommands sdk_repo dist DIST_DIR=/dist/addon Change-Id: Ibaad66f4b1cc476a4146afde7087a10a0557f74c --- build/tools/mk_sdk_repo_xml.sh | 254 +++++++++++++++++++++++++++++++++ build/tools/sdk_repo.mk | 74 ++++++++-- 2 files changed, 316 insertions(+), 12 deletions(-) create mode 100755 build/tools/mk_sdk_repo_xml.sh diff --git a/build/tools/mk_sdk_repo_xml.sh b/build/tools/mk_sdk_repo_xml.sh new file mode 100755 index 000000000..56f426bb3 --- /dev/null +++ b/build/tools/mk_sdk_repo_xml.sh @@ -0,0 +1,254 @@ +#!/bin/bash +# +# Generates an SDK Repository XML based on the input files. + +set -e + +PROG_DIR=$(dirname $0) + +TYPES="tool platform-tool platform sample doc add-on" +OSES="linux macosx windows any linux-x86 darwin" + +TMP_DIR=$(mktemp -d -t sdkrepo.tmp.XXXXXXXX) +trap "rm -rf $TMP_DIR" EXIT + +function error() { + echo "*** ERROR: " $@ + usage +} + +function usage() { + cat < "$OUT" < + +EOFH + +# check_enum value value1 value2 value3... +# returns valueN if matched or nothing. +function check_enum() { + local VALUE="$1" + local i + shift + for i in "$@"; do + if [[ "$i" == "$VALUE" ]]; then + echo "$VALUE" + break; + fi + done +} + +# Parse all archives. + +ATTRS=( + # for repository packages + Pkg.Revision revision + Pkg.Desc description + Platform.Version version + AndroidVersion.ApiLevel api-level + AndroidVersion.CodeName codename + Platform.MinToolsRev min-tools-rev + Platform.MinPlatformToolsRev min-platform-tools-rev + Extra.Path path + Extra.Vendor vendor + Extra.MinApiLevel min-api-level + Sample.MinApiLevel min-api-level + # for addon packages + vendor vendor + name name + description description + api api-level + version revision + revision revision +) + +function parse_attributes() { + local PROPS="$1" + shift + local RESULT="" + local VALUE + + while [[ "$1" ]]; do + # Parse the property, if present. Any space is replaced by @ + VALUE=$( grep "^$1=" "$PROPS" | cut -d = -f 2 | tr ' ' '@' | tr -d '\r' ) + if [[ -n "$VALUE" ]]; then + RESULT="$RESULT $2 $VALUE" + fi + shift + shift + done + + echo "$RESULT" +} + +function output_attributes() { + local OUT="$1" + shift + local KEY VALUE + + while [[ "$1" ]]; do + KEY="$1" + VALUE="${2//@/ }" + echo " $VALUE" >> "$OUT" + shift + shift + done +} + +while [[ -n "$1" ]]; do + # Process archives. + # First we expect a type. For conveniency the type can be plural. + TYPE=$(check_enum "${1%%s}" $TYPES) + [[ -z $TYPE ]] && error "Unknown archive type '$1'." + shift + + MAP="" + FIRST="1" + LIBS_XML="" + + OS=$(check_enum "$1" $OSES) + while [[ $OS ]]; do + shift + [[ $OS == "linux-x86" ]] && OS=linux + [[ $OS == "darwin" ]] && OS=macosx + + SRC="$1" + DST="$1" + if [[ "${SRC/:/}" != "$SRC" ]]; then + DST="${SRC/*:/}" + SRC="${SRC/:*/}" + fi + [[ ! -f "$SRC" ]] && error "Missing file for archive $TYPE/$OS: $SRC" + shift + + # Depending on the archive type, we need a number of attributes + # from the source.properties or the manifest.ini. We'll take + # these attributes from the first zip found. + # + # What we need vs. which package uses it: + # - description all + # - revision all + # - version platform + # - api-level platform sample doc add-on + # - codename platform sample doc add-on + # - min-tools-rev platform sample + # - min-platform-tools-rev tool + # - min-api-level extra + # - vendor extra add-on + # - path extra + # + # We don't actually validate here. + # Just take whatever is defined and put it in the XML. + # XML validation against the schema will be done at the end. + + if [[ $FIRST ]]; then + FIRST="" + + if unzip -t "$SRC" | grep -qs "source.properties" ; then + # Extract Source Properties + # unzip: -j=flat (no dirs), -q=quiet, -o=overwrite, -d=dest dir + unzip -j -q -o -d "$TMP_DIR" "$SRC" "*/source.properties" + PROPS="$TMP_DIR/source.properties" + + elif unzip -t "$SRC" | grep -qs "manifest.ini" ; then + unzip -j -q -o -d "$TMP_DIR" "$SRC" "*/manifest.ini" + PROPS="$TMP_DIR/manifest.ini" + + # Parse the libs for an addon and generate the node + # libraries is a semi-colon separated list + LIBS=$(parse_attributes "$PROPS" "libraries") + LIBS_XML=" " + for LIB in ${LIBS//;/ }; do + LIBS_XML="$LIBS_XML + $LIB" + done + LIBS_XML="$LIBS_XML + " + + else + error "Failed to find source.properties or manifest.ini in $SRC" + fi + + [[ ! -f $PROPS ]] && error "Failed to extract $PROPS from $SRC" + MAP=$(parse_attributes "$PROPS" ${ATTRS[@]}) + + # Time to generate the XML for the package + echo " " >> "$OUT" + output_attributes "$OUT" $MAP + [[ -n "$LIBS_XML" ]] && echo "$LIBS_XML" >> "$OUT" + echo " " >> "$OUT" + fi + + # Generate archive info + echo "## Add $TYPE/$OS archive $SRC" + if [[ $( uname ) == "Darwin" ]]; then + SIZE=$( stat -f %z "$SRC" ) + else + SIZE=$( stat -c %s "$SRC" ) + fi + SHA1=$( sha1sum "$SRC" | cut -d " " -f 1 ) + + cat >> "$OUT" < + $SIZE + $SHA1 + $DST + +EOFA + + # Skip to next arch/zip entry. + # If not a valid OS, close the archives/package nodes. + OS=$(check_enum "$1" $OSES) + + if [[ ! "$OS" ]]; then + echo " " >> "$OUT" + echo " " >> "$OUT" + fi + done + +done + +# Generate XML footer +echo "" >> "$OUT" + +echo "## Validate XML against schema" +xmllint --schema $SCHEMA "$OUT" diff --git a/build/tools/sdk_repo.mk b/build/tools/sdk_repo.mk index 70356c76d..c709502b2 100644 --- a/build/tools/sdk_repo.mk +++ b/build/tools/sdk_repo.mk @@ -2,13 +2,16 @@ .PHONY: sdk_repo +SDK_REPO_DEPS := +SDK_REPO_XML_ARGS := + # Define the name of a package zip file to generate # $1=OS (e.g. linux-x86, windows, etc) # $2=sdk zip (e.g. out/host/linux.../android-eng-sdk.zip) # $3=package to create (e.g. tools, docs, etc.) # define sdk-repo-pkg-zip -$(dir $(2))/sdk-repo-$(1)-$(3).zip +$(dir $(2))/sdk-repo-$(1)-$(3)-$(FILE_NAME_TAG).zip endef # Defines the rule to build an SDK repository package by zipping all @@ -25,10 +28,11 @@ endef define mk-sdk-repo-pkg-1 $(call sdk-repo-pkg-zip,$(1),$(2),$(3)): $(2) @echo "Building SDK repository package $(3) from $(notdir $(2))" - $(hide) cd $(dir $(2)) && \ - zip -9rq ../$(notdir $(call sdk-repo-pkg-zip,$(1),$(2),$(3))) \ - $(basename $(2))/* + $(hide) cd $(basename $(2)) && \ + zip -9rq ../$(notdir $(call sdk-repo-pkg-zip,$(1),$(2),$(3))) $(3)/* $(call dist-for-goals, sdk_repo, $(call sdk-repo-pkg-zip,$(1),$(2),$(3))) +SDK_REPO_XML_ARGS += $(3) $(1) \ + $(call sdk-repo-pkg-zip,$(1),$(2),$(3)):$(notdir $(call sdk-repo-pkg-zip,$(1),$(2),$(3))) endef # Defines the rule to build an SDK repository package when the @@ -45,15 +49,15 @@ endef define mk-sdk-repo-pkg-2 $(call sdk-repo-pkg-zip,$(1),$(2),$(3)): $(2) @echo "Building SDK repository package $(3) from $(notdir $(2))" - $(hide) cd $(dir $(2))/$(3) && \ - zip -9rq ../../$(notdir $(call sdk-repo-pkg-zip,$(1),$(2),$(3))) \ - $(basename $(2))/* + $(hide) cd $(basename $(2))/$(3) && \ + zip -9rq ../../$(notdir $(call sdk-repo-pkg-zip,$(1),$(2),$(3))) * $(call dist-for-goals, sdk_repo, $(call sdk-repo-pkg-zip,$(1),$(2),$(3))) +SDK_REPO_XML_ARGS += $(3) $(1) \ + $(call sdk-repo-pkg-zip,$(1),$(2),$(3)):$(notdir $(call sdk-repo-pkg-zip,$(1),$(2),$(3))) endef -SDK_REPO_DEPS := - +# ----------------------------------------------------------------- # Rules for win_sdk ifneq ($(WIN_SDK_ZIP),) @@ -68,6 +72,7 @@ SDK_REPO_DEPS += \ endif +# ----------------------------------------------------------------- # Rules for main host sdk ifneq ($(filter sdk win_sdk,$(MAKECMDGOALS)),) @@ -87,6 +92,7 @@ SDK_REPO_DEPS += \ endif +# ----------------------------------------------------------------- # Rules for sdk addon ifneq ($(ADDON_SDK_ZIP),) @@ -95,12 +101,56 @@ ifneq ($(ADDON_SDK_ZIP),) # already packaged correctly. All we have to do is dist it with # a different destination name. -$(call dist-for-goals, sdk_repo, \ - $(ADDON_SDK_ZIP):$(notdir $(call sdk-repo-pkg-zip,$(HOST_OS),$(ADDON_SDK_ZIP),addon))) +RENAMED_ADDON_ZIP := $(ADDON_SDK_ZIP):$(notdir $(call sdk-repo-pkg-zip,$(HOST_OS),$(ADDON_SDK_ZIP),addon)) + +$(call dist-for-goals, sdk_repo, $(RENAMED_ADDON_ZIP)) + +# Also generate the addon.xml using the latest schema and the renamed addon zip + +SDK_ADDON_XML := $(dir $(ADDON_SDK_ZIP))/addon.xml + +SDK_ADDON_XSD := \ + $(lastword \ + $(wildcard \ + $(TOPDIR)sdk/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/sdk-addon-*.xsd \ + )) + +$(SDK_ADDON_XML): $(ADDON_SDK_ZIP) + $(hide) $(TOPDIR)development/build/tools/mk_sdk_repo_xml.sh \ + $(SDK_ADDON_XML) $(SDK_ADDON_XSD) add-on $(HOST_OS) $(RENAMED_ADDON_ZIP) + +$(call dist-for-goals, sdk_repo, $(SDK_ADDON_XML)) endif +# ----------------------------------------------------------------- +# Rules for the SDK Repository XML -sdk_repo: $(SDK_REPO_DEPS) +SDK_REPO_XML := $(HOST_OUT)/sdk/repository.xml + +ifneq ($(SDK_REPO_XML_ARGS),) + +# Pickup the most recent xml schema +SDK_REPO_XSD := \ + $(lastword \ + $(wildcard \ + $(TOPDIR)sdk/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/sdk-repository-*.xsd \ + )) + +$(SDK_REPO_XML): $(SDK_REPO_DEPS) + $(hide) $(TOPDIR)development/build/tools/mk_sdk_repo_xml.sh \ + $(SDK_REPO_XML) $(SDK_REPO_XSD) $(SDK_REPO_XML_ARGS) + +$(call dist-for-goals, sdk_repo, $(SDK_REPO_XML)) + +else + +$(SDK_REPO_XML): ; + +endif + +# ----------------------------------------------------------------- + +sdk_repo: $(SDK_REPO_DEPS) $(SDK_REPO_XML) @echo "Packing of SDK repository done"