Skip to content

Commit

Permalink
Made et compilation errors relative to the CWD (flutter#56177)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke authored Oct 29, 2024
1 parent dcc8c65 commit 2f04ae8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tools/pkg/engine_build_configs/lib/src/build_config_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<bool> _runNinja(RunnerEventHandler eventHandler) async {
if (_isRbe) {
if (!await _bootstrapRbe(eventHandler)) {
Expand Down Expand Up @@ -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<int> bytes = utf8.encode('$line\n');
stdoutOutput.addAll(bytes);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 2f04ae8

Please sign in to comment.