55import childProcess from 'node:child_process' ;
66import fs from 'node:fs/promises' ;
77import path from 'node:path' ;
8- import { performance } from 'node:perf_hooks' ;
8+ import { performance } from 'node:perf_hooks' ;
99import util from 'node:util' ;
1010
11- import { autoninjaExecutablePath , gnExecutablePath , rootPath } from './devtools_paths.js' ;
11+ import {
12+ autoninjaExecutablePath ,
13+ gnExecutablePath ,
14+ rootPath ,
15+ } from './devtools_paths.js' ;
1216
1317const execFile = util . promisify ( childProcess . execFile ) ;
1418
@@ -74,7 +78,7 @@ export class FeatureSet {
7478 * Yields the command line parameters to pass to the invocation of
7579 * a Chrome binary for achieving the state of the feature set.
7680 */
77- * [ Symbol . iterator ] ( ) {
81+ * [ Symbol . iterator ] ( ) {
7882 const disabledFeatures = [ ...this . #disabled] ;
7983 if ( disabledFeatures . length ) {
8084 yield `--disable-features=${ disabledFeatures . sort ( ) . join ( ',' ) } ` ;
@@ -104,15 +108,17 @@ export class FeatureSet {
104108 if ( parts . length > 1 ) {
105109 const args = parts [ 1 ] . split ( '/' ) ;
106110 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+ ) ;
108114 }
109115 for ( let i = 0 ; i < args . length ; i += 2 ) {
110116 const key = args [ i + 0 ] ;
111117 const value = args [ i + 1 ] ;
112118 parameters [ key ] = value ;
113119 }
114120 }
115- features . push ( { feature, parameters} ) ;
121+ features . push ( { feature, parameters } ) ;
116122 }
117123 return features ;
118124 }
@@ -134,16 +140,16 @@ export class BuildError extends Error {
134140 * @param {string } options.target the target relative to `//out`.
135141 */
136142 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 } ) ;
139145 this . name = 'BuildError' ;
140146 this . step = step ;
141147 this . target = target ;
142148 this . outDir = outDir ;
143149 }
144150
145151 toString ( ) {
146- const { stdout} = this . cause ;
152+ const { stdout } = this . cause ;
147153 return stdout ;
148154 }
149155}
@@ -156,11 +162,9 @@ export class BuildError extends Error {
156162
157163/**
158164 * @param {string } target
159- * @param {AbortSignal= } signal
160- * @return {Promise<BuildResult> } a `BuildResult` with statistics for the build.
165+ * @return {Promise<void> }
161166 */
162- export async function build ( target , signal ) {
163- const startTime = performance . now ( ) ;
167+ export async function prepareBuild ( target ) {
164168 const outDir = path . join ( rootPath ( ) , 'out' , target ) ;
165169
166170 // Prepare the build directory first.
@@ -170,30 +174,37 @@ export async function build(target, signal) {
170174 try {
171175 const gnExe = gnExecutablePath ( ) ;
172176 const gnArgs = [ '-q' , 'gen' , outDir ] ;
173- await execFile ( gnExe , gnArgs , { signal } ) ;
177+ await execFile ( gnExe , gnArgs ) ;
174178 } 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 } ) ;
179180 }
180181 }
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 ) ;
181192
182193 // Build just the devtools-frontend resources in |outDir|. This is important
183194 // since we might be running in a full Chromium checkout and certainly don't
184195 // want to build all of Chromium first.
185196 try {
186197 const autoninjaExe = autoninjaExecutablePath ( ) ;
187198 const autoninjaArgs = [ '-C' , outDir , '--quiet' , 'devtools_all_files' ] ;
188- await execFile ( autoninjaExe , autoninjaArgs , { signal} ) ;
199+ await execFile ( autoninjaExe , autoninjaArgs , { signal } ) ;
189200 } catch ( cause ) {
190201 if ( cause . name === 'AbortError' ) {
191202 throw cause ;
192203 }
193- throw new BuildError ( BuildStep . AUTONINJA , { cause, outDir, target} ) ;
204+ throw new BuildError ( BuildStep . AUTONINJA , { cause, outDir, target } ) ;
194205 }
195206
196207 // Report the build result.
197208 const time = ( performance . now ( ) - startTime ) / 1000 ;
198- return { time} ;
209+ return { time } ;
199210}
0 commit comments