aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2019-07-14 23:17:09 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2019-07-14 23:17:14 +0200
commitb161cdc7c975686fb0df5b6b67ab0340b563f300 (patch)
tree9083189a56d7163742ea4d5f5969d0983adf797c
parent1028fed081d16ec07a78d99e3853833484289956 (diff)
downloadblogc-b161cdc7c975686fb0df5b6b67ab0340b563f300.tar.gz
blogc-b161cdc7c975686fb0df5b6b67ab0340b563f300.tar.bz2
blogc-b161cdc7c975686fb0df5b6b67ab0340b563f300.zip
make: exec: support printing blogc variables
needs more tests
-rw-r--r--src/blogc-make/exec.c17
-rw-r--r--src/blogc-make/exec.h11
-rw-r--r--src/blogc-make/rules.c31
-rw-r--r--tests/blogc-make/check_exec.c92
4 files changed, 98 insertions, 53 deletions
diff --git a/src/blogc-make/exec.c b/src/blogc-make/exec.c
index a78d506..c36dc2d 100644
--- a/src/blogc-make/exec.c
+++ b/src/blogc-make/exec.c
@@ -218,9 +218,9 @@ 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 *global_variables, bc_trie_t *local_variables, bool listing,
- const char *listing_entry, const char *template, const char *output,
- bool dev, bool sources_stdin)
+ bc_trie_t *global_variables, bc_trie_t *local_variables, const char *print,
+ bool listing, const char *listing_entry, const char *template,
+ const char *output, bool dev, bool sources_stdin)
{
bc_string_t *rv = bc_string_new();
@@ -254,6 +254,10 @@ bm_exec_build_blogc_cmd(const char *blogc_bin, bm_settings_t *settings,
bc_string_append(rv, " -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
}
+ if (print != NULL) {
+ bc_string_append_printf(rv, " -p %s", print);
+ }
+
if (listing) {
bc_string_append(rv, " -l");
if (listing_entry != NULL) {
@@ -285,8 +289,9 @@ bm_exec_build_blogc_cmd(const char *blogc_bin, bm_settings_t *settings,
int
bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_variables,
- bool listing, bm_filectx_t *listing_entry, bm_filectx_t *template,
- bm_filectx_t *output, bc_slist_t *sources, bool only_first_source)
+ const char *print, bool listing, bm_filectx_t *listing_entry,
+ bm_filectx_t *template, bm_filectx_t *output, bc_slist_t *sources,
+ bool only_first_source)
{
if (ctx == NULL)
return 1;
@@ -299,7 +304,7 @@ bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_varia
}
char *cmd = bm_exec_build_blogc_cmd(ctx->blogc, ctx->settings, global_variables,
- local_variables, listing, listing_entry == NULL ? NULL : listing_entry->path,
+ local_variables, print, listing, listing_entry == NULL ? NULL : listing_entry->path,
template->path, output->path, ctx->dev, input->len > 0);
if (ctx->verbose)
diff --git a/src/blogc-make/exec.h b/src/blogc-make/exec.h
index e09e8ee..140ef62 100644
--- a/src/blogc-make/exec.h
+++ b/src/blogc-make/exec.h
@@ -19,12 +19,13 @@ char* bm_exec_find_binary(const char *argv0, const char *bin, const char *env);
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 *global_variables, bc_trie_t *local_variables, bool listing,
- const char *listing_entry, const char *template, const char *output, bool dev,
- bool sources_stdin);
+ bc_trie_t *global_variables, bc_trie_t *local_variables, const char *print,
+ bool listing, const char *listing_entry, const char *template,
+ const char *output, bool dev, bool sources_stdin);
int bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_variables,
- bool listing, bm_filectx_t *listing_entry, bm_filectx_t *template,
- bm_filectx_t *output, bc_slist_t *sources, bool only_first_source);
+ const char *print, bool listing, bm_filectx_t *listing_entry,
+ bm_filectx_t *template, bm_filectx_t *output, bc_slist_t *sources,
+ bool only_first_source);
int bm_exec_blogc_runserver(bm_ctx_t *ctx, const char *host, const char *port,
const char *threads);
diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c
index 96cf51d..422f3a4 100644
--- a/src/blogc-make/rules.c
+++ b/src/blogc-make/rules.c
@@ -117,8 +117,9 @@ index_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
ctx->listing_entry_fctx, ctx->main_template_fctx, fctx, false))
{
- rv = bm_exec_blogc(ctx, variables, NULL, true, ctx->listing_entry_fctx,
- ctx->main_template_fctx, fctx, ctx->posts_fctx, false);
+ rv = bm_exec_blogc(ctx, variables, NULL, NULL, true,
+ ctx->listing_entry_fctx, ctx->main_template_fctx, fctx,
+ ctx->posts_fctx, false);
if (rv != 0)
break;
}
@@ -176,8 +177,8 @@ atom_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx, NULL, NULL,
fctx, false))
{
- rv = bm_exec_blogc(ctx, variables, NULL, true, NULL, ctx->atom_template_fctx,
- fctx, ctx->posts_fctx, false);
+ rv = bm_exec_blogc(ctx, variables, NULL, NULL, true, NULL,
+ ctx->atom_template_fctx, fctx, ctx->posts_fctx, false);
if (rv != 0)
break;
}
@@ -242,8 +243,8 @@ atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx, NULL, NULL,
fctx, false))
{
- rv = bm_exec_blogc(ctx, variables, NULL, true, NULL, ctx->atom_template_fctx,
- fctx, ctx->posts_fctx, false);
+ rv = bm_exec_blogc(ctx, variables, NULL, NULL, true, NULL,
+ ctx->atom_template_fctx, fctx, ctx->posts_fctx, false);
if (rv != 0)
break;
}
@@ -318,8 +319,9 @@ pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
ctx->listing_entry_fctx, ctx->main_template_fctx, fctx, false))
{
- rv = bm_exec_blogc(ctx, variables, NULL, true, ctx->listing_entry_fctx,
- ctx->main_template_fctx, fctx, ctx->posts_fctx, false);
+ rv = bm_exec_blogc(ctx, variables, NULL, NULL, true,
+ ctx->listing_entry_fctx, ctx->main_template_fctx, fctx,
+ ctx->posts_fctx, false);
if (rv != 0)
break;
}
@@ -384,8 +386,8 @@ posts_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
{
bc_trie_t *local = bc_trie_new(NULL);
bc_trie_insert(local, "MAKE_SLUG", s_fctx->slug); // no need to copy
- rv = bm_exec_blogc(ctx, variables, local, false, NULL, ctx->main_template_fctx,
- o_fctx, s, true);
+ rv = bm_exec_blogc(ctx, variables, local, NULL, false, NULL,
+ ctx->main_template_fctx, o_fctx, s, true);
bc_trie_free(local);
if (rv != 0)
break;
@@ -452,8 +454,9 @@ tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
ctx->listing_entry_fctx, ctx->main_template_fctx, fctx, false))
{
- rv = bm_exec_blogc(ctx, variables, NULL, true, ctx->listing_entry_fctx,
- ctx->main_template_fctx, fctx, ctx->posts_fctx, false);
+ rv = bm_exec_blogc(ctx, variables, NULL, NULL, true,
+ ctx->listing_entry_fctx, ctx->main_template_fctx, fctx,
+ ctx->posts_fctx, false);
if (rv != 0)
break;
}
@@ -515,8 +518,8 @@ pages_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
{
bc_trie_t *local = bc_trie_new(NULL);
bc_trie_insert(local, "MAKE_SLUG", s_fctx->slug); // no need to copy
- rv = bm_exec_blogc(ctx, variables, local, false, NULL, ctx->main_template_fctx,
- o_fctx, s, true);
+ rv = bm_exec_blogc(ctx, variables, local, NULL, false, NULL,
+ ctx->main_template_fctx, o_fctx, s, true);
bc_trie_free(local);
if (rv != 0)
break;
diff --git a/tests/blogc-make/check_exec.c b/tests/blogc-make/check_exec.c
index 8193ad7..6812496 100644
--- a/tests/blogc-make/check_exec.c
+++ b/tests/blogc-make/check_exec.c
@@ -87,28 +87,28 @@ test_build_blogc_cmd_with_settings(void **state)
bc_trie_insert(local, "ASD", bc_strdup("QWE"));
settings->tags = NULL;
- char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, true,
- NULL, "main.tmpl", "foo.html", false, true);
+ char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL,
+ true, NULL, "main.tmpl", "foo.html", false, true);
assert_string_equal(rv,
"LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ' -D LOL='HEHE' "
"-D ASD='QWE' -l -t 'main.tmpl' -o 'foo.html' -i");
free(rv);
- rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, true,
+ rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL, true,
"foo.txt", "main.tmpl", "foo.html", false, true);
assert_string_equal(rv,
"LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ' -D LOL='HEHE' "
"-D ASD='QWE' -l -e 'foo.txt' -t 'main.tmpl' -o 'foo.html' -i");
free(rv);
- rv = bm_exec_build_blogc_cmd("blogc", settings, variables, NULL, false, NULL,
- NULL, NULL, false, false);
+ rv = bm_exec_build_blogc_cmd("blogc", settings, variables, NULL, NULL, false,
+ NULL, NULL, NULL, false, false);
assert_string_equal(rv,
"LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ' -D LOL='HEHE'");
free(rv);
- rv = bm_exec_build_blogc_cmd("blogc", settings, NULL, NULL, false, NULL, NULL,
- NULL, false, false);
+ rv = bm_exec_build_blogc_cmd("blogc", settings, NULL, NULL, NULL, false,
+ NULL, NULL, NULL, false, false);
assert_string_equal(rv,
"LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ'");
free(rv);
@@ -136,15 +136,15 @@ test_build_blogc_cmd_with_settings_and_dev(void **state)
bc_trie_insert(local, "ASD", bc_strdup("QWE"));
settings->tags = NULL;
- char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, true,
- NULL, "main.tmpl", "foo.html", true, true);
+ char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL,
+ true, NULL, "main.tmpl", "foo.html", true, true);
assert_string_equal(rv,
"LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ' -D LOL='HEHE' "
"-D ASD='QWE' -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev' -l -t 'main.tmpl' "
"-o 'foo.html' -i");
free(rv);
- rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, true,
+ rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL, true,
"foo.txt", "main.tmpl", "foo.html", true, true);
assert_string_equal(rv,
"LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ' -D LOL='HEHE' "
@@ -152,15 +152,15 @@ test_build_blogc_cmd_with_settings_and_dev(void **state)
"-t 'main.tmpl' -o 'foo.html' -i");
free(rv);
- rv = bm_exec_build_blogc_cmd("blogc", settings, variables, NULL, false, NULL,
- NULL, NULL, true, false);
+ rv = bm_exec_build_blogc_cmd("blogc", settings, variables, NULL, NULL, false,
+ NULL, NULL, NULL, true, false);
assert_string_equal(rv,
"LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ' -D LOL='HEHE' "
"-D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
free(rv);
- rv = bm_exec_build_blogc_cmd("blogc", settings, NULL, NULL, false, NULL, NULL,
- NULL, true, false);
+ rv = bm_exec_build_blogc_cmd("blogc", settings, NULL, NULL, NULL, false,
+ NULL, NULL, NULL, true, false);
assert_string_equal(rv,
"LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ' "
"-D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
@@ -189,15 +189,15 @@ test_build_blogc_cmd_with_settings_and_tags(void **state)
bc_trie_insert(local, "ASD", bc_strdup("QWE"));
settings->tags = bc_str_split("asd foo bar", ' ', 0);
- char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, true,
- NULL, "main.tmpl", "foo.html", true, true);
+ char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL,
+ true, NULL, "main.tmpl", "foo.html", true, true);
assert_string_equal(rv,
"LC_ALL='en_US.utf8' blogc -D MAKE_TAGS='asd foo bar' -D FOO='BAR' "
"-D BAR='BAZ' -D LOL='HEHE' -D ASD='QWE' -D MAKE_ENV_DEV=1 "
"-D MAKE_ENV='dev' -l -t 'main.tmpl' -o 'foo.html' -i");
free(rv);
- rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, true,
+ rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL, true,
"foo.txt", "main.tmpl", "foo.html", true, true);
assert_string_equal(rv,
"LC_ALL='en_US.utf8' blogc -D MAKE_TAGS='asd foo bar' -D FOO='BAR' "
@@ -205,15 +205,15 @@ test_build_blogc_cmd_with_settings_and_tags(void **state)
"-D MAKE_ENV='dev' -l -e 'foo.txt' -t 'main.tmpl' -o 'foo.html' -i");
free(rv);
- rv = bm_exec_build_blogc_cmd("blogc", settings, variables, NULL, false, NULL,
- NULL, NULL, true, false);
+ rv = bm_exec_build_blogc_cmd("blogc", settings, variables, NULL, NULL, false,
+ NULL, NULL, NULL, true, false);
assert_string_equal(rv,
"LC_ALL='en_US.utf8' blogc -D MAKE_TAGS='asd foo bar' -D FOO='BAR' "
"-D BAR='BAZ' -D LOL='HEHE' -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
free(rv);
- rv = bm_exec_build_blogc_cmd("blogc", settings, NULL, NULL, false, NULL, NULL,
- NULL, true, false);
+ rv = bm_exec_build_blogc_cmd("blogc", settings, NULL, NULL, NULL, false,
+ NULL, NULL, NULL, true, false);
assert_string_equal(rv,
"LC_ALL='en_US.utf8' blogc -D MAKE_TAGS='asd foo bar' -D FOO='BAR' "
"-D BAR='BAZ' -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
@@ -236,27 +236,27 @@ test_build_blogc_cmd_without_settings(void **state)
bc_trie_t *local = bc_trie_new(free);
bc_trie_insert(local, "ASD", bc_strdup("QWE"));
- char *rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, local, true,
- NULL, "main.tmpl", "foo.html", false, true);
+ char *rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, local, NULL,
+ true, NULL, "main.tmpl", "foo.html", false, true);
assert_string_equal(rv,
"blogc -D LOL='HEHE' -D ASD='QWE' -l -t 'main.tmpl' -o 'foo.html' -i");
free(rv);
- rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, local, true,
+ rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, local, NULL, true,
"foo.txt", "main.tmpl", "foo.html", false, true);
assert_string_equal(rv,
"blogc -D LOL='HEHE' -D ASD='QWE' -l -e 'foo.txt' -t 'main.tmpl' "
"-o 'foo.html' -i");
free(rv);
- rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, NULL, false, NULL,
- NULL, NULL, false, false);
+ rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, NULL, NULL, false,
+ NULL, NULL, NULL, false, false);
assert_string_equal(rv,
"blogc -D LOL='HEHE'");
free(rv);
- rv = bm_exec_build_blogc_cmd("blogc", NULL, NULL, NULL, false, NULL, NULL,
- NULL, false, false);
+ rv = bm_exec_build_blogc_cmd("blogc", NULL, NULL, NULL, NULL, false, NULL,
+ NULL, NULL, false, false);
assert_string_equal(rv,
"blogc");
free(rv);
@@ -266,6 +266,41 @@ test_build_blogc_cmd_without_settings(void **state)
}
+static void
+test_build_blogc_cmd_print(void **state)
+{
+ bc_trie_t *variables = bc_trie_new(free);
+ bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
+ bc_trie_t *local = bc_trie_new(free);
+ bc_trie_insert(local, "ASD", bc_strdup("QWE"));
+
+ char *rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, local, "LOL",
+ false, NULL, NULL, NULL, false, true);
+ assert_string_equal(rv, "blogc -D LOL='HEHE' -D ASD='QWE' -p LOL -i");
+ free(rv);
+
+ rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, local, "LOL", true,
+ NULL, NULL, NULL, false, false);
+ assert_string_equal(rv, "blogc -D LOL='HEHE' -D ASD='QWE' -p LOL -l");
+ free(rv);
+
+ rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, NULL, "LOL", false,
+ NULL, NULL, NULL, false, true);
+ assert_string_equal(rv,
+ "blogc -D LOL='HEHE' -p LOL -i");
+ free(rv);
+
+ rv = bm_exec_build_blogc_cmd("blogc", NULL, NULL, NULL, "LOL", false, NULL,
+ NULL, NULL, false, false);
+ assert_string_equal(rv,
+ "blogc -p LOL");
+ free(rv);
+
+ bc_trie_free(local);
+ bc_trie_free(variables);
+}
+
+
int
main(void)
{
@@ -277,6 +312,7 @@ main(void)
unit_test(test_build_blogc_cmd_with_settings_and_dev),
unit_test(test_build_blogc_cmd_with_settings_and_tags),
unit_test(test_build_blogc_cmd_without_settings),
+ unit_test(test_build_blogc_cmd_print),
};
return run_tests(tests);
}