File: json-make.sh

package info (click to toggle)
libreswan 4.3-1%2Bdeb11u4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 62,688 kB
  • sloc: ansic: 108,293; sh: 25,973; xml: 11,756; python: 10,230; makefile: 1,580; javascript: 1,353; yacc: 825; sed: 647; perl: 584; lex: 159; awk: 156
file content (59 lines) | stat: -rwxr-xr-x 1,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh

if test $# -lt 1 ; then
    cat >> /dev/stderr <<EOF

Usage:

    $0 [ --json <json> ] --logdir <logdir> <make-target> ....

Update the <json> file with the list of make targets and corresponding
log files (found in <logdir>).  If <json> isn't specified write to
stdout.

EOF
    exit 1
fi

webdir=$(cd $(dirname $0) && pwd)

json=
resultsdir=
targets=
while test $# -gt 0; do
    case $1 in
	--json ) shift ; json=$1 ; shift ;;
	--resultsdir ) shift ; resultsdir=$1 ; shift ;;
	-* ) echo "Unrecognized option: $*" >/dev/stderr ; exit 1 ;;
	* ) targets="${targets}${sp}$1" ; sp=" " ; shift ;;
    esac
done

if test "${resultsdir}" = "" -o ! -d "${resultsdir}" ; then
    echo "no resultsdir: ${resultsdir}" >> /dev/stderr
    exit 1
fi

{
    for t in ${targets} ; do
	if test -r ${resultsdir}/${t}.log || test "${t}" = "${target}"; then
	    # json
	    logfile="\"${t}.log\""
	else
	    # json
	    logfile=null
	fi
	jq --null-input --arg target "${t}" --argjson logfile "${logfile}" \
	   '{ target: $target, logfile: $logfile, }'
    done
} | {
    # convert to an array
    jq -s .
} | {
    if test -n "${json}" ; then
	cat > ${json}.tmp
	mv ${json}.tmp ${json}
    else
	cat
    fi
}