Merge branch 'master' of git.marko10-000.de:flatpaks/tools into master

master
Marko Semet 2020-08-31 23:29:47 +02:00
commit 09d2eeff66
3 changed files with 99 additions and 3 deletions

View File

@ -5,10 +5,20 @@ if [ -z "$BUILD_DIR" ]; then
BUILD_DIR=build
fi
# Reset env
while read i
do
unset "$i"
done < <(printenv | cut -d '=' -f 1 | grep -vE '^(PWD|PATH|HOME|BUILD_DIR)$')
printenv &&
# Build
CONFIG_DIR="$(dirname "$0")" &&
(find '.flatpak-builder/build' '.flatpak-builder/cache' -delete || rm -rf ".flatpak-builder/build/*" ".flatpak-builder/build/.*" '.flatpak-builder/cache') &&
flatpak-builder $3 --arch "$2" --install-deps-from=winebarrels --install-deps-only "$BUILD_DIR" "$1" &&
if [ -z "$4" ]; then
exec flatpak-builder $3 --arch "$2" --rebuild-on-sdk-change "$BUILD_DIR" "$1"
BUILD_DIR= exec flatpak-builder $3 --arch "$2" --sandbox --rebuild-on-sdk-change "$BUILD_DIR" "$1"
else
HASH="$("$CONFIG_DIR/hash_modules.py" --installed "$1" "$2" | sed -n '1p')" &&
exec flatpak-builder $3 --arch "$2" --rebuild-on-sdk-change --gpg-sign=winebarrels@marko10-000.de --repo "$4" -s "WB_HASH='${HASH}'" "$BUILD_DIR" "$1"
HASH="$("$CONFIG_DIR/hash_modules.py" --installed "$1" "$2" | sed -n '1p')" || exit 0 &&
BUILD_DIR= exec flatpak-builder $3 --arch "$2" --sandbox --rebuild-on-sdk-change --repo "$4" -s "WB_HASH='${HASH}'" "$BUILD_DIR" "$1"
fi

21
run_versions.sh 100755
View File

@ -0,0 +1,21 @@
#! /usr/bin/env bash
# Args: <source> <version> <script> <args...>
VERSION_ARGS=()
if [ -z "$VERSIONS_OUT" ]
then
VERSIONS_OUT=".sources"
fi
VERSION_ARGS=("${VERSION_ARGS[@]}" "-f" "$VERSIONS_OUT")
if [ -n "$VERSIONS_NAMES" ]
then
VERSION_ARGS=("${VERSION_ARGS[@]}" "-n" "$VERSIONS_NAMES")
fi
mkdir -p ".sources" &&
while read i
do
"$3" "$i" "${@:4}" || exit "$?"
done < <("$(dirname "$0")/versions.py" -L "${VERSION_ARGS[@]}" "$1" "$2")

65
versions.py 100755
View File

@ -0,0 +1,65 @@
#! /usr/bin/env python3
if __name__ == "__main__":
import argparse
import os
import yaml
import sys
# Parse
parser = argparse.ArgumentParser(description="Generate build scripts for differend versions.")
parser.add_argument("source", metavar="source", type=str, nargs=1, help="The source build script to modify.")
parser.add_argument("versions", metavar="versions", type=str, nargs="+", help="The files they contain the version information.")
parser.add_argument("-f", "--files", dest="files", type=str, nargs="?", default=".", help="The target directory to save the generated scripts in. Default: \".\"")
parser.add_argument("-l", "--list", dest="list", action="store_const", const=True, default=False, help="Output all gerenated file names.")
parser.add_argument("-L", "--list-full", dest="list_full", action="store_const", const=True, default=False, help="Like --list with path from --files.")
parser.add_argument("-n", "--names", dest="names", type=str, nargs="?", default=None, help="Are csv file with first the name and second the version name.")
args = parser.parse_args()
# Load source file
fileData = open(args.source[0], "r").read()
tmpName = os.path.basename(args.source[0])
tmp = tmpName.rfind(".")
if tmp >= 0:
configStart = tmpName[:tmp]
configEnding = tmpName[tmp:]
else:
configStart = tmpName[0]
configEnding = ""
# Parse versions
versions = {}
for version_file in args.versions:
for iName, iValue in yaml.load(open(version_file, "r").read(), Loader=yaml.SafeLoader).items():
versions[iName] = iValue
# Gen mapping
mapping = {}
if args.names is None:
for iName in versions.keys():
mapping[iName] = iName
else:
for i in filter(bool, open(args.names, "r").read().splitlines()):
tmp = i.split(",")
assert len(tmp) == 2
mapping[tmp[0]] = tmp[1]
# Gen build scripts
for version_name, version in mapping.items():
# Gen config file
tmp = fileData.replace("{{VERSION}}", version)
tmp = tmp.replace("{{VERSION_NAME}}", version_name)
for attributeID, attribute in versions[version].items():
tmp = tmp.replace("{{" + attributeID + "}}", attribute)
# Save file
outFileName = "%s_%s%s" % (configStart, version_name, configEnding)
outFile = os.path.join(args.files, outFileName)
with open(outFile, "w") as f:
f.write(tmp)
# Log output
if args.list_full:
print(outFile)
else:
print(outFileName)