-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig-client.rkt
137 lines (113 loc) · 6.03 KB
/
config-client.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
;; The MIT License (MIT)
;;
;; Copyright (c) 2013 Matthew C. Jadud
;;
;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;;
;; The above copyright notice and this permission notice shall be included in
;; all copies or substantial portions of the Software.
;;
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
;; THE SOFTWARE.
#lang racket
(provide client-config%)
(require "config.rkt"
"util.rkt"
"debug.rkt")
(define client-config%
(class config%
(super-new)
(define (bp cmd)
(build-path (send this get-config 'BINPATH) cmd))
(define (occam-lib-path lib)
(build-path (send this get-config 'LIBPATH) (format "~a.lib" lib)))
(define (load-macosx-client-config)
(send this add-config 'HOST-TYPE (system-type))
;; This should give us the root of the Plumb.app
(send this add-config 'APP-ROOT (find-system-path 'run-file))
;; When we are inside a .app bundle, set the contents path
;; one way. When we're running from the command line (which
;; is primarily a development activity), change things around.
(debug 'CONFIG "APP-ROOT is [~a]" (send this get-config 'APP-ROOT))
(cond
;; FIXME: THis should not be in two places (mac and win setup)
;; We're in an app bundle
[(and (regexp-match ".app" (->string (send this get-config 'APP-ROOT)))
;; but we're not running under DrRacket
(not (regexp-match "DrRacket.app" (->string (send this get-config 'APP-ROOT))))
)
(send this add-config 'CONTENTS (build-path
(extract-filedir (send this get-config 'APP-ROOT))
'up
))]
[else
(send this add-config 'APP-ROOT (current-directory))
(send this add-config 'CONTENTS (send this get-config 'APP-ROOT))])
(send this add-config 'BINPATH (build-path
(send this get-config 'CONTENTS)
"client-config"
(->string (send this get-config 'HOST-TYPE))
"bin"))
(send this add-config 'CONFPATH (build-path
(send this get-config 'CONTENTS)
"client-config"
(->string (send this get-config 'HOST-TYPE))
"conf"))
;; This will have to change for Windows. Actually, for the GUI app in general.
(send this add-config 'AVRDUDE.CONF (build-path (send this get-config 'CONFPATH)
"avrdude.conf"))
(send this add-config 'AVRDUDE (build-path (send this get-config 'BINPATH)
"avrdude"))
(debug 'CONFIG "Mac Config: ~a~n" (send this get-data))
)
(define (load-windows-client-config)
(send this add-config 'HOST-TYPE (system-type))
;; This should give us the root of the Plumb.app
(send this add-config 'APP-ROOT (find-system-path 'run-file))
;; When we are inside a .app bundle, set the contents path
;; one way. When we're running from the command line (which
;; is primarily a development activity), change things around.
(debug 'CONFIG "APP-ROOT is [~a]" (send this get-config 'APP-ROOT))
(cond
;; We're in an app bundle
[(and (regexp-match "Plumb.app" (->string (send this get-config 'APP-ROOT)))
;; but we're not running under DrRacket
;(not (regexp-match "DrRacket.app" (->string (send this get-config 'APP-ROOT))))
)
(send this add-config 'CONTENTS (build-path
(send this get-config 'APP-ROOT)
))]
[else
(send this add-config 'APP-ROOT (current-directory))
(send this add-config 'CONTENTS (send this get-config 'APP-ROOT))])
(send this add-config 'BINPATH (build-path (send this get-config 'CONTENTS)
"client-config"
"windows"
"bin"))
(send this add-config 'CONFPATH (build-path (send this get-config 'CONTENTS)
"client-config"
"windows"
"conf"))
(send this add-config 'AVRDUDE.CONF (build-path (send this get-config 'CONFPATH)
"avrdude.conf"))
(send this add-config 'AVRDUDE (build-path (send this get-config 'BINPATH)
"avrdude.exe"))
(debug 'CONFIG "Windows Config: ~a~n" (send this get-data))
)
;; Load the correct config, based on our
;; platform.
(case (->sym (system-type))
[(mac osx macosx) (load-macosx-client-config)]
[(windows) (load-windows-client-config)]
)
))