Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support space and backslash characters in runfile filenames. #587

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions elisp/runfiles/runfiles-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,17 @@
"phst_rules_elisp/elisp/runfiles/test-manifest"))
(runfiles (elisp/runfiles/make :manifest manifest
:directory "/invalid/")))
(should (equal (elisp/runfiles/rlocation "testäα𝐴🐈'.txt" runfiles)
"/:/runfiles/testäα𝐴🐈'.txt"))))
(pcase-dolist (`(,source ,target)
'(("testäα𝐴🐈'.txt"
"/:/runfiles/testäα𝐴🐈'.txt")
("target-with-space"
"/:/runfiles/with space\\and backslash")
("target-with-newline"
"/:/runfiles/with\nnewline\\and backslash")
("source with space,\nnewline,\\and backslash"
"/:/runfiles/with space,\nnewline,\\and backslash")))
(ert-info (source :prefix "Source: ")
(should (equal (elisp/runfiles/rlocation source runfiles) target))))))

(ert-deftest elisp/runfiles/make/empty-file ()
(let* ((manifest (elisp/runfiles/rlocation
Expand Down
32 changes: 25 additions & 7 deletions elisp/runfiles/runfiles.el
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,31 @@ Return an object of type ‘elisp/runfiles/runfiles--manifest’."
;; Perform the same parsing as
;; https://github.com/bazelbuild/bazel/blob/6.4.0/tools/cpp/runfiles/runfiles_src.cc#L241.
(while (not (eobp))
(pcase (buffer-substring-no-properties (point) (line-end-position))
((rx bos (let key (+ (not (any ?\n ?\s))))
?\s (let value (* nonl)) eos)
;; Runfiles are always local, so quote them unconditionally.
(puthash key (if (string-empty-p value) :empty (concat "/:" value))
manifest))
(other (signal 'elisp/runfiles/syntax-error (list filename other))))
(let ((line (buffer-substring-no-properties
(point) (line-end-position)))
(escaped (eql (following-char) ?\s)))
(cl-flet* ((syntax-error ()
(signal 'elisp/runfiles/syntax-error
(list filename line)))
(unescape (string &rest other)
(let ((pairs `(,@other ("\\n" . "\n") ("\\b" . "\\"))))
(replace-regexp-in-string
(rx ?\\ (? anychar))
(lambda (seq)
(or (cdr (assoc seq pairs)) (syntax-error)))
string :fixedcase :literal))))
(pcase (if escaped (substring-no-properties line 1) line)
((rx bos (let key (+ (not (any ?\n ?\s))))
?\s (let value (* nonl)) eos)
(when escaped
(cl-callf unescape key '("\\s" . " "))
(cl-callf unescape value))
(puthash key
;; Runfiles are always local, so quote them
;; unconditionally.
(if (string-empty-p value) :empty (concat "/:" value))
manifest))
(_ (syntax-error)))))
(forward-line)))
(elisp/runfiles/manifest--make filename manifest)))

Expand Down
3 changes: 3 additions & 0 deletions elisp/runfiles/test-manifest
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
__init__.py
foo/bar runfiles/foo/bar
testäα𝐴🐈'.txt /runfiles/testäα𝐴🐈'.txt
target-with-space /runfiles/with space\and backslash
target-with-newline /runfiles/with\nnewline\band backslash
source\swith\sspace,\nnewline,\band\sbackslash /runfiles/with space,\nnewline,\band backslash
Loading