@@ -12,23 +12,22 @@ Options:
12
12
--nim:path use the specified NimSkull compiler
13
13
14
14
Commands:
15
- all [args] builds all programs
16
- single <name> [args ] builds the single program with the given name
17
- generate [ dir] generates the various language-related modules
15
+ build <program> [<arg> ...] builds a program, using the given compiler args
16
+ build all [<arg> ... ] builds all programs
17
+ generate < dir> generates the various language-related modules
18
18
build-defs verifies the language definitions and generates
19
19
the textual representation for them
20
20
"""
21
- Programs : seq [(string , string , bool , bool )] = @ [
22
- (" tester" , " tools/tester.nim" , true , true ),
23
- (" passtool" , " tools/passtool/passtool.nim" , true , true ),
24
- (" queryshell" , " phy/queryshell.nim" , true , true ),
25
- (" repl" , " phy/repl.nim" , false , true ),
26
- (" phy" , " phy/phy.nim" , false , true ),
27
- (" skully" , " skully/skully.nim" , true , false )
28
- # ^^ excluded from 'all' because the program takes too long to compile
29
- ]
30
- # # program name, module path, whether the program doesn't depend on
31
- # # generated modules, and whether the program is built with 'all'
21
+ Programs = {
22
+ " tester" : (" tools/tester.nim" , true ),
23
+ " passtool" : (" tools/passtool/passtool.nim" , true ),
24
+ " queryshell" : (" phy/queryshell.nim" , true ),
25
+ " repl" : (" phy/repl.nim" , false ),
26
+ " phy" : (" phy/phy.nim" , false ),
27
+ " skully" : (" skully/skully.nim" , true ),
28
+ }.toOrderedTable
29
+ # # program name, module path, and whether the program doesn't depend on
30
+ # # generated modules
32
31
33
32
DefaultGenerated = " generated"
34
33
# # the default path for the generated modules
@@ -86,52 +85,43 @@ proc generateModules(dir: string) =
86
85
require run (passtool, " gen-checks" , " languages" , " specification" ,
87
86
" passes/syntax_source" , dir / " source_checks.nim" )
88
87
89
- proc buildSingle (args : string ): bool
88
+ proc build (name : string , args: openArray [ string ])
90
89
91
90
proc regenerate () =
92
91
# # Makes sure the generated modules are up-to-date.
93
92
if not dirExists (DefaultGenerated ):
94
93
# assume that the 'generated' folder existing means that it's up-to-date.
95
- # This is usually *not* correct, but it's the simplest heuristic we have
96
- discard buildSingle (" passtool -d:release" )
94
+ # This is usually *not* correct, but it's the simplest heuristic there is
95
+ build (" passtool" , [ " -d:release" ] )
97
96
generateModules (DefaultGenerated )
98
97
99
98
# command implementations:
100
99
101
- proc buildSingle (args: string ): bool =
102
- # # Builds the single program specified by `args`.
103
- var args = args.saneSplit ()
104
- if args.len == 0 :
105
- return false # not enough arguments, show the help
106
-
107
- let progName = args[0 ]
108
- args.delete (0 )
109
-
110
- result = true
111
-
112
- for (name, path, standalone, _) in Programs .items:
113
- if name == progName:
114
- if not standalone:
115
- # depends on some generated modules; first make sure they're
116
- # up-to-date
117
- regenerate ()
118
-
119
- if not compile (getCurrentDir () / path, name, args):
120
- echo " Failure"
121
- quit (1 )
122
- return
123
-
124
- # report a "not found" error
125
- echo " no program with name: '" , progName, " ' exists. Candidates are:"
126
- echo " " , mapIt (Programs , it[0 ]).join (" , " )
127
- quit (1 )
100
+ proc build (name: string , args: openArray [string ]) =
101
+ # # Builds the program identified by `name`, passing `args` along to
102
+ # # the compiler.
103
+ if name in Programs :
104
+ let (path, standalone) = Programs [name]
105
+ if not standalone:
106
+ # depends on some generated modules; first make sure they're
107
+ # up-to-date
108
+ regenerate ()
109
+
110
+ if not compile (getCurrentDir () / path, name, args):
111
+ echo " Failure"
112
+ quit (1 )
113
+ else :
114
+ # report a "not found" error
115
+ echo " no program with name: '" , name, " ' exists. Candidates are:"
116
+ echo " " , toSeq (Programs .keys).join (" , " )
117
+ quit (1 )
128
118
129
- proc buildAll (args: string ): bool =
119
+ proc build (names, extra: openArray [ string ]) =
130
120
# # Builds all programs, passing `args` along to the compiler.
131
- let extra = args.saneSplit ()
132
121
# build all standalone programs first:
133
- for (name, path, standalone, inAll) in Programs .items:
134
- if standalone and inAll:
122
+ for name in names.items:
123
+ let (path, standalone) = Programs [name]
124
+ if standalone:
135
125
if not compile (getCurrentDir () / path, name, extra):
136
126
echo " Failure"
137
127
quit (1 )
@@ -140,12 +130,29 @@ proc buildAll(args: string): bool =
140
130
generateModules (DefaultGenerated )
141
131
142
132
# finally, build the remaining programs:
143
- for (name, path, standalone, inAll) in Programs .items:
144
- if not standalone and inAll:
133
+ for name in names.items:
134
+ let (path, standalone) = Programs [name]
135
+ if not standalone:
145
136
if not compile (getCurrentDir () / path, name, extra):
146
137
echo " Failure"
147
138
quit (1 )
148
139
140
+ proc build (args: string ): bool =
141
+ # # Implements the `build` command.
142
+ let args = args.saneSplit ()
143
+ if args.len == 0 :
144
+ return false
145
+
146
+ case args[0 ]
147
+ of " all" :
148
+ build (toSeq (Programs .keys), args.toOpenArray (1 , args.high))
149
+ of " all-ws" :
150
+ # ws = without skully
151
+ build (toSeq (Programs .keys).filterIt (it != " skully" ),
152
+ args.toOpenArray (1 , args.high))
153
+ else :
154
+ build (args[0 ], args.toOpenArray (1 , args.high))
155
+
149
156
result = true
150
157
151
158
proc generate (args: string ): bool =
@@ -156,9 +163,7 @@ proc generate(args: string): bool =
156
163
return false
157
164
158
165
# the passtool binary might be out-of-date; it's better to always compile it
159
- result = buildSingle (" passtool -d:release" )
160
- if not result :
161
- return
166
+ build (" passtool" , [" -d:release" ])
162
167
163
168
generateModules ():
164
169
if args.len == 1 : args[0 ] else : DefaultGenerated
@@ -202,10 +207,8 @@ while true:
202
207
of cmdArgument:
203
208
success =
204
209
case normalize (opts.key)
205
- of " all" :
206
- buildAll (opts.cmdLineRest)
207
- of " single" :
208
- buildSingle (opts.cmdLineRest)
210
+ of " build" :
211
+ build (opts.cmdLineRest)
209
212
of " generate" :
210
213
generate (opts.cmdLineRest)
211
214
of " build-defs" :
0 commit comments