Chromium Code Reviews| OLD | NEW |
|---|---|
| (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'); | |
|
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
| |
| 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 const selection = []; | |
| 58 let seenStartLine = false; | |
| 59 for (var i = 0; i < gnLines.length; i++) { | |
|
dgozman
2017/06/08 18:21:37
let!
| |
| 60 let line = gnLines[i].trim(); | |
| 61 if (line === startLine) { | |
| 62 seenStartLine = true; | |
| 63 continue; | |
| 64 } | |
| 65 if (line === endLine && seenStartLine) | |
| 66 break; | |
| 67 if (!seenStartLine) | |
| 68 continue; | |
| 69 selection.push(line); | |
| 70 } | |
| 71 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
| |
| 72 } | |
| OLD | NEW |