Still a messy WIP

This commit is contained in:
Darks 2021-08-31 00:11:27 +02:00
parent 3c0d8d5e66
commit 9bf485e468
Signed by: Darks
GPG Key ID: 7515644268BE1433
29 changed files with 439 additions and 133 deletions

5
.gitignore vendored
View File

@ -1,8 +1,3 @@
__pycache__/
*.py[cod]
*$py.class
packages/
pkgbuilds/
output/
run.sh

View File

@ -3,4 +3,9 @@ repo:
db_name: "casio.db"
arch: "x86_64"
maintainer: "Eldeberen <eldeberen.aur@middleearth.fr>"
chroot:
pacman: "/etc/pacman.conf"
makepkg: "/etc/makepkg.conf"
templates: "./pkgtmpl"
pkgbuilds: "/home/eldeberen/tmp/pkgbuild"

View File

@ -2,14 +2,18 @@
import argparse, logging
import os.path as path
from config import Config, make_chroot
from chroot import Chroot
from config import Config
from package import Package
from repository import Repository
parser = argparse.ArgumentParser(description='Build some packages.')
parser.add_argument('-c', metavar='config', dest="config",
parser.add_argument('-c', '--config', dest='config_dir',
default="/etc/middlearch",
help="configuration directory")
parser.add_argument('--verbose', '-v', action='count', default=0)
parser.add_argument('-v', '--verbose', action='count', default=0)
args = parser.parse_args()
@ -17,6 +21,12 @@ verbosities = [logging.WARNING, logging.INFO, logging.DEBUG]
logging.basicConfig(format="[%(asctime)s] %(levelname)s (%(filename)s.%(funcName)s): %(message)s",
level=verbosities[min(args.verbose, len(verbosities)-1)])
config = Config(args.config)
config = Config(args.config_dir)
repository = Repository(**config.get('repo'))
packages = Package.load(args.config_dir, repository)
#chroot = Chroot(config)
make_chroot(args.config)
for package in packages:
package.render_pkgbuild(config)
# if package.build:
# chroot.makepkg(package, config)

31
middlearch/chroot.py Normal file
View File

@ -0,0 +1,31 @@
import logging, os, tempfile
import os.path as path
class Chroot(object):
def __init__(self, config):
# Create directories
self.basedir = tempfile.mkdtemp()
rootdir = path.join(self.basedir, "root")
logging.info(f"created temporary directory in {self.basedir}")
# Initialize base-devel packages
pacman = f"-C {p}" if (p := config.get('chroot.pacman')) else ""
makepkg = f"-M {p}" if (p := config.get('chroot.makepkg')) else ""
_exec(f"mkarchroot {pacman} {makepkg} {rootdir} base-devel")
# Make sure everything is up-to-date
_exec(f"arch-nspawn {rootdir} pacman -Syu")
logging.info("chroot initialized")
def makepkg(self, package, config):
current_dir = os.getcwd()
os.chdir(path.join(config.get('pkgbuilds'), package.name))
_exec(f"makechrootpkg -c -r {self.basedir}")
os.chdir(current_dir)
def _exec(cmd):
logging.info(cmd)
r = os.popen(cmd)
logging.debug(r.read())

22
middlearch/config.py Normal file
View File

@ -0,0 +1,22 @@
import logging
import os
import os.path as path
import yaml
class Config(object):
def __init__(self, config_dir):
with open(path.join(config_dir, "config.yaml")) as file:
self.conf = yaml.load(file, Loader=yaml.SafeLoader)
logging.info(f"{path.join(config_dir, 'config.yaml')} loaded")
logging.debug('configuration:\n'+yaml.dump(self.conf))
def get(self, key, default=None):
v = self.conf
for k in key.split("."):
try:
v = v[k]
except KeyError:
logging.debug(f"{key} not found")
return default
return v

View File

@ -1,2 +0,0 @@
from .config import Config
from .chroot import make_chroot

View File

@ -1,21 +0,0 @@
import logging, os, tempfile
import os.path as path
def make_chroot(configdir):
# Create directories
basedir = tempfile.mkdtemp()
rootdir = path.join(basedir, "root")
logging.info(f"created temporary directory in {basedir}")
# Initialize base-devel packages
pacman = path.join(configdir, "pacman.conf")
makepkg = path.join(configdir, "makepkg.conf")
r = os.popen(f"mkarchroot -C {pacman} -M {makepkg} {rootdir} base-devel")
logging.debug(r.read())
# Make sure everything is up-to-date
r = os.popen(f"arch-nspawn {rootdir} pacman -Syu")
logging.debug(r.read())
logging.info("chroot initialized")

View File

@ -1,16 +0,0 @@
import logging
import os, shutil
import yaml
import os.path as path
class Config():
def __init__(self, config_dir):
with open(path.join(config_dir, "config.yaml")) as file:
self.params = yaml.load(file, Loader=yaml.SafeLoader)
logging.info(f"{path.join(config_dir, 'config.yaml')} loaded")
logging.debug('\n'+yaml.dump(self.params))
with open(path.join(config_dir, "packages.yaml")) as file:
self.packages = yaml.load(file, Loader=yaml.SafeLoader)
logging.info(f"{len(self.packages)} packages loaded")
logging.debug('\n'+yaml.dump(self.packages))

28
middlearch/git.py Normal file
View File

@ -0,0 +1,28 @@
import logging
import os
import re
def get_tag_from_git(remote):
if remote is None:
logging.warning("cannot retreive tags from None remote")
return None
regex = re.compile("^refs/tags/v?(\d+\.\d+\.\d+)$")
def extract_tag(tag):
m = regex.search(tag)
if m:
return m.groups()[0]
return ""
raw_tags = os.popen(f"git ls-remote --tags {remote}").read().split()
tags = sorted(
list(
filter(''.__ne__,
map(extract_tag, raw_tags)
),
)
)
logging.debug(f"{remote}: {', '.join(tags)}")
return tags[-1]

87
middlearch/package.py Normal file
View File

@ -0,0 +1,87 @@
import hashlib, logging, os, re
import jinja2 as j2
import os.path as path
import requests as r
import yaml
from git import get_tag_from_git
class Package(object):
def __init__(self, name, **params):
self.name = name
self.repo = params.get("repo")
self.tag = params.get("tag") or get_tag_from_git(self.repo)
self.force = params.get("force", False)
self.render = params.get("render", True)
self.maintainers = params.get("maintainers", {})
self.contributors = params.get("contributors", {})
self.build = False
logging.debug(self)
def __repr__(self):
return f"{self.name} [repo: {self.repo}, tag: {self.tag}, force: {self.force}]"
def load(config_dir, repository):
with open(path.join(config_dir, "packages.yaml")) as file:
p_list = yaml.load(file, Loader=yaml.SafeLoader)
packages = []
for p in p_list:
package = Package(**p)
packages.append(package)
current_tag = repository.get_package_version(package.name)
if package.tag > current_tag:
logging.info(f"{package.name} will be updated ({current_tag}{package.tag})")
package.build = True
elif package.force:
logging.info(f"{package.name} will be updated ({package.tag})")
package.build = True
else:
logging.info(f"{package.name} will be skipped")
logging.info(f"{len(packages)} packages loaded")
return packages
def render_pkgbuild(self, config):
def get_hash(name, tag):
regex = re.compile("^source=.+(https://.+\.tar\.[a-z]+)", re.MULTILINE)
with open(f"{config.get('templates', 'templates')}/{name}.j2") as file:
content = file.read()
try:
url = regex.search(content).group(1)
except:
logging.warning(f"cannot find valid source for {name} (is it a git version?)")
return "SKIP"
url = url.replace("${pkgver}", tag)
url = url.replace("${pkgname}", name)
archive = r.get(url)
hash = hashlib.sha256(archive.content).hexdigest()
return hash
env = j2.Environment(
loader=j2.FileSystemLoader(config.get('templates', 'templates')),
autoescape=j2.select_autoescape([])
)
template = env.get_template(f"{self.name}.j2")
hash = get_hash(self.name, self.tag)
sysenv = j2.Environment(
loader=j2.FileSystemLoader('templates'),
autoescape=j2.select_autoescape([])
)
maintainers_template = sysenv.get_template("maintainers.j2")
dest_dir = path.join(config.get('pkgbuilds', "pkgbuilds"), self.name)
os.makedirs(dest_dir, exist_ok=True)
with open(f"{config.get('pkgbuilds')}/{self.name}/PKGBUILD", "w") as file:
file.write(maintainers_template.render(
maintainers=self.maintainers,
contributors=self.contributors
))
file.write(template.render(name=self.name, tag=self.tag, hash=hash))

37
middlearch/repository.py Normal file
View File

@ -0,0 +1,37 @@
from io import BytesIO
import logging
import re
import requests as r
import tarfile
class Repository(object):
def __init__(self, base_url, arch, db_name):
self.base_url = base_url
self.arch = arch
self.db_name = db_name
self.db = tarfile.open(fileobj=BytesIO(r.get(self.db_url).content))
logging.info(f"{self} loaded")
@property
def db_url(self):
return f"{self.base_url}/{self.arch}/{self.db_name}"
def __repr__(self):
return self.db_url
def get_package_version(self, pkgname):
try:
name = list(filter(
lambda item: item.isdir() and pkgname in item.name,
self.db.getmembers()
))[0].name
except IndexError:
logging.warning(f"{pkgname} is not online")
version = "0.0.0"
else:
regex = re.compile(".+-(\d+\.\d+(?:\.\d+)?)-\d+")
version = regex.search(name).group(1)
logging.debug(f"{pkgname} is {version} online")
return version

View File

@ -1,13 +1,9 @@
import hashlib, logging, os, re
import jinja2 as j2
import os.path as path
import requests as r
env = j2.Environment(
loader=j2.FileSystemLoader('templates'),
autoescape=j2.select_autoescape([])
)
def get_hash(name, tag):
regex = re.compile("^source=.+(https://.+\.tar\.[a-z]+)", re.MULTILINE)
with open(f"templates/{name}.j2") as file:
@ -24,12 +20,3 @@ def get_hash(name, tag):
hash = hashlib.sha256(archive.content).hexdigest()
return hash
def render_pkgbuild(name, tag):
template = env.get_template(f"{name}.j2")
hash = get_hash(name, tag)
os.mkdir(f"pkgbuilds/{name}")
with open(f"pkgbuilds/{name}/PKGBUILD", "w") as file:
file.write(template.render(tag=tag, hash=hash, maintainer=MAINTAINER))

View File

@ -1,44 +1,82 @@
- name: isl
tag: "0.24"
maintainers:
- "Andrew Sun <adsun701 at gmail dot com>"
contributors:
- "Kritias <theodoridisgr at gmail dot com>"
- "sudokode <sudokode at gmail dot com>"
- "Allan McRae <allan at archlinux dot org>"
- "Eldeberen <eldeberen at middleearth dot fr>"
- name: sh-elf-binutils-casio
tag: "2.37"
maintainers:
- "Eldeberen <eldeberen@middleearth.fr>"
- name: sh-elf-gcc-casio
tag: "11.2.0"
maintainers:
- "Eldeberen <eldeberen@middleearth.fr>"
- name: openlibm-casio
repo: https://gitea.planet-casio.com/Lephenixnoir/OpenLibm.git
force: true
maintainers:
- "Eldeberen <eldeberen@middleearth.fr>"
- name: mkg3a
repo: https://github.com/tari/mkg3a.git
force: true
- name: "mkg3a"
repo: "https://github.com/tari/mkg3a.git"
maintainers:
- "Peter Marheine <peter@taricorp.net>"
contributors:
- "Eldeberen <eldeberen@middleearth.fr>"
- name: fxsdk
repo: https://gitea.planet-casio.com/Lephenixnoir/fxsdk.git
force: true
- name: "fxsdk"
repo: "https://gitea.planet-casio.com/Lephenixnoir/fxsdk.git"
maintainers:
- "Eldeberen <eldeberen@middleearth.fr>"
- name: fxlibc
repo: https://gitea.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
force: true
- name: "fxlibc"
repo: "https://gitea.planet-casio.com/Vhex-Kernel-Core/fxlibc.git"
maintainers:
- "Eldeberen <eldeberen@middleearth.fr>"
- name: gint
repo: https://gitea.planet-casio.com/Lephenixnoir/gint.git
force: true
- name: "gint"
repo: "https://gitea.planet-casio.com/Lephenixnoir/gint.git"
maintainers:
- "Eldeberen <eldeberen@middleearth.fr>"
- name: libimg
repo: https://gitea.planet-casio.com/Lephenixnoir/libimg.git
force: true
- name: "libimg"
repo: "https://gitea.planet-casio.com/Lephenixnoir/libimg.git"
maintainers:
- "Eldeberen <eldeberen@middleearth.fr>"
- name: libprof
repo: https://gitea.planet-casio.com/Lephenixnoir/libprof.git
force: true
- name: "libprof"
repo: "https://gitea.planet-casio.com/Lephenixnoir/libprof.git"
maintainers:
- "Eldeberen <eldeberen@middleearth.fr>"
- name: justui
repo: https://gitea.planet-casio.com/Lephenixnoir/justui.git
force: true
- name: "justui"
repo: "https://gitea.planet-casio.com/Lephenixnoir/justui.git"
maintainers:
- "Eldeberen <eldeberen@middleearth.fr>"
- name: libp7
- name: "libp7"
tag: "3.0"
maintainers:
- "Breizh <breizh@breizh.pm>"
contributors:
- "Eldeberen <eldeberen@middleearth.fr>"
- name: p7
- name: "p7"
tag: "3.0"
maintainers:
- "Breizh <breizh@breizh.pm>"
contributors:
- "Eldeberen <eldeberen@middleearth.fr>"
- name: p7screen
- name: "p7screen"
tag: "3.0"
maintainers:
- "Breizh <breizh@breizh.pm>"
contributors:
- "Eldeberen <eldeberen@middleearth.fr>"

View File

@ -1,12 +1,11 @@
# Maintainer: {{ maintainer }}
pkgname=fxlibc
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgdesc="A C standard library for fx Casio calculators, built for gint"
arch=('i686' 'x86_64')
url="https://gitea.planet-casio.com/Lephenixnoir/${pkgname}"
licence=('unkwown')
depends=('fxsdk')
depends=('fxsdk' 'openlibm-casio')
makedepends=('fxsdk')
options=('!buildflags' '!strip')
source=("$pkgname-$pkgver.tar.gz::https://gitea.planet-casio.com/Vhex-Kernel-Core/fxlibc/archive/${pkgver}.tar.gz")

View File

@ -1,5 +1,4 @@
# Maintainer: {{ maintainer }}
pkgname=fxsdk
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgdesc='Tools to program for the Casio fx9860 calculators'

View File

@ -1,5 +1,4 @@
# Maintainer: {{ maintainer }}
pkgname=gint
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgdesc='Alternative library and kernel for add-in development on fx-9860G and fx-CG50 under Linux'

33
pkgtmpl/isl.j2 Normal file
View File

@ -0,0 +1,33 @@
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgdesc="Library for manipulating sets and relations of integer points bounded by linear constraints"
arch=('i686' 'x86_64')
url="http://isl.gforge.inria.fr/"
depends=('gmp')
license=('MIT')
conflicts=('isl-git' 'isl14' 'isl15' 'isl16' 'isl17')
source=("http://isl.gforge.inria.fr/isl-${pkgver}.tar.gz")
sha256sums=('{{ hash }}')
build() {
cd ${srcdir}/${pkgname}-${pkgver}
./configure --prefix=/usr
make
}
check() {
cd ${srcdir}/${pkgname}-${pkgver}
make check || true
}
package() {
cd ${srcdir}/${pkgname}-${pkgver}
make DESTDIR="$pkgdir" install
install -dm755 "$pkgdir"/usr/share/gdb/auto-load/usr/lib/
mv "$pkgdir"/usr/lib/libisl.so.*-gdb.py "$pkgdir"/usr/share/gdb/auto-load/usr/lib/
install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/isl/LICENSE
}

View File

@ -1,7 +1,6 @@
# Maintainer: {{ maintainer }}
pkgname=justui
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgrel=2
pkgdesc="Lephe's GUI toolkit for gint"
arch=('i686' 'x86_64')
url="https://gitea.planet-casio.com/Lephenixnoir/${pkgname}"

View File

@ -1,7 +1,6 @@
# Maintainer: {{ maintainer }}
pkgname=libimg
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgrel=2
pkgdesc="Lephe's GUI toolkit for gint"
arch=('i686' 'x86_64')
url="https://gitea.planet-casio.com/Lephenixnoir/${pkgname}"

View File

@ -1,6 +1,4 @@
# Maintainer: Breizh <breizh@breizh.pm>
# Contributor: {{ maintainer }}
pkgname=libp7
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgdesc="Casio Communication Protocol 7.00 implementation"

View File

@ -1,7 +1,6 @@
# Maintainer: {{ maintainer }}
pkgname=libprof
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgrel=2
pkgdesc="A microsecond-level performance profiling library for gint"
arch=('i686' 'x86_64')
url="https://gitea.planet-casio.com/Lephenixnoir/${pkgname}"

View File

@ -1,6 +1,4 @@
# Maintainer: Peter Marheine <peter@taricorp.net>
# Contributor: {{ maintainer }}
pkgname=mkg3a
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgdesc="A tool to create Casio FX-CG addon (.g3a) files."

View File

@ -1,7 +1,6 @@
# Maintainer: {{ maintainer }}
pkgname=openlibm-casio
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=2
pkgrel=3
pkgdesc='Fork of the OpenLibm math library with support for fx-9860G and fx-CG 50'
arch=('i686' 'x86_64')
url="https://gitea.planet-casio.com/Lephenixnoir/OpenLibm"

View File

@ -1,6 +1,4 @@
# Maintainer: Breizh <breizh.craft.98@openmailbox.org>
# Contributor: {{ maintainer }}
pkgname=p7
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgdesc="Casio Communication Protocol 7.00 implementation"

View File

@ -1,26 +1,15 @@
# Maintainer: Breizh <breizh.craft.98@openmailbox.org>
# Contributor: {{ maintainer }}
pkgname=p7screen
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgdesc="Casio Communication Protocol 7.00 implementation"
arch=('i686' 'x86_64')
url="https://p7.planet-casio.com/"
license=('GPL2')
groups=()
depends=('libusb>=1.0' 'libp7>=3.0' 'sdl>=1.2.15')
makedepends=('asciidoc>=8.6.9')
optdepends=()
provides=('p7screen')
conflicts=()
replaces=()
backup=()
options=()
install=
changelog=
source=(https://p7.planet-casio.com/pub/p7utils-${pkgver}.tar.gz)
sha256sums=('{{ hash }}')
noextract=()
build() {
cd "p7utils-$pkgver"

View File

@ -0,0 +1,49 @@
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgdesc="GNU binary utilities for the Casio calculators SuperH processors."
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/binutils/"
license=('GPL')
depends=('binutils' 'flex' 'zlib')
makedepends=('gcc')
options=('!emptydirs' '!libtool')
source=("https://ftp.gnu.org/gnu/binutils/binutils-${pkgver}.tar.xz")
sha256sums=('{{ hash }}')
_target="sh-elf"
prepare() {
cd "${srcdir}/binutils-${pkgver}"
# ensure a clean build
[[ -d binutils-build ]] && rm -rf binutils-build
mkdir binutils-build
}
build() {
export CPPFLAGS=""
cd "${srcdir}/binutils-${pkgver}/binutils-build"
../configure \
--prefix=/usr \
--target=sh3eb-elf \
--with-multilib-list=m3,m4-nofpu \
--program-prefix=${_target}- \
--disable-nls \
--enable-libssp \
--enable-lto
make configure-host
make
}
package() {
cd "${srcdir}/binutils-${pkgver}/binutils-build"
echo "Install on ${pkgdir}"
make DESTDIR="${pkgdir}" install-strip
# Remove info documents that conflicts with host version
rm -rf "${pkgdir}/usr/share/info"
# Remove libraries that conflict with host version
rm -rf "${pkgdir}/usr/lib"
}

View File

@ -0,0 +1,49 @@
pkgname={{ name }}
pkgver={{ tag }}
pkgrel=1
pkgdesc="The GNU Compiler Collection for the Casio calculators SuperH processors."
arch=(i686 x86_64)
license=('GPL' 'LGPL')
url='http://gcc.gnu.org'
depends=("sh-elf-binutils-casio" 'libmpc' 'elfutils' 'gmp' 'mpfr')
optdepends=('isl: integer set library')
options=('!buildflags' '!libtool' '!emptydirs' 'zipman' 'docs' '!strip')
source=("https://gcc.gnu.org/pub/gcc/releases/gcc-${pkgver}/gcc-${pkgver}.tar.xz")
sha256sums=('{{ hash }}')
_target="sh-elf"
prepare() {
cd "${srcdir}/gcc-${pkgver}"
# Ensure a clean build
[[ -d gcc-build ]] && rm -rf gcc-build
mkdir gcc-build
}
build() {
cd "${srcdir}/gcc-${pkgver}/gcc-build"
../configure \
--prefix=/usr \
--target=sh3eb-elf \
--with-multilib-list=m3,m4-nofpu \
--program-prefix=${_target}- \
--enable-languages=c,c++ \
--without-headers \
--with-newlib \
--disable-nls \
--enable-libssp \
--enable-lto \
--disable-werror
make all-gcc all-target-libgcc
}
package() {
cd "${srcdir}/gcc-${pkgver}/gcc-build"
make DESTDIR="${pkgdir}" install-strip-gcc install-strip-target-libgcc
# Remove unwanted files
rm -rf "${pkgdir}/usr/share/"
}

View File

@ -1,4 +0,0 @@
#!/usr/bin/env bash
cd $1
makepkg -si --noconfirm

2
templates/maintainers.j2 Normal file
View File

@ -0,0 +1,2 @@
{% for maintainer in maintainers %}# Maintainer: {{ maintainer }}{% endfor %}
{% for contributor in contributors %}# Contributor: {{ contributor }}{% endfor %}