[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/02: lint: formatting: Gracefully handle relative file names.
From: |
guix-commits |
Subject: |
02/02: lint: formatting: Gracefully handle relative file names. |
Date: |
Sun, 23 Aug 2020 17:08:28 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit d10474c38d58bdc676e64336769dc2e00cdfa8ed
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Aug 23 22:48:19 2020 +0200
lint: formatting: Gracefully handle relative file names.
Fixes <https://bugs.gnu.org/42543>.
Reported by Jack Hill <jackhill@jackhill.us>.
* guix/lint.scm (check-formatting): Always return a list (previously we
would return #f when 'search-path' returns #f). Check whether
LOCATION's file is a relative file name. Return a warning if not.
* tests/guix-lint.sh: Add test.
---
guix/lint.scm | 20 ++++++++++++++------
tests/guix-lint.sh | 13 +++++++++++--
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/guix/lint.scm b/guix/lint.scm
index 4a6abe4..ec43a4d 100644
--- a/guix/lint.scm
+++ b/guix/lint.scm
@@ -1355,12 +1355,20 @@ them for PACKAGE."
"Check the formatting of the source code of PACKAGE."
(let ((location (package-location package)))
(if location
- (and=> (search-path %load-path (location-file location))
- (lambda (file)
- ;; Report issues starting from the line before the 'package'
- ;; form, which usually contains the 'define' form.
- (report-formatting-issues package file
- (- (location-line location) 1))))
+ ;; Report issues starting from the line before the 'package'
+ ;; form, which usually contains the 'define' form.
+ (let ((line (- (location-line location) 1)))
+ (match (search-path %load-path (location-file location))
+ ((? string? file)
+ (report-formatting-issues package file line))
+ (#f
+ ;; It could be that LOCATION lists a "true" relative file
+ ;; name--i.e., not relative to an element of %LOAD-PATH.
+ (let ((file (location-file location)))
+ (if (file-exists? file)
+ (report-formatting-issues package file line)
+ (list (make-warning package
+ (G_ "source file not found"))))))))
'())))
diff --git a/tests/guix-lint.sh b/tests/guix-lint.sh
index f0df1fd..ebe79ef 100644
--- a/tests/guix-lint.sh
+++ b/tests/guix-lint.sh
@@ -22,8 +22,11 @@
guix lint --version
-module_dir="t-guix-lint-$$"
-mkdir "$module_dir"
+# Choose a module directory not below any %LOAD-PATH component. This is
+# necessary when testing '-L' with a relative file name.
+module_dir="$(mktemp -d)"
+
+mkdir -p "$module_dir"
trap "rm -rf $module_dir" EXIT
@@ -87,3 +90,9 @@ then false; else true; fi
# Make sure specifying multiple packages works.
guix lint -L $module_dir -c inputs-should-be-native dummy dummy@42 dummy
+
+# Test '-L' with a relative file name. 'guix lint' will see "t-xyz/foo.scm"
+# (instead of "foo.scm") and will thus fail to find it in %LOAD-PATH. Check
+# that it does find it anyway. See <https://bugs.gnu.org/42543>.
+(cd "$module_dir"/.. ; guix lint -c formatting -L "$(basename "$module_dir")"
dummy@42) 2>&1 > "$module_dir/out"
+test -z "$(cat "$module_dir/out")"