Sygaldry
Loading...
Searching...
No Matches
sh/lili.sh Literate Programming Convenience Script

Copyright 2023 Travis J. West, https://traviswest.ca, Input Devices and Music Interaction Laboratory (IDMIL), Centre for Interdisciplinary Research in Music Media and Technology (CIRMMT), McGill University, Montréal, Canada, and Univ. Lille, Inria, CNRS, Centrale Lille, UMR 9189 CRIStAL, F-59000 Lille, France

SPDX-License-Identifier: MIT

Literate programming is employed throughout the project. The literate sources are considered authoritative, and are used to generate most other source files, including many CMakeLists.txt files.

The following shell script can regenerate all machine sources from the lili literate source files, and it (or something equivalent) should be run before every build. It is used by many other convenience scripts, and depends on the environment variable SYGALDRY_ROOT set by the shell hook in the nix shell build environment.

For each .lili.md file found in the repository with find, the script finds the first file generated by that literate source, and if the source is more recently modified than the generated file, reruns lili to regenerate all files derived from that literate source. GNU parallel is used to perform this subroutine for all literate sources. The command exits with a failure code in case any invocation of lili fails, which is used to short-circuit execution of other convenience scripts.

# @#'lili.sh'
#!/usr/bin/env sh
# generate machine sources from literate source code
# Copyright 2023 Travis J. West, https://traviswest.ca, Input Devices and Music Interaction Laboratory
# (IDMIL), Centre for Interdisciplinary Research in Music Media and Technology
# (CIRMMT), McGill University, Montréal, Canada, and Univ. Lille, Inria, CNRS,
# Centrale Lille, UMR 9189 CRIStAL, F-59000 Lille, France
# SPDX-License-Identifier: MIT
cd "$SYGALDRY_ROOT"
find -iname '*.lili.md' | parallel '
cd {//}
generated="$(grep -m 1 -h -r -I "@@#" {/} | head -n 1 | sed 's/^.*@#.//' | sed 's/.$//')"
[ "$generated" ] && [ {/} -nt "$generated" ] &&
{
echo {} "newer than $generated, running lili..."
lili {/} || exit 1 # short circuit on any lili error with failure return code
} || exit 0
' && generate_components_cmake.sh
# @/