blob: 61a12e75da1b9ce3d4a8bb3a65382c4c1cec2186 [file] [log] [blame]
Deepanjan Royd7b03b22018-05-17 09:05:13 -04001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * Configuration file for lite-server. Contains configuration for auto rerunning
19 * ninja on file change.
20 */
21'use strict';
22
23const { spawn } = require('child_process');
Hector Dearman262cbe22018-05-31 13:28:21 +010024const path = require('path');
Deepanjan Royd7b03b22018-05-17 09:05:13 -040025
26// Print without added new line.
27const print = data => process.stdout.write(data);
28const printErr = data => process.stderr.write(data);
29
Hector Dearman262cbe22018-05-31 13:28:21 +010030const ninjaOutDir = process.env.OUT_DIR;
31const uiOutDir = path.join(ninjaOutDir, 'ui');
32const perfettoRoot = process.env.ROOT_DIR;
33const ninjaPath = path.join(perfettoRoot, 'tools', 'ninja');
Deepanjan Royd7b03b22018-05-17 09:05:13 -040034let ninjaRunning = false;
35
Hector Dearman262cbe22018-05-31 13:28:21 +010036function rebasePath(relative_path) {
37 return path.join(perfettoRoot, relative_path);
38}
39
Deepanjan Royd7b03b22018-05-17 09:05:13 -040040module.exports = function(bs) {
41 return {
42 files: [
43 {
Hector Dearman262cbe22018-05-31 13:28:21 +010044 match: [
45 "ui/**",
46 "src/trace_processor/**",
47 "protos/**",
48 ].map(rebasePath),
Deepanjan Royd7b03b22018-05-17 09:05:13 -040049 fn: function(event, file) {
50 console.log(`Change detected on ${file}`);
51 if (ninjaRunning) {
52 console.log("Already have a ninja build running. Doing nothing.");
53 return;
54 }
55
56 ninjaRunning = true;
57
58 console.log(`Executing: ninja -C ${ninjaOutDir} ui`);
Hector Dearman262cbe22018-05-31 13:28:21 +010059 const ninja = spawn(ninjaPath, ['-C', ninjaOutDir, 'ui']);
Deepanjan Royd7b03b22018-05-17 09:05:13 -040060 ninja.stdout.on('data', data => print(data.toString()));
61 ninja.stderr.on('data', data => printErr(data.toString()));
62
63 // We can be smarter and load just the file we need. Need to
64 // resolve to the dist/location of the file in that case.
65 // For now, we're reloading the whole page.
66 ninja.on('exit', () => {
67 ninjaRunning = false;
68 bs.reload();
69 });
70 },
71 options: {
Hector Dearman262cbe22018-05-31 13:28:21 +010072 ignored: [
73 "ui/dist/",
74 "ui/.git/",
75 "ui/node_modules/",
76 ].map(rebasePath),
77 ignoreInitial: true,
Deepanjan Royd7b03b22018-05-17 09:05:13 -040078 }
79 }
80 ],
81 server: {
Hector Dearman262cbe22018-05-31 13:28:21 +010082 baseDir: uiOutDir,
Deepanjan Royd7b03b22018-05-17 09:05:13 -040083 },
84 };
85};