Blame SOURCES/otp-make-subpackages.py

844843
import glob
844843
import os
844843
import re
844843
import rpm
844843
import sys
844843
844843
ts = rpm.TransactionSet()
844843
844843
packages = []
844843
for arg in sys.argv[1:]:
844843
	packages += glob.glob(arg)
844843
844843
erlang_provides = {}
844843
erlang_requires = {}
844843
844843
package_names = []
844843
package_headers = {}
844843
844843
##
844843
## Custom tweaks begins here
844843
##
844843
844843
# These packages should be marked as noarch
b2acbd
package_noarch = [
b2acbd
		"emacs-erlang",
b2acbd
		"emacs-erlang-el",
8a3190
		"erlang-doc"]
844843
844843
# These are additional Requires which cannot be picked up automatically (yet).
844843
# TODO these should be added automatically
844843
package_additional_requires = {
844843
		"emacs-erlang": ["emacs-common-erlang = %{version}-%{release}", "emacs(bin) >= %{_emacs_version}" ],
844843
		"emacs-erlang-el": ["emacs-erlang = %{version}-%{release}"],
844843
		"erlang-dialyzer": ["graphviz"],
844843
		"erlang-erl_interface": ["%{name}-erts%{?_isa} = %{version}-%{release}"],
b2acbd
		# This library (lksctp-tools) is dlopened so it can't be picked
b2acbd
		# up automatically by the RPM dependency checker
844843
		"erlang-erts": ["lksctp-tools"],
844843
		"erlang-gs": ["tk"],
b2acbd
		# Stores files/links in /usr/share/java so has to depend on jpackage-utils
b2acbd
		"erlang-ic": ["jpackage-utils"],
b2acbd
		# Stores files/links in /usr/share/java so has to depend on jpackage-utils
b2acbd
		"erlang-jinterface": ["%{name}-erts%{?_isa} = %{version}-%{release}", "jpackage-utils"],
844843
		"erlang-wx": ["mesa-libGL", "mesa-libGLU"],
844843
		}
844843
844843
package_additional_buildrequires = {
b2acbd
		"emacs-erlang": ["emacs", "emacs-el"],
b2acbd
		"erlang-crypto": ["openssl-devel"],
844843
		"erlang-diameter": ["ed"],
b2acbd
b2acbd
		# BEWARE. No fop for EPEL5, and only for x86/x86_64 in EPEL6,
b2acbd
		# so we cannot regenerate docs here. (Un)Fortunately we dropped
b2acbd
		# support for EPEL6 and older versions.
b2acbd
		# FIXME add bootstrap condition first.
b2acbd
		"erlang-doc": ["fop", "libxslt"],
b2acbd
b2acbd
		"erlang-erts": ["lksctp-tools-devel", "m4", "ncurses-devel", "zlib-devel"],
844843
		"erlang-gs": ["tcl-devel", "tk-devel"],
b2acbd
844843
		# in EPEL6 on arches different from %{ix86} x86_64 we have to
844843
		# use java-devel-gcj, so technically this requirement makes it
844843
		# impossible to build Java support there. (Un)Fortunately we
b2acbd
		# already dropped full support for EPEL6 and older versions.
844843
		"erlang-ic": ["java-devel"],
844843
		"erlang-jinterface": ["java-devel"],
b2acbd
844843
		"erlang-odbc": ["unixODBC-devel"],
844843
		}
844843
844843
package_additional_obsoletes = {
b2acbd
		"erlang-erts": [
b2acbd
			"erlang-appmon",
b2acbd
			"erlang-docbuilder",
b2acbd
			"erlang-inviso",
b2acbd
			"erlang-pman",
b2acbd
			"erlang-toolbar",
b2acbd
			"erlang-tv"],
844843
		}
844843
844843
##
844843
## Custom tweaks ends here
844843
##
844843
844843
# To match 'erlang(asn1ct_eval_ext:transform_to_EXTERNAL1994/1)'
844843
prog = re.compile("^erlang(.*:.*/\d+)")
844843
rpmmask = re.compile(".*\.rpm")
844843
844843
# iterate over all rpms
844843
for package in sorted([p for p in packages if rpmmask.match(p)]):
b2acbd
b2acbd
	# A tricky part. We are processing packages, rebuilt with
b2acbd
	# %{__erlang_provides_requires}. Otherwise we won't get information
b2acbd
	# about imports/exports (until we learn how to parse Erlang BEAM file
b2acbd
	# headers with Python.
844843
	fd = os.open(package, os.O_RDONLY)
844843
	h = ts.hdrFromFdno(fd)
844843
	os.close(fd)
844843
844843
	rpm_name = h[rpm.RPMTAG_NAME]
844843
844843
	# Let's calculate provides
844843
	# We'll create dictionary to speedup future use
844843
	# FIXME duplicate provides
844843
	local_provides = [p for p in h[rpm.RPMTAG_PROVIDENAME] if prog.match(p)]
844843
	erlang_provides.update({k: rpm_name for k in local_provides})
844843
844843
	# Let's calculate requires
844843
	erlang_requires.update({rpm_name: [r for r in h[rpm.RPMTAG_REQUIRENAME] if prog.match(r) and not r in local_provides]})
844843
844843
	package_headers.update({rpm_name: h})
844843
844843
	package_names.append(rpm_name)
844843
844843
namemask = re.compile("^erlang-[a-zA-Z0-9_]*$")
844843
844843
print "### BEGIN OF AUTOGENERATED LIST ###"
844843
print ""
844843
844843
for name in package_names:
844843
	h = package_headers[name]
844843
844843
	if name == "erlang-doc":
844843
		# Additional ifdef just for this sub-package (see below)
844843
		print "%if %{with doc}"
844843
844843
	if namemask.match(name):
844843
		print "%%package %s" % name.replace("erlang-", "")
844843
	else:
844843
		print "%%package -n %s" % name
844843
844843
	print "Summary: %s" % h[rpm.RPMTAG_SUMMARY]
844843
	print "Group: %s" % h[rpm.RPMTAG_GROUP]
844843
844843
	rawdeps = [erlang_provides.get(r, "Error: missing requires: %s" % r) for r in erlang_requires[name]]
844843
844843
	deps = set()
844843
	dependency_add = deps.add
844843
	[x for x in rawdeps if not (x in deps or dependency_add(x))]
844843
844843
	# Additional BuildRequires (if any):
844843
	for br in package_additional_buildrequires.get(name, []):
844843
		print "BuildRequires: %s" % br
844843
844843
	# Add basic autogenerated Requires:
844843
	for r in sorted(deps):
844843
		#Requires: %{name}-stdlib%{?_isa} = %{version}-%{release}
844843
		print "Requires: %s%%{?_isa} = %%{version}-%%{release}" % r.replace("erlang-", "%{name}-")
844843
844843
	# Add custom additional Requires (if any):
844843
	for r in package_additional_requires.get(name, []):
844843
		print "Requires: %s" % r
844843
844843
	# Add custom additional Obsoletes (if any):
844843
	for os in package_additional_obsoletes.get(name, []):
844843
		print "Obsoletes: %s" % os
844843
844843
	if name in package_noarch:
844843
		print "BuildArch: noarch"
844843
844843
	print ""
844843
	if namemask.match(name):
844843
		print "%%description %s" % name.replace("erlang-", "")
844843
	else:
844843
		print "%%description -n %s" % name
844843
	print "%s" % h[rpm.RPMTAG_DESCRIPTION]
844843
844843
	if name == "erlang-doc":
844843
		# Additional ifdef just for this sub-package (see above)
844843
		print "%endif"
844843
844843
	print ""
844843
844843
print "### END OF AUTOGENERATED LIST ###"