1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2013, 2014, 2015 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
5 ;;; Copyright © 2014 Ian Denhardt <ian@zenhack.net>
6 ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
7 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
8 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
9 ;;; Copyright © 2018, 2020 Marius Bakke <marius@gnu.org>
11 ;;; This file is part of GNU Guix.
13 ;;; GNU Guix is free software; you can redistribute it and/or modify it
14 ;;; under the terms of the GNU General Public License as published by
15 ;;; the Free Software Foundation; either version 3 of the License, or (at
16 ;;; your option) any later version.
18 ;;; GNU Guix is distributed in the hope that it will be useful, but
19 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;;; GNU General Public License for more details.
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26 (define-module (guix utils)
27 #:use-module (guix config)
28 #:use-module (srfi srfi-1)
29 #:use-module (srfi srfi-9)
30 #:use-module (srfi srfi-11)
31 #:use-module (srfi srfi-26)
32 #:use-module (srfi srfi-35)
33 #:use-module (srfi srfi-39)
34 #:use-module (ice-9 ftw)
35 #:use-module (rnrs io ports) ;need 'port-position' etc.
36 #:use-module ((rnrs bytevectors) #:select (bytevector-u8-set!))
37 #:use-module (guix memoization)
38 #:use-module ((guix build utils) #:select (dump-port mkdir-p delete-file-recursively))
39 #:use-module ((guix build syscalls) #:select (mkdtemp! fdatasync))
40 #:use-module (ice-9 format)
41 #:use-module (ice-9 regex)
42 #:use-module (ice-9 match)
43 #:use-module (ice-9 format)
44 #:use-module ((ice-9 iconv) #:prefix iconv:)
45 #:use-module (system foreign)
46 #:re-export (memoize) ; for backwards compatibility
47 #:export (strip-keyword-arguments
48 default-keyword-arguments
49 substitute-keyword-arguments
50 ensure-keyword-arguments
52 current-source-directory
60 source-properties->location
61 location->source-properties
71 nix-system->gnu-triplet
72 gnu-triplet->nix-system
74 %current-target-system
75 package-name->name+version
91 string-replace-substring
94 tarball-sans-extension
97 call-with-temporary-output-file
98 call-with-temporary-directory
99 with-atomic-file-output
101 with-environment-variables
102 arguments-from-environment-variable
113 call-with-decompressed-port
114 compressed-output-port
115 call-with-compressed-output-port
116 canonical-newline-port))
120 ;;; Environment variables.
123 (define (call-with-environment-variables variables thunk)
124 "Call THUNK with the environment VARIABLES set."
125 (let ((environment (environ)))
128 (for-each (match-lambda
130 (setenv variable value)))
134 (environ environment)))))
136 (define-syntax-rule (with-environment-variables variables exp ...)
137 "Evaluate EXP with the given environment VARIABLES set."
138 (call-with-environment-variables variables
139 (lambda () exp ...)))
141 (define (arguments-from-environment-variable variable)
142 "Retrieve value of environment variable denoted by string VARIABLE in the
143 form of a list of strings (`char-set:graphic' tokens) suitable for consumption
144 by `args-fold', if VARIABLE is defined, otherwise return an empty list."
145 (let ((env (getenv variable)))
147 (string-tokenize env char-set:graphic)
152 ;;; Filtering & pipes.
155 (define (filtered-port command input)
156 "Return an input port where data drained from INPUT is filtered through
157 COMMAND (a list). In addition, return a list of PIDs that the caller must
158 wait. When INPUT is a file port, it must be unbuffered; otherwise, any
159 buffered data is lost."
160 (let loop ((input input)
162 (if (file-port? input)
165 (match (primitive-fork)
171 (close-port (current-input-port))
172 (dup2 (fileno input) 0)
173 (close-port (current-output-port))
174 (dup2 (fileno out) 1)
177 (apply execl (car command) command))
179 (format (current-error-port)
180 "filtered-port: failed to execute '~{~a ~}': ~a~%"
181 command (strerror (system-error-errno args))))))
183 (primitive-_exit 1))))
186 (values in (cons child pids))))))
188 ;; INPUT is not a file port, so fork just for the sake of tunneling it
189 ;; through a file port.
192 (match (primitive-fork)
198 (dump-port input out))
201 (false-if-exception (close out))
202 (primitive-_exit 0))))
206 (loop in (cons child pids)))))))))
208 (define (lzip-port proc port . args)
209 "Return the lzip port produced by calling PROC (a symbol) on PORT and ARGS.
210 Raise an error if lzlib support is missing."
211 (let* ((lzlib (false-if-exception (resolve-interface '(guix lzlib))))
212 (supported? (and lzlib
213 ((module-ref lzlib 'lzlib-available?)))))
215 (let ((make-port (module-ref lzlib proc)))
216 (values (make-port port) '()))
217 (error "lzip compression not supported" lzlib))))
219 (define (decompressed-port compression input)
220 "Return an input port where INPUT is decompressed according to COMPRESSION,
221 a symbol such as 'xz."
223 ((or #f 'none) (values input '()))
224 ('bzip2 (filtered-port `(,%bzip2 "-dc") input))
225 ('xz (filtered-port `(,%xz "-dc") input))
226 ('gzip (filtered-port `(,%gzip "-dc") input))
227 ('lzip (values (lzip-port 'make-lzip-input-port input)
229 (_ (error "unsupported compression scheme" compression))))
231 (define (compressed-port compression input)
232 "Return an input port where INPUT is compressed according to COMPRESSION,
233 a symbol such as 'xz."
235 ((or #f 'none) (values input '()))
236 ('bzip2 (filtered-port `(,%bzip2 "-c") input))
237 ('xz (filtered-port `(,%xz "-c") input))
238 ('gzip (filtered-port `(,%gzip "-c") input))
239 ('lzip (values (lzip-port 'make-lzip-input-port/compressed input)
241 (_ (error "unsupported compression scheme" compression))))
243 (define (call-with-decompressed-port compression port proc)
244 "Call PROC with a wrapper around PORT, a file port, that decompresses data
245 read from PORT according to COMPRESSION, a symbol such as 'xz."
246 (let-values (((decompressed pids)
247 (decompressed-port compression port)))
253 (close-port decompressed)
254 (unless (every (compose zero? cdr waitpid) pids)
255 (error "decompressed-port failure" pids))))))
257 (define (filtered-output-port command output)
258 "Return an output port. Data written to that port is filtered through
259 COMMAND and written to OUTPUT, an output file port. In addition, return a
260 list of PIDs to wait for. OUTPUT must be unbuffered; otherwise, any buffered
264 (match (primitive-fork)
270 (close-port (current-input-port))
272 (close-port (current-output-port))
273 (dup2 (fileno output) 1)
276 (apply execl (car command) command))
278 (format (current-error-port)
279 "filtered-output-port: failed to execute '~{~a ~}': ~a~%"
280 command (strerror (system-error-errno args))))))
282 (primitive-_exit 1))))
285 (values out (list child)))))))
287 (define* (compressed-output-port compression output
289 "Return an output port whose input is compressed according to COMPRESSION,
290 a symbol such as 'xz, and then written to OUTPUT. In addition return a list
291 of PIDs to wait for. OPTIONS is a list of strings passed to the compression
292 program--e.g., '(\"--fast\")."
294 ((or #f 'none) (values output '()))
295 ('bzip2 (filtered-output-port `(,%bzip2 "-c" ,@options) output))
296 ('xz (filtered-output-port `(,%xz "-c" ,@options) output))
297 ('gzip (filtered-output-port `(,%gzip "-c" ,@options) output))
298 ('lzip (values (lzip-port 'make-lzip-output-port output)
300 (_ (error "unsupported compression scheme" compression))))
302 (define* (call-with-compressed-output-port compression port proc
304 "Call PROC with a wrapper around PORT, a file port, that compresses data
305 that goes to PORT according to COMPRESSION, a symbol such as 'xz. OPTIONS is
306 a list of command-line arguments passed to the compression program."
307 (let-values (((compressed pids)
308 (compressed-output-port compression port
315 (close-port compressed)
316 (unless (every (compose zero? cdr waitpid) pids)
317 (error "compressed-output-port failure" pids))))))
319 (define* (edit-expression source-properties proc #:key (encoding "UTF-8"))
320 "Edit the expression specified by SOURCE-PROPERTIES using PROC, which should
321 be a procedure that takes the original expression in string and returns a new
322 one. ENCODING will be used to interpret all port I/O, it default to UTF-8.
323 This procedure returns #t on success."
324 (with-fluids ((%default-port-encoding encoding))
325 (let* ((file (assq-ref source-properties 'filename))
326 (line (assq-ref source-properties 'line))
327 (column (assq-ref source-properties 'column))
328 (in (open-input-file file))
329 ;; The start byte position of the expression.
330 (start (begin (while (not (and (= line (port-line in))
331 (= column (port-column in))))
332 (when (eof-object? (read-char in))
333 (error (format #f "~a: end of file~%" in))))
335 ;; The end byte position of the expression.
336 (end (begin (read in) (ftell in))))
337 (seek in 0 SEEK_SET) ; read from the beginning of the file.
338 (let* ((pre-bv (get-bytevector-n in start))
339 ;; The expression in string form.
340 (str (iconv:bytevector->string
341 (get-bytevector-n in (- end start))
343 (post-bv (get-bytevector-all in))
345 ;; Verify the edited expression is still a scheme expression.
346 (call-with-input-string str* read)
347 ;; Update the file with edited expression.
348 (with-atomic-file-output file
350 (put-bytevector out pre-bv)
352 ;; post-bv maybe the end-of-file object.
353 (when (not (eof-object? post-bv))
354 (put-bytevector out post-bv))
359 ;;; Keyword arguments.
362 (define (strip-keyword-arguments keywords args)
363 "Remove all of the keyword arguments listed in KEYWORDS from ARGS."
364 (let loop ((args args)
369 (((? keyword? kw) arg . rest)
371 (if (memq kw keywords)
373 (cons* arg kw result))))
375 (loop tail (cons head result))))))
377 (define (default-keyword-arguments args defaults)
378 "Return ARGS augmented with any keyword/value from DEFAULTS for
379 keywords not already present in ARGS."
380 (let loop ((defaults defaults)
387 (cons* kw value args))))
391 (define-syntax collect-default-args
396 (collect-default-args rest ...))
397 ((_ (kw _ dflt) rest ...)
398 (cons* kw dflt (collect-default-args rest ...)))))
400 (define-syntax substitute-keyword-arguments
402 "Return a new list of arguments where the value for keyword arg KW is
403 replaced by EXP. EXP is evaluated in a context where VAR is bound to the
404 previous value of the keyword argument, or DFLT if given."
405 ((_ original-args ((kw var dflt ...) exp) ...)
406 (let loop ((args (default-keyword-arguments
408 (collect-default-args (kw var dflt ...) ...)))
411 ((kw var rest (... ...))
412 (loop rest (cons* exp kw before)))
415 (loop rest (cons x before)))
417 (reverse before)))))))
419 (define (delkw kw lst)
420 "Remove KW and its associated value from LST, a keyword/value list such
421 as '(#:foo 1 #:bar 2)."
427 ((kw? value rest ...)
429 (append (reverse result) rest)
430 (loop rest (cons* value kw? result)))))))
432 (define (ensure-keyword-arguments args kw/values)
433 "Force the keywords arguments KW/VALUES in the keyword argument list ARGS.
436 (ensure-keyword-arguments '(#:foo 2) '(#:foo 2))
439 (ensure-keyword-arguments '(#:foo 2) '(#:bar 3))
442 (ensure-keyword-arguments '(#:foo 2) '(#:bar 3 #:foo 42))
443 => (#:foo 42 #:bar 3)
445 (let loop ((args args)
446 (kw/values kw/values)
450 (append (reverse result) kw/values))
452 (match (memq kw kw/values)
454 (loop rest (delkw kw kw/values) (cons* value kw result)))
456 (loop rest kw/values (cons* value kw result))))))))
463 (define* (nix-system->gnu-triplet
464 #:optional (system (%current-system)) (vendor "unknown"))
465 "Return a guess of the GNU triplet corresponding to Nix system
469 (string-append "arm-" vendor "-linux-gnueabihf"))
471 (let* ((dash (string-index system #\-))
472 (arch (substring system 0 dash))
473 (os (substring system (+ 1 dash))))
476 (if (string=? os "linux")
480 (define (gnu-triplet->nix-system triplet)
481 "Return the Nix system type corresponding to TRIPLET, a GNU triplet as
482 returned by `config.guess'."
483 (let ((triplet (cond ((string-match "^i[345]86-(.*)$" triplet)
486 (string-append "i686-" (match:substring m 1))))
488 (cond ((string-match "^arm[^-]*-([^-]+-)?linux-gnueabihf" triplet)
490 ((string-match "^([^-]+)-([^-]+-)?linux-gnu.*" triplet)
493 ;; Nix omits `-gnu' for GNU/Linux.
494 (string-append (match:substring m 1) "-linux")))
495 ((string-match "^([^-]+)-([^-]+-)?([[:alpha:]]+)([0-9]+\\.?)*$" triplet)
498 ;; Nix strip the version number from names such as `gnu0.3',
499 ;; `darwin10.2.0', etc., and always strips the vendor part.
500 (string-append (match:substring m 1) "-"
501 (match:substring m 3))))
504 (define %current-system
505 ;; System type as expected by Nix, usually ARCHITECTURE-KERNEL.
506 ;; By default, this is equal to (gnu-triplet->nix-system %host-type).
507 (make-parameter %system))
509 (define %current-target-system
510 ;; Either #f or a GNU triplet representing the target system we are
511 ;; cross-building to.
514 (define* (package-name->name+version spec
515 #:optional (delimiter #\@))
516 "Given SPEC, a package name like \"foo@0.9.1b\", return two values: \"foo\"
517 and \"0.9.1b\". When the version part is unavailable, SPEC and #f are
518 returned. Both parts must not contain any '@'. Optionally, DELIMITER can be
519 a character other than '@'."
520 (match (string-rindex spec delimiter)
521 (#f (values spec #f))
522 (idx (values (substring spec 0 idx)
523 (substring spec (1+ idx))))))
525 (define* (target-mingw? #:optional (target (%current-target-system)))
527 (string-suffix? "-mingw32" target)))
529 (define* (target-arm32? #:optional (target (or (%current-target-system)
531 (string-prefix? "arm" target))
533 (define* (target-aarch64? #:optional (target (or (%current-target-system)
535 (string-prefix? "aarch64" target))
537 (define* (target-arm? #:optional (target (or (%current-target-system)
539 (or (target-arm32? target) (target-aarch64? target)))
541 (define* (target-64bit? #:optional (system (or (%current-target-system)
543 (any (cut string-prefix? <> system) '("x86_64" "aarch64" "mips64" "ppc64")))
545 (define* (cc-for-target #:optional (target (%current-target-system)))
547 (string-append target "-gcc")
550 (define version-compare
552 (let ((sym (or (dynamic-func "strverscmp" (dynamic-link))
553 (error "could not find `strverscmp' (from GNU libc)"))))
554 (pointer->procedure int sym (list '* '*)))))
556 "Return '> when A denotes a newer version than B,
557 '< when A denotes a older version than B,
558 or '= when they denote equal versions."
559 (let ((result (strverscmp (string->pointer a) (string->pointer b))))
560 (cond ((positive? result) '>)
561 ((negative? result) '<)
564 (define (version-prefix version-string num-parts)
565 "Truncate version-string to the first num-parts components of the version.
566 For example, (version-prefix \"2.1.47.4.23\" 3) returns \"2.1.47\""
567 (string-join (take (string-split version-string #\.) num-parts) "."))
570 (define (version-major+minor version-string)
571 "Return \"<major>.<minor>\", where major and minor are the major and
572 minor version numbers from version-string."
573 (version-prefix version-string 2))
575 (define (version-major version-string)
576 "Return the major version number as string from the version-string."
577 (version-prefix version-string 1))
579 (define (version>? a b)
580 "Return #t when A denotes a version strictly newer than B."
581 (eq? '> (version-compare a b)))
583 (define (version>=? a b)
584 "Return #t when A denotes a version newer or equal to B."
585 (case (version-compare a b)
589 (define (guile-version>? str)
590 "Return #t if the running Guile version is greater than STR."
591 ;; Note: Using (version>? (version) "2.0.5") or similar doesn't work,
592 ;; because the result of (version) can have a prefix, like "2.0.5-deb1".
593 (version>? (string-append (major-version) "."
598 (define version-prefix?
599 (let ((not-dot (char-set-complement (char-set #\.))))
601 "Return true if V1 is a version prefix of V2:
603 (version-prefix? \"4.1\" \"4.16.2\") => #f
604 (version-prefix? \"4.1\" \"4.1.2\") => #t
606 (define (list-prefix? lst1 lst2)
613 (and (equal? head1 head2)
614 (list-prefix? tail1 tail2)))))))
616 (list-prefix? (string-tokenize v1 not-dot)
617 (string-tokenize v2 not-dot)))))
624 (define (file-extension file)
625 "Return the extension of FILE or #f if there is none."
626 (let ((dot (string-rindex file #\.)))
627 (and dot (substring file (+ 1 dot) (string-length file)))))
629 (define (file-sans-extension file)
630 "Return the substring of FILE without its extension, if any."
631 (let ((dot (string-rindex file #\.)))
633 (substring file 0 dot)
636 (define (tarball-sans-extension tarball)
637 "Return TARBALL without its .tar.* or .zip extension."
638 (let ((end (or (string-contains tarball ".tar")
639 (string-contains tarball ".zip"))))
640 (substring tarball 0 end)))
642 (define (compressed-file? file)
643 "Return true if FILE denotes a compressed file."
644 (->bool (member (file-extension file)
645 '("gz" "bz2" "xz" "lz" "lzma" "tgz" "tbz2" "zip"))))
647 (define (switch-symlinks link target)
648 "Atomically switch LINK, a symbolic link, to point to TARGET. Works
649 both when LINK already exists and when it does not."
650 (let ((pivot (string-append link ".new")))
651 (symlink target pivot)
652 (rename-file pivot link)))
654 (define* (string-replace-substring str substr replacement
657 (end (string-length str)))
658 "Replace all occurrences of SUBSTR in the START--END range of STR by
660 (match (string-length substr)
662 (error "string-replace-substring: empty substring"))
664 (let loop ((start start)
665 (pieces (list (substring str 0 start))))
666 (match (string-contains str substr start end)
668 (string-concatenate-reverse
669 (cons (substring str start) pieces)))
671 (loop (+ index substr-length)
673 (substring str start index)
676 (define (call-with-temporary-output-file proc)
677 "Call PROC with a name of a temporary file and open output port to that
678 file; close the file and delete it when leaving the dynamic extent of this
680 (let* ((directory (or (getenv "TMPDIR") "/tmp"))
681 (template (string-append directory "/guix-file.XXXXXX"))
682 (out (mkstemp! template)))
689 (false-if-exception (close out))
690 (false-if-exception (delete-file template))))))
692 (define (call-with-temporary-directory proc)
693 "Call PROC with a name of a temporary directory; close the directory and
694 delete it when leaving the dynamic extent of this call."
695 (let* ((directory (or (getenv "TMPDIR") "/tmp"))
696 (template (string-append directory "/guix-directory.XXXXXX"))
697 (tmp-dir (mkdtemp! template)))
703 (false-if-exception (delete-file-recursively tmp-dir))))))
705 (define (with-atomic-file-output file proc)
706 "Call PROC with an output port for the file that is going to replace FILE.
707 Upon success, FILE is atomically replaced by what has been written to the
708 output port, and PROC's result is returned."
709 (let* ((template (string-append file ".XXXXXX"))
710 (out (mkstemp! template)))
711 (with-throw-handler #t
713 (let ((result (proc out)))
716 (rename-file template file)
719 (false-if-exception (delete-file template))
722 (define* (xdg-directory variable suffix #:key (ensure? #t))
723 "Return the name of the XDG directory that matches VARIABLE and SUFFIX,
724 after making sure that it exists if ENSURE? is true. VARIABLE is an
725 environment variable name like \"XDG_CONFIG_HOME\"; SUFFIX is a suffix like
726 \"/.config\". Honor the XDG specs,
727 <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>."
728 (let ((dir (and=> (or (getenv variable)
729 (and=> (or (getenv "HOME")
730 (passwd:dir (getpwuid (getuid))))
731 (cut string-append <> suffix)))
732 (cut string-append <> "/guix"))))
737 (define config-directory
738 (cut xdg-directory "XDG_CONFIG_HOME" "/.config" <...>))
740 (define cache-directory
741 (cut xdg-directory "XDG_CACHE_HOME" "/.cache" <...>))
743 (define (readlink* file)
744 "Call 'readlink' until the result is not a symlink."
745 (define %max-symlink-depth 50)
747 (let loop ((file file)
749 (define (absolute target)
750 (if (absolute-file-name? target)
752 (string-append (dirname file) "/" target)))
754 (if (>= depth %max-symlink-depth)
760 (values #t (readlink file)))
762 (let ((errno (system-error-errno args)))
763 (if (or (= errno EINVAL))
765 (apply throw args))))))
766 (lambda (success? target)
768 (loop (absolute target) (+ depth 1))
771 (define (canonical-newline-port port)
772 "Return an input port that wraps PORT such that all newlines consist
773 of a single linefeed."
774 (define (get-position)
775 (if (port-has-port-position? port) (port-position port) #f))
776 (define (set-position! position)
777 (if (port-has-set-port-position!? port)
778 (set-port-position! position port)
780 (define (close) (close-port port))
781 (define (read! bv start n)
783 (byte (get-u8 port)))
784 (cond ((eof-object? byte) count)
785 ;; XXX: consume all CRs even if not followed by LF.
786 ((eqv? byte (char->integer #\return)) (loop count (get-u8 port)))
788 (bytevector-u8-set! bv (+ start count) byte)
791 (bytevector-u8-set! bv (+ start count) byte)
792 (loop (+ count 1) (get-u8 port))))))
793 (make-custom-binary-input-port "canonical-newline-port"
803 (define absolute-dirname
804 ;; Memoize to avoid repeated 'stat' storms from 'search-path'.
806 "Return the absolute name of the directory containing FILE, or #f upon
808 (match (search-path %load-path file)
811 ;; If there are relative names in %LOAD-PATH, FILE can be relative and
812 ;; needs to be canonicalized.
813 (if (string-prefix? "/" file)
815 (canonicalize-path (dirname file)))))))
817 (define-syntax current-source-directory
819 "Return the absolute name of the current directory, or #f if it could not
823 (match (assq 'filename (or (syntax-source s) '()))
824 (('filename . (? string? file-name))
825 ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME
826 ;; can be relative. In that case, we try to find out at run time
827 ;; the absolute file name by looking at %LOAD-PATH; doing this at
828 ;; run time rather than expansion time is necessary to allow files
829 ;; to be moved on the file system.
830 (if (string-prefix? "/" file-name)
832 #`(absolute-dirname #,file-name)))
833 ((or ('filename . #f) #f)
834 ;; raising an error would upset Geiser users
837 ;; A source location.
838 (define-record-type <location>
839 (make-location file line column)
841 (file location-file) ; file name
842 (line location-line) ; 1-indexed line
843 (column location-column)) ; 0-indexed column
845 (define (location file line column)
846 "Return the <location> object for the given FILE, LINE, and COLUMN."
847 (and line column file
848 (make-location file line column)))
850 (define (source-properties->location loc)
851 "Return a location object based on the info in LOC, an alist as returned
852 by Guile's `source-properties', `frame-source', `current-source-location',
854 ;; In accordance with the GCS, start line and column numbers at 1. Note
855 ;; that unlike LINE and `port-column', COL is actually 1-indexed here...
857 ((('line . line) ('column . col) ('filename . file)) ;common case
859 (make-location file (+ line 1) col)))
863 (let ((file (assq-ref loc 'filename))
864 (line (assq-ref loc 'line))
865 (col (assq-ref loc 'column)))
866 (location file (and line (+ line 1)) col)))))
868 (define (location->source-properties loc)
869 "Return the source property association list based on the info in LOC,
871 `((line . ,(and=> (location-line loc) 1-))
872 (column . ,(location-column loc))
873 (filename . ,(location-file loc))))
875 (define-condition-type &error-location &error
877 (location error-location)) ;<location>
879 (define-condition-type &fix-hint &condition
881 (hint condition-fix-hint)) ;string
884 ;;; eval: (put 'call-with-progress-reporter 'scheme-indent-function 1)