diff --git a/README.md b/README.md index d4b4674..82cb259 100644 --- a/README.md +++ b/README.md @@ -227,8 +227,9 @@ there). task basically just call `tasks.sh` with a different command flag. * `.vscode/tasks.sh` is a bash script with a big switch statement that implements all tasks exposed by `tasks.json`. They all share a common - preamble customizable - locally by local.sh. + preamble customizable locally by local.sh. Tasks can be overridden in + local.sh by defining a method called `task_()`. + Example: "start-wait-dbg" => `task_start_wait_dbg` * `.vscode/settings.jsonnet` [provides per-workspace configuration values to VSCode](https://code.visualstudio.com/docs/getstarted/settings) and its extensions. This is constructed by `tasks.sh` by evaluating diff --git a/local.sh b/local.sh index dda21bd..209bc19 100644 --- a/local.sh +++ b/local.sh @@ -12,6 +12,18 @@ ## Generate objects in a subdirectory # MAKE="$MAKE O=.vscode/build-$TARGET_ARCH/" +# +## Fully override any task by defining task_(). +## Hyphens in command names become underscores in function names. +## Example: override "defconfig" +# task_defconfig() { +# if [ ! -f "${WORKSPACE_DIR}/.config" ]; then +# eval ${MAKE} ARCH=${TARGET_ARCH} tinyconfig +# scripts/config --enable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT +# eval ${MAKE} ARCH=${TARGET_ARCH} olddefconfig +# fi +# } + ## Enable some random kernel CONFIG by default as part of the .config generation # if [ $COMMAND = "defconfig" ]; then # trap "scripts/config -e BPF_SYSCALL" EXIT diff --git a/tasks.sh b/tasks.sh index 0bd8afe..5304c2f 100755 --- a/tasks.sh +++ b/tasks.sh @@ -55,7 +55,8 @@ done # Default context variables, can be overridden by local.sh or in environment. : ${WORKSPACE_DIR:=`realpath -s "${SCRIPT_DIR}/.."`} -: ${MAKE:="make -j`nproc` LLVM=1 LLVM_IAS=1 CC='ccache clang'"} +: ${MAKE_VARS:="LLVM=1 LLVM_IAS=1 CC='ccache clang'"} +: ${MAKE:="make -j`nproc` ${MAKE_VARS}"} : ${TARGET_ARCH:="x86_64"} : ${TARGET_GDB:="gdb-multiarch"} : ${SILENT_BUILD_FLAG="-s"} @@ -129,6 +130,15 @@ fi -append \"console=${SERIAL_TTY},115200 root=${ROOT_MNT} rw nokaslr init=/lib/systemd/systemd debug systemd.log_level=info ${KERNEL_CMDLINE_EXTRA}\" \ -drive file=${IMAGE_PATH},format=raw -kernel ${KERNEL_PATH} ${VM_START_ARGS}"} +# Optional local task override hook: +# Define task_() in local.sh to fully handle a task. +# Example: "start-wait-dbg" => task_start_wait_dbg +TASK_OVERRIDE_FN="task_${COMMAND//-/_}" +if declare -F "${TASK_OVERRIDE_FN}" > /dev/null; then + "${TASK_OVERRIDE_FN}" "$@" + exit $? +fi + case "${COMMAND}" in # Virtual machine life-cycle "start")