From 3f82948f4f9fb9d3e1332f306e36c317c67f5575 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 2 Jun 2024 00:01:35 +0200 Subject: make: added setting to allow enforcing to run from make --- man/blogcfile.5.ronn | 8 +++++++- src/blogc-make/main.c | 8 ++++++++ src/blogc-make/settings.c | 1 + tests/blogc-make/check_blogc_make.sh.in | 25 +++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/man/blogcfile.5.ronn b/man/blogcfile.5.ronn index 7feb964..669086b 100644 --- a/man/blogcfile.5.ronn +++ b/man/blogcfile.5.ronn @@ -125,6 +125,12 @@ however these rules can be customized with the following settings, from the in the `[posts]` section, in descending order. This setting is compatible with `html_order` and `atom_order` settings, to control the order of the posts. + * `run_from_make` (default: `false`): + If true, enforces blogc-make(1) to check if it is running as a make(1) subprocess, + and exit with an error otherwise. This is useful when blogc-make(1) is called by + make(1) as part of a larger build infrastructure, and calling blogc-make(1) directly + could cause errors due to some generated dependencies missing. + * `source_ext` (default: `.txt`): The extension of the source files. @@ -209,4 +215,4 @@ Rafael G. Martins <> ## SEE ALSO -blogc(1), blogc-make(1), blogc-template(7) strftime(3) +blogc(1), blogc-make(1), make(1), blogc-template(7), strftime(3) diff --git a/src/blogc-make/main.c b/src/blogc-make/main.c index 7007c1a..5643a45 100644 --- a/src/blogc-make/main.c +++ b/src/blogc-make/main.c @@ -120,6 +120,14 @@ main(int argc, char **argv) ctx->dev = dev; ctx->verbose = verbose; + if (bc_str_to_bool(bm_ctx_settings_lookup_str(ctx, "run_from_make"))) { + if (getenv("MAKEFLAGS") == NULL) { + fprintf(stderr, "blogc-make: error: must run from `make`, try:\n\n $ make\n"); + rv = 1; + goto cleanup; + } + } + rv = bm_rule_executor(ctx, rules); cleanup: diff --git a/src/blogc-make/settings.c b/src/blogc-make/settings.c index 2b78177..20bf3f8 100644 --- a/src/blogc-make/settings.c +++ b/src/blogc-make/settings.c @@ -47,6 +47,7 @@ static const struct default_settings_map { // generic {"date_format", "%b %d, %Y, %I:%M %p GMT"}, {"locale", NULL}, + {"run_from_make", NULL}, {NULL, NULL}, }; diff --git a/tests/blogc-make/check_blogc_make.sh.in b/tests/blogc-make/check_blogc_make.sh.in index 179529a..50af17c 100755 --- a/tests/blogc-make/check_blogc_make.sh.in +++ b/tests/blogc-make/check_blogc_make.sh.in @@ -20,6 +20,31 @@ trap_func() { trap trap_func EXIT +mkdir -p "${TEMP}/proj/" + + +### minimal settings, failure when not running from make + +cat > "${TEMP}/proj/blogcfile" <&1 | tee "${TEMP}/output.txt" +set -e + +grep "error: must run from " "${TEMP}/output.txt" + +rm -rf "${TEMP}/proj/" + mkdir -p "${TEMP}"/proj{,/templates,/content/post} -- cgit v1.2.3-18-g5258