diff options
-rw-r--r-- | man/blogcfile.5.ronn | 8 | ||||
-rw-r--r-- | src/blogc-make/main.c | 8 | ||||
-rw-r--r-- | src/blogc-make/settings.c | 1 | ||||
-rwxr-xr-x | tests/blogc-make/check_blogc_make.sh.in | 25 |
4 files changed, 41 insertions, 1 deletions
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 <<rafael@rafaelmartins.eng.br>> ## 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" <<EOF +[global] +AUTHOR_NAME = Lol +AUTHOR_EMAIL = author@example.com +SITE_TITLE = Lol's Website +SITE_TAGLINE = WAT?! +BASE_DOMAIN = http://example.org + +[settings] +run_from_make = true +EOF + +set +e +${TESTS_ENVIRONMENT} ${BLOGC_MAKE} -f "${TEMP}/proj/blogcfile" 2>&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} |