ww: group lex.ww + tok.ww into lib/ww/lex/ submodule
This commit is contained in:
@@ -59,10 +59,15 @@ slurp_eq(const char *a, const char *b)
|
||||
* the build directory. Returns 0 on success. */
|
||||
static int
|
||||
build_via(const char *bin, const char *driver, const char *src,
|
||||
const char *workdir, const char *includes_a, const char *includes_b)
|
||||
const char *workdir, const char *includes_a, const char *includes_b,
|
||||
const char *includes_c)
|
||||
{
|
||||
char cmd[4096];
|
||||
if (includes_b && includes_b[0]) {
|
||||
if (includes_c && includes_c[0]) {
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd %s && %s/%s build -I %s -I %s -I %s %s 2>/dev/null",
|
||||
workdir, bin, driver, includes_a, includes_b, includes_c, src);
|
||||
} else if (includes_b && includes_b[0]) {
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd %s && %s/%s build -I %s -I %s %s 2>/dev/null",
|
||||
workdir, bin, driver, includes_a, includes_b, src);
|
||||
@@ -81,7 +86,7 @@ build_via(const char *bin, const char *driver, const char *src,
|
||||
static int
|
||||
diff_one(const char *bin, const char *cwd, const char *label,
|
||||
const char *src, const char *out_basename,
|
||||
const char *inc_a, const char *inc_b)
|
||||
const char *inc_a, const char *inc_b, const char *inc_c)
|
||||
{
|
||||
char dc[64], dw[64];
|
||||
snprintf(dc, sizeof dc, "/tmp/ww_d_%d_c", getpid());
|
||||
@@ -91,11 +96,11 @@ diff_one(const char *bin, const char *cwd, const char *label,
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s %s && mkdir -p %s %s", dc, dw, dc, dw);
|
||||
if (runwait(cmd) != 0) return -1;
|
||||
|
||||
if (build_via(bin, "ww", src, dc, inc_a, inc_b) != 0) {
|
||||
if (build_via(bin, "ww", src, dc, inc_a, inc_b, inc_c) != 0) {
|
||||
fprintf(stderr, "ww_ww FAIL: C ww errored on %s\n", label);
|
||||
return -1;
|
||||
}
|
||||
if (build_via(bin, "ww_ww", src, dw, inc_a, inc_b) != 0) {
|
||||
if (build_via(bin, "ww_ww", src, dw, inc_a, inc_b, inc_c) != 0) {
|
||||
fprintf(stderr, "ww_ww FAIL: ww ww errored on %s\n", label);
|
||||
return -1;
|
||||
}
|
||||
@@ -142,27 +147,31 @@ main(void)
|
||||
const char *out; /* basename of expected output */
|
||||
const char *inc_a;
|
||||
const char *inc_b;
|
||||
const char *inc_c;
|
||||
} cases[] = {
|
||||
{ "hello", "/tmp/ww_d_hello.ww", "ww_d_hello", "", "" },
|
||||
{ "wwdump", NULL, "main", NULL, NULL }, /* filled in below */
|
||||
{ NULL, NULL, NULL, NULL, NULL },
|
||||
{ "hello", "/tmp/ww_d_hello.ww", "ww_d_hello", "", "", "" },
|
||||
{ "wwdump", NULL, "main", NULL, NULL, NULL }, /* filled in below */
|
||||
{ NULL, NULL, NULL, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
/* wwdump case: absolute paths so the driver finds the imports
|
||||
* regardless of the per-driver workdir. */
|
||||
static char wwdump_src[2048], wwdump_inc_a[2048], wwdump_inc_b[2048];
|
||||
static char wwdump_src[2048], wwdump_inc_a[2048], wwdump_inc_b[2048], wwdump_inc_c[2048];
|
||||
snprintf(wwdump_src, sizeof wwdump_src, "%s/selfhost/cmd/wwdump/main.ww", cwd);
|
||||
snprintf(wwdump_inc_a, sizeof wwdump_inc_a, "%s/lib/ww", cwd);
|
||||
snprintf(wwdump_inc_b, sizeof wwdump_inc_b, "%s/selfhost/cmd/wcc", cwd);
|
||||
snprintf(wwdump_inc_b, sizeof wwdump_inc_b, "%s/lib/ww/lex", cwd);
|
||||
snprintf(wwdump_inc_c, sizeof wwdump_inc_c, "%s/selfhost/cmd/wcc", cwd);
|
||||
cases[1].src = wwdump_src;
|
||||
cases[1].inc_a = wwdump_inc_a;
|
||||
cases[1].inc_b = wwdump_inc_b;
|
||||
cases[1].inc_c = wwdump_inc_c;
|
||||
|
||||
int fail = 0;
|
||||
int n = 0;
|
||||
for (int i = 0; cases[i].label; i++) {
|
||||
if (diff_one(bin, cwd, cases[i].label, cases[i].src,
|
||||
cases[i].out, cases[i].inc_a, cases[i].inc_b) != 0)
|
||||
cases[i].out, cases[i].inc_a, cases[i].inc_b,
|
||||
cases[i].inc_c) != 0)
|
||||
fail++;
|
||||
n++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user