Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 36 additions & 20 deletions packages/pigeon/tool/shared/test_suites.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// ignore_for_file: avoid_print

import 'dart:ffi';
import 'dart:io' show Directory, File;

import 'package:meta/meta.dart';
Expand Down Expand Up @@ -411,17 +412,31 @@ Future<int> _runLinuxUnitTests({bool ciMode = false}) async {

const buildDirBase = '$examplePath/build/linux';
const buildRelativeBinaryPath = 'debug/plugins/test_plugin/test_plugin_test';
const arm64Path = '$buildDirBase/arm64/$buildRelativeBinaryPath';
const x64Path = '$buildDirBase/x64/$buildRelativeBinaryPath';
final testBinary = File(arm64Path).existsSync() ? arm64Path : x64Path;

final abi = Abi.current();
final String? arch = switch (abi) {
Abi.linuxArm64 => 'arm64',
Abi.linuxX64 => 'x64',
Abi.linuxRiscv64 => 'riscv64',
_ => null,
};

if (arch == null) {
print(
'The host platform and architecture "$abi" is not supported for Linux test suite.',
);
return 1;
}

final binaryPath = '$buildDirBase/$arch/$buildRelativeBinaryPath';
if (ciMode) {
// To avoid having all custom tests in the repo run under xvfb, xvfb-run is
// done here rather than at the CI config level. Ideally, Pigeon tests
// should be incorporated into the repo tooling's standard runs, at which
// point this won't be necessary.
return runProcess('xvfb-run', <String>[testBinary]);
return runProcess('xvfb-run', <String>[binaryPath]);
} else {
return runProcess(testBinary, <String>[]);
return runProcess(binaryPath, <String>[]);
}
}

Expand All @@ -446,25 +461,26 @@ Future<int> _runWindowsUnitTests({bool ciMode = false}) async {
return compileCode;
}

// Depending on the Flutter version, the build output path may be different.
// To handle both master and stable, and to future-proof against the changes
// that will happen in https://github.com/flutter/flutter/issues/129807
// - Try arm64, to future-proof against arm64 support.
// - Try x64, to cover pre-arm64 support on arm64 hosts, as well as x64 hosts.
// TODO(stuartmorgan): Remove all this when these tests no longer need to
// support a version of Flutter without
// https://github.com/flutter/flutter/issues/129807, and just construct the
// version of the path with the current architecture.
const buildDirBase = '$examplePath/build/windows';
const buildRelativeBinaryPath =
'plugins/test_plugin/Debug/test_plugin_test.exe';
const arm64Path = '$buildDirBase/arm64/$buildRelativeBinaryPath';
const x64Path = '$buildDirBase/x64/$buildRelativeBinaryPath';
if (File(arm64Path).existsSync()) {
return runProcess(arm64Path, <String>[]);
} else {
return runProcess(x64Path, <String>[]);

final abi = Abi.current();
final String? arch = switch (abi) {
Abi.windowsArm64 => 'arm64',
Abi.windowsX64 => 'x64',
_ => null,
};

if (arch == null) {
print(
'The host platform and architecture "$abi" is not supported for Windows test suite.',
);
return 1;
}

final binaryPath = '$buildDirBase/$arch/$buildRelativeBinaryPath';
return runProcess(binaryPath, <String>[]);
}

Future<int> _runWindowsIntegrationTests({bool ciMode = false}) async {
Expand Down
14 changes: 5 additions & 9 deletions script/tool/lib/src/common/cmake.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CMakeProject {
required this.buildMode,
this.processRunner = const ProcessRunner(),
this.platform = const LocalPlatform(),
this.arch,
required this.arch,
});

/// The directory of a Flutter project to run Gradle commands in.
Expand All @@ -33,13 +33,11 @@ class CMakeProject {
final Platform platform;

/// The architecture subdirectory of the build.
// TODO(stuartmorgan): Make this non-nullable once Flutter 3.13 is no longer
// supported, since at that point there will always be a subdirectory.
final String? arch;
final String arch;

/// The build mode (e.g., Debug, Release).
///
/// This is a constructor paramater because on Linux many properties depend
/// This is a constructor parameter because on Linux many properties depend
/// on the build mode since it uses a single-configuration generator.
final String buildMode;

Expand All @@ -52,10 +50,8 @@ class CMakeProject {
Directory get buildDirectory {
Directory buildDir = flutterProject
.childDirectory('build')
.childDirectory(_platformDirName);
if (arch != null) {
buildDir = buildDir.childDirectory(arch!);
}
.childDirectory(_platformDirName)
.childDirectory(arch);
if (platform.isLinux) {
// Linux uses a single-config generator, so the base build directory
// includes the configuration.
Expand Down
52 changes: 15 additions & 37 deletions script/tool/lib/src/native_test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -677,51 +677,29 @@ this command.
final testBinaries = <File>[];
var hasMissingBuild = false;
var buildFailed = false;
String? arch;
const x64DirName = 'x64';
const arm64DirName = 'arm64';
if (platform.isWindows) {
arch = _abi == Abi.windowsX64 ? x64DirName : arm64DirName;
} else if (platform.isLinux) {
// TODO(stuartmorgan): Support arm64 if that ever becomes a supported
// CI configuration for the repository.
arch = 'x64';

final String? arch = switch (_abi) {
Abi.windowsX64 || Abi.linuxX64 => 'x64',
Abi.windowsArm64 || Abi.linuxArm64 => 'arm64',
_ => null,
};

if (arch == null) {
return _PlatformResult(
RunState.failed,
error:
'Testing on platform and architecture "$_abi" as CMakeProjects is not supported.',
);
}

for (final RepositoryPackage example in plugin.getExamples()) {
var project = CMakeProject(
final project = CMakeProject(
example.directory,
buildMode: buildMode,
processRunner: processRunner,
platform: platform,
arch: arch,
);
if (platform.isWindows) {
if (arch == arm64DirName && !project.isConfigured()) {
// Check for x64, to handle builds newer than 3.13, but that don't yet
// have https://github.com/flutter/flutter/issues/129807.
// TODO(stuartmorgan): Remove this when CI no longer supports a
// version of Flutter without the issue above fixed.
project = CMakeProject(
example.directory,
buildMode: buildMode,
processRunner: processRunner,
platform: platform,
arch: x64DirName,
);
}
if (!project.isConfigured()) {
// Check again without the arch subdirectory, since 3.13 doesn't
// have it yet.
// TODO(stuartmorgan): Remove this when CI no longer supports Flutter
// 3.13.
project = CMakeProject(
example.directory,
buildMode: buildMode,
processRunner: processRunner,
platform: platform,
);
}
}
if (!project.isConfigured()) {
printError(
'ERROR: Run "flutter build" on ${example.displayName}, '
Expand Down