diff options
-rw-r--r-- | include/omc.h | 3 | ||||
-rw-r--r-- | include/utils.h | 9 | ||||
-rw-r--r-- | src/deliverable.c | 19 | ||||
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/utils.c | 58 |
5 files changed, 89 insertions, 1 deletions
diff --git a/include/omc.h b/include/omc.h index 11252b1..0b1c562 100644 --- a/include/omc.h +++ b/include/omc.h @@ -59,6 +59,9 @@ struct OMC_GLOBAL { char *tmpdir; //!< Path to temporary storage directory char *conda_install_prefix; //!< Path to install conda char *sysconfdir; //!< Path where OMC reads its configuration files (mission directory, etc) + struct { + char *tox_posargs; + } workaround; struct Jfrog { char *jfrog_artifactory_base_url; char *jfrog_artifactory_product; diff --git a/include/utils.h b/include/utils.h index b03d99e..4d3cd3d 100644 --- a/include/utils.h +++ b/include/utils.h @@ -254,4 +254,13 @@ int isempty_dir(const char *path); * @return 0 on success, -1 on error */ int xml_pretty_print_in_place(const char *filename, const char *pretty_print_prog, const char *pretty_print_args); + +/** + * Applies OMC fixups to a tox ini config + * @param filename path to tox.ini + * @param result path to processed configuration + * @return 0 on success, -1 on error + */ +int fix_tox_conf(const char *filename, char **result); + #endif //OMC_UTILS_H diff --git a/src/deliverable.c b/src/deliverable.c index 0ddf17a..0b166d9 100644 --- a/src/deliverable.c +++ b/src/deliverable.c @@ -1393,6 +1393,20 @@ void delivery_tests_run(struct Delivery *ctx) { msg(OMC_MSG_L3, "Testing %s\n", ctx->tests[i].name); memset(&proc, 0, sizeof(proc)); + // Apply workaround for tox positional arguments + char *toxconf = NULL; + if (!access("tox.ini", F_OK)) { + msg(OMC_MSG_L3, "Fixing tox positional arguments\n"); + + fix_tox_conf("tox.ini", &toxconf); + if (!globals.workaround.tox_posargs) { + globals.workaround.tox_posargs = calloc(PATH_MAX, sizeof(*globals.workaround.tox_posargs)); + } else { + memset(globals.workaround.tox_posargs, 0, PATH_MAX); + } + snprintf(globals.workaround.tox_posargs, PATH_MAX - 1, "-c %s --root .", toxconf); + } + // enable trace mode before executing each test script memset(cmd, 0, sizeof(cmd)); sprintf(cmd, "set -x ; %s", ctx->tests[i].script); @@ -1410,6 +1424,11 @@ void delivery_tests_run(struct Delivery *ctx) { msg(OMC_MSG_ERROR, "Script failure: %s\n%s\n\nExit code: %d\n", ctx->tests[i].name, ctx->tests[i].script, status); COE_CHECK_ABORT(!globals.continue_on_error, "Test failure") } + + if (toxconf) { + remove(toxconf); + guard_free(toxconf); + } popd(); #else msg(OMC_MSG_WARNING | OMC_MSG_L3, "TESTING DISABLED BY CODE!\n"); @@ -254,6 +254,7 @@ int main(int argc, char *argv[], char *arge[]) { tpl_register("system.platform", &ctx.system.platform[DELIVERY_PLATFORM_RELEASE]); tpl_register("deploy.jfrog.repo", &globals.jfrog.repo); tpl_register("deploy.docker.registry", &ctx.deploy.docker.registry); + tpl_register("workaround.tox_posargs", &globals.workaround.tox_posargs); // Set up PREFIX/etc directory information // The user may manipulate the base directory path with OMC_SYSCONFDIR diff --git a/src/utils.c b/src/utils.c index 047a266..85a3b56 100644 --- a/src/utils.c +++ b/src/utils.c @@ -590,4 +590,60 @@ int xml_pretty_print_in_place(const char *filename, const char *pretty_print_pro guard_free(tempfile); guard_free(result); return -1; -}
\ No newline at end of file +} + +int fix_tox_conf(const char *filename, char **result) { + struct INIFILE *toxini; + FILE *fptemp; + char *tempfile; + const char *with_posargs = " \\\n {posargs}\n"; + + tempfile = xmkstemp(&fptemp, "w+"); + if (!tempfile) { + return -1; + } + + if (!*result) { + *result = calloc(PATH_MAX, sizeof(*result)); + if (!*result) { + return -1; + } + } + + toxini = ini_open(filename); + if (!toxini) { + if (fptemp) { + guard_free(tempfile); + fclose(fptemp); + } + guard_free(*result); + return -1; + } + + for (size_t i = 0; i < toxini->section_count; i++) { + struct INISection *section = toxini->section[i]; + if (section) { + if (startswith(section->key, "testenv")) { + for (size_t k = 0; k < section->data_count; k++) { + struct INIData *data = section->data[k]; + if (data) { + if (!strcmp(data->key, "commands") && (startswith(data->value, "pytest") && !strstr(data->value, "{posargs}"))) { + strip(data->value); + data->value = realloc(data->value, strlen(data->value) + strlen(with_posargs) + 1); + strcat(data->value, with_posargs); + } + } + } + } + } + } + + if (ini_write(toxini, &fptemp)) { + guard_free(tempfile); + } + fclose(fptemp); + + *result = tempfile; + ini_free(&toxini); + return 0; +} |