~ chicken-core (chicken-5) /egg-information.scm
Trap1;;; loading and accessing egg-information
2;
3; Copyright (c) 2017-2022, The CHICKEN Team
4; All rights reserved.
5;
6; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
7; conditions are met:
8;
9; Redistributions of source code must retain the above copyright notice, this list of conditions and the following
10; disclaimer.
11; Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
12; disclaimer in the documentation and/or other materials provided with the distribution.
13; Neither the name of the author nor the names of its contributors may be used to endorse or promote
14; products derived from this software without specific prior written permission.
15;
16; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24; POSSIBILITY OF SUCH DAMAGE.
25
26
27;;; load egg-info from file and perform validation
28
29(define (locate-egg-file fname)
30 (let ((fname* (make-pathname (make-pathname (pathname-directory fname)
31 "chicken")
32 (pathname-file fname)
33 (pathname-extension fname))))
34 (if (file-exists? fname*) fname* fname)))
35
36(define (load-egg-info fname)
37 (let* ((fname (locate-egg-file fname))
38 (info (with-input-from-file fname read)))
39 (if (eof-object? info)
40 (error "empty egg-info file, possibly due to an aborted egg-install - please remove the file and reinstall the corresponding egg" fname)
41 info)))
42
43
44;;; lookup specific toplevel properties of egg-information
45
46(define (get-egg-property info prop #!optional default)
47 (let ((p (assq prop info)))
48 (or (and p (cadr p)) default)))
49
50(define (get-egg-property* info prop #!optional (default '()))
51 (let ((p (assq prop info)))
52 (or (and p (cdr p)) default)))
53
54
55;;; lookup specific properties for specific extensions
56
57(define (get-extension-property/internal info ext prop get default host)
58 (define (find-prop exp)
59 (and (not (null? exp))
60 (case (caar exp)
61 ((target)
62 (or (and (not host) (find-prop (cdar exp)))
63 (find-prop (cdr exp))))
64 ((host)
65 (or (and host (find-prop (cdar exp)))
66 (find-prop (cdr exp))))
67 (else (if (eq? prop (caar exp))
68 (car exp)
69 (find-prop (cdr exp)))))))
70 (or (let walk ((p (cdr (assq 'components info))))
71 (and (not (null? p))
72 (case (caar p)
73 ((target)
74 (or (and (not host) (walk (cdar p)))
75 (walk (cdr p))))
76 ((host)
77 (or (and host (walk (cdar p)))
78 (walk (cdr p))))
79 ((extension)
80 (and (eq? ext (cadar p))
81 (let ((p (find-prop (caddr p))))
82 (and p (get p)))))
83 (else (walk (cdr p))))))
84 default))
85
86(define (get-extension-property info ext prop #!optional default host)
87 (get-extension-property/internal info ext prop cadr default host))
88
89(define (get-extension-property* info ext prop #!optional default host)
90 (get-extension-property/internal info ext prop cdr default host))