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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/devtools/package.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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
5 const fs = require('fs');
6 const path = require('path');
7
8 const inspectorManifest = require('../front_end/inspector.json');
9 const utils = require('./utils');
10
11 const gnPath = path.resolve(__dirname, '..', 'BUILD.gn');
12 const gnFile = fs.readFileSync(gnPath, 'utf-8');
13 const gnLines = gnFile.split('\n');
14
15 function main() {
16 let errors = [];
17 errors = errors.concat(checkNonAutostartNonRemoteModules());
18 if (errors.length) {
19 console.log('DevTools BUILD.gn checker detected errors!');
20 console.log(`There's an issue with: ${gnPath}`);
21 console.log(errors.join('\n'));
22 process.exit(1);
23 }
24 console.log('DevTools BUILD.gn checker passed');
25 }
26
27 main();
28
29 function checkNonAutostartNonRemoteModules() {
30 const errors = [];
31 const gnVariable = 'generated_non_autostart_non_remote_modules';
32 const lines = selectGNLines(`${gnVariable} = [`, ']');
33 if (!lines.length) {
34 return [
35 'Could not identify non-autostart non-remote modules in gn file',
36 'Please look at: ' + __filename,
37 ];
38 }
39 const text = lines.join('\n');
40 const modules = inspectorManifest.modules.filter(m => m.type !== 'autostart' & & m.type !== 'remote').map(m => m.name);
41
42 const missingModules = modules.filter(m => !utils.includes(text, `${m}/${m}_mo dule.js`));
43 if (missingModules.length)
44 errors.push(`Check that you've included [${missingModules.join(', ')}] modul es in: ` + gnVariable);
45
46 // e.g. "$resources_out_dir/audits/audits_module.js" => "audits"
47 const mapLineToModuleName = line => line.split('/')[2].split('_module')[0];
48
49 const extraneousModules = lines.map(mapLineToModuleName).filter(module => !uti ls.includes(modules, module));
50 if (extraneousModules.length)
51 errors.push(`Found extraneous modules [${extraneousModules.join(', ')}] in: ` + gnVariable);
52
53 return errors;
54 }
55
56 function selectGNLines(startLine, endLine) {
57 let lines = gnLines.map(line => line.trim());
58 let startIndex = lines.indexOf(startLine);
59 if (startIndex === -1)
60 return [];
61 let endIndex = lines.indexOf(endLine, startIndex);
62 if (endIndex === -1)
63 return [];
64 return lines.slice(startIndex + 1, endIndex);
65 }
OLDNEW
« 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