async build()

in src/drivers/driver.ts [1468:1539]


    async build(targets?: string[], consumer?: proc.OutputConsumer): Promise<number | null> {
        log.debug(localize('start.build', 'Start build'), targets?.join(', ') || '');
        if (this.configRunning) {
            await this.preconditionHandler(CMakePreconditionProblems.ConfigureIsAlreadyRunning);
            return -1;
        }
        if (this.buildRunning) {
            await this.preconditionHandler(CMakePreconditionProblems.BuildIsAlreadyRunning);
            return -1;
        }
        this.buildRunning = true;

        const pre_build_ok = await this.doPreBuild();
        if (!pre_build_ok) {
            this.buildRunning = false;
            return -1;
        }
        const timeStart: number = new Date().getTime();
        const child = await this._doCMakeBuild(targets, consumer);
        const timeEnd: number = new Date().getTime();
        const telemetryProperties: telemetry.Properties | undefined = this.useCMakePresets ? undefined : {
            ConfigType: this.isMultiConfFast ? 'MultiConf' : this.currentBuildType || ''
        };
        const telemetryMeasures: telemetry.Measures = {
            Duration: timeEnd - timeStart
        };
        if (child) {
            if (consumer) {
                if (consumer instanceof CMakeBuildConsumer &&
                    consumer.compileConsumer instanceof CompileOutputConsumer) {
                    let errorCount: number = 0;
                    let warningCount: number = 0;
                    for (const compiler in consumer.compileConsumer.compilers) {
                        const parser: RawDiagnosticParser = consumer.compileConsumer.compilers[compiler];
                        parser.diagnostics.forEach(v => {
                            if (v.severity === 'error' || v.severity === 'fatal error') {
                                errorCount++;
                            } else if (v.severity === 'warning') {
                                warningCount++;
                            }
                        });
                    }
                    telemetryMeasures['ErrorCount'] = errorCount;
                    telemetryMeasures['WarningCount'] = warningCount;
                } else {
                    // Wrong type: shouldn't get here, just in case
                    rollbar.error('Wrong build result type.');
                    telemetryMeasures['ErrorCount'] = (await child.result).retc ? 1 : 0;
                }
            }
            telemetry.logEvent('build', telemetryProperties, telemetryMeasures);
        } else {
            // Not sure what happened but there's an error...
            telemetryMeasures['ErrorCount'] = 1;
            telemetry.logEvent('build', telemetryProperties, telemetryMeasures);
            this.buildRunning = false;
            return -1;
        }
        if (!this.m_stop_process) {
            const post_build_ok = await this.doPostBuild();
            if (!post_build_ok) {
                this.buildRunning = false;
                return -1;
            }
        }
        if (!this.m_stop_process) {
            await this._refreshExpansions();
        }

        this.buildRunning = false;
        return (await child.result).retc;
    }