1 ;;; api-diff --- diff guile-api.alist files
3 ;; Copyright (C) 2002, 2006, 2011 Free Software Foundation, Inc.
5 ;; This program is free software; you can redistribute it and/or
6 ;; modify it under the terms of the GNU Lesser General Public License
7 ;; as published by the Free Software Foundation; either version 3, or
8 ;; (at your option) any later version.
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;; Lesser General Public License for more details.
15 ;; You should have received a copy of the GNU Lesser General Public
16 ;; License along with this software; see the file COPYING.LESSER. If
17 ;; not, write to the Free Software Foundation, Inc., 51 Franklin
18 ;; Street, Fifth Floor, Boston, MA 02110-1301 USA
20 ;;; Author: Thien-Thi Nguyen <ttn@gnu.org>
24 ;; Usage: api-diff [-d GROUPS] ALIST-FILE-A ALIST-FILE-B
26 ;; Read in the alists from files ALIST-FILE-A and ALIST-FILE-B
27 ;; and display a (count) summary of the groups defined therein.
28 ;; Optional arg "--details" (or "-d") specifies a comma-separated
29 ;; list of groups, in which case api-diff displays instead the
30 ;; elements added and deleted for each of the specified groups.
32 ;; For scheme programming, this module exports the proc:
33 ;; (api-diff A-file B-file)
35 ;; Note that the convention is that the "older" alist/file is
38 ;; TODO: Develop scheme interface.
42 (define-module (scripts api-diff)
43 :use-module (ice-9 common-list)
44 :use-module (ice-9 format)
45 :use-module (ice-9 getopt-long)
46 :autoload (srfi srfi-13) (string-tokenize)
49 (define %include-in-guild-list #f)
50 (define %summary "Show differences between two scan-api files.")
52 (define (read-alist-file file)
53 (with-input-from-file file
56 (define put set-object-property!)
57 (define get object-property)
59 (define (read-api-alist-file file)
60 (let* ((alist (read-alist-file file))
61 (meta (assq-ref alist 'meta))
62 (interface (assq-ref alist 'interface)))
63 (put interface 'meta meta)
64 (put interface 'groups (let ((ht (make-hash-table 31)))
65 (for-each (lambda (group)
66 (hashq-set! ht group '()))
67 (assq-ref meta 'groups))
71 (define (hang-by-the-roots interface)
72 (let ((ht (get interface 'groups)))
74 (for-each (lambda (group)
77 (hashq-ref ht group))))
78 (assq-ref x 'groups)))
83 (let ((result (set-difference a b)))
85 #f ; CL weenies bite me
88 (define (diff+note! a b note-removals note-additions note-same)
90 (cond ((diff? a b) => (lambda (x) (note-removals x) (set! same? #f))))
91 (cond ((diff? b a) => (lambda (x) (note-additions x) (set! same? #f))))
92 (and same? (note-same))))
94 (define (group-diff i-old i-new . options)
95 (let* ((i-old (hang-by-the-roots i-old))
96 (g-old (hash-fold acons '() (get i-old 'groups)))
97 (g-old-names (map car g-old))
98 (i-new (hang-by-the-roots i-new))
99 (g-new (hash-fold acons '() (get i-new 'groups)))
100 (g-new-names (map car g-new)))
101 (cond ((null? options)
102 (diff+note! g-old-names g-new-names
104 (format #t "groups-removed: ~A\n" removals))
106 (format #t "groups-added: ~A\n" additions))
108 (for-each (lambda (group)
109 (let* ((old (assq-ref g-old group))
110 (new (assq-ref g-new group))
111 (old-count (and old (length old)))
112 (new-count (and new (length new)))
113 (delta (and old new (- new-count old-count))))
114 (format #t " ~5@A ~5@A : "
118 (let ((add-count 0) (sub-count 0))
122 (set! sub-count (length subs)))
124 (set! add-count (length adds)))
126 (format #t "~5@D ~5@D : ~5@D"
127 add-count (- sub-count) delta)))
129 (format #t "~5@A ~5@A : ~5@A" "-" "-" "-")))
130 (format #t " ~A\n" group)))
131 (sort (union g-old-names g-new-names)
133 (string<? (symbol->string a)
134 (symbol->string b))))))
135 ((assq-ref options 'details)
137 (for-each (lambda (group)
138 (let* ((old (or (assq-ref g-old group) '()))
139 (new (or (assq-ref g-new group) '()))
140 (>>! (lambda (label ls)
141 (format #t "~A ~A:\n" group label)
142 (for-each (lambda (x)
143 (format #t " ~A\n" x))
147 (>>! 'removals removals))
149 (>>! 'additions additions))
151 (format #t "~A: no changes\n"
155 (error "api-diff: group-diff: bad options")))))
157 (define (api-diff . args)
158 (let* ((p (getopt-long (cons 'api-diff args)
159 '((details (single-char #\d)
163 (rest (option-ref p '() '("/dev/null" "/dev/null")))
164 (i-old (read-api-alist-file (car rest)))
165 (i-new (read-api-alist-file (cadr rest)))
167 (cond ((option-ref p 'details #f)
169 (set! options (cons (cons 'details
175 (apply group-diff i-old i-new options)))
177 (define main api-diff)
179 ;;; api-diff ends here