Blame 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
844843
package_noarch = ["emacs-erlang", "emacs-erlang-el", "erlang-doc", "xemacs-erlang", "xemacs-erlang-el"]
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}"],
844843
		# This library is dlopened so it can't be picked up automatically by the RPM
844843
		# dependency checker
844843
		"erlang-erts": ["lksctp-tools"],
844843
		"erlang-gs": ["tk"],
844843
		# FIXME stores files/links in jpackage-utils' directory "erlang-ic": ["jpackage-utils"],
844843
		# FIXME stores files/links in jpackage-utils' directory "erlang-jinterface": ["%{name}-erts%{?_isa} = %{version}-%{release}, "jpackage-utils"],
844843
		"erlang-jinterface": ["%{name}-erts%{?_isa} = %{version}-%{release}"],
844843
		"erlang-wx": ["mesa-libGL", "mesa-libGLU"],
844843
		"xemacs-erlang": ["emacs-common-erlang = %{version}-%{release}", "xemacs(bin) >= %{_xemacs_version}"],
844843
		"xemacs-erlang-el": ["xemacs-erlang = %{version}-%{release}"]
844843
		}
844843
844843
package_additional_buildrequires = {
844843
		"erlang-diameter": ["ed"],
844843
		"erlang-gs": ["tcl-devel", "tk-devel"],
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
844843
		# already dropped full support for EPEL6
844843
		"erlang-ic": ["java-devel"],
844843
		"erlang-jinterface": ["java-devel"],
844843
		"erlang-odbc": ["unixODBC-devel"],
844843
		"erlang-wx": ["wxGTK-devel"],
844843
		}
844843
844843
package_additional_obsoletes = {
844843
		"erlang-erts": ["erlang-appmon", "erlang-docbuilder", "erlang-inviso", "erlang-pman", "erlang-toolbar", "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)]):
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 ###"