summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Drung <bdrung@ubuntu.com>2009-12-13 20:16:31 +0100
committerBenjamin Drung <bdrung@ubuntu.com>2009-12-13 20:16:31 +0100
commit2664bca2f6b30f0f96178f69981418b48a7314b4 (patch)
tree098b24377cf0e7addb9dca2ab443c37e2c034b44 /src
parentcb986ffa0293dcffe72673a65d1825890e7dce80 (diff)
* dh_xul-ext:
- Split substvars calculation from xpi.mk into new dh_xul-ext. - add src/dh_xul-ext - update src/Makefile - update src/xpi.mk
Diffstat (limited to 'src')
-rw-r--r--src/Makefile1
-rwxr-xr-xsrc/dh_xul-ext213
-rw-r--r--src/xpi.mk55
3 files changed, 217 insertions, 52 deletions
diff --git a/src/Makefile b/src/Makefile
index 0660c90..517d03c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -57,6 +57,7 @@ extra_files = \
$(NULL)
bindir_files = \
+ dh_xul-ext \
xpi-pack \
xpi-unpack \
moz-version
diff --git a/src/dh_xul-ext b/src/dh_xul-ext
new file mode 100755
index 0000000..15177dc
--- /dev/null
+++ b/src/dh_xul-ext
@@ -0,0 +1,213 @@
+#!/usr/bin/python
+
+# Copyright (c) 2009 Benjamin Drung <bdrung@ubuntu.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+import getopt
+import glob
+import os
+import subprocess
+import sys
+
+# error codes
+COMMAND_LINE_SYNTAX_ERROR = 1
+MULTIPLE_INSTALL_RDFs = 2
+
+def get_xul_apps():
+ packages = list()
+ for filename in glob.glob("/var/lib/apt/lists/*_Packages"):
+ with open(filename) as f:
+ package_name = None
+ version = None
+ xul_appid = None
+ xul_eol = "*"
+ for line in f:
+ if line == "\n":
+ if xul_appid is not None:
+ # find duplicates and keep older version
+ found_duclicate = False
+ for i in xrange(len(packages) - 1, -1, -1):
+ if packages[i][0] == package_name:
+ command = ['dpkg', '--compare-versions', version, 'lt', packages[i][1]]
+ if subprocess.call(command) == 0:
+ del packages[i]
+ else:
+ found_duclicate = True
+ break
+ if not found_duclicate:
+ packages.append([package_name, version, xul_appid, xul_eol])
+ package_name = None
+ version = None
+ xul_appid = None
+ xul_eol = "*"
+ elif line.startswith("Package:"):
+ package_name = line[line.find(":")+1:].strip()
+ elif line.startswith("Version:"):
+ version = line[line.find(":")+1:].strip()
+ elif line.startswith("Xul-AppId"):
+ xul_appid = line[line.find(":")+1:].strip()
+ elif line.startswith("Xul-Eol"):
+ xul_eol = line[line.find(":")+1:].strip()
+ return sorted(packages)
+
+def get_supported_apps(xul_apps, install_rdf, package):
+ # TODO
+## data for XPI_RECOMMENDS/CHECK_VERSION magic - targetApplication min-/maxVersions
+## call parameters_
+## 1- target app id
+## 2- maxVersion | minVersion
+#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) | //RDF:Description[@em:id="$(1)"]/em:$(2)/text() | //RDF:Description[@em:id="$(1)"]/@em:$(2)' $(install_dir)/install.rdf | sed -e 's/.*"\(.*\)"/\1/')
+
+## call parameters_
+## 1- target app id
+## 2- package name
+#CHECK_VERSION = $(shell \
+# moz-version -cs "$($(2)_eol)" ge $(call TARGET_VERSION,$(1),minVersion) && \
+# moz-version -cs "$($(2)_sol)" le $(call TARGET_VERSION,$(1),maxVersion) && \
+# echo $(2))
+
+#XPI_RECOMMENDS = $(strip $(foreach id,$(XPI_TARGET_EMIDs), \
+# $(foreach package,$(packages_$(id)),$(call CHECK_VERSION,$(id),$(package)))))
+ return ["firefox-3.5", "abrowser-3.5", "firefox-3.0"]
+
+def get_all_packages():
+ lines = open("debian/control").readlines()
+ package_lines = filter(lambda x: x.find("Package:") >= 0, lines)
+ packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines)
+ return packages
+
+def get_source_package_name():
+ source = None
+ with open("debian/control") as f:
+ for line in f:
+ if line.startswith("Source:"):
+ source = line[line.find(":")+1:].strip()
+ break
+ return source
+
+
+def get_provided_package_names(package, supported_apps):
+ # check if MOZ_XPI_EXT_NAME is defined in debian/rules
+ lines = open("debian/rules").readlines()
+ lines = filter(lambda x: x.find("MOZ_XPI_EXT_NAME") != -1 or x.find("MOZ_EXT_NAME") != -1, lines)
+ if len(lines) > 0:
+ ext_name = lines[-1][line.find("=")+1:].strip()
+ else:
+ ext_name = package
+ for prefix in ("firefox-", "iceweasel-", "mozilla-", "xul-ext-"):
+ if ext_name.startswith(prefix):
+ ext_name = ext_name[len(prefix):]
+
+ provides = set()
+ provides.add("xul-ext-" + ext_name)
+ if ext_name == get_source_package_name():
+ provides.add(ext_name)
+
+ for app in supported_apps:
+ for i in xrange(len(app) - 1, -1, -1):
+ if app[i] == '-':
+ app = app[:i]
+ elif not app[i].isdigit() and not app[i] == '.':
+ break
+ provides.add(app + "-" + ext_name)
+
+ # remove package name from provide list
+ provides.discard(package)
+
+ return list(provides)
+
+def find_install_rdfs(package):
+ install_rdfs = list()
+ for root, dirs, files in os.walk("debian/" + package):
+ if "install.rdf" in files:
+ install_rdfs.append(os.path.join(root, "install.rdf"))
+ dirs = filter(lambda d: not os.path.islink(os.path.join(root, d)), dirs)
+ return install_rdfs
+
+def generate_substvars(xul_apps, package):
+ install_rdfs = find_install_rdfs(package)
+ if len(install_rdfs) == 0:
+ # this package does not contain a xul extension
+ return
+ elif len(install_rdfs) > 1:
+ print >> sys.stderr, "%s: %s contains multiple install.rdf files. That's not supported." % (sys.argv[0], package)
+ sys.exit(MULTIPLE_INSTALL_RDFs)
+ install_rdf = install_rdfs.pop()
+
+ filename = "debian/" + package + ".substvars"
+ if os.path.exists(filename):
+ f = open(filename)
+ lines = f.readlines()
+ f.close()
+ else:
+ lines = list()
+
+ # remove existing varibles
+ lines = filter(lambda s: not s.startswith("xpi:"), lines)
+
+ packages = get_supported_apps(xul_apps, install_rdf, package)
+ lines.append("xpi:Recommends=" + " | ".join(packages) + "\n")
+ lines.append("xpi:Enhances=" + ", ".join(sorted(packages)) + "\n")
+ packages = get_provided_package_names(package, packages)
+ lines.append("xpi:Provides=" + ", ".join(sorted(packages)) + "\n")
+
+ # write new variables
+ f = open(filename, "w")
+ f.writelines(lines)
+ f.close()
+
+if __name__ == "__main__":
+ try:
+ long_opts = ["help", "package", "verbose"]
+ opts, args = getopt.gnu_getopt(sys.argv[1:], "hp:v", 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)
+
+ packages = list()
+ verbose = False
+
+ for o, a in opts:
+ if o in ("-h", "--help"):
+ usage(sys.stdout)
+ sys.exit()
+ elif o in ("-p", "--package"):
+ packages.append(a)
+ elif o in ("-v", "--verbose"):
+ verbose = True
+ else:
+ assert False, "unhandled option"
+
+ if len(packages) == 0:
+ packages = get_all_packages()
+
+ if verbose:
+ print sys.argv[0] + ": packages:", ", ".join(packages)
+
+ xul_apps = get_xul_apps()
+ if verbose and len(xul_apps) > 0:
+ print sys.argv[0] + ": found %i Xul applications:" % (len(xul_apps))
+ for xul_app in xul_apps:
+ print xul_app[0] + " " + xul_app[1] + " (" + xul_app[2] + ")"
+
+ for package in packages:
+ generate_substvars(xul_apps, package)
diff --git a/src/xpi.mk b/src/xpi.mk
index 56f50b7..dbf01a3 100644
--- a/src/xpi.mk
+++ b/src/xpi.mk
@@ -88,51 +88,12 @@
# to MOZ_XPI_EXT_NAME
#
-_xpi_makefile_path ?= /usr/share/mozilla-devscripts
-
--include $(_xpi_makefile_path)/xpi-config.mk
-
-MOZ_XPI_DISTRO ?= all
-
-# xpi-data-*.mk must define packages_*, *_sol, and *_eol
-include $(_xpi_makefile_path)/xpi-data-$(MOZ_XPI_DISTRO).mk
-
-# data for XPI_RECOMMENDS/CHECK_VERSION magic - targetApplication min-/maxVersions
-# call parameters_
-# 1- target app id
-# 2- maxVersion | minVersion
-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) | //RDF:Description[@em:id="$(1)"]/em:$(2)/text() | //RDF:Description[@em:id="$(1)"]/@em:$(2)' $(install_dir)/install.rdf | sed -e 's/.*"\(.*\)"/\1/')
-
-# call parameters_
-# 1- target app id
-# 2- package name
-CHECK_VERSION = $(shell \
- moz-version -cs "$($(2)_eol)" ge $(call TARGET_VERSION,$(1),minVersion) && \
- moz-version -cs "$($(2)_sol)" le $(call TARGET_VERSION,$(1),maxVersion) && \
- echo $(2))
-
MOZ_EXTENSION_PKG ?= $(strip $(shell grep ^Package: debian/control | head -n 1 | sed "s/^Package://"))
MOZ_XPI_ARCH := $(strip $(shell egrep '^Package:|^Architecture:' debian/control | grep -A1 '^Package:[ \t]*$(MOZ_EXTENSION_PKG)[ \t]*$$' | grep ^Architecture: | sed -e 's/Architecture://'))
MOZ_XPI_BUILD_COMMAND ?= xpi-pack $(CURDIR) $(MOZ_EXTENSION_PKG).xpi
-XPI_RECOMMENDS = $(strip $(foreach id,$(XPI_TARGET_EMIDs), \
- $(foreach package,$(packages_$(id)),$(call CHECK_VERSION,$(id),$(package)))))
-
-# support for deprecated MOZ_EXT_NAME
-ifneq (,$(MOZ_EXT_NAME))
-MOZ_XPI_EXT_NAME := $(MOZ_EXT_NAME)
-endif
-
-MOZ_XPI_EXT_NAME ?= $(shell echo $(MOZ_EXTENSION_PKG) | sed "s/^firefox-//;s/^iceweasel-//;s/^mozilla-//;s/^xul-ext-//")
-
-ifeq ($(MOZ_XPI_EXT_NAME),$(strip $(shell grep ^Source: debian/control | sed "s/^Source://")))
-ADDITIONAL_PROVIDES := $(MOZ_XPI_EXT_NAME)
-endif
-strip_version = $(sort $(foreach package,$(1),$(shell echo $(package) | sed "s/-[0-9.]*$$//")))
-XPI_PROVIDES = $(sort $(filter-out $(MOZ_EXTENSION_PKG),$(ADDITIONAL_PROVIDES) $(addsuffix -$(MOZ_XPI_EXT_NAME),xul-ext $(call strip_version,$(XPI_RECOMMENDS)))))
-
ifneq (,$(MOZ_XPI_FILE))
XPI_FILE = $(wildcard $(MOZ_XPI_FILE))
else
@@ -211,21 +172,13 @@ autolinks-stamp: $(patsubst %,install-%-stamp,$(XPI_BASE_FILE)) $(foreach mozill
$(foreach id,$(XPI_TARGET_EMIDs),dh_link -p$(MOZ_EXTENSION_PKG) /usr/$(lib_share_dir)/$(MOZ_EXTENSION_PKG) /usr/lib/mozilla/extensions/$(id)/$(XPI_EMID);)
touch $@
-xpi-recommends-stamp: $(patsubst %,install-%-stamp,$(XPI_BASE_FILE))
- if test -f debian/$(MOZ_EXTENSION_PKG).substvars; then sed -i '/^xpi:Recommends=/d' debian/$(MOZ_EXTENSION_PKG).substvars; fi
- echo "xpi:Recommends=$(XPI_RECOMMENDS)" | sed "s/ / | /g" >> debian/$(MOZ_EXTENSION_PKG).substvars
+xpi-install: $(patsubst %,install-%-stamp,$(XPI_BASE_FILE)) autolinks-stamp
+ dh_xul-ext -p$(MOZ_EXTENSION_PKG)
ifneq ($(shell grep '$${xpi:Depends}' debian/control),)
@echo 'xpi.mk: $${xpi:Depends} is deprecated, please use $${xpi:Recommends} instead.'
if test -f debian/$(MOZ_EXTENSION_PKG).substvars; then sed -i '/^xpi:Depends=/d' debian/$(MOZ_EXTENSION_PKG).substvars; fi
- echo "xpi:Depends=$(XPI_RECOMMENDS)" | sed "s/ / | /g" >> debian/$(MOZ_EXTENSION_PKG).substvars
+ grep '^xpi:Recommends=' debian/$(MOZ_EXTENSION_PKG).substvars | sed "s/^xpi:Recommends=/xpi:Depends=/g" >> debian/$(MOZ_EXTENSION_PKG).substvars
endif
- if test -f debian/$(MOZ_EXTENSION_PKG).substvars; then sed -i '/^xpi:Provides=/d' debian/$(MOZ_EXTENSION_PKG).substvars; fi
- echo "xpi:Provides=$(XPI_PROVIDES)" | sed "s/ /, /g" >> debian/$(MOZ_EXTENSION_PKG).substvars
- if test -f debian/$(MOZ_EXTENSION_PKG).substvars; then sed -i '/^xpi:Enhances=/d' debian/$(MOZ_EXTENSION_PKG).substvars; fi
- echo "xpi:Enhances=$(sort $(XPI_RECOMMENDS))" | sed "s/ /, /g" >> debian/$(MOZ_EXTENSION_PKG).substvars
- touch $@
-
-xpi-install: $(patsubst %,install-%-stamp,$(XPI_BASE_FILE)) autolinks-stamp xpi-recommends-stamp
# clean build and remove all .xpi in top-level if a MOZ_XPI_BUILD_COMMAND is defined
clean::
@@ -244,7 +197,5 @@ print-vars:
@echo "XPI_EMID: $(XPI_EMID)"
@echo "RDF_RESOURCES: $(RDF_RESOURCES)"
@echo "XPI_TARGET_EMIDs: $(XPI_TARGET_EMIDs)"
- @echo "XPI_RECOMMENDS: $(XPI_RECOMMENDS)"
- @echo "packages: $(foreach id,$(XPI_TARGET_EMIDs),$(packages_$(id)))"
.PHONY: clean xpi-install print-vars