Chromium Code Reviews| 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..71169a6d1d98072275c8c28ffd5791ecc352257d |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/devtools/scripts/check_gn.js |
| @@ -0,0 +1,72 @@ |
| +// 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'); |
|
dgozman
2017/06/08 18:21:37
Should we check all apps?
chenwilliam
2017/06/08 18:49:04
Let's do it in a f/u CL. I'd like to create valida
|
| +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) { |
| + const selection = []; |
| + let seenStartLine = false; |
| + for (var i = 0; i < gnLines.length; i++) { |
|
dgozman
2017/06/08 18:21:37
let!
|
| + let line = gnLines[i].trim(); |
| + if (line === startLine) { |
| + seenStartLine = true; |
| + continue; |
| + } |
| + if (line === endLine && seenStartLine) |
| + break; |
| + if (!seenStartLine) |
| + continue; |
| + selection.push(line); |
| + } |
| + return selection; |
|
dgozman
2017/06/08 18:21:37
let lines = gnLines.map(line => line.trim())
let s
chenwilliam
2017/06/08 18:49:04
done. slight modification so if endIndex is not fo
|
| +} |