5
5
import childProcess from 'node:child_process' ;
6
6
import fs from 'node:fs/promises' ;
7
7
import path from 'node:path' ;
8
- import { performance } from 'node:perf_hooks' ;
8
+ import { performance } from 'node:perf_hooks' ;
9
9
import util from 'node:util' ;
10
10
11
- import { autoninjaExecutablePath , gnExecutablePath , rootPath } from './devtools_paths.js' ;
11
+ import {
12
+ autoninjaExecutablePath ,
13
+ gnExecutablePath ,
14
+ rootPath ,
15
+ } from './devtools_paths.js' ;
12
16
13
17
const execFile = util . promisify ( childProcess . execFile ) ;
14
18
@@ -74,7 +78,7 @@ export class FeatureSet {
74
78
* Yields the command line parameters to pass to the invocation of
75
79
* a Chrome binary for achieving the state of the feature set.
76
80
*/
77
- * [ Symbol . iterator ] ( ) {
81
+ * [ Symbol . iterator ] ( ) {
78
82
const disabledFeatures = [ ...this . #disabled] ;
79
83
if ( disabledFeatures . length ) {
80
84
yield `--disable-features=${ disabledFeatures . sort ( ) . join ( ',' ) } ` ;
@@ -104,15 +108,17 @@ export class FeatureSet {
104
108
if ( parts . length > 1 ) {
105
109
const args = parts [ 1 ] . split ( '/' ) ;
106
110
if ( args . length % 2 !== 0 ) {
107
- throw new Error ( `Invalid parameters '${ parts [ 1 ] } ' for feature ${ feature } ` ) ;
111
+ throw new Error (
112
+ `Invalid parameters '${ parts [ 1 ] } ' for feature ${ feature } ` ,
113
+ ) ;
108
114
}
109
115
for ( let i = 0 ; i < args . length ; i += 2 ) {
110
116
const key = args [ i + 0 ] ;
111
117
const value = args [ i + 1 ] ;
112
118
parameters [ key ] = value ;
113
119
}
114
120
}
115
- features . push ( { feature, parameters} ) ;
121
+ features . push ( { feature, parameters } ) ;
116
122
}
117
123
return features ;
118
124
}
@@ -134,16 +140,16 @@ export class BuildError extends Error {
134
140
* @param {string } options.target the target relative to `//out`.
135
141
*/
136
142
constructor ( step , options ) {
137
- const { cause, outDir, target} = options ;
138
- super ( `Failed to build target ${ target } in ${ outDir } ` , { cause} ) ;
143
+ const { cause, outDir, target } = options ;
144
+ super ( `Failed to build target ${ target } in ${ outDir } ` , { cause } ) ;
139
145
this . name = 'BuildError' ;
140
146
this . step = step ;
141
147
this . target = target ;
142
148
this . outDir = outDir ;
143
149
}
144
150
145
151
toString ( ) {
146
- const { stdout} = this . cause ;
152
+ const { stdout } = this . cause ;
147
153
return stdout ;
148
154
}
149
155
}
@@ -156,11 +162,9 @@ export class BuildError extends Error {
156
162
157
163
/**
158
164
* @param {string } target
159
- * @param {AbortSignal= } signal
160
- * @return {Promise<BuildResult> } a `BuildResult` with statistics for the build.
165
+ * @return {Promise<void> }
161
166
*/
162
- export async function build ( target , signal ) {
163
- const startTime = performance . now ( ) ;
167
+ export async function prepareBuild ( target ) {
164
168
const outDir = path . join ( rootPath ( ) , 'out' , target ) ;
165
169
166
170
// Prepare the build directory first.
@@ -170,30 +174,37 @@ export async function build(target, signal) {
170
174
try {
171
175
const gnExe = gnExecutablePath ( ) ;
172
176
const gnArgs = [ '-q' , 'gen' , outDir ] ;
173
- await execFile ( gnExe , gnArgs , { signal } ) ;
177
+ await execFile ( gnExe , gnArgs ) ;
174
178
} catch ( cause ) {
175
- if ( cause . name === 'AbortError' ) {
176
- throw cause ;
177
- }
178
- throw new BuildError ( BuildStep . GN , { cause, outDir, target} ) ;
179
+ throw new BuildError ( BuildStep . GN , { cause, outDir, target } ) ;
179
180
}
180
181
}
182
+ }
183
+
184
+ /**
185
+ * @param {string } target
186
+ * @param {AbortSignal= } signal
187
+ * @return {Promise<BuildResult> } a `BuildResult` with statistics for the build.
188
+ */
189
+ export async function build ( target , signal ) {
190
+ const startTime = performance . now ( ) ;
191
+ const outDir = path . join ( rootPath ( ) , 'out' , target ) ;
181
192
182
193
// Build just the devtools-frontend resources in |outDir|. This is important
183
194
// since we might be running in a full Chromium checkout and certainly don't
184
195
// want to build all of Chromium first.
185
196
try {
186
197
const autoninjaExe = autoninjaExecutablePath ( ) ;
187
198
const autoninjaArgs = [ '-C' , outDir , '--quiet' , 'devtools_all_files' ] ;
188
- await execFile ( autoninjaExe , autoninjaArgs , { signal} ) ;
199
+ await execFile ( autoninjaExe , autoninjaArgs , { signal } ) ;
189
200
} catch ( cause ) {
190
201
if ( cause . name === 'AbortError' ) {
191
202
throw cause ;
192
203
}
193
- throw new BuildError ( BuildStep . AUTONINJA , { cause, outDir, target} ) ;
204
+ throw new BuildError ( BuildStep . AUTONINJA , { cause, outDir, target } ) ;
194
205
}
195
206
196
207
// Report the build result.
197
208
const time = ( performance . now ( ) - startTime ) / 1000 ;
198
- return { time} ;
209
+ return { time } ;
199
210
}
0 commit comments