Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Unified Diff: third_party/WebKit/Source/devtools/scripts/check_gn.js

Issue 2926563004: DevTools: check BUILD.gn file as part of PRESUBMIT (Closed)
Patch Set: fixup Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/devtools/package.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/devtools/scripts/check_gn.js
diff --git a/third_party/WebKit/Source/devtools/scripts/check_gn.js b/third_party/WebKit/Source/devtools/scripts/check_gn.js
new file mode 100644
index 0000000000000000000000000000000000000000..f46e72ca2d733e1d6d615b9ad048e8a3ff2b1d2b
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/scripts/check_gn.js
@@ -0,0 +1,65 @@
+// Copyright 2017 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 inspectorManifest = require('../front_end/inspector.json');
+const utils = require('./utils');
+
+const gnPath = path.resolve(__dirname, '..', 'BUILD.gn');
+const gnFile = fs.readFileSync(gnPath, 'utf-8');
+const gnLines = gnFile.split('\n');
+
+function main() {
+ let errors = [];
+ errors = errors.concat(checkNonAutostartNonRemoteModules());
+ if (errors.length) {
+ console.log('DevTools BUILD.gn checker detected errors!');
+ console.log(`There's an issue with: ${gnPath}`);
+ console.log(errors.join('\n'));
+ process.exit(1);
+ }
+ console.log('DevTools BUILD.gn checker passed');
+}
+
+main();
+
+function checkNonAutostartNonRemoteModules() {
+ const errors = [];
+ const gnVariable = 'generated_non_autostart_non_remote_modules';
+ const lines = selectGNLines(`${gnVariable} = [`, ']');
+ if (!lines.length) {
+ return [
+ 'Could not identify non-autostart non-remote modules in gn file',
+ 'Please look at: ' + __filename,
+ ];
+ }
+ const text = lines.join('\n');
+ const modules = inspectorManifest.modules.filter(m => m.type !== 'autostart' && m.type !== 'remote').map(m => m.name);
+
+ const missingModules = modules.filter(m => !utils.includes(text, `${m}/${m}_module.js`));
+ if (missingModules.length)
+ errors.push(`Check that you've included [${missingModules.join(', ')}] modules in: ` + gnVariable);
+
+ // e.g. "$resources_out_dir/audits/audits_module.js" => "audits"
+ const mapLineToModuleName = line => line.split('/')[2].split('_module')[0];
+
+ const extraneousModules = lines.map(mapLineToModuleName).filter(module => !utils.includes(modules, module));
+ if (extraneousModules.length)
+ errors.push(`Found extraneous modules [${extraneousModules.join(', ')}] in: ` + gnVariable);
+
+ return errors;
+}
+
+function selectGNLines(startLine, endLine) {
+ let lines = gnLines.map(line => line.trim());
+ let startIndex = lines.indexOf(startLine);
+ if (startIndex === -1)
+ return [];
+ let endIndex = lines.indexOf(endLine, startIndex);
+ if (endIndex === -1)
+ return [];
+ return lines.slice(startIndex + 1, endIndex);
+}
« no previous file with comments | « third_party/WebKit/Source/devtools/package.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698