blob: 179c66ff4378b3e967f42fa962fd6b0a88d15926 [file] [log] [blame]
Paul Lewis64ba20b2020-06-29 16:17:21 +01001// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5const fs = require('fs');
6const path = require('path');
7const childProcess = require('child_process');
8const cwd = process.cwd();
9const env = process.env;
10const frontEnd = path.join(cwd, 'front_end');
11
12// Extract the target if it's provided.
13let target = 'Default';
14const targetArg = process.argv.find(value => value.startsWith('--target='));
15if (targetArg) {
16 target = targetArg.slice('--target='.length);
17}
18
19let isBuilding = false;
20let filesChangedDuringBuild = false;
21const onFileChange = () => {
22 if (isBuilding) {
23 filesChangedDuringBuild = true;
24 return;
25 }
26
27 filesChangedDuringBuild = false;
28 isBuilding = true;
29
30 const autoninja = childProcess.spawn('autoninja', ['-C', `out/${target}`, 'front_end'], {cwd, env, stdio: 'inherit'});
31 autoninja.on('close', () => {
32 if (filesChangedDuringBuild) {
33 console.warn('Warning: files changed during build, you may wish to trigger a fresh rebuild.');
34 }
35
36 isBuilding = false;
37 });
38};
39
40// Watch the front_end folder and build on any change.
41console.log(`Watching for changes in /front_end; building to out/${target}`);
42fs.watch(`${frontEnd}`, {recursive: true}, onFileChange);