forked from greghendershott/frog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefer using setup/getinfo plus more fallbacks; fixes greghendershott…
…#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
1 parent
2836c79
commit 0d4625a
Showing
2 changed files
with
45 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |