From d41c2fcdd9366fb3f1fcb11aceed919bfebbed61 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 6 Mar 2017 21:38:41 +0100 Subject: make: add support to "production" builds this is used by blogc-github-lambda and blogc-git-receiver. --- src/blogc-git-receiver/pre-receive.c | 2 +- src/blogc-github-lambda/lambda_function.py | 3 ++- src/blogc-make/ctx.c | 1 + src/blogc-make/ctx.h | 2 ++ src/blogc-make/exec.c | 9 +++++++-- src/blogc-make/exec.h | 2 +- src/blogc-make/main.c | 10 ++++++++-- 7 files changed, 22 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c index c2fe080..3b05e07 100644 --- a/src/blogc-git-receiver/pre-receive.c +++ b/src/blogc-git-receiver/pre-receive.c @@ -202,7 +202,7 @@ bgr_pre_receive_hook(int argc, char *argv[]) rv = 3; goto cleanup; } - build_cmd = bc_strdup_printf("OUTPUT_DIR=\"%s\" blogc-make -V all", + build_cmd = bc_strdup_printf("OUTPUT_DIR=\"%s\" blogc-make -p -V all", output_dir); } else if ((0 == access("Makefile", F_OK)) || (0 == access("GNUMakefile", F_OK))) { diff --git a/src/blogc-github-lambda/lambda_function.py b/src/blogc-github-lambda/lambda_function.py index f8a259d..fb8492f 100644 --- a/src/blogc-github-lambda/lambda_function.py +++ b/src/blogc-github-lambda/lambda_function.py @@ -165,7 +165,7 @@ def sns_handler(message): if os.path.isfile(blogcfile): # deploy using blogc-make - args = [os.path.join(cwd, 'blogc'), '-m', '-f', blogcfile, + args = [os.path.join(cwd, 'blogc'), '-m', '-p', '-f', blogcfile, 'all'] if debug: args.append('-V') @@ -186,6 +186,7 @@ def sns_handler(message): else: print "Commit not for master branch, skipping: %s" % payload['ref'] + def lambda_handler(event, context): for record in event['Records']: if 'Sns' in record: diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c index fc59457..753aadf 100644 --- a/src/blogc-make/ctx.c +++ b/src/blogc-make/ctx.c @@ -143,6 +143,7 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0, rv->blogc = bm_exec_find_binary(argv0, "blogc", "BLOGC"); rv->blogc_runserver = bm_exec_find_binary(argv0, "blogc-runserver", "BLOGC_RUNSERVER"); + rv->production = false; rv->verbose = false; } else { diff --git a/src/blogc-make/ctx.h b/src/blogc-make/ctx.h index 8d87163..e36fa4c 100644 --- a/src/blogc-make/ctx.h +++ b/src/blogc-make/ctx.h @@ -31,6 +31,8 @@ typedef struct { typedef struct { char *blogc; char *blogc_runserver; + + bool production; bool verbose; bm_settings_t *settings; diff --git a/src/blogc-make/exec.c b/src/blogc-make/exec.c index df028c2..db20cae 100644 --- a/src/blogc-make/exec.c +++ b/src/blogc-make/exec.c @@ -205,7 +205,7 @@ list_variables(const char *key, const char *value, bc_string_t *str) char* bm_exec_build_blogc_cmd(const char *blogc_bin, bm_settings_t *settings, bc_trie_t *variables, bool listing, const char *template, - const char *output, bool sources_stdin) + const char *output, bool production, bool sources_stdin) { bc_string_t *rv = bc_string_new(); @@ -228,6 +228,11 @@ bm_exec_build_blogc_cmd(const char *blogc_bin, bm_settings_t *settings, bc_trie_foreach(variables, (bc_trie_foreach_func_t) list_variables, rv); + if (production) { + bc_string_append(rv, + " -D MAKE_ENV_PRODUCTION=1 -D MAKE_ENV='production'"); + } + if (listing) { bc_string_append(rv, " -l"); } @@ -268,7 +273,7 @@ bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *variables, bool listing, } char *cmd = bm_exec_build_blogc_cmd(ctx->blogc, ctx->settings, variables, - listing, template->path, output->path, input->len > 0); + listing, template->path, output->path, ctx->production, input->len > 0); if (ctx->verbose) printf("%s\n", cmd); diff --git a/src/blogc-make/exec.h b/src/blogc-make/exec.h index 08cc608..fadaafe 100644 --- a/src/blogc-make/exec.h +++ b/src/blogc-make/exec.h @@ -20,7 +20,7 @@ int bm_exec_command(const char *cmd, const char *input, char **output, char **error, bc_error_t **err); char* bm_exec_build_blogc_cmd(const char *blogc_bin, bm_settings_t *settings, bc_trie_t *variables, bool listing, const char *template, - const char *output, bool sources_stdin); + const char *output, bool production, bool sources_stdin); int bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *variables, bool listing, bm_filectx_t *template, bm_filectx_t *output, bc_slist_t *sources, bool only_first_source); diff --git a/src/blogc-make/main.c b/src/blogc-make/main.c index 8e15981..eb7f504 100644 --- a/src/blogc-make/main.c +++ b/src/blogc-make/main.c @@ -36,7 +36,8 @@ print_help(void) " -h show this help message and exit\n" " -v show version and exit\n" " -V be verbose when executing commands\n" - " -f FILE read FILE as blogcfile\n"); + " -f FILE read FILE as blogcfile\n" + " -p build for production environment\n"); bm_rule_print_help(); } @@ -44,7 +45,7 @@ print_help(void) static void print_usage(void) { - printf("usage: blogc-make [-h] [-v] [-V] [-f FILE] [RULE ...]\n"); + printf("usage: blogc-make [-h] [-v] [-V] [-f FILE] [-p] [RULE ...]\n"); } @@ -62,6 +63,7 @@ main(int argc, char **argv) bc_slist_t *rules = NULL; bool verbose = false; + bool production = false; char *blogcfile = NULL; bm_ctx_t *ctx = NULL; @@ -83,6 +85,9 @@ main(int argc, char **argv) else if (i + 1 < argc) blogcfile = bc_strdup(argv[++i]); break; + case 'p': + production = true; + break; #ifdef MAKE_EMBEDDED case 'm': // no-op, for embedding into blogc binary. @@ -112,6 +117,7 @@ main(int argc, char **argv) rv = 3; goto cleanup; } + ctx->production = production; ctx->verbose = verbose; rv = bm_rule_executor(ctx, rules); -- cgit v1.2.3-18-g5258