summary refs log tree commit diff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2021-12-18 22:45:32 +0100
committerLudovic Courtès <ludo@gnu.org>2021-12-18 22:51:55 +0100
commita9892f8f2daceb5bc8595e4d01611936e2c403a4 (patch)
treeafc9f6ef0b7e2d95375ba064d52c22fcd9a1edb1
parenta5c24f6511e1f2652531dd6aaabf1c2c3d5ac6e5 (diff)
downloadguix-a9892f8f2daceb5bc8595e4d01611936e2c403a4.tar.gz
style: Refer to source files by absolute file names.
Previously, "guix style PACKAGE" would end up modifying a file looked up
under the current directory since the location associated with PACKAGE
is usually a relative file name.

* guix/scripts/style.scm (absolute-location): New procedure.
(simplify-package-inputs): Use it.
-rw-r--r--guix/scripts/style.scm10
1 files changed, 9 insertions, 1 deletions
diff --git a/guix/scripts/style.scm b/guix/scripts/style.scm
index 86a46f693c..01196eb3e4 100644
--- a/guix/scripts/style.scm
+++ b/guix/scripts/style.scm
@@ -392,6 +392,14 @@ doing it."
                              (G_ "would be edited~%")))
                      str)))
 
+(define (absolute-location loc)
+  "Replace the file name in LOC by an absolute location."
+  (location (if (string-prefix? "/" (location-file loc))
+                (location-file loc)
+                (search-path %load-path (location-file loc)))
+            (location-line loc)
+            (location-column loc)))
+
 (define* (simplify-package-inputs package
                                   #:key (policy 'silent)
                                   (edit-expression edit-expression))
@@ -413,7 +421,7 @@ PACKAGE."
                     #f)
                    (location
                     (edit-expression
-                     (location->source-properties location)
+                     (location->source-properties (absolute-location location))
                      (lambda (str)
                        (define matches?
                          (match policy