summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pietri2018-10-07 18:55:31 +0200
committerAntoine Pietri2018-10-07 18:55:31 +0200
commit0f497e327654a700727c0d7a081d77abc141da45 (patch)
treedee04c73022542400b8beb79c4efa417406ea768
parent7f3159239edcac76f8b543cfb271001d1cff4178 (diff)
downloadaur-0f497e327654a700727c0d7a081d77abc141da45.tar.gz
Add PKGBUILD generation toolchain
-rw-r--r--.gitignore3
-rw-r--r--Makefile18
-rw-r--r--PKGBUILD1
-rwxr-xr-xbuild_depends.py64
4 files changed, 85 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000000..9f1a04d8934
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+pkg/
+src/
+*.pkg.*
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000000..30051c8b145
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,18 @@
+all: PKGBUILD .SRCINFO
+
+PKGBUILD:
+ sed -i '/depends=/,/)/d' $@
+ ./build_depends.py >> $@
+ updpkgsums
+ sed -i '/^$$/d' $@ # updpkgsums adds a newline
+
+.SRCINFO: PKGBUILD
+ makepkg --printsrcinfo > .SRCINFO
+
+check: PKGBUILD
+ makepkg -fc
+
+clean:
+ $(RM) *.pkg.*
+
+.PHONY: all check clean PKGBUILD
diff --git a/PKGBUILD b/PKGBUILD
index c24758f36c0..104802e8cb9 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -22,4 +22,3 @@ depends=('dmd' # handle D sources
'ruby' # handle Ruby sources
'rust' # handle Rust sources
'swi-prolog') # handle Prolog sources
-
diff --git a/build_depends.py b/build_depends.py
new file mode 100755
index 00000000000..dd187493758
--- /dev/null
+++ b/build_depends.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+
+import logging
+import subprocess
+import sys
+from pathlib import Path
+from collections import defaultdict
+
+from camisole.languages import Lang, load_builtins
+
+load_builtins()
+
+
+def by_name(name):
+ return Lang._full_registry[name]
+
+
+OVERWRITE = {
+ # java packages consist of symlinks to handle both Java 7 & 8, so we force
+ # the version (8) here
+ by_name('java'): {'/usr/lib/jvm/java-8-openjdk/bin/java',
+ '/usr/lib/jvm/java-8-openjdk/bin/javac'},
+ # go is provided by both 'go' and 'gcc-go'
+ by_name('go'): {'/usr/lib/go/bin/go'},
+}
+
+
+def list_paths():
+ for lang in Lang._full_registry:
+ cls = by_name(lang)
+ if cls in OVERWRITE:
+ for path in OVERWRITE[cls]:
+ yield cls, Path(path)
+ continue
+ for p in cls.required_binaries():
+ yield cls, Path(p.cmd)
+
+
+def get_package(binary):
+ try:
+ pkg = (subprocess.check_output(['pkgfile', '-qb', binary])
+ .decode().split('\n')[0]) or None
+ return pkg
+ except subprocess.CalledProcessError:
+ return None
+
+
+if __name__ == '__main__':
+ packages = defaultdict(set)
+ for lang, binary in list_paths():
+ pkg = get_package(binary)
+ if pkg is None:
+ logging.error("no package for %s", binary)
+ continue
+ packages[pkg].add(lang)
+ packages.pop('python', None) # already a strong dependency
+ packages = sorted(packages.items())
+ lines = ["{:<20} # handle {} sources".format(
+ "'{}'{}".format(pkg, ')' if i == len(packages) - 1 else ''),
+ ', '.join(sorted(lang.name for lang in langs)))
+ for i, (pkg, langs) in enumerate(packages)]
+ prefix = 'depends=('
+ print('{}{}'.format(prefix, lines[0]))
+ print('\n'.join(' ' * len(prefix) + line for line in lines[1:]))