mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-07 07:26:13 -05:00
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.
This commit is contained in:
parent
68193624d1
commit
d10474c38d
2 changed files with 25 additions and 8 deletions
|
@ -1355,12 +1355,20 @@ (define (check-formatting package)
|
||||||
"Check the formatting of the source code of PACKAGE."
|
"Check the formatting of the source code of PACKAGE."
|
||||||
(let ((location (package-location package)))
|
(let ((location (package-location package)))
|
||||||
(if location
|
(if location
|
||||||
(and=> (search-path %load-path (location-file location))
|
;; Report issues starting from the line before the 'package'
|
||||||
(lambda (file)
|
;; form, which usually contains the 'define' form.
|
||||||
;; Report issues starting from the line before the 'package'
|
(let ((line (- (location-line location) 1)))
|
||||||
;; form, which usually contains the 'define' form.
|
(match (search-path %load-path (location-file location))
|
||||||
(report-formatting-issues package file
|
((? string? file)
|
||||||
(- (location-line location) 1))))
|
(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"))))))))
|
||||||
'())))
|
'())))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,11 @@
|
||||||
|
|
||||||
guix lint --version
|
guix lint --version
|
||||||
|
|
||||||
module_dir="t-guix-lint-$$"
|
# Choose a module directory not below any %LOAD-PATH component. This is
|
||||||
mkdir "$module_dir"
|
# necessary when testing '-L' with a relative file name.
|
||||||
|
module_dir="$(mktemp -d)"
|
||||||
|
|
||||||
|
mkdir -p "$module_dir"
|
||||||
trap "rm -rf $module_dir" EXIT
|
trap "rm -rf $module_dir" EXIT
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,3 +90,9 @@ then false; else true; fi
|
||||||
|
|
||||||
# Make sure specifying multiple packages works.
|
# Make sure specifying multiple packages works.
|
||||||
guix lint -L $module_dir -c inputs-should-be-native dummy dummy@42 dummy
|
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")"
|
||||||
|
|
Loading…
Reference in a new issue