Merge pull request #1106 from AladW/depends-reqby-dict
[aurutils.git] / lib / aur-sync--ninja
blob599c4ac5e16a393ee97b73769b6f54dd43daa311
1 #!/bin/bash
2 [[ -v AUR_DEBUG ]] && set -o xtrace
3 PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
5 # parent of PKGBUILD directories (relative or absolute)
6 srcdir=.
7 if [[ -d $1 ]]; then
8 srcdir=$1
9 # https://github.com/ninja-build/ninja/blob/master/misc/ninja_syntax.py
10 srcdir=${srcdir//\$ /\$\$} srcdir=${srcdir// /\$ } srcdir=${srcdir//:/\$:}
12 shift
14 # use quoted expansion (@Q) - heredocs are expanded like double-quoted strings
15 # shellcheck disable=SC2154
16 cat <<EOF
17 rule aurbuild
18 command = env -C \${directory} ${@@Q} && date --rfc-3339=ns > \${out}
19 pool = console
20 EOF
22 # input is assumed to be ordered by pkgbase (e.g. aur-depends --graph)
23 current_package=
24 while read -r pkgbase depends_pkgbase _; do
25 if [[ $pkgbase != "$current_package" ]] && [[ $current_package ]]; then
26 printf '\n%-4sdirectory = %s\n' ' ' "$srcdir/$current_package"
28 if [[ $pkgbase != "$current_package" ]] || [[ ! $current_package ]]; then
29 # TODO: take input file (monitored for changes by ninja) as argument
30 printf 'build %s.stamp: aurbuild %s/PKGBUILD | ' "$pkgbase" "$srcdir/$pkgbase"
32 current_package=$pkgbase
34 # don't add dependency to self
35 if [[ $pkgbase != "$depends_pkgbase" ]]; then
36 printf '%s.stamp ' "$depends_pkgbase"
38 done
39 printf '\n%-4sdirectory = %s\n' ' ' "$srcdir/$current_package"
41 # vim: set et sw=4 sts=4 ft=sh: