build: separate package identity from storage paths
This commit is contained in:
@@ -22,6 +22,18 @@ slurp(const char *path, char **outbuf, u64 *outlen)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
export_owner_matches(const char *buf, u64 len, const char *path)
|
||||
{
|
||||
static const char prefix[] = "//ww:module ";
|
||||
size_t pn = strlen(path);
|
||||
size_t need = sizeof prefix - 1 + pn + 1;
|
||||
return len >= need
|
||||
&& memcmp(buf, prefix, sizeof prefix - 1) == 0
|
||||
&& memcmp(buf + sizeof prefix - 1, path, pn) == 0
|
||||
&& buf[need - 1] == '\n';
|
||||
}
|
||||
|
||||
struct importin {
|
||||
const char *path;
|
||||
const char *file;
|
||||
@@ -164,6 +176,13 @@ main(int argc, char **argv)
|
||||
imports[i].path, imports[i].file);
|
||||
return 1;
|
||||
}
|
||||
if (!export_owner_matches(imports[i].buf, imports[i].len,
|
||||
imports[i].path)) {
|
||||
fprintf(stderr,
|
||||
"w6c: import %s: export owner mismatch in %s\n",
|
||||
imports[i].path, imports[i].file);
|
||||
return 1;
|
||||
}
|
||||
int bad = 0;
|
||||
Node *f = parseinput(a, imports[i].file, imports[i].buf,
|
||||
imports[i].len, imports[i].path, testsupport, 0, &bad);
|
||||
|
||||
@@ -864,6 +864,8 @@ wwi_emit(Checker *c, FILE *of, Node *file)
|
||||
const char *dot = strrchr(file->module, '.');
|
||||
pkg = dot ? dot + 1 : file->module;
|
||||
}
|
||||
if (file->module != NULL && file->module[0] != '\0')
|
||||
fprintf(of, "//ww:module %s\n", file->module);
|
||||
fprintf(of, "package %s;\n", pkg);
|
||||
|
||||
/* imports — primary N_USE, byte-sorted by import path. */
|
||||
|
||||
Reference in New Issue
Block a user