Skip to content

Commit b8b84b2

Browse files
[tools,pigeon] Update tooling to handle Windows build output changes (flutter#4826)
Updates the tooling that builds and runs Windows unit tests to handle the build output path changes in flutter#131843
1 parent cd94db1 commit b8b84b2

File tree

4 files changed

+330
-43
lines changed

4 files changed

+330
-43
lines changed

packages/pigeon/tool/shared/test_suites.dart

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,30 @@ Future<int> _runWindowsUnitTests() async {
313313
return compileCode;
314314
}
315315

316-
return runProcess(
317-
'$examplePath/build/windows/plugins/test_plugin/Debug/test_plugin_test.exe',
318-
<String>[]);
316+
// Depending on the Flutter version, the build output path is different. To
317+
// handle both master and stable, and to future-proof against the changes
318+
// that will happen in https://github.com/flutter/flutter/issues/129807
319+
// - Try arm64, to future-proof against arm64 support.
320+
// - Try x64, to cover pre-arm64 support on arm64 hosts, as well as x64 hosts
321+
// running newer versions of Flutter.
322+
// - Fall back to the pre-arch path, to support running against stable.
323+
// TODO(stuartmorgan): Remove all this when these tests no longer need to
324+
// support a version of Flutter without
325+
// https://github.com/flutter/flutter/issues/129807, and just construct the
326+
// version of the path with the current architecture.
327+
const String buildDirBase = '$examplePath/build/windows';
328+
const String buildRelativeBinaryPath =
329+
'plugins/test_plugin/Debug/test_plugin_test.exe';
330+
const String arm64Path = '$buildDirBase/arm64/$buildRelativeBinaryPath';
331+
const String x64Path = '$buildDirBase/x64/$buildRelativeBinaryPath';
332+
const String oldPath = '$buildDirBase/$buildRelativeBinaryPath';
333+
if (File(arm64Path).existsSync()) {
334+
return runProcess(arm64Path, <String>[]);
335+
} else if (File(x64Path).existsSync()) {
336+
return runProcess(x64Path, <String>[]);
337+
} else {
338+
return runProcess(oldPath, <String>[]);
339+
}
319340
}
320341

321342
Future<int> _runWindowsIntegrationTests() async {

script/tool/lib/src/common/cmake.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CMakeProject {
2020
required this.buildMode,
2121
this.processRunner = const ProcessRunner(),
2222
this.platform = const LocalPlatform(),
23+
this.arch,
2324
});
2425

2526
/// The directory of a Flutter project to run Gradle commands in.
@@ -31,6 +32,11 @@ class CMakeProject {
3132
/// The platform that commands are being run on.
3233
final Platform platform;
3334

35+
/// The architecture subdirectory of the build.
36+
// TODO(stuartmorgan): Make this non-nullable once Flutter 3.13 is no longer
37+
// supported, since at that point there will always be a subdirectory.
38+
final String? arch;
39+
3440
/// The build mode (e.g., Debug, Release).
3541
///
3642
/// This is a constructor paramater because on Linux many properties depend
@@ -46,14 +52,13 @@ class CMakeProject {
4652
Directory get buildDirectory {
4753
Directory buildDir =
4854
flutterProject.childDirectory('build').childDirectory(_platformDirName);
55+
if (arch != null) {
56+
buildDir = buildDir.childDirectory(arch!);
57+
}
4958
if (platform.isLinux) {
50-
buildDir = buildDir
51-
// TODO(stuartmorgan): Support arm64 if that ever becomes a supported
52-
// CI configuration for the repository.
53-
.childDirectory('x64')
54-
// Linux uses a single-config generator, so the base build directory
55-
// includes the configuration.
56-
.childDirectory(buildMode.toLowerCase());
59+
// Linux uses a single-config generator, so the base build directory
60+
// includes the configuration.
61+
buildDir = buildDir.childDirectory(buildMode.toLowerCase());
5762
}
5863
return buildDir;
5964
}

script/tool/lib/src/native_test_command.dart

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:ffi';
6+
57
import 'package:file/file.dart';
68
import 'package:meta/meta.dart';
79

@@ -41,7 +43,9 @@ class NativeTestCommand extends PackageLoopingCommand {
4143
super.packagesDir, {
4244
super.processRunner,
4345
super.platform,
44-
}) : _xcode = Xcode(processRunner: processRunner, log: true) {
46+
Abi? abi,
47+
}) : _abi = abi ?? Abi.current(),
48+
_xcode = Xcode(processRunner: processRunner, log: true) {
4549
argParser.addOption(
4650
_iOSDestinationFlag,
4751
help: 'Specify the destination when running iOS tests.\n'
@@ -63,6 +67,9 @@ class NativeTestCommand extends PackageLoopingCommand {
6367
help: 'Runs native integration (UI) tests', defaultsTo: true);
6468
}
6569

70+
// The ABI of the host.
71+
final Abi _abi;
72+
6673
// The device destination flags for iOS tests.
6774
List<String> _iOSDestinationFlags = <String>[];
6875

@@ -548,9 +555,10 @@ this command.
548555
isTestBinary: isTestBinary);
549556
}
550557

551-
/// Finds every file in the [buildDirectoryName] subdirectory of [plugin]'s
552-
/// build directory for which [isTestBinary] is true, and runs all of them,
553-
/// returning the overall result.
558+
/// Finds every file in the relevant (based on [platformName], [buildMode],
559+
/// and [arch]) subdirectory of [plugin]'s build directory for which
560+
/// [isTestBinary] is true, and runs all of them, returning the overall
561+
/// result.
554562
///
555563
/// The binaries are assumed to be Google Test test binaries, thus returning
556564
/// zero for success and non-zero for failure.
@@ -563,11 +571,45 @@ this command.
563571
final List<File> testBinaries = <File>[];
564572
bool hasMissingBuild = false;
565573
bool buildFailed = false;
574+
String? arch;
575+
const String x64DirName = 'x64';
576+
const String arm64DirName = 'arm64';
577+
if (platform.isWindows) {
578+
arch = _abi == Abi.windowsX64 ? x64DirName : arm64DirName;
579+
} else if (platform.isLinux) {
580+
// TODO(stuartmorgan): Support arm64 if that ever becomes a supported
581+
// CI configuration for the repository.
582+
arch = 'x64';
583+
}
566584
for (final RepositoryPackage example in plugin.getExamples()) {
567-
final CMakeProject project = CMakeProject(example.directory,
585+
CMakeProject project = CMakeProject(example.directory,
568586
buildMode: buildMode,
569587
processRunner: processRunner,
570-
platform: platform);
588+
platform: platform,
589+
arch: arch);
590+
if (platform.isWindows) {
591+
if (arch == arm64DirName && !project.isConfigured()) {
592+
// Check for x64, to handle builds newer than 3.13, but that don't yet
593+
// have https://github.com/flutter/flutter/issues/129807.
594+
// TODO(stuartmorgan): Remove this when CI no longer supports a
595+
// version of Flutter without the issue above fixed.
596+
project = CMakeProject(example.directory,
597+
buildMode: buildMode,
598+
processRunner: processRunner,
599+
platform: platform,
600+
arch: x64DirName);
601+
}
602+
if (!project.isConfigured()) {
603+
// Check again without the arch subdirectory, since 3.13 doesn't
604+
// have it yet.
605+
// TODO(stuartmorgan): Remove this when CI no longer supports Flutter
606+
// 3.13.
607+
project = CMakeProject(example.directory,
608+
buildMode: buildMode,
609+
processRunner: processRunner,
610+
platform: platform);
611+
}
612+
}
571613
if (!project.isConfigured()) {
572614
printError('ERROR: Run "flutter build" on ${example.displayName}, '
573615
'or run this tool\'s "build-examples" command, for the target '

0 commit comments

Comments
 (0)