aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2017-01-04 20:49:27 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2017-01-04 20:49:27 +0100
commitce37047336fb2eb190b1cce15dd93dcc6146adc2 (patch)
tree87793e51a4200d77a9b089eb7ffa615ba322e4b2
parent77d89f64161e001c91fd7ca60e298a69d35e2050 (diff)
downloadblogc-ce37047336fb2eb190b1cce15dd93dcc6146adc2.tar.gz
blogc-ce37047336fb2eb190b1cce15dd93dcc6146adc2.tar.bz2
blogc-ce37047336fb2eb190b1cce15dd93dcc6146adc2.zip
git-receiver: support blogc-make
-rw-r--r--src/blogc-git-receiver/pre-receive.c69
-rwxr-xr-xtests/blogc-git-receiver/check_pre_receive.sh.in32
2 files changed, 71 insertions, 30 deletions
diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c
index c780055..15db99a 100644
--- a/src/blogc-git-receiver/pre-receive.c
+++ b/src/blogc-git-receiver/pre-receive.c
@@ -40,8 +40,6 @@ rmdir_recursive(const char *dir)
return;
struct stat buf;
if (0 != stat(dir, &buf)) {
- fprintf(stderr, "warning: failed to remove directory (%s): %s\n", dir,
- strerror(errno));
return;
}
if (!S_ISDIR(buf.st_mode)) {
@@ -178,11 +176,6 @@ bgr_pre_receive_hook(int argc, char *argv[])
goto cleanup;
}
- if ((0 != access("Makefile", F_OK)) && (0 != access("GNUMakefile", F_OK))) {
- fprintf(stderr, "warning: no makefile found. skipping ...\n");
- goto cleanup;
- }
-
char *home = getenv("HOME");
if (home == NULL) {
fprintf(stderr, "error: failed to find user home path\n");
@@ -190,21 +183,6 @@ bgr_pre_receive_hook(int argc, char *argv[])
goto cleanup;
}
- const char *make_impl = NULL;
-
- if (127 != WEXITSTATUS(system("gmake -f /dev/null 2> /dev/null > /dev/null"))) {
- make_impl = "gmake";
- }
- else if (127 != WEXITSTATUS(system("make -f /dev/null 2> /dev/null > /dev/null"))) {
- make_impl = "make";
- }
-
- if (make_impl == NULL) {
- fprintf(stderr, "error: no 'make' implementation found\n");
- rv = 3;
- goto cleanup;
- }
-
unsigned long epoch = time(NULL);
output_dir = bc_strdup_printf("%s/builds/%s-%lu", home, master, epoch);
@@ -214,19 +192,52 @@ bgr_pre_receive_hook(int argc, char *argv[])
free(tmp);
}
- char *gmake_cmd = bc_strdup_printf(
- "%s -j%d OUTPUT_DIR=\"%s\" BLOGC_GIT_RECEIVER=1", make_impl,
- cpu_count(), output_dir);
- fprintf(stdout, "running command: %s\n\n", gmake_cmd);
+ // detect if we will run blogc-make, make or nothing, and generate the
+ // command.
+ char *build_cmd = NULL;
+ if (0 == access("blogcfile", F_OK)) {
+ if (127 == WEXITSTATUS(system("blogc-make -v 2> /dev/null > /dev/null"))) {
+ fprintf(stderr, "error: failed to find blogc-make binary\n");
+ rv = 3;
+ goto cleanup;
+ }
+ build_cmd = bc_strdup_printf("OUTPUT_DIR=\"%s\" blogc-make -V all",
+ output_dir);
+ }
+ else if ((0 == access("Makefile", F_OK)) || (0 == access("GNUMakefile", F_OK))) {
+ const char *make_impl = NULL;
+
+ if (127 != WEXITSTATUS(system("gmake -f /dev/null 2> /dev/null > /dev/null"))) {
+ make_impl = "gmake";
+ }
+ else if (127 != WEXITSTATUS(system("make -f /dev/null 2> /dev/null > /dev/null"))) {
+ make_impl = "make";
+ }
+
+ if (make_impl == NULL) {
+ fprintf(stderr, "error: no 'make' implementation found\n");
+ rv = 3;
+ goto cleanup;
+ }
+ build_cmd = bc_strdup_printf(
+ "%s -j%d OUTPUT_DIR=\"%s\" BLOGC_GIT_RECEIVER=1", make_impl,
+ cpu_count(), output_dir);
+ }
+ else {
+ fprintf(stderr, "warning: no blogcfile or Makefile found. skipping ...\n");
+ goto cleanup;
+ }
+
+ fprintf(stdout, "running command: %s\n\n", build_cmd);
fflush(stdout);
- if (0 != system(gmake_cmd)) {
+ if (0 != system(build_cmd)) {
fprintf(stderr, "error: failed to build website ...\n");
rmdir_recursive(output_dir);
- free(gmake_cmd);
+ free(build_cmd);
rv = 3;
goto cleanup;
}
- free(gmake_cmd);
+ free(build_cmd);
if (0 != chdir(repo_dir)) {
fprintf(stderr, "error: failed to chdir (%s): %s\n", repo_dir,
diff --git a/tests/blogc-git-receiver/check_pre_receive.sh.in b/tests/blogc-git-receiver/check_pre_receive.sh.in
index ba3d78c..eff8691 100755
--- a/tests/blogc-git-receiver/check_pre_receive.sh.in
+++ b/tests/blogc-git-receiver/check_pre_receive.sh.in
@@ -59,7 +59,7 @@ cat > "${TEMP}/payload.txt" <<EOF
EOF
SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt"
-grep "warning: no makefile found. skipping ..." "${TEMP}/output.txt" &> /dev/null
+grep "warning: no blogcfile or Makefile found. skipping ..." "${TEMP}/output.txt" &> /dev/null
cd "${TEMP}"
git init --bare "${TEMP}/repos/foo2.git" &> /dev/null
@@ -171,4 +171,34 @@ HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./repos/foo3.git/hooks/pre-receive 2>&1 | te
[[ "${DEST}" != "$(readlink repos/foo3.git/htdocs)" ]]
[[ ! -e "${DEST}" ]]
+cd "${TEMP}"
+git init --bare "${TEMP}/repos/foo4.git" &> /dev/null
+ln -s "${SELF}" "${TEMP}/repos/foo4.git/hooks/pre-receive"
+
+cat > "${TEMP}/tmp.txt" <<EOF
+blob
+mark :1
+data 0
+
+reset refs/heads/master
+commit refs/heads/master
+mark :2
+author Rafael G. Martins <rafael@rafaelmartins.eng.br> 1483558736 +0100
+committer Rafael G. Martins <rafael@rafaelmartins.eng.br> 1483558736 +0100
+data 12
+testing3...
+M 100644 :1 blogcfile
+
+EOF
+
+cd "${TEMP}/repos/foo4.git"
+git fast-import < "${TEMP}/tmp.txt" &> /dev/null
+
+cat > "${TEMP}/payload.txt" <<EOF
+0000000000000000000000000000000000000000 $(git rev-parse HEAD) refs/heads/master
+EOF
+
+SHELL="${SELF}" HOME="${TEMP}" PATH="@abs_top_builddir@:${PATH}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt" || true
+grep "blogc-make: error: settings: " "${TEMP}/output.txt" &> /dev/null
+
rm "${TEMP}/output.txt"