14 (define ref assoc-ref)
16 (define (sref alist key)
17 ;; Used to reach b in pairs like (a . (b))
18 (anif ((ref alist key) := t)
22 (define (printf str . args)
23 (display (apply format (cons str args))))
27 ((symbol? x) (symbol->string x))
28 ((number? x) (number->string x))
31 (define (module-name->string module)
33 (string-join (map ->string module) "-")
36 (define (normalize-deps deps)
37 (map (compose module-name->string car) deps))
39 (define (parse-license license)
40 (let ((res (with-input-from-string license read)))
42 (map (compose string-downcase ->string)
43 (filter (lambda (sym) (not (eq? sym 'AND))) res))
44 (string-downcase (->string res)))))
46 (define (parse-version-info alist)
47 (let* ((lock (ref alist 'lock))
48 (url (sref (ref lock 'location) 'url))
49 (sha256 (sref (ref lock 'content) 'sha256))
50 (depends (normalize-deps (ref alist 'depends)))
52 (anif ((ref alist 'depends/dev) := t)
55 (license (parse-license (sref alist 'license))))
56 (append `((license ,license)
60 (dev-depends ,dev-depends))
63 (define (format-list lst)
68 (apply string-join (list (map surround lst) ", "))
71 (define (write-package sexp)
72 (let* ((latest (parse-version-info (last (ref sexp 'versions))))
73 (license (sref latest 'license))
74 (url (sref latest 'url)))
75 (printf "[~a]\n" (module-name->string (sref sexp 'name)))
76 (printf "dependencies = ~a\n" (format-list (sref latest 'depends)))
77 (printf "dev-dependencies = ~a\n" (format-list (sref latest 'dev-depends)))
79 (printf "license = ~a\n" (format-list license))
80 (printf "license = ~s\n" license))
81 (printf "url = ~s\n" url)
82 (printf "sha256 = ~s\n" (sref latest 'sha256))
86 ;; because #f could be returned
87 ((eqv? 0 (string-contains url "https://archive.akkuscm.org/")) "akku")
88 ((eqv? 0 (string-contains url "http://snow-fort.org/")) "snow-fort")
90 (anif ((sref latest 'synopsis) := t)
91 (printf "synopsis = ~s\n" t))
92 (printf "version = ~s\n" (sref latest 'version))
93 (anif ((sref latest 'hompeage) := t)
94 (printf "homepage = ~s\n" t))
101 (write-package (cdr res))
105 (define (read-meta meta)
106 (with-input-from-file meta read))
108 (define (find-definition meta sym)
110 ;; (define sym definition ...)
112 (cddr (find (lambda (a)
114 (eq? (car a) 'define)
118 (define (installed-libraries meta)
120 ;; ((quote ((chibi diff) (chibi diff-test))))
122 (cadar (find-definition meta 'installed-libraries)))
124 (define (installed-assets meta)
125 (cadar (find-definition meta 'installed-assets)))
127 (define (main-merge name version self-path . rest-paths)
128 (let* ((self (read-meta self-path))
129 (metas (map read-meta (cons self-path rest-paths)))
130 (joined-libraries (append-map installed-libraries metas))
131 (joined-assets (append-map installed-assets metas)))
132 (set-car! (find-definition self 'installed-libraries)
133 `',(delete-duplicates joined-libraries))
134 (set-car! (find-definition self 'installed-assets)
135 `',(delete-duplicates joined-assets))
136 (set-car! (find-definition self 'main-package-name)
138 (set-car! (find-definition self 'main-package-version)
142 (case (string->symbol (cadr (command-line)))
147 (pretty-print (apply main-merge (cddr (command-line)))))
149 (display "mode not found")