diff --git a/examples/fennel/basic/BUILD.bazel b/examples/fennel/basic/BUILD.bazel index 5ba3a19..77fdd6d 100644 --- a/examples/fennel/basic/BUILD.bazel +++ b/examples/fennel/basic/BUILD.bazel @@ -9,6 +9,7 @@ fennel_library( fennel_binary( name = "main", + data = ["data.txt"], tool = "main.fnl", deps = [":example"], ) diff --git a/examples/fennel/basic/data.txt b/examples/fennel/basic/data.txt new file mode 100644 index 0000000..2edafd4 --- /dev/null +++ b/examples/fennel/basic/data.txt @@ -0,0 +1 @@ +from data diff --git a/examples/fennel/basic/main.fnl b/examples/fennel/basic/main.fnl index 98c6a1b..ebc459c 100644 --- a/examples/fennel/basic/main.fnl +++ b/examples/fennel/basic/main.fnl @@ -1,3 +1,7 @@ (local example (require :fennel.basic.example)) +(local runfiles (require :runfiles)) (print (example.add-2 2)) + +(with-open [f (assert (io.open (runfiles.rlocation :fennel/basic/data.txt)))] + (print (f:read :*l))) diff --git a/examples/fennel/basic/main_outside_runfiles_test.sh b/examples/fennel/basic/main_outside_runfiles_test.sh index 1e069d3..3d5784a 100755 --- a/examples/fennel/basic/main_outside_runfiles_test.sh +++ b/examples/fennel/basic/main_outside_runfiles_test.sh @@ -10,8 +10,8 @@ cd "$TEST_TMPDIR" out=$("$bin") echo "runfiles tree: $out" -[[ "$out" == 4 ]] +[[ "$out" == $'4\nfrom data' ]] out=$(env -u RUNFILES_DIR RUNFILES_MANIFEST_FILE="$TEST_TMPDIR/MANIFEST" "$bin") echo "manifest only: $out" -[[ "$out" == 4 ]] +[[ "$out" == $'4\nfrom data' ]] diff --git a/lua/private/binary_wrapper.lua b/lua/private/binary_wrapper.lua index 20feac6..589fb62 100644 --- a/lua/private/binary_wrapper.lua +++ b/lua/private/binary_wrapper.lua @@ -180,8 +180,10 @@ if os.getenv("RUNFILES_DIR") then return load_resolved(mapping[2] .. "." .. module_name:gsub(real_module_toplevel_name, mapping[2])) end) elseif os.getenv("RUNFILES_MANIFEST_FILE") then + local manifest = {} + local function rlocation(workspace_relative) - error("not implemented") + return manifest["_main/" .. workspace_relative] end package.preload["runfiles"] = function() @@ -198,8 +200,6 @@ elseif os.getenv("RUNFILES_MANIFEST_FILE") then inverted[v[1]] = k end - local manifest = {} - for line in io.lines(os.getenv("RUNFILES_MANIFEST_FILE")) do local t = {} -- // a manifest file that maps logical runfile paths to absolute paths paths for the real files in Bazel's cache.