1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2026-03-02 04:09:18 +00:00

Merge commit 'b19a54d2f9d8a3e83366c638aace4cf3b5daa96e' as 'build/dobuild'

This commit is contained in:
nosamad
2020-05-25 23:24:23 +02:00
95 changed files with 7843 additions and 0 deletions

95
build/dobuild/bin/container_run Executable file
View File

@@ -0,0 +1,95 @@
#!/bin/sh
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file is part of dobuild.
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
#
# SPDX-License-Identifier: MPL-2.0
set -e
enabled() {
{ [ "$1" -ne 0 ] || [ "$1" = 'true' ]; } 2>/dev/null
}
physical_pwd() {
pwd -P 2>/dev/null || pwd
}
try_canonicalize() {
readlink -f "$@" 2>/dev/null || realpath "$@"
}
canonicalize() {
if ! try_canonicalize "$1" 2>/dev/null; then
echo "$(cd "$(dirname "$1")" && physical_pwd)/$(basename "$1")"
fi
}
scriptdir() {
dirname "$(canonicalize "${BASH_SOURCE:-$1}")"
}
DOBUILDDIR="${DOBUILDDIR:-"$(dirname "$(scriptdir "$0")")"}"
PATH="$DOBUILDDIR/bin:$PATH"
DOCKER="${DOCKER:-docker}"
USERID="${DOBUILD_USERID:-$(id -u)}"
HOSTENVFILTER="^DOCKER_\|_proxy=\|^SOURCE_DATE_EPOCH=${DOBUILD_HOSTENVFILTER:+\|$DOBUILD_HOSTENVFILTER}"
ENVFLAGS="$(printenv | grep -e "$HOSTENVFILTER" | sed -n -e 's/\([^=]*\)=.*/-e \1/p')" || true
#shellcheck disable=SC2086
set -- $ENVFLAGS "$@"
set -- --user "$USERID:$USERID" "$@"
if [ -n "$DOBUILD_CGROUPPARENT" ]; then
set -- --cgroup-parent "$DOBUILD_CGROUPPARENT" "$@"
fi
HOST_TZ="${DOBUILD_HOSTTZ:-1}"
if enabled "$HOST_TZ"; then
set -- -v "/etc/timezone:/etc/timezone:ro" "$@"
set -- -v "/etc/localtime:/etc/localtime:ro" "$@"
fi
HOST_CONTAINER="${DOBUILD_HOSTCONTAINER:-"$(get_container_id.sh)"}" || true
if [ -n "$HOST_CONTAINER" ]; then
set -- --volumes-from "$HOST_CONTAINER" "$@"
elif [ -n "$DOBUILD_PROJECTDIR" ]; then
PROJECTDIR="$(canonicalize "$DOBUILD_PROJECTDIR")"
set -- --volume "$PROJECTDIR:$PROJECTDIR:cached" "$@"
fi
# setup options for connection to docker host
DOCKERSOCK="$(echo "$DOCKER_HOST" | sed -ne 's/^unix:\/\/\(.*\)/\1/p')"
if [ -S "$DOCKERSOCK" ]; then
DOCKERSOCK_GROUP="$(stat -c '%g' "$DOCKERSOCK")"
set -- -e DOCKERSOCK_GROUP="$DOCKERSOCK_GROUP" --group-add "$DOCKERSOCK_GROUP" --volume "$DOCKERSOCK:$DOCKERSOCK" "$@"
elif [ -n "$DOCKER_HOST" ]; then
# select the network to reach the daemon
if [ -n "$HOST_CONTAINER" ] && [ -z "${DOBUILD_NETWORK+x}" ]; then
set -- --network "$("$DOCKER" inspect --format='{{.HostConfig.NetworkMode}}' "$HOST_CONTAINER")" "$@"
else
DOBUILD_NETWORK="${DOBUILD_NETWORK:-host}"
set -- --network "$DOBUILD_NETWORK" "$@"
fi
fi
if [ -t 0 ] && ! is_running_in_bg.sh $$; then
set -- --interactive "$@"
fi
# if STDIN piped or redirected
if [ -p /dev/stdin ] || { [ ! -t 0 ] && [ ! -p /dev/stdin ]; }; then
set -- --interactive "$@"
elif [ -t 1 ]; then
set -- --tty "$@"
fi
set -- "$DOCKER" run --rm "$@"
exec "$@"

240
build/dobuild/bin/dobuild Executable file
View File

@@ -0,0 +1,240 @@
#!/bin/sh
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file is part of dobuild.
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
#
# SPDX-License-Identifier: MPL-2.0
set -e
physical_pwd() {
pwd -P 2>/dev/null || pwd
}
try_canonicalize() {
readlink -f "$@" 2>/dev/null || realpath "$@"
}
canonicalize() {
if ! try_canonicalize "$1" 2>/dev/null; then
echo "$(cd "$(dirname "$1")" && physical_pwd)/$(basename "$1")"
fi
}
scriptdir() {
dirname "$(canonicalize "${BASH_SOURCE:-$1}")"
}
template_subst() {
sed \
-e "s!%MARCH%!${MARCH}!g" \
-e "s!%DISTRIB%!${DISTRIB}!g" \
-e "s!%REGISTRY_PREFIX%!${REGISTRY_PREFIX}!g"
}
mktemp_dockerfile() {
mkdir -p "$1"
echo "$1/dobuild_generated.dockerfile"
}
findonly_file() {
workingdir="$1"
name="$2"
filter="$3"
find "$workingdir" -maxdepth 1 -type f -name "$name" \
| grep "^${workingdir}/${filter}" \
| {
firstfound=
lastfound=
while IFS= read -r line; do
firstfound="${firstfound:-$line}"
lastfound="$line"
done
if [ "$firstfound" != "$lastfound" ]; then
printf 'error: more than one match found for %s in %s using filter %s\n' "$name" "$workingdir" "$filter" 1>&2
return 3
fi
echo "$firstfound"
}
}
export LANG=C
export LC_ALL=C
DOBUILDDIR="${DOBUILDDIR:-"$(dirname "$(scriptdir "$0")")"}"
MAKE="${MAKE:-$(command -v make)}"
PATH="$DOBUILDDIR/bin:$PATH"
set -- "$@" --
FILTER="$DOBUILD_FILTER"
WORKINGDIR=
MAKEFILE=
DISTRIB=
MARCH=
IMAGE=
while :; do
case $1 in
-f|--file|--makefile)
if [ "$2" != '--' ]; then
MAKEFILE="${MAKEFILE:-$2}"
set -- "$@" "$1" "$2"
shift
else
printf 'error: "%s" requires a non-empty option argument.\n' "$1" >&2
exit 3
fi
;;
--file=|--makefile=)
printf 'error: "%s" requires a non-empty option argument.\n' "$1" >&2
exit 3
;;
--file=?*|--makefile=?*)
MAKEFILE="${MAKEFILE:-${1#*=}}"
set -- "$@" "$1"
;;
-C|--directory)
if [ "$2" != '--' ]; then
WORKINGDIR="$2"
shift
else
printf 'error: "%s" requires a non-empty option argument.\n' "$1" >&2
exit 3
fi
;;
--directory=)
printf 'error: "%s" requires a non-empty option argument.\n' "$1" >&2
exit 3
;;
--directory=?*)
WORKINGDIR="${1#*=}"
;;
--dockerfile)
if [ "$2" != '--' ]; then
DOCKERFILE="$2"
shift
else
printf 'warning: "%s" ignored, requires a non-empty option argument.\n' "$1" >&2
fi
;;
--dockerfile=)
printf 'warning: "%s" ignored, requires a non-empty option argument.\n' "$1" >&2
;;
--dockerfile=?*|DOCKERFILE=?*)
DOCKERFILE="${1#*=}"
;;
--image)
if [ "$2" != '--' ]; then
IMAGE="$2"
shift
else
printf 'error: "%s" requires a non-empty option argument.\n' "$1" >&2
exit 3
fi
;;
--image=)
printf 'error: "%s" requires a non-empty option argument.\n' "$1" >&2
exit 3
;;
--image=?*|IMAGE=?*)
IMAGE="${1#*=}"
;;
--filter)
if [ "$2" != '--' ]; then
FILTER="$2"
set -- "$@" "FILTER=$FILTER"
shift
else
printf 'warning: "%s" ignored, requires a non-empty option argument.\n' "$1" >&2
fi
;;
--filter=)
printf 'warning: "%s" ignored, requires a non-empty option argument.\n' "$1" >&2
;;
--filter=?*|FILTER=?*)
FILTER="${1#*=}"
set -- "$@" "FILTER=$FILTER"
;;
MARCH=?*)
MARCH="${1#*=}"
;;
DISTRIB=?*)
DISTRIB="${1#*=}"
;;
PROJECTDIR=?*)
PROJECTDIR="${1#*=}"
;;
--)
shift
break
;;
*)
set -- "$@" "$1"
;;
esac
shift
done
if [ -n "$WORKINGDIR" ]; then
cd "$WORKINGDIR"
fi
PROJECTDIR="${DOBUILD_PROJECTDIR:-.}"
OUTDIR="${DOBUILD_OUTDIR:-$PROJECTDIR/.build}"
DISTRIB_SUFFIX="${DISTRIB:+-${DISTRIB}}"
MARCH_DISTRIB="${MARCH:-[^-]*}${DISTRIB_SUFFIX}"
FILTER="${FILTER:-${MARCH_DISTRIB:+${MARCH_DISTRIB}-}[^.]*}"
BUILD_DOCKERFILE="${DOCKERFILE:-$(findonly_file "$PROJECTDIR" '*.dockerfile' "$FILTER")}"
BUILD_DOCKERFILE="${BUILD_DOCKERFILE:-$(find "$PROJECTDIR" -maxdepth 1 -type f -name 'Dockerfile')}" || true
if [ -z "$MAKEFILE" ]; then
if [ -f "$PROJECTDIR/CMakeLists.txt" ]; then
set -- --file="$DOBUILDDIR/examples/cmake-gtest-example/Makefile" "$@"
elif [ -f "$PROJECTDIR/Makefile" ] || [ -f "$PROJECTDIR/makefile" ] || [ -f "$PROJECTDIR/GNUmakefile" ]; then
printf 'error: makefile project support not implemented.\n' >&2
exit 3
else
printf 'error: unknown project kind.\n' >&2
exit 3
fi
fi
set -- "$@" "PROJECTDIR=$PROJECTDIR" "DOBUILDDIR=$DOBUILDDIR" "OUTDIR=$OUTDIR"
if [ -n "$IMAGE" ]; then
BUILD_DOCKERFILE="$(mktemp_dockerfile "$OUTDIR")"
{ \
echo "FROM %REGISTRY_PREFIX%${IMAGE}"; \
echo; \
} | template_subst > "$BUILD_DOCKERFILE"
fi
if [ -n "$BUILD_DOCKERFILE" ]; then
if [ "$BUILD_DOCKERFILE" = '-' ]; then
BUILD_DOCKERFILE="$(mktemp_dockerfile "$OUTDIR")"
template_subst > "$BUILD_DOCKERFILE"
fi
set -- "$@" "DOCKERFILE=$BUILD_DOCKERFILE"
fi
if [ -n "$MARCH" ]; then
set -- "$@" "MARCH=$MARCH"
fi
if [ -n "$DISTRIB" ]; then
set -- "$@" "DISTRIB=$DISTRIB"
fi
exec "$MAKE" "$@"

View File

@@ -0,0 +1,85 @@
#!/bin/sh
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file is part of dobuild.
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
#
# SPDX-License-Identifier: MPL-2.0
set -e
physical_pwd() {
pwd -P 2>/dev/null || pwd
}
try_canonicalize() {
readlink -f "$@" 2>/dev/null || realpath "$@"
}
canonicalize() {
if ! try_canonicalize "$1" 2>/dev/null; then
echo "$(cd "$(dirname "$1")" && physical_pwd)/$(basename "$1")"
fi
}
scriptdir() {
dirname "$(canonicalize "${BASH_SOURCE:-$1}")"
}
DOBUILDDIR="${DOBUILDDIR:-"$(dirname "$(scriptdir "$0")")"}"
PATH="$DOBUILDDIR/bin:$PATH"
DOBUILD_COMPOSEVERSION="${DOBUILD_COMPOSEVERSION:-1.24.0}"
DOBUILD_COMPOSEIMAGE="${REGISTRY_PREFIX}docker/compose:${DOBUILD_COMPOSEVERSION}"
DOBUILD_COMPOSEENTRYPOINT="${DOBUILD_COMPOSEENTRYPOINT:-docker-compose}"
export DOBUILDDIR
export DOBUILD_PROJECTDIR="${DOBUILD_COMPOSEPROJECTDIR:-"$PWD"}"
export DOBUILD_HOSTENVFILTER="${DOBUILD_COMPOSEHOSTENVFILTER:-^COMPOSE}"
set -- "$@" --
WORKINGDIR=
while :; do
case $1 in
--project-directory)
if [ "$2" != '--' ]; then
WORKINGDIR="$2"
shift
else
printf 'error: "%s" requires a non-empty option argument.\n' "$1" >&2
exit 3
fi
;;
--project-directory=)
printf 'error: "%s" requires a non-empty option argument.\n' "$1" >&2
exit 3
;;
--project-directory=?*)
WORKINGDIR="${1#*=}"
;;
--)
shift
break
;;
*)
set -- "$@" "$1"
;;
esac
shift
done
WORKINGDIR="${WORKINGDIR:-"$DOBUILD_PROJECTDIR"}"
if [ -z "${DOCKER_HOST+x}" ]; then
export DOCKER_HOST='unix:///var/run/docker.sock'
fi
set -- container_run --workdir "$(canonicalize "$WORKINGDIR")" --entrypoint "$DOBUILD_COMPOSEENTRYPOINT" "$DOBUILD_COMPOSEIMAGE" "$@"
exec "$@"

View File

@@ -0,0 +1,39 @@
#!/bin/sh
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file is part of dobuild.
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
#
# SPDX-License-Identifier: MPL-2.0
set -e
container_id() {
if [ "$#" -le 0 ]; then
container_id_by_cgroup < /proc/self/cgroup
else
container_id_by_object "$@"
fi
}
container_id_by_object() {
"$DOCKER" inspect --format='{{.Id}}' "$@"
}
container_id_by_cgroup() {
while IFS= read -r cmd; do
id="$(echo "$cmd" | sed -n -e 's/[^:]*:[^:]*:.*\/\([0-9a-fA-F]\+\)$/\1/p')"
if container_id_by_object "$id" >/dev/null 2>&1; then
echo "$id"
return 0
fi
done
return 3
}
DOCKER="${DOCKER:-docker}"
container_id "$@"

View File

@@ -0,0 +1,40 @@
#!/bin/sh
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file is part of dobuild.
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
#
# SPDX-License-Identifier: MPL-2.0
exec 0<&-
set -e
export LANG=C
export LC_ALL=C
TOPDIR="$1"
[ -z "$TOPDIR" ] || cd "$TOPDIR"
try_git() {
[ -d .git ] || return 1
git show -s --format=format:%ct HEAD
}
try_svn() {
[ -d .svn ] || return 1
LAST_CHANGED_DATE="$(svn info | sed -n -e 's/^Last Changed Date: //p')"
[ -n "$LAST_CHANGED_DATE" ] || return 2
SOURCE_DATE_EPOCH="$(date -d "$LAST_CHANGED_DATE" +%s)"
}
try_mtime() {
stat -c '%Y' "$PWD"
}
SOURCE_DATE_EPOCH="$(try_git || try_svn || try_mtime)"
echo "$SOURCE_DATE_EPOCH"

50
build/dobuild/bin/groovy3 Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/sh
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file is part of dobuild.
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
#
# SPDX-License-Identifier: MPL-2.0
set -e
physical_pwd() {
pwd -P 2>/dev/null || pwd
}
try_canonicalize() {
readlink -f "$@" 2>/dev/null || realpath "$@"
}
canonicalize() {
if ! try_canonicalize "$1" 2>/dev/null; then
echo "$(cd "$(dirname "$1")" && physical_pwd)/$(basename "$1")"
fi
}
scriptdir() {
dirname "$(canonicalize "${BASH_SOURCE:-$1}")"
}
DOBUILDDIR="${DOBUILDDIR:-"$(dirname "$(scriptdir "$0")")"}"
PATH="$DOBUILDDIR/bin:$PATH"
DOBUILD_GROOVYVERSION="${DOBUILD_GROOVYVERSION:-3.0-jre13}"
DOBUILD_GROOVYIMAGE="${REGISTRY_PREFIX}groovy:${DOBUILD_GROOVYVERSION}"
DOBUILD_GROOVYENTRYPOINT="${DOBUILD_GROOVYENTRYPOINT:-groovy}"
export DOBUILDDIR
export DOBUILD_PROJECTDIR="${DOBUILD_GROOVYPROJECTDIR:-"$PWD"}"
set -- --entrypoint "$DOBUILD_GROOVYENTRYPOINT" "$DOBUILD_GROOVYIMAGE" "$@"
if [ -n "$DOBUILD_GRAPESCACHE" ]; then
set -- -v "${DOBUILD_GRAPESCACHE}:/home/groovy/.groovy/grapes:delegated" "$@"
fi
set -- container_run --workdir "$(canonicalize "$DOBUILD_PROJECTDIR")" "$@"
exec "$@"

View File

@@ -0,0 +1,21 @@
#!/bin/sh
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file is part of dobuild.
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
#
# SPDX-License-Identifier: MPL-2.0
set -e
running_in_background() {
pid="$1"
{ "$PS" -o stat= -p "$pid" 2>/dev/null || echo '+'; } | grep -vq -e '+$'
}
PS="${PS:-ps}"
running_in_background "${@:-$$}"

View File

@@ -0,0 +1,67 @@
#!/bin/sh
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file is part of dobuild.
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
#
# SPDX-License-Identifier: MPL-2.0
set -e
# Derived based on https://stackoverflow.com/questions/4219255/how-do-you-get-the-list-of-targets-in-a-makefile
#
# Note: This relies on -p printing the database nonetheless, which is the case as of GNU make 3.82.
# Sadly, GNU make offers no direct option to just print the database.
#
# Invokes make in order to print the database derived from a makefile:
# -p prints the database
# -Rr suppresses inclusion of built-in rules and variables
# -q only tests the up-to-date-status of a target (without remaking anything), but that by itself doesn't
# prevent execution of recipe commands in all cases
# "$@" list of separate commandline parameters (additional make parameters)
# : is a deliberately invalid target that is meant to ensure that no commands are executed;
# 2>&1 1>&3
# redirect stderr to stdout and stdout to fd 3 to allow filtering unwanted error message
# grep -v '.*\s\+No rule to make target\s\+.*:.*' 1>&2
# suppresses the resulting error message - "make: *** No rule to make target ':'. Stop." and redirect
# other output to stderr
# 3>&1 redirect fd 3 back to stdout
print_make_db() {
{ "$MAKE" -pRrq "$@" : 2>&1 1>&3 | grep -v '.*\s\+No rule to make target\s\+.*:.*' 1>&2; } 3>&1
}
export LANG=C
export LC_ALL=C
MAKE="${MAKE:-make}"
print_make_db "$@" \
| awk -v RS= -F: '/^# File/,/^# Finished Make database/ {if ($1 !~ "^[#.]") {print $1}}' \
| sort \
| grep -v -e '^[^[:alnum:]]' -e '[%]$'
# Pipe-chain explanation:
# awk -v RS= -F: '/^# File/,/^# Finished Make database/ {if ($1 !~ "^[#.]") {print $1}}'
# v RS= this is an awk idiom that breaks the input into blocks of contiguous non-empty lines.
# -F: input field speparator
# /^# File/,/^# Finished Make database/
# matches the range of lines in the output that contains all targets (true as of GNU make 3.82) - by limiting
# parsing to this range, there is no need to deal with false positives from other output sections.
# if ($$1 !~ "^[#.]")
# selectively ignores blocks:
# # ... ignores non-targets, whose blocks start with # Not a target:
# . ... ignores special targets
# all other blocks should each start with a line containing only the name of an explicitly defined target
# followed by :
# sort
# sorts the resulting list of targets, which is the best option, since not sorting doesn't produce a helpful
# ordering in that the order in which the targets appear in the makefile is not preserved.
# grep -v -e '^[^[:alnum:]]' -e '[%]$$' removes unwanted targets from the output:
# -v revert machtes
# -e '^[^[:alnum:]]'
# ... hidden targets, which - by convention - are targets that start neither with a letter nor a digit.
# -e '[%]$$'
# ... targets ending with % (pattern targets)

View File

@@ -0,0 +1,147 @@
#!/bin/sh -e
# <host-arch>+<target-arch><sub>-<vendor>-<sys>-<abi>+<id>
#
# arch = x86_64, i386, arm, thumb, mips, etc.
# sub = for ex. on ARM: v5, v6m, v7a, v7m, etc.
# vendor = pc, apple, nvidia, ibm etc.
# sys = none, linux, win32, darwin, cuda, etc.
# abi = eabi, gnu, android, macho, elf, etc.
sh_escape() {
sed \
-e "s/\\([;\\*&\\|\\'\\\"\\\$\\(\\)]\\)/\\\\\\1/g" \
-e "s/\\([^$ESCCHAR]\\)$ESCCHAR\\(\\s\\)/\\1$ESCCHAR\\\\\\2/g" \
-e "s/$ESCCHAR/\\\\$ESCCHAR/"
}
split() {
delimiter="$1"
shift
printf -- '%s\n' "$@" | sed -e "s/\\([^$ESCCHAR]\\)$delimiter/\\1\\n/g"
}
unescape() {
printf -- '%s\n' "$@" | sed -e "s/[$ESCCHAR]\\(.\\)\\?/\\1/g"
}
join() {
paste -s -d"$1" -
}
tail() {
skip 1 "$@"
}
skip() {
toskip="$1"
shift
if [ "$toskip" -gt "$#" ]; then
toskip="$#"
fi
while [ "$toskip" -gt '0' ]
do
shift
toskip="$((toskip - 1))"
done
printf -- '%s\n' "$@"
}
host_march() {
uname -m
}
if [ "$#" -eq 0 ]; then
{
printf 'Usage:\n%s <target-name>\n\n' "$0"
printf 'Format of target-name:\n'
printf '[<host-arch>+][<target-triple>+]<id>\n'
printf 'or\n'
printf '[<host-arch>] [<target-triple>] <id>\n\n'
printf 'Format of target-triple:\n'
printf '<target-arch><sub>[-<vendor>][-<sys>][-<abi>]\n'
printf 'or\n'
printf '<target-arch><sub>[-<distrib>[@distrib-version]][-<sys>][-<abi>]\n\n'
printf 'Special characters: %s,+,-,@\n' "$ESCCHAR"
printf 'Escape character: %s\n\n' "$ESCCHAR"
printf 'Examples:\n'
printf '%s myapp\n' "$0"
printf '%s x86_64+myapp\n' "$0"
printf '%s x86_64 myapp\n' "$0"
printf '%s x86_64-alpine@3.9-linux-gnueabihf+myapp\n' "$0"
printf '%s x86_64-alpine@3.9-linux-gnueabihf myapp\n' "$0"
printf '%s x86_64+arm32v7-alpine@3.9-linux-gnueabihf+myapp\n' "$0"
printf '%s x86_64 arm32v7-alpine@3.9-linux-gnueabihf myapp\n' "$0"
printf '%s x86_64+arm32v7-alpine@3.9-linux-gnueabihf+myapp+id\n' "$0"
printf '%s x86_64 arm32v7-alpine@3.9-linux-gnueabihf myapp id\n\n' "$0"
} >&2
return 1
fi
ESCCHAR='~'
TARGET="$(echo "$@" | join '+')"
# TODO: remove ugly hack
# necessary while posix shell can not handle arrays except the argument array
# maybe re-implement using a more suitable language!
#shellcheck disable=SC2046
eval set -- $(split '+' "$@" | sh_escape)
if [ "$#" -gt 2 ]; then
HOST_ARCH="$1"
shift
fi
if [ "$#" -eq 1 ]; then
set -- "$(host_march)" "$@"
fi
ID_VARIANT="$(tail "$@" | join '+')"
TARGET_TRIPLE="$1"
#shellcheck disable=SC2046
eval set -- $(split '@' "$ID_VARIANT" | sh_escape)
ID="$1"
if [ -z "$ID" ]; then
printf 'error: failed to parse "%s" aka "%s", unsupported target name\n' "$*" "$TARGET" >&2
return 2
fi
VARIANT="$(tail "$@" | join '@')"
VARIANT="${VARIANT:-release}"
#shellcheck disable=SC2046
eval set -- $(split '-' "$TARGET_TRIPLE" | sh_escape)
TARGET_ARCH_SUB="$1"
HOST_ARCH="${HOST_ARCH:-$TARGET_ARCH_SUB}"
VENDOR="${2:-unknown}"
TARGET_SYS="${3:-linux}"
TARGET_ABI="$(skip 3 "$@" | join '-')"
TARGET_ABI="${TARGET_ABI:-gnu}"
#shellcheck disable=SC2046
eval set -- $(split '@' "$VENDOR" | sh_escape)
VENDOR_OR_DISTRIB_ID="$1"
DISTRIB_VERSION="$(tail "$@" | join '@')"
DISTRIB_VERSION="${DISTRIB_VERSION:-latest}"
set -- \
"$HOST_ARCH" \
"$TARGET_ARCH_SUB" \
"$VENDOR_OR_DISTRIB_ID" \
"$TARGET_SYS" \
"$TARGET_ABI" \
"$ID" \
"$DISTRIB_VERSION" \
"$VARIANT"
unescape "$@" | cat

44
build/dobuild/bin/shellcheck Executable file
View File

@@ -0,0 +1,44 @@
#!/bin/sh
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file is part of dobuild.
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
#
# SPDX-License-Identifier: MPL-2.0
set -e
physical_pwd() {
pwd -P 2>/dev/null || pwd
}
try_canonicalize() {
readlink -f "$@" 2>/dev/null || realpath "$@"
}
canonicalize() {
if ! try_canonicalize "$1" 2>/dev/null; then
echo "$(cd "$(dirname "$1")" && physical_pwd)/$(basename "$1")"
fi
}
scriptdir() {
dirname "$(canonicalize "${BASH_SOURCE:-$1}")"
}
DOBUILDDIR="${DOBUILDDIR:-"$(dirname "$(scriptdir "$0")")"}"
PATH="$DOBUILDDIR/bin:$PATH"
DOBUILD_SHELLCHECKVERSION="${DOBUILD_SHELLCHECKVERSION:-v0.6.0}"
DOBUILD_SHELLCHECKIMAGE="${REGISTRY_PREFIX}koalaman/shellcheck:${DOBUILD_SHELLCHECKVERSION}"
export DOBUILDDIR
export DOBUILD_PROJECTDIR="${DOBUILD_SHELLCHECKPROJECTDIR:-"$PWD"}"
export DOBUILD_HOSTENVFILTER="${DOBUILD_SHELLCHECKHOSTENVFILTER:-^SHELLCHECK_}"
set -- container_run --workdir "$(canonicalize "$DOBUILD_PROJECTDIR")" "$DOBUILD_SHELLCHECKIMAGE" "$@"
exec "$@"

290
build/dobuild/bin/tar_cc_settings Executable file
View File

@@ -0,0 +1,290 @@
#!/bin/sh
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file is part of dobuild.
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
#
# SPDX-License-Identifier: MPL-2.0
set -e
# FIXME: don't depend on cmake internals
discover_cmake_includes() {
if [ $# -gt 0 ]; then
sed -n -e 's/.*_INCLUDE_DIRS:INTERNAL=\(.*\)$/\1/p' "$@";
fi
}
discover_system_includes() {
case "$BUILDSYSTEM" in
cmake-?*)
discover_cmake_includes "$@"
;;
*)
;;
esac
}
# FIXME: handle different compilers and language standards
discover_cc_includes() {
{
echo | "$CXX" -xc++ -E -Wp,-v - 2>&1
echo | "$CC" -xc -E -Wp,-v - 2>&1
} \
| sed -n -e 's/\s\+\(\/.*$\).*/\1/p'
}
discover_includes() {
{
discover_cc_includes;
discover_system_includes "$@"
} \
| sed 's/;/\n/g' | sed '/^$/d' | sort -u 2>/dev/null \
| while IFS= read -r file; do
if [ -e "$file" ]; then
canonicalize "$file"
fi
done
}
detect_toolchain() {
case "$BUILDSYSTEM" in
cmake-?*)
cmake -LA -N "$(dirname "$1")" > "$CACHED_VALUES_TMPFILE"
CXX="$(sed -n -e 's/CMAKE_CXX_COMPILER:FILEPATH=\(.*\)$/\1/p' -e 's/CMAKE_CXX_COMPILER:STRING=\(.*\)$/\1/p' "$CACHED_VALUES_TMPFILE")"
CC="$(sed -n -e 's/CMAKE_C_COMPILER:FILEPATH=\(.*\)$/\1/p' -e 's/CMAKE_C_COMPILER:STRING=\(.*\)$/\1/p' "$CACHED_VALUES_TMPFILE")"
;;
*)
;;
esac
}
parse_make_targets() {
parse_make_targets.sh -C "$WORKINGDIR"
}
parse_ninja_targets() {
"$NINJA" -C "$WORKINGDIR" -t targets all | sed -n -e 's/\([^:]*\):.*/\1/p' | sort 2>/dev/null
}
discover_targets() {
case "$BUILDSYSTEM" in
cmake-make|make)
parse_make_targets
;;
cmake-ninja|ninja)
parse_ninja_targets
;;
*)
;;
esac
}
prefix_dir() {
while IFS= read -r dir; do
printf '%s%s\n' "$1" "$dir"
done
}
sed_keyword() {
printf '%s\n' "$@" | sed -e 's/[]\/$*.^[]/\\&/g'
}
sed_replacement() {
printf '%s\n' "$@" | sed -e 's/[\/&]/\\&/g'
}
format_json() {
i=0
printf '[\n'
while IFS= read -r line; do
if [ "$i" -gt 0 ]; then
printf ',\n'
fi
printf '"%s"' "$line"
i="$((i+1))"
done
printf '\n]\n'
}
physical_pwd() {
pwd -P 2>/dev/null || pwd
}
try_canonicalize() {
readlink -f "$@" 2>/dev/null || realpath "$@"
}
canonicalize() {
if ! try_canonicalize "$1" 2>/dev/null; then
echo "$(cd "$(dirname "$1")" && physical_pwd)/$(basename "$1")"
fi
}
scriptdir() {
dirname "$(canonicalize "${BASH_SOURCE:-$1}")"
}
cleanup() {
EXITCODE="${EXITCODE:-$?}"
rm -f "$INCLUDE_DIRS_TMPFILE" "$CACHED_VALUES_TMPFILE"
return "$EXITCODE"
}
trap cleanup TERM INT EXIT
export LANG=C
export LC_ALL=C
DOBUILDDIR="${DOBUILDDIR:-"$(dirname "$(scriptdir "$0")")"}"
NINJA="${NINJA:-ninja}"
PATH="$DOBUILDDIR/bin:$PATH"
set -- "$@" --
CXX=
CC=
BUILDSYSTEM=
WORKINGDIR="$PWD"
PROJECTDIR=
INCLUDE_PREFIX="$WORKINGDIR"
COMPILE_COMMANDS_JSON_FILE=
while :; do
case $1 in
-C|--directory)
if [ "$2" != '--' ]; then
WORKINGDIR="$2"
shift
else
printf 'error: "%s" requires a non-empty option argument.\n' "$1" >&2
exit 3
fi
;;
--directory=)
printf 'error: "%s" requires a non-empty option argument.\n' "$1" >&2
exit 3
;;
--directory=?*)
WORKINGDIR="${1#*=}"
;;
--project-root)
if [ "$2" != '--' ]; then
PROJECTDIR="$2"
shift
else
PROJECTDIR=
fi
;;
--project-root=)
PROJECTDIR=
;;
--project-root=?*)
PROJECTDIR="${1#*=}"
;;
--build-system)
if [ "$2" != '--' ]; then
BUILDSYSTEM="$2"
shift
else
BUILDSYSTEM=
fi
;;
--build-system=)
BUILDSYSTEM=
;;
--build-system=?*)
BUILDSYSTEM="${1#*=}"
;;
-p|--include-prefix)
if [ "$2" != '--' ]; then
INCLUDE_PREFIX="$2"
shift
else
INCLUDE_PREFIX=
fi
;;
--include-prefix=)
INCLUDE_PREFIX=
;;
--include-prefix=?*)
INCLUDE_PREFIX="${1#*=}"
;;
compile_commands.json|?*/compile_commands.json)
COMPILE_COMMANDS_JSON_FILE="$1"
;;
--help)
{
printf 'Usage: %s [option...] [file...]\n' "$(basename "$0")"
printf 'Options:\n'
printf '\t-C|--directory\t\tWorking directory\n'
printf '\t--build-system\t\tBuildsystem kind e.g. cmake-make,cmake-ninja\n'
printf '\t--project-root\t\tProject root directory\n'
printf '\t-p|--include-prefix\tInclude prefix appended to all discovered include dirs\n'
printf 'Files:\n'
printf '\tBuildsystem specific configurations files e.g. CMakeCache.txt\n'
} >&2
exit 0
;;
--)
shift
break
;;
*)
set -- "$@" "$1"
;;
esac
shift
done
OUTDIR="$WORKINGDIR/DoBuildFiles"
mkdir -p "$OUTDIR"
INCLUDE_PREFIX_REPLACEMENT="%OUTDIR%/$INCLUDE_PREFIX"
CACHED_VALUES_TMPFILE="$(mktemp -p "$OUTDIR" cached_values_XXXXXXXXXX.txt)"
INCLUDE_DIRS_TMPFILE="$(mktemp -p "$OUTDIR" include_dirs_XXXXXXXXXX.txt)"
INCLUDE_DIRS_TMPL_FILE="$OUTDIR/include_dirs.json.template"
TARGETS_JSON_FILE="$OUTDIR/targets.json"
TARGETS_TXT_FILE="$OUTDIR/targets.txt"
COMPILE_COMMANDS_TMPL_FILE="$OUTDIR/compile_commands.json.template"
C_BUILTIN_FILE="$OUTDIR/builtins.h"
CXX_BUILTIN_FILE="$OUTDIR/builtins.hpp"
detect_toolchain "$@"
discover_targets "$@" | tee "$TARGETS_TXT_FILE" | format_json > "$TARGETS_JSON_FILE"
discover_includes "$@" | tee "$INCLUDE_DIRS_TMPFILE" | prefix_dir "$INCLUDE_PREFIX_REPLACEMENT" | format_json > "$INCLUDE_DIRS_TMPL_FILE"
# FIXME: handle different compilers and language standards
"$CC" -xc -dM -E - < /dev/null > "$C_BUILTIN_FILE"
"$CXX" -xc++ -dM -E - < /dev/null > "$CXX_BUILTIN_FILE"
if [ -n "$COMPILE_COMMANDS_JSON_FILE" ]; then
set --
while IFS= read -r line; do
set -- "$@" -e "s/$(sed_keyword "${line}")/$(sed_replacement "${INCLUDE_PREFIX_REPLACEMENT}${line}")/g"
done < "$INCLUDE_DIRS_TMPFILE"
set -- "$@" -e "s/$(sed_keyword "$WORKINGDIR")/$(sed_replacement "%OUTDIR%")/g"
if [ -n "$PROJECTDIR" ]; then
set -- "$@" -e "s/$(sed_keyword "$PROJECTDIR")/$(sed_replacement "%PROJECTDIR%")/g"
fi
set -- "$@" "$COMPILE_COMMANDS_JSON_FILE"
sed "$@" > "$COMPILE_COMMANDS_TMPL_FILE"
fi
set --
if [ -n "$INCLUDE_PREFIX" ]; then
while IFS= read -r file; do
set -- "$@" "$file"
done < "$INCLUDE_DIRS_TMPFILE"
fi
cleanup
exec tar cf - -C / "$@"