ww+selfhost: prepend source dir to import search path
This commit is contained in:
@@ -862,10 +862,40 @@ fn buildone(selfdir: *u8, src: *u8, out: *u8, incs: *u8, lf: *lflags) i32 = {
|
||||
cstrseal(dotdotlib, off);
|
||||
};
|
||||
|
||||
// Compose searchpath: incs + ':' + dotdotlib (or just dotdotlib).
|
||||
let searchpath: *u8 = os.alloc(PATH_MAX * 2u64): *u8;
|
||||
// Compute the source-file's directory: bytes of `src` up to the
|
||||
// last '/'. If `src` has no '/', use ".". Hare's CWD-first
|
||||
// convention assumes you're running from the module dir; our
|
||||
// wrappers don't cd, so dirname(src) stands in as the closest
|
||||
// analog. Source-dir wins ties over the system path (cc -I.).
|
||||
let srcd: *u8 = os.alloc(PATH_MAX): *u8;
|
||||
{
|
||||
let off: u64 = 0u64;
|
||||
let slen: u64 = cstrlen(src);
|
||||
let last: u64 = slen;
|
||||
let found: bool = false;
|
||||
let i: u64 = slen;
|
||||
for (i > 0u64) {
|
||||
i -= 1u64;
|
||||
if (src[i] == 47u8) { // '/'
|
||||
last = i;
|
||||
found = true;
|
||||
i = 0u64;
|
||||
};
|
||||
};
|
||||
if (found) {
|
||||
let k: u64 = 0u64;
|
||||
for (k < last) { srcd[k] = src[k]; k += 1u64; };
|
||||
srcd[last] = 0u8;
|
||||
} else {
|
||||
srcd[0] = 46u8; // '.'
|
||||
srcd[1] = 0u8;
|
||||
};
|
||||
};
|
||||
|
||||
// Compose searchpath: srcd + ':' + incs + ':' + dotdotlib.
|
||||
let searchpath: *u8 = os.alloc(PATH_MAX * 3u64): *u8;
|
||||
{
|
||||
let off: u64 = cstrinto(searchpath, 0u64, srcd);
|
||||
off = byteinto(searchpath, off, 58u8); // ':'
|
||||
if (incs[0u64] != 0u8) {
|
||||
off = cstrinto(searchpath, off, incs);
|
||||
off = byteinto(searchpath, off, 58u8); // ':'
|
||||
|
||||
@@ -508,10 +508,40 @@ fn buildone(selfdir: *u8, src: *u8, out: *u8, incs: *u8, lf: *lflags) i32 = {
|
||||
cstrseal(dotdotlib, off);
|
||||
};
|
||||
|
||||
// Compose searchpath: incs + ':' + dotdotlib (or just dotdotlib).
|
||||
let searchpath: *u8 = os.alloc(PATH_MAX * 2u64): *u8;
|
||||
// Compute the source-file's directory: bytes of `src` up to the
|
||||
// last '/'. If `src` has no '/', use ".". Hare's CWD-first
|
||||
// convention assumes you're running from the module dir; our
|
||||
// wrappers don't cd, so dirname(src) stands in as the closest
|
||||
// analog. Source-dir wins ties over the system path (cc -I.).
|
||||
let srcd: *u8 = os.alloc(PATH_MAX): *u8;
|
||||
{
|
||||
let off: u64 = 0u64;
|
||||
let slen: u64 = cstrlen(src);
|
||||
let last: u64 = slen;
|
||||
let found: bool = false;
|
||||
let i: u64 = slen;
|
||||
for (i > 0u64) {
|
||||
i -= 1u64;
|
||||
if (src[i] == 47u8) { // '/'
|
||||
last = i;
|
||||
found = true;
|
||||
i = 0u64;
|
||||
};
|
||||
};
|
||||
if (found) {
|
||||
let k: u64 = 0u64;
|
||||
for (k < last) { srcd[k] = src[k]; k += 1u64; };
|
||||
srcd[last] = 0u8;
|
||||
} else {
|
||||
srcd[0] = 46u8; // '.'
|
||||
srcd[1] = 0u8;
|
||||
};
|
||||
};
|
||||
|
||||
// Compose searchpath: srcd + ':' + incs + ':' + dotdotlib.
|
||||
let searchpath: *u8 = os.alloc(PATH_MAX * 3u64): *u8;
|
||||
{
|
||||
let off: u64 = cstrinto(searchpath, 0u64, srcd);
|
||||
off = byteinto(searchpath, off, 58u8); // ':'
|
||||
if (incs[0u64] != 0u8) {
|
||||
off = cstrinto(searchpath, off, incs);
|
||||
off = byteinto(searchpath, off, 58u8); // ':'
|
||||
|
||||
Reference in New Issue
Block a user