From 42d7b648bd295e2204c5d064256fb1ad382b41c9 Mon Sep 17 00:00:00 2001 From: Niklas Claesson Date: Wed, 29 Jan 2020 00:50:15 +0100 Subject: [PATCH] configurator: Enable running configurator in wrapper Since the probing binaries compiled by the configurator needs to run on the host machine we provide a variable CONFIGURATOR_WRAPPER that can be set to anything that you want to wrap the calls with. One example is `qemu-aarch64-static`. --- tools/configurator/configurator.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tools/configurator/configurator.c b/tools/configurator/configurator.c index d99d4a00..048b801d 100644 --- a/tools/configurator/configurator.c +++ b/tools/configurator/configurator.c @@ -639,7 +639,7 @@ static struct test *find_test(const char *name) #define MAIN_BODY_BOILERPLATE "return 0;\n" #define MAIN_END_BOILERPLATE "}\n" -static bool run_test(const char *cmd, struct test *test) +static bool run_test(const char *cmd, const char* wrapper, struct test *test) { char *output, *newcmd; FILE *outf; @@ -667,7 +667,7 @@ static bool run_test(const char *cmd, struct test *test) dep++; positive = false; } - if (run_test(cmd, find_test(dep)) != positive) { + if (run_test(cmd, wrapper, find_test(dep)) != positive) { test->answer = false; test->done = true; return test->answer; @@ -757,7 +757,21 @@ static bool run_test(const char *cmd, struct test *test) /* We run INSIDE_MAIN tests for sanity checking. */ if (strstr(test->style, "EXECUTE") || strstr(test->style, "INSIDE_MAIN")) { - output = run("." DIR_SEP OUTPUT_FILE, &status); + char* cmd = "." DIR_SEP OUTPUT_FILE; + if(wrapper) { + // string length and null terminator. + size_t size = strlen(wrapper) + strlen(" ") + strlen(cmd) + 1; + char* newcmd = malloc(size); + memset(newcmd, '\0', size); + strcat(newcmd, wrapper); + strcat(newcmd, " "); + strcat(newcmd, cmd); + cmd = newcmd; + } + output = run(cmd, &status); + if (wrapper) { + free(cmd); + } if (!strstr(test->style, "EXECUTE") && status != 0) c12r_errx(EXIT_BAD_TEST, "Test for %s failed with %i:\n%s", @@ -908,6 +922,7 @@ int main(int argc, const char *argv[]) = { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL }; const char *outflag = DEFAULT_OUTPUT_EXE_FLAG; const char *configurator_cc = NULL; + const char *wrapper = NULL; const char *orig_cc; const char *varfile = NULL; const char *headerfile = NULL; @@ -919,7 +934,7 @@ int main(int argc, const char *argv[]) while (argc > 1) { if (strcmp(argv[1], "--help") == 0) { - printf("Usage: configurator [-v] [--var-file=] [-O] [--configurator-cc=] [--autotools-style] [--extra-tests] [ ...]\n" + printf("Usage: configurator [-v] [--var-file=] [-O] [--configurator-cc=] [--wrapper=] [--autotools-style] [--extra-tests] [ ...]\n" " will have \" \" appended\n" "Default: %s %s %s\n", DEFAULT_COMPILER, DEFAULT_FLAGS, @@ -948,6 +963,10 @@ int main(int argc, const char *argv[]) configurator_cc = argv[1] + 18; argc--; argv++; + } else if (strncmp(argv[1], "--wrapper=", 10) == 0) { + wrapper = argv[1] + 10; + argc--; + argv++; } else if (strncmp(argv[1], "--var-file=", 11) == 0) { varfile = argv[1] + 11; argc--; @@ -995,7 +1014,7 @@ int main(int argc, const char *argv[]) end_test(1); } for (i = 0; tests[i].name; i++) - run_test(cmd, &tests[i]); + run_test(cmd, wrapper, &tests[i]); free(cmd); remove(OUTPUT_FILE); -- 2.39.2