Skip to content

Commit 5f7e033

Browse files
Eric LeeseDevtools-frontend LUCI CQ
authored andcommitted
Fix npm run start and build scripts to work in full Chromium checkout
Also simplified code for test script to use devtools_paths.js Bug: none Change-Id: I699808267782f55150eabaacf9f86298ab3741d1 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6403238 Commit-Queue: Benedikt Meurer <[email protected]> Reviewed-by: Benedikt Meurer <[email protected]>
1 parent 1ffa94d commit 5f7e033

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

scripts/devtools_paths.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function isInChromiumDirectory() {
4747
}
4848

4949
const normalizedPath = PATH_TO_EXECUTED_FILE.split(path.sep).join('/');
50-
const devtoolsPath = 'src/third_party/devtools-frontend';
50+
const devtoolsPath = 'third_party/devtools-frontend/src';
5151
const isInChromium = normalizedPath.includes(devtoolsPath);
5252
const potentialChromiumDir = PATH_TO_EXECUTED_FILE.substring(
5353
0,
@@ -78,7 +78,7 @@ function devtoolsRootPath() {
7878
function rootPath() {
7979
const {isInChromium, chromiumDirectory} = isInChromiumDirectory();
8080
if (isInChromium) {
81-
return path.join(chromiumDirectory, 'src');
81+
return chromiumDirectory;
8282
}
8383
return devtoolsRootPath();
8484
}
@@ -166,6 +166,7 @@ function downloadedChromeBinaryPath() {
166166
module.exports = {
167167
devtoolsRootPath,
168168
downloadedChromeBinaryPath,
169+
isInChromiumDirectory,
169170
litAnalyzerExecutablePath,
170171
mochaExecutablePath,
171172
nodeModulesPath,

scripts/run_build.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import path from 'node:path';
88
import yargs from 'yargs';
99
import {hideBin} from 'yargs/helpers';
1010

11+
import {rootPath} from './devtools_paths.js';
12+
1113
const argv = yargs(hideBin(process.argv))
1214
.option('target', {
1315
alias: 't',
@@ -37,7 +39,7 @@ const cwd = process.cwd();
3739
const {env} = process;
3840

3941
// Create and initialize the `out/<target>` directory as needed.
40-
const outDir = path.join('out', target);
42+
const outDir = path.join(rootPath(), 'out', target);
4143
if (!fs.existsSync(outDir)) {
4244
const gnExe = path.join(cwd, 'third_party', 'depot_tools', 'gn');
4345
fs.mkdirSync(outDir, {recursive: true});
@@ -51,7 +53,7 @@ if (!fs.existsSync(outDir)) {
5153

5254
function build() {
5355
const autoninjaExe = path.join(cwd, 'third_party', 'depot_tools', 'autoninja');
54-
childProcess.spawnSync(autoninjaExe, ['-C', outDir], {
56+
childProcess.spawnSync(autoninjaExe, ['-C', outDir, 'devtools_all_files'], {
5557
cwd,
5658
env,
5759
stdio: 'inherit',

scripts/run_on_target.mjs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import * as path from 'path';
88
import yargs from 'yargs';
99
import unparse from 'yargs-unparser';
1010

11+
import {isInChromiumDirectory, nodeModulesPath, rootPath} from './devtools_paths.js';
12+
1113
const argv = yargs(process.argv.slice(2))
1214
.parserConfiguration({
1315
'strip-aliased': true,
@@ -24,32 +26,22 @@ let script = argv.script;
2426
delete argv.target;
2527
delete argv.script;
2628

27-
let sourceRoot = path.dirname(path.dirname(path.resolve(argv['$0'])));
29+
const sourceRoot = rootPath();
2830

2931
// Ensure that we can find the node_modules folder even if the out folder is
3032
// not a sibling of the node_modules folder.
3133
const env = process.env;
32-
env.NODE_PATH = path.join(sourceRoot, 'node_modules');
34+
env.NODE_PATH = nodeModulesPath();
3335

34-
let cwd = path.join(sourceRoot, 'out', target);
36+
const cwd = path.join(sourceRoot, 'out', target);
3537

36-
if (!fs.existsSync(cwd)) {
37-
// Check if we are in a Chromium checkout and look for the out folder there.
38-
const maybeChromiumRoot = path.dirname(
39-
path.dirname(path.dirname(sourceRoot)),
40-
);
41-
if (
42-
sourceRoot ===
43-
path.join(maybeChromiumRoot, 'third_party', 'devtools-frontend', 'src')
44-
) {
45-
sourceRoot = maybeChromiumRoot;
46-
cwd = path.join(sourceRoot, 'out', target);
47-
const pathParts = script.split(path.sep);
48-
if (pathParts[0] === 'gen') {
49-
pathParts.shift();
50-
pathParts.unshift('gen', 'third_party', 'devtools-frontend', 'src');
51-
script = pathParts.join(path.sep);
52-
}
38+
if (isInChromiumDirectory().isInChromium) {
39+
// Check if we need to change the location of the gen folder.
40+
const pathParts = script.split(path.sep);
41+
if (pathParts[0] === 'gen') {
42+
pathParts.shift();
43+
pathParts.unshift('gen', 'third_party', 'devtools-frontend', 'src');
44+
script = pathParts.join(path.sep);
5345
}
5446
}
5547

scripts/run_start.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import path from 'node:path';
77
import yargs from 'yargs';
88
import {hideBin} from 'yargs/helpers';
99

10-
import {downloadedChromeBinaryPath, rootPath} from './devtools_paths.js';
10+
import {downloadedChromeBinaryPath, isInChromiumDirectory, rootPath} from './devtools_paths.js';
1111

1212
// The list of features that are enabled by default.
1313
const ENABLE_FEATURES = [
@@ -30,7 +30,7 @@ const argv = yargs(hideBin(process.argv))
3030
.option('browser', {
3131
type: 'string',
3232
choices: ['cft', 'canary'],
33-
default: 'cft',
33+
default: isInChromiumDirectory().isInChromium ? 'canary' : 'cft',
3434
description: 'Launch in the specified browser',
3535
})
3636
.option('open', {
@@ -62,7 +62,7 @@ const runBuildPath = path.join(import.meta.dirname, 'run_build.mjs');
6262
function findBrowserBinary() {
6363
if (browser === 'canary') {
6464
const binary = ({
65-
linux: path.join('/usr', 'bin', 'google-chrome-canary'),
65+
linux: path.join('/usr', 'bin', 'google-chrome-unstable'),
6666
darwin: path.join('/Applications', 'Google Chrome Canary.app', 'Contents', 'MacOS', 'Google Chrome Canary'),
6767
})[process.platform];
6868
if (verbose) {
@@ -107,7 +107,10 @@ function start() {
107107
args.push(`--enable-features=${ENABLE_FEATURES.join(',')}`);
108108

109109
// Open with our freshly built DevTools front-end.
110-
const customDevToolsFrontEndPath = path.join(rootPath(), 'out', target, 'gen', 'front_end');
110+
const genDir = path.join(rootPath(), 'out', target, 'gen');
111+
const customDevToolsFrontEndPath = isInChromiumDirectory().isInChromium ?
112+
path.join(genDir, 'third_party', 'devtools-frontend', 'src', 'front_end') :
113+
path.join(genDir, 'front_end');
111114
args.push(`--custom-devtools-frontend=file://${customDevToolsFrontEndPath}`);
112115

113116
// Chrome flags and URLs.

0 commit comments

Comments
 (0)