diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 2 | ||||
-rwxr-xr-x | src/moz-version (renamed from src/moz-version-compare) | 112 | ||||
-rw-r--r-- | src/xpi.mk | 84 |
3 files changed, 158 insertions, 40 deletions
diff --git a/src/Makefile b/src/Makefile index 09421f3..51e8ede 100644 --- a/src/Makefile +++ b/src/Makefile @@ -53,7 +53,7 @@ extra_files = \ bindir_files = \ med-xpi-pack \ med-xpi-unpack \ - moz-version-compare + moz-version extra_dirs = \ mozclient \ diff --git a/src/moz-version-compare b/src/moz-version index 6301053..512ab8d 100755 --- a/src/moz-version-compare +++ b/src/moz-version @@ -22,8 +22,14 @@ # Reference: https://developer.mozilla.org/en/Toolkit_version_format +import getopt import sys +# error codes +COMMAND_LINE_SYNTAX_ERROR = 2 +INVALID_COMPARATOR = 3 +EMPTY_VERSION_STRING = 4 + def decode_part(part): """Decodes a version part (like 5pre4) to <number-a><string-b><number-c><string-d>""" subpart = [0,"",0,""] @@ -74,13 +80,15 @@ def decode_part(part): return subpart -def decode_version(version): +def decode_version(version, verbose=False): """Decodes a version string like 1.1pre1a""" parts = version.split(".") decoded_parts = map(decode_part, parts) + if verbose: + print "I: Split %s up into %s." % (version, decoded_parts) return decoded_parts -def compare((a, b)): +def compare_subpart((a, b)): # A string-part that exists is always less-then a nonexisting string-part if a == "": if b == "": @@ -96,7 +104,7 @@ def compare((a, b)): return cmp(a, b) def compare_part((x, y)): - compared_subparts = filter(lambda x: x != 0, map(compare, zip(x, y))) + compared_subparts = filter(lambda x: x != 0, map(compare_subpart, zip(x, y))) if compared_subparts: return compared_subparts[0] else: @@ -114,32 +122,94 @@ def compare_versions(a, b): else: return 0 -def moz_compare_versions(version1, operator, version2): - """Return true if the expression version1 operator version2 is valid, otherwise false""" - operators = ("lt", "le", "eq", "ne", "ge", "gt") - if operator not in operators: - print "E: The operator " + operator + " is not valid. It should one of " + ", ".join(operators) + "." - sys.exit(2) +comparators = ("lt", "le", "eq", "ne", "ge", "gt") + +def moz_version_compare(version1, comparator, version2, silent=False, verbose=False): + """Return true if the expression version1 comparator version2 is valid, otherwise false""" + if comparator not in comparators: + if not silent: + print >> sys.stderr, "E: The comparator " + comparator + \ + " is not valid. It should one of " + ", ".join(comparators) + "." + sys.exit(INVALID_COMPARATOR) + + if version1.strip() == "" or version2.strip() == "": + if not silent: + print >> sys.stderr, "E: At least one version string is empty." + sys.exit(EMPTY_VERSION_STRING) - a = decode_version(version1) - b = decode_version(version2) + if verbose: + symbol = {"lt": "<", "le": "<=", "eq": "=", "ne": "!=", "ge": ">=", "gt": ">"} + print "I: Comparing %s %s %s." % (version1, symbol[comparator], version2) - if operator == "lt": + a = decode_version(version1, verbose) + b = decode_version(version2, verbose) + + if comparator == "lt": return compare_versions(a, b) < 0 - elif operator == "le": + elif comparator == "le": return compare_versions(a, b) <= 0 - elif operator == "eq": + elif comparator == "eq": return compare_versions(a, b) == 0 - elif operator == "ne": + elif comparator == "ne": return compare_versions(a, b) != 0 - elif operator == "ge": + elif comparator == "ge": return compare_versions(a, b) >= 0 - elif operator == "gt": + elif comparator == "gt": return compare_versions(a, b) > 0 + +def usage(output): + print >> output, """Usage: %s --compare version1 comparator version2 + + -h, --help display this help and exit + -s, --silent do not print anything and die silent on errors + -v, --verbose print more information + +comparator must be one of %s.""" % (sys.argv[0], ", ".join(comparators)) + + if __name__ == "__main__": - if moz_compare_versions(sys.argv[1], sys.argv[2], sys.argv[3]): - sys.exit(0) + try: + long_opts = ["compare", "help", "silent", "verbose"] + opts, args = getopt.gnu_getopt(sys.argv[1:], "chsv", long_opts) + except getopt.GetoptError, e: + # print help information and exit: + print >> sys.stderr, str(e) # will print something like "option -a not recognized" + usage(sys.stderr) + sys.exit(COMMAND_LINE_SYNTAX_ERROR) + + compare = False + silent = False + verbose = False + + for o, a in opts: + if o in ("-c", "--compare"): + compare = True + elif o in ("-h", "--help"): + usage(sys.stdout) + sys.exit() + elif o in ("-s", "--silent"): + silent = True + elif o in ("-v", "--verbose"): + verbose = True + else: + assert False, "unhandled option" + + if compare: + if len(args) != 3: + if not silent: + usage(sys.stderr) + sys.exit(COMMAND_LINE_SYNTAX_ERROR) + if moz_version_compare(args[0], args[1], args[2], silent, verbose): + if verbose: + print "I: Compare expression true." + sys.exit(0) + else: + if verbose: + print "I: Compare expression false." + sys.exit(1) else: - sys.exit(1) - + if not silent: + print >> sys.stderr, "E: You should specify the command --compare." + usage(sys.stderr) + sys.exit(COMMAND_LINE_SYNTAX_ERROR) @@ -3,6 +3,7 @@ # Copyright (c) 2008-2009 Canonical Ltd. # Author(s): Alexander Sack <asac@ubuntu.com> # Fabien Tassin <fta@sofaraway.org> +# Benjamin Drung <bdrung@ubuntu.com> # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -23,8 +24,10 @@ # Usage: include this file in your cdbs debian/rules file and define the # following variables: # -# MOZ_EXTENSION_PKG (MANDATORY): -# define the binary package name used to ship this xpi +# MOZ_EXTENSION_PKG (OPTIONAL): +# if defined the given binary package name is used to ship this +# xpi; otherwise the first binary package listed in debian/control +# is used # # MOZ_XPI_FILE (OPTIONAL): # if defined the given .xpi file is used; otherwise we try to @@ -62,34 +65,79 @@ # your code to MOZ_XPI_MOZILLA_EXTRA_DIRS # -# data for XPI_DEPENDS/CHECK_VERSION magic - targetApplication to package mapping -target_packages_{ec8030f7-c20a-464f-9b0e-13a3a9e97384}_3.0 := abrowser-3.0 firefox-3.0 iceweasel -target_packages_{ec8030f7-c20a-464f-9b0e-13a3a9e97384}_3.5 := abrowser-3.5 firefox-3.5 iceweasel -target_packages_{ec8030f7-c20a-464f-9b0e-13a3a9e97384}_3.6 := abrowser-3.6 firefox-3.6 -target_packages_{3550f703-e582-4d05-9a08-453d09bdfdc6}_2.0 := icedove thunderbird -target_packages_{3550f703-e582-4d05-9a08-453d09bdfdc6}_3.0 := icedove thunderbird-3.0 -target_packages_prism@developer.mozilla.org_1.0 := prism - -# data for XPI_DEPENDS/CHECK_VERSION magic - targetApplication versions -target_versions_{ec8030f7-c20a-464f-9b0e-13a3a9e97384} := 3.0 3.5 3.6 -target_versions_{3550f703-e582-4d05-9a08-453d09bdfdc6} := 2.0 3.0 -target_versions_prism@developer.mozilla.org := 1.0 +# data for XPI_DEPENDS/CHECK_VERSION magic - start/end of life of binary packages +abrowser-3.0_sol := 3.0a8 +abrowser-3.0_eol := 3.0.* +abrowser-3.5_sol := 3.5b4 +abrowser-3.5_eol := 3.5.* +abrowser-3.6_sol := 3.6a1pre +abrowser-3.6_eol := 3.6.* +firefox-3.0_sol := 3.0a8 +firefox-3.0_eol := 3.0.* +firefox-3.5_sol := 3.5b4 +firefox-3.5_eol := 3.5.* +firefox-3.6_sol := 3.6a1pre +firefox-3.6_eol := 3.6.* +iceweasel_sol := 2.0 +iceweasel_eol := * + +icedove_sol := 1.5.0.7 +icedove_eol := * +thunderbird_sol := 2.0 +thunderbird_eol := 2.0.0.* +thunderbird-3.0_sol := 3.0a1pre +thunderbird-3.0_eol := 3.0.* + +iceape_sol := 1.0.6 +iceape_eol := * +seamonkey_sol := 1.1.6 +seamonkey_eol := * + +conkeror_sol := 0.9 +conkeror_eol := * + +prism_sol := 0.8 +prism_eol := * + +sunbird_sol := 0.5 +sunbird_eol := * + +xulrunner-1.9_sol := 1.9a1pre +xulrunner-1.9_eol := 1.9.0.* +xulrunner-1.9.1_sol := 1.9.1a1pre +xulrunner-1.9.1_eol := 1.9.1.* +xulrunner-1.9.2_sol := 1.9.2a1pre +xulrunner-1.9.2_eol := 1.9.2.* + +# data for XPI_DEPENDS/CHECK_VERSION magic - targetApplication packages +packages_{ec8030f7-c20a-464f-9b0e-13a3a9e97384} := abrowser-3.0 abrowser-3.5 abrowser-3.6 firefox-3.0 firefox-3.5 firefox-3.6 iceweasel +packages_{3550f703-e582-4d05-9a08-453d09bdfdc6} := icedove thunderbird thunderbird-3.0 +packages_{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a} := iceape seamonkey +packages_{a79fe89b-6662-4ff4-8e88-09950ad4dfde} := conkeror +packages_prism@developer.mozilla.org := prism +packages_toolkit@mozilla.org := xulrunner-1.9 xulrunner-1.9.1 xulrunner-1.9.2 # data for XPI_DEPENDS/CHECK_VERSION magic - targetApplication min-/maxVersions -# FIXME: find a way to get this information # call parameters_ # 1- target app id # 2- maxVersion | minVersion # 3- extension dir TARGET_VERSION = $(shell xpath -q -e '//em:targetApplication/Description[em:id="$(1)" or @em:id="$(1)"]/em:$(2)/text() | //em:targetApplication/Description[em:id="$(1)" or @em:id="$(1)"]/@em:$(2)' $(3)/install.rdf) -# TODO: Use correct comparison -CHECK_VERSION = $(shell moz-version-compare $(call TARGET_VERSION,$(1),minVersion,$(TEMPDIR)) le $(2) && moz-version-compare $(2) le $(call TARGET_VERSION,$(1),maxVersion,$(TEMPDIR)) && echo $(target_packages_$(1)_$(2))) +# call parameters_ +# 1- target app id +# 2- package name +CHECK_VERSION = $(shell \ + moz-version -cs "$($(2)_eol)" ge $(call TARGET_VERSION,$(1),minVersion,$(TEMPDIR)) && \ + moz-version -cs "$($(2)_sol)" le $(call TARGET_VERSION,$(1),maxVersion,$(TEMPDIR)) && \ + echo $(2)) MOZ_XPI_BUILD_COMMAND ?= med-xpi-pack $(CURDIR) $(MOZ_EXTENSION_PKG).xpi; XPI_DEPENDS = $(sort $(foreach id,$(call XPI_TARGET_EMIDs,$(TEMPDIR)), \ - $(foreach version,$(target_versions_$(id)),$(call CHECK_VERSION,$(id),$(version))))) + $(foreach package,$(packages_$(id)),$(call CHECK_VERSION,$(id),$(package))))) + +MOZ_EXTENSION_PKG ?= $(strip $(shell grep ^Package: debian/control | head -n 1 | sed "s/^Package://")) TEMPDIR := temp-xpi-unpacked |