1
1
const fs = require ( 'fs' ) ;
2
2
const path = require ( 'path' ) ;
3
3
const crypto = require ( 'crypto' ) ;
4
- const { spawnSync } = require ( 'child_process' ) ;
5
4
6
5
console . log ( 'TetrisGYM buildscript' ) ;
7
6
console . time ( 'build' ) ;
@@ -117,7 +116,10 @@ console.timeEnd('CHR');
117
116
118
117
// build object files
119
118
120
- function handleSpawn ( exe , ...args ) {
119
+ const { spawnSync } = require ( 'child_process' ) ;
120
+
121
+ function exec ( cmd ) {
122
+ const [ exe , ...args ] = cmd . split ( ' ' ) ;
121
123
const output = spawnSync ( exe , args ) . output . flatMap (
122
124
( d ) => d ?. toString ( ) || [ ] ,
123
125
) ;
@@ -127,36 +129,23 @@ function handleSpawn(exe, ...args) {
127
129
}
128
130
}
129
131
130
- const ca65bin = nativeCC65 ? [ 'ca65' ] : [ 'node' , './tools/assemble/ca65.js' ] ;
132
+ const ca65bin = nativeCC65 ? 'ca65' : 'node ./tools/assemble/ca65.js' ;
133
+ const flags = compileFlags . join ( ' ' ) ;
131
134
132
135
console . time ( 'assemble' ) ;
133
136
134
- handleSpawn (
135
- ...ca65bin ,
136
- ...compileFlags ,
137
- ...'-g src/header.asm -o header.o' . split ( ' ' ) ,
138
- ) ;
139
-
140
- handleSpawn (
141
- ...ca65bin ,
142
- ...compileFlags ,
143
- ...'-l tetris.lst -g src/main.asm -o main.o' . split ( ' ' ) ,
144
- ) ;
137
+ exec ( `${ ca65bin } ${ flags } -g src/header.asm -o header.o` ) ;
138
+ exec ( `${ ca65bin } ${ flags } -l tetris.lst -g src/main.asm -o main.o` ) ;
145
139
146
140
console . timeEnd ( 'assemble' ) ;
147
141
148
142
// link object files
149
143
150
- const ld65bin = nativeCC65 ? [ 'ld65' ] : [ 'node' , ' ./tools/assemble/ld65.js'] ;
144
+ const ld65bin = nativeCC65 ? 'ld65' : 'node ./tools/assemble/ld65.js' ;
151
145
152
146
console . time ( 'link' ) ;
153
147
154
- handleSpawn (
155
- ...ld65bin ,
156
- ...'-m tetris.map -Ln tetris.lbl --dbgfile tetris.dbg -o tetris.nes -C src/tetris.nes.cfg main.o header.o' . split (
157
- ' ' ,
158
- ) ,
159
- ) ;
148
+ exec ( `${ ld65bin } -m tetris.map -Ln tetris.lbl --dbgfile tetris.dbg -o tetris.nes -C src/tetris.nes.cfg main.o header.o` ) ;
160
149
161
150
console . timeEnd ( 'link' ) ;
162
151
@@ -200,5 +189,5 @@ console.timeEnd('build');
200
189
201
190
if ( args . includes ( '-t' ) ) {
202
191
console . log ( '\nrunning tests' ) ;
203
- handleSpawn ( 'cargo' , ... ' run --release --manifest-path tests/Cargo.toml -- -t'. split ( ' ' ) ) ;
192
+ exec ( 'cargo run --release --manifest-path tests/Cargo.toml -- -t' ) ;
204
193
}
0 commit comments