forked from ChromeDevTools/devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug-check.ts
46 lines (40 loc) · 1.31 KB
/
debug-check.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2020 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.
import {readFileSync} from 'fs';
import {join} from 'path';
const isDebug = /^\s*is_debug\s*=\s*(.*)/;
/**
* Tests the args.gn file to ensure that the is_debug flag is set to true.
* We don't cover every case here, for example where is_debug is redefined
* in the gn.args several times. Instead we use the first declaration of
* is_debug's value.
*/
export function debugCheck(dirName: string): boolean {
const argsFile = join(dirName, '..', '..', 'args.gn');
try {
const fileDetails = readFileSync(argsFile, {encoding: 'utf8'});
for (const line of fileDetails.split('\n')) {
if (!isDebug.test(line)) {
continue;
}
const matches = isDebug.exec(line);
// For any match we expect:
// 0: the whole line
// 1: the value itself
if (!matches || matches.length < 2) {
return false;
}
const value = matches[1].toLowerCase();
if (value === 'true' || value === '1') {
return true;
}
return false;
}
// By default, a DevTools build is always a debug build,
// unless `is_debug` is explicitly set to false
return true;
} catch {
return false;
}
}