-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.rkt
53 lines (41 loc) · 1.7 KB
/
main.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#lang racket/base
(require racket/path
racket/contract
(prefix-in js-vm: "js-vm/main.rkt")
"js-vm/private/misc.rkt"
"js-vm/private/log-port.rkt"
"src/android/android-packager.ss")
(provide/contract
[create-android-phone-package (path-string? path-string? . -> . any)]
[run-in-browser (path-string? . -> . any)])
;; make-package-name: path -> string
(define (make-package-name a-path)
(let-values ([(base name dir?)
(split-path a-path)])
(remove-filename-extension name)))
;; At the moment, reuse js-vm's run-in-browser. We may need to do some extra
;; work to add mock classes for cell-phone functionality.
(define run-in-browser js-vm:run-in-browser)
;; create-android-phone-package: path-string path-string -> void
;;
;; Compiles a-filename into an android package, and write it
;; out at the given output-file path.
(define (create-android-phone-package a-filename output-file)
(let ([a-filename (normalize-path a-filename)]
[output-file (normalize-path output-file)])
(with-handlers
([exn:fail?
(lambda (exn)
(log-warning (format "An internal error occurred during compilation: ~a\n"
(exn-message exn)))
(raise exn))])
(call-with-output-file output-file
(lambda (op)
(log-info (format "Writing package to file ~a...\n" output-file))
(log-info (format "This may take up to a minute. Please wait...\n"))
(write-bytes (build-android-package
(make-package-name output-file)
a-filename)
op))
#:exists 'replace)
(log-info "Done!\n"))))