Skip to content

Commit

Permalink
Support manifest runfiles that map to directories.
Browse files Browse the repository at this point in the history
This is equivalent to the fixes made for
bazelbuild/bazel#14336.
  • Loading branch information
phst committed Apr 17, 2022
1 parent 2ca3fe5 commit 6153986
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 11 additions & 0 deletions elisp/runfiles/runfiles-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@
(should-error (elisp/runfiles/rlocation "__init__.py" runfiles)
:type 'elisp/runfiles/empty)))

(ert-deftest elisp/runfiles/make/manifest/directory ()
"Check that we find runfiles in a mapped directory.
See https://github.com/bazelbuild/bazel/issues/14336 for
context."
(let* ((manifest (elisp/runfiles/rlocation
"phst_rules_elisp/elisp/runfiles/test-manifest"))
(runfiles (elisp/runfiles/make :manifest manifest
:directory "/invalid/")))
(should (equal (elisp/runfiles/rlocation "foo/bar/baz" runfiles)
"/:runfiles/foo/bar/baz"))))

(ert-deftest elisp/runfiles/file-handler ()
(let ((file-name-handler-alist file-name-handler-alist))
(elisp/runfiles/install-handler)
Expand Down
18 changes: 16 additions & 2 deletions elisp/runfiles/runfiles.el
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,22 @@ RUNFILES is a runfiles object and FILENAME the name to look up."
(let ((result (gethash filename (oref runfiles manifest))))
(cond
((not result)
(signal 'elisp/runfiles/not-found
(list filename (oref runfiles filename))))
;; Look for ancestor directory mapping. See
;; https://github.com/bazelbuild/bazel/issues/14336.
(let ((continue t)
(candidate filename))
(while continue
(pcase candidate
((rx bos (let prefix (+ anything)) ?/ (+ anything) (? ?/) eos)
(if-let ((dir (gethash prefix (oref runfiles manifest))))
(setq result (concat dir (substring-no-properties
filename (length prefix)))
continue nil)
(setq candidate prefix)))
(_ (setq continue nil)))))
(or result
(signal 'elisp/runfiles/not-found
(list filename (oref runfiles filename)))))
((eq result :empty)
(signal 'elisp/runfiles/empty
(list filename (oref runfiles filename))))
Expand Down

0 comments on commit 6153986

Please sign in to comment.