aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-12-27 21:52:25 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-12-27 21:52:25 +0100
commit6974c7030339b0e07086d8a34548396313725346 (patch)
treed7142decb8f5557703bf3026deceef19a96b32e4
parent4755ad22cdfa2c7414cc66e068b884f90f2cc639 (diff)
downloadblogc-6974c7030339b0e07086d8a34548396313725346.tar.gz
blogc-6974c7030339b0e07086d8a34548396313725346.tar.bz2
blogc-6974c7030339b0e07086d8a34548396313725346.zip
make: implemented runserver rule
-rw-r--r--src/blogc-make/exec.c31
-rw-r--r--src/blogc-make/exec.h1
-rw-r--r--src/blogc-make/rules.c20
-rw-r--r--src/blogc-make/settings.c5
-rw-r--r--tests/blogc-make/check_settings.c5
5 files changed, 61 insertions, 1 deletions
diff --git a/src/blogc-make/exec.c b/src/blogc-make/exec.c
index 8b961e7..28dc73d 100644
--- a/src/blogc-make/exec.c
+++ b/src/blogc-make/exec.c
@@ -302,3 +302,34 @@ bm_exec_blogc(bm_settings_t *settings, bc_trie_t *variables, bool listing,
return rv;
}
+
+
+int
+bm_exec_blogc_runserver(bm_settings_t *settings, bool verbose)
+{
+ // use blogc binary from environment, if provided
+ const char *blogc_runserver = getenv("BLOGC_RUNSERVER");
+
+ char *cmd = bc_strdup_printf("%s -t %s -p %s -m %s %s",
+ blogc_runserver != NULL ? blogc_runserver : "blogc-runserver",
+ bc_trie_lookup(settings->settings, "runserver_host"),
+ bc_trie_lookup(settings->settings, "runserver_port"),
+ bc_trie_lookup(settings->settings, "runserver_threads"),
+ bc_trie_lookup(settings->settings, "output_dir"));
+
+ if (verbose)
+ printf("%s\n", cmd);
+ else
+ printf("\n");
+ fflush(stdout);
+
+ // we don't need pipes to run blogc-runserver, because it is "interactive"
+ int rv = system(cmd);
+ free(cmd);
+
+ if (rv != 0)
+ fprintf(stderr,
+ "error: Failed to execute command, returned status code: %d\n", rv);
+
+ return rv;
+}
diff --git a/src/blogc-make/exec.h b/src/blogc-make/exec.h
index 907109a..ecc7f2c 100644
--- a/src/blogc-make/exec.h
+++ b/src/blogc-make/exec.h
@@ -20,5 +20,6 @@ char* bm_exec_build_blogc_cmd(bm_settings_t *settings, bc_trie_t *variables,
int bm_exec_blogc(bm_settings_t *settings, bc_trie_t *variables, bool listing,
bm_filectx_t *template, bm_filectx_t *output, bc_slist_t *sources,
bool verbose, bool only_first_source);
+int bm_exec_blogc_runserver(bm_settings_t *settings, bool verbose);
#endif /* _MAKE_EXEC_H */
diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c
index a471b0b..de7d6cc 100644
--- a/src/blogc-make/rules.c
+++ b/src/blogc-make/rules.c
@@ -548,6 +548,19 @@ clean_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bool verbose)
static int all_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bool verbose);
+
+// RUNSERVER RULE
+static int
+runserver_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bool verbose)
+{
+ int rv = all_exec(ctx, NULL, verbose);
+ if (rv != 0)
+ return rv;
+
+ return bm_exec_blogc_runserver(ctx->settings, verbose);
+}
+
+
const bm_rule_t const rules[] = {
{
.name = "all",
@@ -619,6 +632,13 @@ const bm_rule_t const rules[] = {
.exec_func = clean_exec,
.generate_files = false,
},
+ {
+ .name = "runserver",
+ .help = "run blogc-runserver pointing to output directory, if available",
+ .outputlist_func = NULL,
+ .exec_func = runserver_exec,
+ .generate_files = false,
+ },
{NULL, NULL, NULL, NULL, false},
};
diff --git a/src/blogc-make/settings.c b/src/blogc-make/settings.c
index 3df410f..27b3d80 100644
--- a/src/blogc-make/settings.c
+++ b/src/blogc-make/settings.c
@@ -44,6 +44,11 @@ static const struct default_settings_map {
{"atom_prefix", "atom"},
{"atom_ext", ".xml"},
+ // runserver
+ {"runserver_host", "127.0.0.1"},
+ {"runserver_port", "8080"},
+ {"runserver_threads", "20"},
+
// generic
{"date_format", "%b %d, %Y, %I:%M %p GMT"},
{"locale", NULL},
diff --git a/tests/blogc-make/check_settings.c b/tests/blogc-make/check_settings.c
index 0078073..3b19f2f 100644
--- a/tests/blogc-make/check_settings.c
+++ b/tests/blogc-make/check_settings.c
@@ -106,7 +106,7 @@ test_settings2(void **state)
assert_string_equal(bc_trie_lookup(s->env, "SITE_TITLE"), "Fuuuuuuuuu");
assert_string_equal(bc_trie_lookup(s->env, "SITE_TAGLINE"), "My cool tagline");
assert_string_equal(bc_trie_lookup(s->env, "BASE_DOMAIN"), "http://example.com");
- assert_int_equal(bc_trie_size(s->settings), 14);
+ assert_int_equal(bc_trie_size(s->settings), 17);
assert_string_equal(bc_trie_lookup(s->settings, "source_ext"), ".txt");
assert_string_equal(bc_trie_lookup(s->settings, "html_ext"), "/index.html");
assert_string_equal(bc_trie_lookup(s->settings, "output_dir"), "bola");
@@ -122,6 +122,9 @@ test_settings2(void **state)
assert_string_equal(bc_trie_lookup(s->settings, "pagination_prefix"), "page");
assert_string_equal(bc_trie_lookup(s->settings, "post_prefix"), "post");
assert_string_equal(bc_trie_lookup(s->settings, "tag_prefix"), "tag");
+ assert_string_equal(bc_trie_lookup(s->settings, "runserver_host"), "127.0.0.1");
+ assert_string_equal(bc_trie_lookup(s->settings, "runserver_port"), "8080");
+ assert_string_equal(bc_trie_lookup(s->settings, "runserver_threads"), "20");
assert_non_null(s->posts);
assert_string_equal(s->posts[0], "aaaa");
assert_string_equal(s->posts[1], "bbbb");