aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2024-08-15 15:27:45 -0400
committerGitHub <noreply@github.com>2024-08-15 15:27:45 -0400
commitc069d0da7645eb1e596a53178960149224af8d48 (patch)
tree4f69e4ec146bbbae85f64207fac795b03060cd59
parentcc5fa8b386200cce03ef8a081acccc92dc44ddfb (diff)
downloadstasis-c069d0da7645eb1e596a53178960149224af8d48.tar.gz
Add template convience functions (and bug fixes) (#29)
* Die when render variable is NULL * This was caught when a call to {{ func:xyz() }} lacked opening/closing parenthesis * Scripts in tests should only render template strings right before execution * Remove conda version pin * This avoids updating conda in the base environment * This also avoids pitfalls associated with newly released (always broken) versions of conda * Add two template convenience functions * get_junitxml_result_auto() * get_basetemp_result_auto() * Handle rendering error for test script * Rename functions * get_junitxml_result_auto -> junitxml_file * get_basetemp_result_auto -> basetemp_dir * Thank you, @zacharyburnett
-rw-r--r--include/template_func_proto.h2
-rw-r--r--src/delivery.c5
-rw-r--r--src/ini.c5
-rw-r--r--src/stasis_main.c2
-rw-r--r--src/template_func_proto.c44
-rw-r--r--stasis.ini1
6 files changed, 57 insertions, 2 deletions
diff --git a/include/template_func_proto.h b/include/template_func_proto.h
index 212759c..7778a11 100644
--- a/include/template_func_proto.h
+++ b/include/template_func_proto.h
@@ -5,5 +5,7 @@
int get_github_release_notes_tplfunc_entrypoint(void *frame, void *data_out);
int get_github_release_notes_auto_tplfunc_entrypoint(void *frame, void *data_out);
+int get_junitxml_file_entrypoint(void *frame, void *data_out);
+int get_basetemp_dir_entrypoint(void *frame, void *data_out);
#endif //TEMPLATE_FUNC_PROTO_H \ No newline at end of file
diff --git a/src/delivery.c b/src/delivery.c
index 4a92b92..16b1f74 100644
--- a/src/delivery.c
+++ b/src/delivery.c
@@ -560,7 +560,7 @@ static int populate_delivery_ini(struct Delivery *ctx, int render_mode) {
test->version = ini_getval_str(ini, section_name, "version", render_mode, &err);
test->repository = ini_getval_str(ini, section_name, "repository", render_mode, &err);
- test->script = ini_getval_str(ini, section_name, "script", render_mode, &err);
+ test->script = ini_getval_str(ini, section_name, "script", INI_READ_RAW, &err);
test->repository_remove_tags = ini_getval_strlist(ini, section_name, "repository_remove_tags", LINE_SEP, render_mode, &err);
test->build_recipe = ini_getval_str(ini, section_name, "build_recipe", render_mode, &err);
test->runtime.environ = ini_getval_strlist(ini, section_name, "runtime", LINE_SEP, render_mode, &err);
@@ -1771,6 +1771,9 @@ void delivery_tests_run(struct Delivery *ctx) {
cmd[strlen(cmd_rendered) ? strlen(cmd_rendered) - 1 : 0] = 0;
}
guard_free(cmd_rendered);
+ } else {
+ SYSERROR("An error occurred while rendering the following:\n%s", cmd);
+ exit(1);
}
FILE *runner_fp;
diff --git a/src/ini.c b/src/ini.c
index 42891ef..e98b409 100644
--- a/src/ini.c
+++ b/src/ini.c
@@ -451,6 +451,11 @@ int ini_write(struct INIFILE *ini, FILE **stream, unsigned mode) {
render = parts[p];
}
+ if (!render) {
+ SYSERROR("%s", "rendered string value can never be NULL!\n");
+ return -1;
+ }
+
if (*hint == INIVAL_TYPE_STR_ARRAY) {
int leading_space = isspace(*render);
if (leading_space) {
diff --git a/src/stasis_main.c b/src/stasis_main.c
index 4c47672..dca9be8 100644
--- a/src/stasis_main.c
+++ b/src/stasis_main.c
@@ -328,6 +328,8 @@ int main(int argc, char *argv[]) {
// Prototypes can be found in template_func_proto.h
tpl_register_func("get_github_release_notes", &get_github_release_notes_tplfunc_entrypoint, 3, NULL);
tpl_register_func("get_github_release_notes_auto", &get_github_release_notes_auto_tplfunc_entrypoint, 1, &ctx);
+ tpl_register_func("junitxml_file", &get_junitxml_file_entrypoint, 1, &ctx);
+ tpl_register_func("basetemp_dir", &get_basetemp_dir_entrypoint, 1, &ctx);
// Set up PREFIX/etc directory information
// The user may manipulate the base directory path with STASIS_SYSCONFDIR
diff --git a/src/template_func_proto.c b/src/template_func_proto.c
index 92ae355..3cf66e4 100644
--- a/src/template_func_proto.c
+++ b/src/template_func_proto.c
@@ -66,3 +66,47 @@ int get_github_release_notes_auto_tplfunc_entrypoint(void *frame, void *data_out
return result;
}
+
+int get_junitxml_file_entrypoint(void *frame, void *data_out) {
+ int result = 0;
+ char **output = (char **) data_out;
+ struct tplfunc_frame *f = (struct tplfunc_frame *) frame;
+ const struct Delivery *ctx = (const struct Delivery *) f->data_in;
+
+ char cwd[PATH_MAX] = {0};
+ getcwd(cwd, PATH_MAX - 1);
+ char nametmp[PATH_MAX] = {0};
+ strcpy(nametmp, cwd);
+ char *name = path_basename(nametmp);
+
+ *output = calloc(PATH_MAX, sizeof(**output));
+ if (!*output) {
+ SYSERROR("failed to allocate output string: %s", strerror(errno));
+ return -1;
+ }
+ sprintf(*output, "%s/results-%s-%s.xml", ctx->storage.results_dir, name, ctx->info.release_name);
+
+ return result;
+}
+
+int get_basetemp_dir_entrypoint(void *frame, void *data_out) {
+ int result = 0;
+ char **output = (char **) data_out;
+ struct tplfunc_frame *f = (struct tplfunc_frame *) frame;
+ const struct Delivery *ctx = (const struct Delivery *) f->data_in;
+
+ char cwd[PATH_MAX] = {0};
+ getcwd(cwd, PATH_MAX - 1);
+ char nametmp[PATH_MAX] = {0};
+ strcpy(nametmp, cwd);
+ char *name = path_basename(nametmp);
+
+ *output = calloc(PATH_MAX, sizeof(**output));
+ if (!*output) {
+ SYSERROR("failed to allocate output string: %s", strerror(errno));
+ return -1;
+ }
+ sprintf(*output, "%s/truth-%s-%s", ctx->storage.tmpdir, name, ctx->info.release_name);
+
+ return result;
+} \ No newline at end of file
diff --git a/stasis.ini b/stasis.ini
index 00fd3f4..875ca26 100644
--- a/stasis.ini
+++ b/stasis.ini
@@ -16,7 +16,6 @@ conda_fresh_start = true
; (list) Conda packages to be installed/overridden in the base environment
conda_packages =
- conda>=23.7.0
conda-build>=3.22.0
boa
conda-verify