Adds watch mode for rebuillding changes
Since we are moving to running from built content in the gen/ directory,
we need to have a watcher to ensure convenience for anyone working on
the codebase. This CL introduces a watcher that calls autoninja whenever
a file is changed in the front_end folder. It also updates node.py so
that it outputs the contents of stdout and stderr when the --output flag
is set.
R=tvanderlippe@chromium.org
DISABLE_THIRD_PARTY_CHECK=Updating node alongside relevant changes
Bug: 1098694
Change-Id: I4ddb3d250d0fd80455ea24e95055de74b2be879c
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2272559
Commit-Queue: Paul Lewis <aerotwist@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
diff --git a/scripts/watch_build.js b/scripts/watch_build.js
new file mode 100644
index 0000000..179c66f
--- /dev/null
+++ b/scripts/watch_build.js
@@ -0,0 +1,42 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+const fs = require('fs');
+const path = require('path');
+const childProcess = require('child_process');
+const cwd = process.cwd();
+const env = process.env;
+const frontEnd = path.join(cwd, 'front_end');
+
+// Extract the target if it's provided.
+let target = 'Default';
+const targetArg = process.argv.find(value => value.startsWith('--target='));
+if (targetArg) {
+ target = targetArg.slice('--target='.length);
+}
+
+let isBuilding = false;
+let filesChangedDuringBuild = false;
+const onFileChange = () => {
+ if (isBuilding) {
+ filesChangedDuringBuild = true;
+ return;
+ }
+
+ filesChangedDuringBuild = false;
+ isBuilding = true;
+
+ const autoninja = childProcess.spawn('autoninja', ['-C', `out/${target}`, 'front_end'], {cwd, env, stdio: 'inherit'});
+ autoninja.on('close', () => {
+ if (filesChangedDuringBuild) {
+ console.warn('Warning: files changed during build, you may wish to trigger a fresh rebuild.');
+ }
+
+ isBuilding = false;
+ });
+};
+
+// Watch the front_end folder and build on any change.
+console.log(`Watching for changes in /front_end; building to out/${target}`);
+fs.watch(`${frontEnd}`, {recursive: true}, onFileChange);