Skip to content

Commit cf04e03

Browse files
committed
build: speed up license extraction
Apparently licensecheck has a high startup cost, so merging invocations promises a neat speedup. However, currently some "\x{....} cannot be represented as ascii" error messages appear in our logs. If that happens licensecheck exits with 255, which omits all following files of the same invocation and also prompts `find -exec .. {} +` or `xargs` to not spwan any more invocations. If we were to simply merge invocations by one of those means it would result in an incomplete COPYRIGHT file. Those encoding errors appear to be due to an ASCII locale being set in the container, so override LC_ALL to an UTF-8 one. To further make this bit more resilient ensure licensecheck errors are no longer ignored by capturing and processing its exit code.
1 parent 0d8d68b commit cf04e03

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

.github/workflows/emscripten.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
- name: Build Binaries
6464
run: |
6565
mkdir -p /tmp/emcc_lto
66-
docker run --rm -v "${PWD}":/code -v "/tmp/emcc_lto:/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto" libass/jso:latest
66+
docker run --rm --env LC_ALL=C.UTF-8 -v "${PWD}":/code -v "/tmp/emcc_lto:/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto" libass/jso:latest
6767
6868
- name: Upload Nightly Build
6969
uses: actions/upload-artifact@v3

build/license_extract.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,16 @@ else
4141
fi
4242

4343

44-
find "$base_dir" $FINDOPTS -type f -regextype egrep -regex '.*\.(c|h|cpp|hpp|js)$' -exec \
45-
licensecheck --machine --copyright --deb-fmt '{}' \; \
46-
| awk -F"$tabulator" -v base_dir="$base_dir" \
44+
FIFO="$base_dir"/__LICENSE_EXTRACT_QUEUE.tmp
45+
mkfifo "$FIFO"
46+
# We want to be able to clean up the named pipe on error
47+
# and will check the exit codes ourselves
48+
set +e
49+
50+
find "$base_dir" $FINDOPTS -type f -regextype egrep -regex '.*\.(c|h|cpp|hpp|js)$' -print0 \
51+
| xargs -0 -P1 licensecheck --machine --copyright --deb-fmt --encoding UTF-8 > "$FIFO"\
52+
& scan_pid="$!"
53+
awk -F"$tabulator" -v base_dir="$base_dir" \
4754
-v def_license="$def_license" -v def_copy="$def_copy" '
4855
BEGIN {
4956
split("", lcfiles) # Clear array with only pre-Issue 8 POSIX
@@ -100,4 +107,10 @@ find "$base_dir" $FINDOPTS -type f -regextype egrep -regex '.*\.(c|h|cpp|hpp|js)
100107
printf "\n"
101108
}
102109
}
103-
'
110+
' \
111+
< "$FIFO"
112+
fret="$?"
113+
wait "$scan_pid"
114+
sret="$?"
115+
rm "$FIFO"
116+
exit "$((fret | sret))"

run-buildah-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ if [ "$FAST" -eq 0 ] ; then
1515
buildah rm "$CONTAINER" >/dev/null 2>&1 || :
1616
buildah from --name "$CONTAINER" "$IMAGE":latest
1717
fi
18-
buildah run -t -v "${PWD}":/code "$CONTAINER" $cmd "$@"
18+
buildah run -t --env LC_ALL=C.UTF-8 -v "${PWD}":/code "$CONTAINER" $cmd "$@"

run-docker-build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if [ "$FAST" -eq 0 ] ; then
88
docker build -t "$IMAGE" .
99
fi
1010
if [ "$#" -eq 0 ] ; then
11-
docker run --rm -v "${PWD}":/code --name "$CONTAINER" "$IMAGE":latest
11+
docker run --rm --env LC_ALL=C.UTF-8 -v "${PWD}":/code --name "$CONTAINER" "$IMAGE":latest
1212
else
13-
docker run --rm -v "${PWD}":/code --name "$CONTAINER" "$IMAGE":latest "$@"
13+
docker run --rm --env LC_ALL=C.UTF-8 -v "${PWD}":/code --name "$CONTAINER" "$IMAGE":latest "$@"
1414
fi

0 commit comments

Comments
 (0)