Skip to content

Instantly share code, notes, and snippets.

@jbclements
Created August 8, 2020 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbclements/6b1432b468c39985d740c87e5e06914a to your computer and use it in GitHub Desktop.
Save jbclements/6b1432b468c39985d740c87e5e06914a to your computer and use it in GitHub Desktop.
#lang racket
;; filter the lines in "installer-data" as indicated in the release
;; checklist.
;; filter out lines that match a predicate, report on the remaining set
(define (filter-out description pred l)
(define new-l (filter (compose not pred) l))
(printf "discarding these ~v:\n" description)
(pretty-print (set-subtract l new-l))
(printf "remaining lines: ~v\n" (length new-l))
new-l)
;; a line contains a size, a tab, and a path:
(define (line-path l)
(match l
[(regexp #px"^[0-9]+\t(.*)$" (list _ path)) path]
[other (error 'line-path "unexpected line format: ~e" l)]))
;; 1) Remove non-installers:
(define ignored-extensions
(list "ico" "png" "rktd" "html" "htaccess" "txt"))
(define (ignored-extension? str) (member str ignored-extensions))
(define (non-installer? line)
(match-define (list _ extension)
(regexp-match #px"\\.([^.]*)$" (line-path line)))
(ignored-extension? extension))
;; 2) remove natipkg builds
(define (natipkg? l)
(regexp-match? #px"-natipkg" (line-path l)))
;; 3) remove win/mac/linux tgz builds
(define (win-mac-linux-tgz? l)
(regexp-match? #px"(macos|windows|linux).*tgz$" (line-path l)))
;; 4) put CS builds later
(define (has-cs? l)
(regexp-match #px"-cs" (line-path l)))
(define (cs<? a b)
(cond [(and (not (has-cs? a)) (has-cs? b)) #t]
[else #f]))
(define (go input-file output-file)
(define lines (file->lines input-file))
(printf "lines in installer-data: ~v\n" (length lines))
(define output-lines
(sort
(filter-out
"win/mac/linux tgz installers" win-mac-linux-tgz?
(filter-out
"natipkg installers" natipkg?
(filter-out
"non-installers" non-installer? lines)))
cs<?))
(call-with-output-file output-file
#:exists 'truncate
(λ (port)
(for-each (λ (l) (displayln l port)) output-lines))))
(module+ main
(command-line #:args (input-file output-file)
(go input-file output-file)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment