diff --git a/cmd/ww/main.c b/cmd/ww/main.c index 5ad1aa2c..ace14165 100644 --- a/cmd/ww/main.c +++ b/cmd/ww/main.c @@ -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; diff --git a/selfhost/cmd/ww/main.ww b/selfhost/cmd/ww/main.ww index 1f16ff22..a584c9ab 100644 --- a/selfhost/cmd/ww/main.ww +++ b/selfhost/cmd/ww/main.ww @@ -8,8 +8,8 @@ // ww version → print version // // Tool paths default to siblings of $0 so a fresh build runs out of -// out/bin/. Env-var overrides (WW_W6C / WW_W6A / WW_W6L / WW_LIB) are -// not yet supported in this port; the bootstrap doesn't need them. +// out/bin/. WW_W6C / WW_W6A / WW_W6L select exact executable paths. +// Source-library and runtime-library overrides are not yet supported. package main; @@ -162,6 +162,16 @@ fn owncstr(s: str) *u8 = { return b.ptr; }; +fn toolpath(selfdir: *u8, envvar: str, name: str) *u8 = { + match (os.getenv(envvar)) { + case let p: str => { + if (p.len != 0) { return owncstr(p); }; + }; + case void => void; + }; + return joinpathlit(selfdir, name); +}; + // execpackagetests — replace the driver with the native WW package // coordinator for directory/default invocations. Explicit generated // package.ww roots stay on runsingletest, which is the recursion boundary when @@ -2018,9 +2028,9 @@ fn buildonesepimpl(selfdir: *u8, src: *u8, entryisdir: i32, }; statusi += 1; }; - let c6: *u8 = joinpathlit(selfdir, "w6c_ww"); - let a6: *u8 = joinpathlit(selfdir, "w6a_ww"); - let l6: *u8 = joinpathlit(selfdir, "w6l_ww"); + let c6: *u8 = toolpath(selfdir, "WW_W6C", "w6c_ww"); + let a6: *u8 = toolpath(selfdir, "WW_W6A", "w6a_ww"); + let l6: *u8 = toolpath(selfdir, "WW_W6L", "w6l_ww"); let dotdotlib: []u8 = alloc([], (os.PATH_MAX: u64))!; dotdotlib.len = os.PATH_MAX;