Skip to content

Commit 5c0b783

Browse files
committed
clean up exec
1 parent a127196 commit 5c0b783

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

build.js

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fs = require('fs');
22
const path = require('path');
33
const crypto = require('crypto');
4-
const { spawnSync } = require('child_process');
54

65
console.log('TetrisGYM buildscript');
76
console.time('build');
@@ -117,7 +116,10 @@ console.timeEnd('CHR');
117116

118117
// build object files
119118

120-
function handleSpawn(exe, ...args) {
119+
const { spawnSync } = require('child_process');
120+
121+
function exec(cmd) {
122+
const [exe, ...args] = cmd.split(' ');
121123
const output = spawnSync(exe, args).output.flatMap(
122124
(d) => d?.toString() || [],
123125
);
@@ -127,36 +129,23 @@ function handleSpawn(exe, ...args) {
127129
}
128130
}
129131

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(' ');
131134

132135
console.time('assemble');
133136

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`);
145139

146140
console.timeEnd('assemble');
147141

148142
// link object files
149143

150-
const ld65bin = nativeCC65 ? ['ld65'] : ['node', './tools/assemble/ld65.js'];
144+
const ld65bin = nativeCC65 ? 'ld65' : 'node ./tools/assemble/ld65.js';
151145

152146
console.time('link');
153147

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`);
160149

161150
console.timeEnd('link');
162151

@@ -200,5 +189,5 @@ console.timeEnd('build');
200189

201190
if (args.includes('-t')) {
202191
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');
204193
}

0 commit comments

Comments
 (0)