Skip to content

Commit

Permalink
Prefer using setup/getinfo plus more fallbacks; fixes greghendershott…
Browse files Browse the repository at this point in the history
…#253

Try to find the 'version from the package info.rkt in a variety of
ways. As the final fallback, say that the version can't be found.

I suspect that ultimate fallback might be used in the scenario for
issue greghendershott#253. Why? The _package_ info.rkt data might not even exist for
a prebuilt package (maybe just one for the _collection_)?

I think a generic "version not found" message (instead of an abend)
will suffice for the issue greghendershott#253 scenario, where someone is using Frog
via CI. Justification: What matters most is that it not abend
unnecessarily -- not that some version number is printed.
  • Loading branch information
greghendershott committed Dec 18, 2019
1 parent 2836c79 commit 0d4625a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
12 changes: 1 addition & 11 deletions frog/private/main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
racket/file
racket/function
racket/match
racket/path ;moved to racket/base only as of Racket 6
racket/runtime-path
racket/set
racket/vector
rackjure/threading
Expand All @@ -30,6 +28,7 @@
"tags.rkt"
(except-in "util.rkt" path-get-extension)
"verbosity.rkt"
"version.rkt"
"watch-dir.rkt")

(provide main
Expand Down Expand Up @@ -173,15 +172,6 @@
(and x (simplify-path x)))
(current-directory)))

(define-runtime-path info.rkt "../../info.rkt")
(define (frog-version)
;; Because (require "../info.rkt") (#%info-lookup version) errors in
;; some cases with Racket 6, resort to regexp-ing info.rkt as text.
(match (file->string info.rkt #:mode 'text)
[(pregexp "^#lang info\n+\\(define version \"([^\"]+)\""
(list _ v))
v]))

(define (init-project)
(define (copy path)
(define from (~> (build-path example path) simplify-path))
Expand Down
44 changes: 44 additions & 0 deletions frog/private/version.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#lang racket/base

(require racket/file
racket/match
racket/path
racket/runtime-path
setup/getinfo
(for-syntax racket/base syntax/parse))

(provide frog-version)

(define (frog-version)
(trying (version-from-get-info)
(version-from-info.txt-file)
"version can't be found from package info.rkt"))

(define (version-from-get-info)
((get-info/full "frog") 'version))

;; As fallback for some older versions of Racket, try the ugly hack of
;; regexp-ing info.rkt as text.
(define-runtime-path info.rkt "../../info.rkt")
(define (version-from-info.txt-file . _)
(match (file->string info.rkt #:mode 'text)
[(pregexp "^#lang info\n+\\(define version \"([^\"]+)\""
(list _ v))
v]))

;;; trying

(define-syntax (trying stx)
(syntax-parse stx
[(_ e:expr)
#'e]
[(_ e:expr more:expr ...)
#'(with-handlers ([exn:fail? (λ _ (trying more ...))])
e)]))

(module+ test
(require rackunit)
(check-equal? (trying 42) 42)
(check-equal? (trying (error '0) 42) 42)
(check-equal? (trying (error '0) (error '1) 42) 42)
(check-equal? (trying 42 (error '0)) 42))

0 comments on commit 0d4625a

Please sign in to comment.