diff --git a/tools/pkg/engine_build_configs/lib/src/build_config_runner.dart b/tools/pkg/engine_build_configs/lib/src/build_config_runner.dart index 20068571658e8..c15aead301771 100644 --- a/tools/pkg/engine_build_configs/lib/src/build_config_runner.dart +++ b/tools/pkg/engine_build_configs/lib/src/build_config_runner.dart @@ -8,6 +8,7 @@ import 'dart:ffi' as ffi; import 'dart:io' as io show Directory, File, Process, ProcessResult; import 'dart:math'; +import 'package:meta/meta.dart' show visibleForTesting; import 'package:path/path.dart' as p; import 'package:platform/platform.dart'; import 'package:process_runner/process_runner.dart'; @@ -579,6 +580,28 @@ final class BuildRunner extends Runner { return min(multiplier * cores, 1000); }(); + static final RegExp _gccRegex = + RegExp(r'^(.+)(:\d+:\d+:\s+(?:error|note|warning):\s+.*)$'); + + /// Converts relative [path], who is relative to [dirPath] to a relative path + /// of the `CWD`. + static String _makeRelative(String path, String dirPath) { + final String abs = p.join(dirPath, path); + return './${p.relative(abs)}'; + } + + /// Takes a [line] from compilation and makes the path relative to `CWD` where + /// the paths are relative to [outDir]. + @visibleForTesting + static String fixGccPaths(String line, String outDir) { + final Match? match = _gccRegex.firstMatch(line); + if (match == null) { + return line; + } else { + return '${_makeRelative(match.group(1)!, outDir)}${match.group(2)}'; + } + } + Future _runNinja(RunnerEventHandler eventHandler) async { if (_isRbe) { if (!await _bootstrapRbe(eventHandler)) { @@ -637,6 +660,8 @@ final class BuildRunner extends Runner { if (_ninjaProgress(eventHandler, command, line)) { return; } + // TODO(157816): Forward errors to `et`. + line = fixGccPaths(line, outDir); final List bytes = utf8.encode('$line\n'); stdoutOutput.addAll(bytes); }, diff --git a/tools/pkg/engine_build_configs/test/build_config_runner_test.dart b/tools/pkg/engine_build_configs/test/build_config_runner_test.dart index b98474d91feab..48c00256e3547 100644 --- a/tools/pkg/engine_build_configs/test/build_config_runner_test.dart +++ b/tools/pkg/engine_build_configs/test/build_config_runner_test.dart @@ -530,6 +530,13 @@ void main() { expect(events[3].name, equals('generator_task')); }); + test('fixes gcc paths', () { + final String outDir = path.join(io.Directory.current.path, 'foo', 'bar'); + const String error = 'flutter/impeller/renderer/backend/metal/allocator_mtl.h:69:33: error: foobar'; + final String fixed = BuildRunner.fixGccPaths('../../$error', outDir); + expect(fixed, './$error'); + }); + test('GlobalBuildRunner skips generators when runGenerators is false', () async { final Build targetBuild = buildConfig.builds[0];