Commit 578982b9
578982b94c50Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Plain require: resolve the bundled stdlib one level above the compiler binary
require "optparse" resolved the bundled lib/ directory relative to the
compiler executable only (<exe_dir>/lib). The C compiler lives in build/, so
the lookup missed the repo's lib/ and warned the library away. On a miss, retry
<exe_dir>/../lib/.rb (computed from the exe dir, not via the nonexistent
<exe_dir>/lib, whose dangling ".." would fail POSIX resolution).
Fixes require_first_line. Zero errors remain in the test suite.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 578982b94c50
- Parent
- ecfd6cd49aff
spinel_parse.cmodifiedView file
@@ -1868,6 +1868,19 @@
18681868
free(canonical);18691869
content = read_file(lib_path);18701870
if (!content) {1871+
/* the compiler binary may live one level below the repo root (e.g.1872+
build/spinelc with the stdlib at ../lib): retry one level up */1873+
char alt_path[1024];1874+
int exe_len = (int)strlen(lib_dir) - 4; /* strip the trailing "/lib" */1875+
if (exe_len < 0) exe_len = 0;1876+
snprintf(alt_path, sizeof(alt_path), "%.*s/../lib/%s", exe_len, lib_dir, lib_name);1877+
size_t al = strlen(alt_path);1878+
if (al < sizeof(alt_path) - 4 && (al < 3 || strcmp(alt_path + al - 3, ".rb") != 0))1879+
strcat(alt_path, ".rb");1880+
content = read_file(alt_path);1881+
if (content) snprintf(lib_path, sizeof(lib_path), "%s", alt_path);1882+
}1883+
if (!content) {18711884
if (sp_lib_is_native(lib_name)) {18721885
/* Provided natively by the Spinel runtime; the require is a18731886
harmless no-op, so don't warn. */