cmd: invoke package tools with exact arguments

This commit is contained in:
2026-08-12 14:13:51 +09:00
parent 8dfff85388
commit 7dad3a6db4
2 changed files with 40 additions and 33 deletions

View File

@@ -43,15 +43,6 @@ toolpath(const char *envvar, const char *name)
return strdup(buf);
}
static int
run(const char *cmd)
{
int rc = system(cmd);
if (rc == -1) return -1;
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
return 1;
}
static int
run_argv(const char *prog, char *const argv[])
{
@@ -1949,7 +1940,7 @@ build_one_sep_impl(const char *src, int entry_is_dir,
char asmf[SEP_ARTIFACT_MAX], obj[SEP_ARTIFACT_MAX];
char apath[SEP_ARTIFACT_MAX], unitnew[SEP_ARTIFACT_MAX];
char wwinew[SEP_ARTIFACT_MAX], asmnew[SEP_ARTIFACT_MAX];
char objnew[SEP_ARTIFACT_MAX], anew[SEP_ARTIFACT_MAX], cmd[8192];
char objnew[SEP_ARTIFACT_MAX], anew[SEP_ARTIFACT_MAX];
sep_fname(g, pi, scratch, ".unit.ww", unitf, sizeof unitf);
sep_fname(g, pi, scratch, ".wwi", wwi, sizeof wwi);
sep_fname(g, pi, scratch, ".s", asmf, sizeof asmf);
@@ -1994,25 +1985,30 @@ build_one_sep_impl(const char *src, int entry_is_dir,
* LOCAL type (the root is never imported), which the
* export-check rejects. Skip -I for the root; its `.wwi`
* is never consumed. */
if (!needs_export) {
char *cargv[12];
int cpos = 0;
cargv[cpos++] = "w6c";
if (!needs_export && is_test && g->pkg[pi].root) {
/* #79: the root carries -T under `ww test`
* so w6c synthesizes the test main. Deps never
* get -T. */
if (is_test && g->pkg[pi].root)
snprintf(cmd, sizeof cmd,
"%s -T --test-support-module %s -c -o %s %s",
c6, test_support_module, cs, cu);
else
snprintf(cmd, sizeof cmd, "%s -c -o %s %s",
c6, cs, cu);
} else
snprintf(cmd, sizeof cmd, "%s %s%s%s-c -I %s -o %s %s",
c6, g->pkg[pi].test_support
? "--test-support-module " : "",
g->pkg[pi].test_support ? test_support_module : "",
g->pkg[pi].test_support ? " " : "",
cw, cs, cu);
if (run(cmd) != 0) {
cargv[cpos++] = "-T";
cargv[cpos++] = "--test-support-module";
cargv[cpos++] = (char *)test_support_module;
} else if (needs_export && g->pkg[pi].test_support) {
cargv[cpos++] = "--test-support-module";
cargv[cpos++] = (char *)test_support_module;
}
cargv[cpos++] = "-c";
if (needs_export) {
cargv[cpos++] = "-I";
cargv[cpos++] = (char *)cw;
}
cargv[cpos++] = "-o";
cargv[cpos++] = (char *)cs;
cargv[cpos++] = (char *)cu;
cargv[cpos] = NULL;
if (run_argv(c6, cargv) != 0) {
fprintf(stderr, "ww: w6c failed for %s\n",
g->pkg[pi].path[0] ? g->pkg[pi].path : "(root)");
g->pkg[pi].failed = 1;
@@ -2020,8 +2016,9 @@ build_one_sep_impl(const char *src, int entry_is_dir,
continue;
}
if (!emit_asm) {
snprintf(cmd, sizeof cmd, "%s -o %s %s", a6, co, cs);
if (run(cmd) != 0) {
char *aargv[] = {"w6a", "-o", (char *)co,
(char *)cs, NULL};
if (run_argv(a6, aargv) != 0) {
fprintf(stderr, "ww: w6a failed for %s\n",
g->pkg[pi].path[0] ? g->pkg[pi].path : "(root)");
g->pkg[pi].failed = 1;