Make build script better

master
Marko Semet 2020-07-07 18:04:12 +02:00
parent 6f4999cb54
commit 52f391815f
3 changed files with 74 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")" &&
flatpak-builder $3 --arch "$2" --install-deps-from=winebarrels --install-deps-only "$BUILD_DIR" "$1" &&
(find '.flatpak-builder/build' -delete || rm -rf ".flatpak-builder/build/*" ".flatpak-builder/build/.*") &&
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

13
run_versions.sh 100755
View File

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

48
versions.py 100755
View File

@ -0,0 +1,48 @@
#! /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.")
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
for version_file in args.versions:
versions = yaml.load(open(version_file, "r").read(), Loader=yaml.SafeLoader)
for version, attributes in versions.items():
# Gen config file
tmp = fileData.replace("{{VERSION}}", version)
for attributeID, attribute in attributes.items():
tmp = tmp.replace("{{" + attributeID + "}}", attribute)
# Save file
outFileName = "%s_%s%s" % (configStart, version, 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)