~ chicken-core (chicken-5) /egg-information.scm
Trap1;;; loading and accessing egg-information2;3; Copyright (c) 2017-2022, The CHICKEN Team4; All rights reserved.5;6; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following7; conditions are met:8;9; Redistributions of source code must retain the above copyright notice, this list of conditions and the following10; disclaimer.11; Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following12; 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 promote14; 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 EXPRESS17; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY18; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR19; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR20; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR21; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY22; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR23; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE24; POSSIBILITY OF SUCH DAMAGE.252627;;; load egg-info from file and perform validation2829(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)))3536(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)))424344;;; lookup specific toplevel properties of egg-information4546(define (get-egg-property info prop #!optional default)47 (let ((p (assq prop info)))48 (or (and p (cadr p)) default)))4950(define (get-egg-property* info prop #!optional (default '()))51 (let ((p (assq prop info)))52 (or (and p (cdr p)) default)))535455;;; lookup specific properties for specific extensions5657(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))8586(define (get-extension-property info ext prop #!optional default host)87 (get-extension-property/internal info ext prop cadr default host))8889(define (get-extension-property* info ext prop #!optional default host)90 (get-extension-property/internal info ext prop cdr default host))