[flutter_tools] Add ARM64 Linux host and cross-building option support (#61221)

This commit is contained in:
Hidenori Matsubayashi
2021-02-12 14:25:30 -08:00
committed by GitHub
parent 97a9f2ae93
commit 4cc0ab2d19
40 changed files with 794 additions and 150 deletions

View File

@@ -8,8 +8,10 @@ import 'package:args/command_runner.dart';
import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/utils.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/cmake.dart';
import 'package:flutter_tools/src/commands/build.dart';
@@ -17,6 +19,7 @@ import 'package:flutter_tools/src/commands/build_linux.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../../src/common.dart';
@@ -39,7 +42,6 @@ final Platform notLinuxPlatform = FakePlatform(
}
);
void main() {
setUpAll(() {
Cache.disableLocking();
@@ -69,16 +71,20 @@ void main() {
}
// Returns the command matching the build_linux call to cmake.
FakeCommand cmakeCommand(String buildMode, {void Function() onRun}) {
FakeCommand cmakeCommand(String buildMode, {
String target = 'x64',
void Function() onRun,
}) {
return FakeCommand(
command: <String>[
'cmake',
'-G',
'Ninja',
'-DCMAKE_BUILD_TYPE=${toTitleCase(buildMode)}',
'-DFLUTTER_TARGET_PLATFORM=linux-$target',
'/linux',
],
workingDirectory: 'build/linux/$buildMode',
workingDirectory: 'build/linux/$target/$buildMode',
onRun: onRun,
);
}
@@ -86,6 +92,7 @@ void main() {
// Returns the command matching the build_linux call to ninja.
FakeCommand ninjaCommand(String buildMode, {
Map<String, String> environment,
String target = 'x64',
void Function() onRun,
String stdout = '',
}) {
@@ -93,7 +100,7 @@ void main() {
command: <String>[
'ninja',
'-C',
'build/linux/$buildMode',
'build/linux/$target/$buildMode',
'install',
],
environment: environment,
@@ -148,6 +155,7 @@ void main() {
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
});
testUsingContext('Handles argument error from missing cmake', () async {
@@ -167,6 +175,7 @@ void main() {
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
});
testUsingContext('Handles argument error from missing ninja', () async {
@@ -187,6 +196,7 @@ void main() {
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
});
testUsingContext('Linux build does not spew stdout to status logger', () async {
@@ -209,6 +219,7 @@ void main() {
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
});
testUsingContext('Linux build extracts errors from stdout', () async {
@@ -218,7 +229,7 @@ void main() {
// This contains a mix of routine build output and various types of errors
// (Dart error, compile error, link error), edited down for compactness.
const String stdout = r'''
ninja: Entering directory `build/linux/release'
ninja: Entering directory `build/linux/x64/release'
[1/6] Generating /foo/linux/flutter/ephemeral/libflutter_linux_gtk.so, /foo/linux/flutter/ephemeral/flutter_linux/flutter_linux.h, _phony
lib/main.dart:4:3: Error: Method not found: 'foo'.
[2/6] Building CXX object CMakeFiles/foo.dir/main.cc.o
@@ -262,6 +273,7 @@ ERROR: No file or variants found for asset: images/a_dot_burr.jpeg
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
});
testUsingContext('Linux verbose build sets VERBOSE_SCRIPT_LOGGING', () async {
@@ -287,9 +299,10 @@ ERROR: No file or variants found for asset: images/a_dot_burr.jpeg
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
});
testUsingContext('Linux build --debug passes debug mode to cmake and ninja', () async {
testUsingContext('Linux on x64 build --debug passes debug mode to cmake and ninja', () async {
final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[
@@ -297,7 +310,6 @@ ERROR: No file or variants found for asset: images/a_dot_burr.jpeg
ninjaCommand('debug'),
]);
await createTestCommandRunner(command).run(
const <String>['build', 'linux', '--debug', '--no-pub']
);
@@ -306,9 +318,29 @@ ERROR: No file or variants found for asset: images/a_dot_burr.jpeg
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
});
testUsingContext('Linux build --profile passes profile mode to make', () async {
testUsingContext('Linux on ARM64 build --debug passes debug mode to cmake and ninja', () async {
final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[
cmakeCommand('debug', target: 'arm64'),
ninjaCommand('debug', target: 'arm64'),
]);
await createTestCommandRunner(command).run(
const <String>['build', 'linux', '--debug', '--no-pub']
);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => CustomFakeOperatingSystemUtils(hostPlatform: HostPlatform.linux_arm64),
});
testUsingContext('Linux on x64 build --profile passes profile mode to make', () async {
final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[
@@ -324,6 +356,38 @@ ERROR: No file or variants found for asset: images/a_dot_burr.jpeg
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
});
testUsingContext('Linux on ARM64 build --profile passes profile mode to make', () async {
final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[
cmakeCommand('profile', target: 'arm64'),
ninjaCommand('profile', target: 'arm64'),
]);
await createTestCommandRunner(command).run(
const <String>['build', 'linux', '--profile', '--no-pub']
);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => CustomFakeOperatingSystemUtils(hostPlatform: HostPlatform.linux_arm64),
});
testUsingContext('Not support Linux cross-build for x64 on arm64', () async {
final BuildCommand command = BuildCommand();
expect(createTestCommandRunner(command).run(
const <String>['build', 'linux', '--no-pub', '--target-platform=linux-x64']
), throwsToolExit());
}, overrides: <Type, Generator>{
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => CustomFakeOperatingSystemUtils(hostPlatform: HostPlatform.linux_arm64),
});
testUsingContext('Linux build configures CMake exports', () async {
@@ -385,6 +449,7 @@ ERROR: No file or variants found for asset: images/a_dot_burr.jpeg
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
});
testUsingContext('linux can extract binary name from CMake file', () async {
@@ -417,14 +482,14 @@ set(BINARY_NAME "fizz_bar")
});
testUsingContext('hidden when not enabled on Linux host', () {
expect(BuildLinuxCommand().hidden, true);
expect(BuildLinuxCommand(operatingSystemUtils: FakeOperatingSystemUtils()).hidden, true);
}, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: false),
Platform: () => notLinuxPlatform,
});
testUsingContext('Not hidden when enabled and on Linux host', () {
expect(BuildLinuxCommand().hidden, false);
expect(BuildLinuxCommand(operatingSystemUtils: FakeOperatingSystemUtils()).hidden, false);
}, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
Platform: () => linuxPlatform,
@@ -453,7 +518,7 @@ set(BINARY_NAME "fizz_bar")
}),
]);
fileSystem.file('build/linux/release/bundle/libapp.so')
fileSystem.file('build/linux/x64/release/bundle/libapp.so')
..createSync(recursive: true)
..writeAsBytesSync(List<int>.filled(10000, 0));
@@ -472,5 +537,68 @@ set(BINARY_NAME "fizz_bar")
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
Usage: () => usage,
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
});
testUsingContext('Linux on ARM64 build --release passes, and check if the LinuxBuildDirectory for arm64 can be referenced correctly by using analytics', () async {
final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[
cmakeCommand('release', target: 'arm64'),
ninjaCommand('release', target: 'arm64', onRun: () {
fileSystem.file('build/flutter_size_01/snapshot.linux-arm64.json')
..createSync(recursive: true)
..writeAsStringSync('''
[
{
"l": "dart:_internal",
"c": "SubListIterable",
"n": "[Optimized] skip",
"s": 2400
}
]''');
fileSystem.file('build/flutter_size_01/trace.linux-arm64.json')
..createSync(recursive: true)
..writeAsStringSync('{}');
}),
]);
fileSystem.file('build/linux/arm64/release/bundle/libapp.so')
..createSync(recursive: true)
..writeAsBytesSync(List<int>.filled(10000, 0));
await createTestCommandRunner(command).run(
const <String>['build', 'linux', '--no-pub', '--analyze-size']
);
// check if libapp.so of "build/linux/arm64/release" directory can be referenced.
expect(testLogger.statusText, contains('libapp.so (Dart AOT)'));
expect(usage.events, contains(
const TestUsageEvent('code-size-analysis', 'linux'),
));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
Usage: () => usage,
OperatingSystemUtils: () => CustomFakeOperatingSystemUtils(hostPlatform: HostPlatform.linux_arm64),
});
}
class CustomFakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
CustomFakeOperatingSystemUtils({
HostPlatform hostPlatform = HostPlatform.linux_x64
}) : _hostPlatform = hostPlatform;
final HostPlatform _hostPlatform;
@override
String get name => 'Linux';
@override
HostPlatform get hostPlatform => _hostPlatform;
@override
List<File> whichAll(String execName) => <File>[];
}

View File

@@ -118,6 +118,7 @@ void main() {
cache: globals.cache,
fileSystem: fileSystem,
platform: platform,
operatingSystemUtils: FakeOperatingSystemUtils(),
);
Cache.flutterRoot = Cache.defaultFlutterRoot(
fileSystem: fileSystem,

View File

@@ -15,6 +15,7 @@ import 'package:flutter_tools/src/device.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fake_process_manager.dart';
import '../../src/testbed.dart';
@@ -25,6 +26,7 @@ void main() {
androidWorkflow = AndroidWorkflow(
androidSdk: FakeAndroidSdk(),
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
);
});
@@ -35,6 +37,7 @@ void main() {
androidWorkflow: AndroidWorkflow(
androidSdk: FakeAndroidSdk(null),
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
processManager: FakeProcessManager.list(<FakeCommand>[]),
fileSystem: MemoryFileSystem.test(),
@@ -55,6 +58,7 @@ void main() {
androidWorkflow: AndroidWorkflow(
androidSdk: FakeAndroidSdk('adb'),
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
processManager: fakeProcessManager,
fileSystem: MemoryFileSystem.test(),
@@ -74,6 +78,7 @@ void main() {
androidWorkflow: AndroidWorkflow(
androidSdk: FakeAndroidSdk(null),
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
processManager: FakeProcessManager.list(<FakeCommand>[]),
fileSystem: MemoryFileSystem.test(),
@@ -115,6 +120,7 @@ void main() {
featureFlags: TestFeatureFlags(
isAndroidEnabled: false,
),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
processManager: FakeProcessManager.any(),
fileSystem: MemoryFileSystem.test(),

View File

@@ -9,9 +9,11 @@ import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/android/android_workflow.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/base/version.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:mockito/mockito.dart';
@@ -49,6 +51,7 @@ void main() {
final AndroidWorkflow androidWorkflow = AndroidWorkflow(
featureFlags: TestFeatureFlags(),
androidSdk: null,
operatingSystemUtils: FakeOperatingSystemUtils(),
);
expect(androidWorkflow.canLaunchDevices, false);
@@ -62,6 +65,7 @@ void main() {
final AndroidWorkflow androidWorkflow = AndroidWorkflow(
featureFlags: TestFeatureFlags(),
androidSdk: androidSdk,
operatingSystemUtils: FakeOperatingSystemUtils(),
);
expect(androidWorkflow.canLaunchDevices, false);
@@ -69,6 +73,18 @@ void main() {
expect(androidWorkflow.canListEmulators, false);
});
// Android Studio is not currently supported on Linux Arm64 hosts.
testWithoutContext('Not supported AndroidStudio on Linux Arm Hosts', () {
final MockAndroidSdk androidSdk = MockAndroidSdk();
when(androidSdk.adbPath).thenReturn(null);
final AndroidWorkflow androidWorkflow = AndroidWorkflow(
featureFlags: TestFeatureFlags(),
androidSdk: androidSdk,
operatingSystemUtils: CustomFakeOperatingSystemUtils(hostPlatform: HostPlatform.linux_arm64),
);
expect(androidWorkflow.appliesToHostPlatform, false);
});
testWithoutContext('licensesAccepted returns LicensesAccepted.unknown if cannot find sdkmanager', () async {
processManager.canRunSucceeds = false;
@@ -394,3 +410,17 @@ void main() {
);
});
}
class CustomFakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
CustomFakeOperatingSystemUtils({
HostPlatform hostPlatform = HostPlatform.linux_x64
}) : _hostPlatform = hostPlatform;
final HostPlatform _hostPlatform;
@override
String get name => 'Linux';
@override
HostPlatform get hostPlatform => _hostPlatform;
}

View File

@@ -8,11 +8,9 @@ import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:mockito/mockito.dart';
import '../src/common.dart';
import '../src/context.dart';
@@ -34,12 +32,13 @@ void main() {
fileSystem: fileSystem,
platform: platform,
logger: BufferLogger.test(),
osUtils: MockOperatingSystemUtils(),
osUtils: FakeOperatingSystemUtils(),
);
artifacts = CachedArtifacts(
fileSystem: fileSystem,
cache: cache,
platform: platform,
operatingSystemUtils: FakeOperatingSystemUtils(),
);
});
@@ -114,6 +113,10 @@ void main() {
artifacts.getArtifactPath(Artifact.flutterTester),
fileSystem.path.join('root', 'bin', 'cache', 'artifacts', 'engine', 'linux-x64', 'flutter_tester'),
);
expect(
artifacts.getArtifactPath(Artifact.flutterTester, platform: TargetPlatform.linux_arm64),
fileSystem.path.join('root', 'bin', 'cache', 'artifacts', 'engine', 'linux-arm64', 'flutter_tester'),
);
});
testWithoutContext('precompiled web artifact paths are correct', () {
@@ -183,7 +186,7 @@ void main() {
fileSystem: fileSystem,
platform: platform,
logger: BufferLogger.test(),
osUtils: MockOperatingSystemUtils(),
osUtils: FakeOperatingSystemUtils(),
);
artifacts = LocalEngineArtifacts(
fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'android_debug_unopt'),
@@ -192,6 +195,7 @@ void main() {
fileSystem: fileSystem,
platform: platform,
processManager: FakeProcessManager.any(),
operatingSystemUtils: FakeOperatingSystemUtils(),
);
});
@@ -302,6 +306,7 @@ void main() {
fileSystem: fileSystem,
platform: FakePlatform(operatingSystem: 'windows'),
processManager: FakeProcessManager.any(),
operatingSystemUtils: FakeOperatingSystemUtils(),
);
expect(artifacts.getArtifactPath(Artifact.engineDartBinary), contains('.exe'));
@@ -312,5 +317,3 @@ void main() {
});
});
}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}

View File

@@ -151,6 +151,16 @@ void main() {
group('host platform', () {
testWithoutContext('unknown defaults to Linux', () async {
fakeProcessManager.addCommand(
const FakeCommand(
command: <String>[
'uname',
'-m',
],
stdout: 'x86_64',
),
);
final OperatingSystemUtils utils =
createOSUtils(FakePlatform(operatingSystem: 'fuchsia'));
expect(utils.hostPlatform, HostPlatform.linux_x64);
@@ -162,12 +172,38 @@ void main() {
expect(utils.hostPlatform, HostPlatform.windows_x64);
});
testWithoutContext('Linux', () async {
testWithoutContext('Linux x64', () async {
fakeProcessManager.addCommand(
const FakeCommand(
command: <String>[
'uname',
'-m',
],
stdout: 'x86_64',
),
);
final OperatingSystemUtils utils =
createOSUtils(FakePlatform(operatingSystem: 'linux'));
expect(utils.hostPlatform, HostPlatform.linux_x64);
});
testWithoutContext('Linux ARM', () async {
fakeProcessManager.addCommand(
const FakeCommand(
command: <String>[
'uname',
'-m',
],
stdout: 'aarch64',
),
);
final OperatingSystemUtils utils =
createOSUtils(FakePlatform(operatingSystem: 'linux'));
expect(utils.hostPlatform, HostPlatform.linux_arm64);
});
testWithoutContext('macOS ARM', () async {
fakeProcessManager.addCommands(
<FakeCommand>[

View File

@@ -20,7 +20,7 @@ import '../../../src/common.dart';
import '../../../src/context.dart';
void main() {
testWithoutContext('Copies files to correct cache directory, excluding unrelated code', () async {
testWithoutContext('Copies files to correct cache directory, excluding unrelated code on a x64 host', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final Artifacts artifacts = Artifacts.test();
setUpCacheDirectory(fileSystem, artifacts);
@@ -37,16 +37,57 @@ void main() {
);
testEnvironment.buildDir.createSync(recursive: true);
await const UnpackLinux().build(testEnvironment);
await const UnpackLinux(TargetPlatform.linux_x64).build(testEnvironment);
expect(fileSystem.file('linux/flutter/ephemeral/libflutter_linux_gtk.so'), exists);
final String headersPath = artifacts.getArtifactPath(Artifact.linuxHeaders, platform: TargetPlatform.linux_x64, mode: BuildMode.debug);
expect(fileSystem.file('linux/flutter/ephemeral/$headersPath/foo.h'), exists);
final String icuDataPath = artifacts.getArtifactPath(Artifact.icuData, platform: TargetPlatform.linux_x64);
expect(fileSystem.file('linux/flutter/ephemeral/$icuDataPath'), exists);
expect(fileSystem.file('linux/flutter/ephemeral/unrelated-stuff'), isNot(exists));
// Check if the target files are copied correctly.
final String headersPathForX64 = artifacts.getArtifactPath(Artifact.linuxHeaders, platform: TargetPlatform.linux_x64, mode: BuildMode.debug);
final String headersPathForArm64 = artifacts.getArtifactPath(Artifact.linuxHeaders, platform: TargetPlatform.linux_arm64, mode: BuildMode.debug);
expect(fileSystem.file('linux/flutter/ephemeral/$headersPathForX64/foo.h'), exists);
expect(fileSystem.file('linux/flutter/ephemeral/$headersPathForArm64/foo.h'), isNot(exists));
final String icuDataPathForX64 = artifacts.getArtifactPath(Artifact.icuData, platform: TargetPlatform.linux_x64);
final String icuDataPathForArm64 = artifacts.getArtifactPath(Artifact.icuData, platform: TargetPlatform.linux_arm64);
expect(fileSystem.file('linux/flutter/ephemeral/$icuDataPathForX64'), exists);
expect(fileSystem.file('linux/flutter/ephemeral/$icuDataPathForArm64'), isNot(exists));
});
// This test is basically the same logic as the above test.
// The difference is the target CPU architecture.
testWithoutContext('Copies files to correct cache directory, excluding unrelated code on a arm64 host', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final Artifacts artifacts = Artifacts.test();
setUpCacheDirectory(fileSystem, artifacts);
final Environment testEnvironment = Environment.test(
fileSystem.currentDirectory,
defines: <String, String>{
kBuildMode: 'debug',
},
artifacts: artifacts,
processManager: FakeProcessManager.any(),
fileSystem: fileSystem,
logger: BufferLogger.test(),
);
testEnvironment.buildDir.createSync(recursive: true);
await const UnpackLinux(TargetPlatform.linux_arm64).build(testEnvironment);
expect(fileSystem.file('linux/flutter/ephemeral/libflutter_linux_gtk.so'), exists);
expect(fileSystem.file('linux/flutter/ephemeral/unrelated-stuff'), isNot(exists));
// Check if the target files are copied correctly.
final String headersPathForX64 = artifacts.getArtifactPath(Artifact.linuxHeaders, platform: TargetPlatform.linux_x64, mode: BuildMode.debug);
final String headersPathForArm64 = artifacts.getArtifactPath(Artifact.linuxHeaders, platform: TargetPlatform.linux_arm64, mode: BuildMode.debug);
expect(fileSystem.file('linux/flutter/ephemeral/$headersPathForX64/foo.h'), isNot(exists));
expect(fileSystem.file('linux/flutter/ephemeral/$headersPathForArm64/foo.h'), exists);
final String icuDataPathForX64 = artifacts.getArtifactPath(Artifact.icuData, platform: TargetPlatform.linux_x64);
final String icuDataPathForArm64 = artifacts.getArtifactPath(Artifact.icuData, platform: TargetPlatform.linux_arm64);
expect(fileSystem.file('linux/flutter/ephemeral/$icuDataPathForX64'), isNot(exists));
expect(fileSystem.file('linux/flutter/ephemeral/$icuDataPathForArm64'), exists);
});
// Only required for the test below that still depends on the context.
@@ -85,7 +126,8 @@ void main() {
}
));
await const DebugBundleLinuxAssets().build(testEnvironment);
await const DebugBundleLinuxAssets(TargetPlatform.linux_x64).build(testEnvironment);
final Directory output = testEnvironment.outputDir
.childDirectory('flutter_assets');
@@ -103,6 +145,11 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
});
testWithoutContext('DebugBundleLinuxAssets\'s name depends on target platforms', () async {
expect(const DebugBundleLinuxAssets(TargetPlatform.linux_x64).name, 'debug_bundle_linux-x64_assets');
expect(const DebugBundleLinuxAssets(TargetPlatform.linux_arm64).name, 'debug_bundle_linux-arm64_assets');
});
testUsingContext('ProfileBundleLinuxAssets copies artifacts to out directory', () async {
final Environment testEnvironment = Environment.test(
fileSystem.currentDirectory,
@@ -121,7 +168,7 @@ void main() {
testEnvironment.buildDir.childFile('app.so').createSync();
await const LinuxAotBundle(AotElfProfile(TargetPlatform.linux_x64)).build(testEnvironment);
await const ProfileBundleLinuxAssets().build(testEnvironment);
await const ProfileBundleLinuxAssets(TargetPlatform.linux_x64).build(testEnvironment);
final Directory libDir = testEnvironment.outputDir
.childDirectory('lib');
final Directory assetsDir = testEnvironment.outputDir
@@ -137,6 +184,11 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
});
testWithoutContext('ProfileBundleLinuxAssets\'s name depends on target platforms', () async {
expect(const ProfileBundleLinuxAssets(TargetPlatform.linux_x64).name, 'profile_bundle_linux-x64_assets');
expect(const ProfileBundleLinuxAssets(TargetPlatform.linux_arm64).name, 'profile_bundle_linux-arm64_assets');
});
testUsingContext('ReleaseBundleLinuxAssets copies artifacts to out directory', () async {
final Environment testEnvironment = Environment.test(
fileSystem.currentDirectory,
@@ -155,7 +207,7 @@ void main() {
testEnvironment.buildDir.childFile('app.so').createSync();
await const LinuxAotBundle(AotElfRelease(TargetPlatform.linux_x64)).build(testEnvironment);
await const ReleaseBundleLinuxAssets().build(testEnvironment);
await const ReleaseBundleLinuxAssets(TargetPlatform.linux_x64).build(testEnvironment);
final Directory libDir = testEnvironment.outputDir
.childDirectory('lib');
final Directory assetsDir = testEnvironment.outputDir
@@ -170,16 +222,28 @@ void main() {
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testWithoutContext('ReleaseBundleLinuxAssets\'s name depends on target platforms', () async {
expect(const ReleaseBundleLinuxAssets(TargetPlatform.linux_x64).name, 'release_bundle_linux-x64_assets');
expect(const ReleaseBundleLinuxAssets(TargetPlatform.linux_arm64).name, 'release_bundle_linux-arm64_assets');
});
}
void setUpCacheDirectory(FileSystem fileSystem, Artifacts artifacts) {
final String desktopPath = artifacts.getArtifactPath(Artifact.linuxDesktopPath, platform: TargetPlatform.linux_x64, mode: BuildMode.debug);
fileSystem.file('$desktopPath/unrelated-stuff').createSync(recursive: true);
fileSystem.file('$desktopPath/libflutter_linux_gtk.so').createSync(recursive: true);
final String desktopPathForX64 = artifacts.getArtifactPath(Artifact.linuxDesktopPath, platform: TargetPlatform.linux_x64, mode: BuildMode.debug);
final String desktopPathForArm64 = artifacts.getArtifactPath(Artifact.linuxDesktopPath, platform: TargetPlatform.linux_arm64, mode: BuildMode.debug);
fileSystem.file('$desktopPathForX64/unrelated-stuff').createSync(recursive: true);
fileSystem.file('$desktopPathForX64/libflutter_linux_gtk.so').createSync(recursive: true);
fileSystem.file('$desktopPathForArm64/unrelated-stuff').createSync(recursive: true);
fileSystem.file('$desktopPathForArm64/libflutter_linux_gtk.so').createSync(recursive: true);
final String headersPath = artifacts.getArtifactPath(Artifact.linuxHeaders, platform: TargetPlatform.linux_x64, mode: BuildMode.debug);
fileSystem.file('$headersPath/foo.h').createSync(recursive: true);
final String headersPathForX64 = artifacts.getArtifactPath(Artifact.linuxHeaders, platform: TargetPlatform.linux_x64, mode: BuildMode.debug);
final String headersPathForArm64 = artifacts.getArtifactPath(Artifact.linuxHeaders, platform: TargetPlatform.linux_arm64, mode: BuildMode.debug);
fileSystem.file('$headersPathForX64/foo.h').createSync(recursive: true);
fileSystem.file('$headersPathForArm64/foo.h').createSync(recursive: true);
fileSystem.file(artifacts.getArtifactPath(Artifact.icuData, platform: TargetPlatform.linux_x64)).createSync();
fileSystem.file(artifacts.getArtifactPath(Artifact.icuData, platform: TargetPlatform.linux_arm64)).createSync();
fileSystem.file('packages/flutter_tools/lib/src/build_system/targets/linux.dart').createSync(recursive: true);
}

View File

@@ -23,7 +23,36 @@ import 'package:process/process.dart';
import '../src/common.dart';
import '../src/context.dart';
const FakeCommand unameCommandForX64 = FakeCommand(
command: <String>[
'uname',
'-m',
],
stdout: 'x86_64',
);
const FakeCommand unameCommandForArm64 = FakeCommand(
command: <String>[
'uname',
'-m',
],
stdout: 'aarch64',
);
void main() {
FakeProcessManager fakeProcessManager;
setUp(() {
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
});
Cache createCache(Platform platform) {
return Cache.test(
platform: platform,
processManager: fakeProcessManager
);
}
group('Cache.checkLockAcquired', () {
setUp(() {
Cache.enableLocking();
@@ -365,16 +394,28 @@ void main() {
expect(artifacts.developmentArtifact, DevelopmentArtifact.universal);
});
testWithoutContext('FontSubset artifacts on linux', () {
final Cache cache = Cache.test();
testWithoutContext('FontSubset artifacts on x64 linux', () {
fakeProcessManager.addCommand(unameCommandForX64);
final Cache cache = createCache(FakePlatform(operatingSystem: 'linux'));
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache, platform: FakePlatform(operatingSystem: 'linux'));
cache.includeAllPlatforms = false;
expect(artifacts.getBinaryDirs(), <List<String>>[<String>['linux-x64', 'linux-x64/font-subset.zip']]);
});
testWithoutContext('FontSubset artifacts on arm64 linux', () {
fakeProcessManager.addCommand(unameCommandForArm64);
final Cache cache = createCache(FakePlatform(operatingSystem: 'linux'));
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache, platform: FakePlatform(operatingSystem: 'linux'));
cache.includeAllPlatforms = false;
expect(artifacts.getBinaryDirs(), <List<String>>[<String>['linux-arm64', 'linux-arm64/font-subset.zip']]);
});
testWithoutContext('FontSubset artifacts on windows', () {
final Cache cache = Cache.test();
final Cache cache = createCache(FakePlatform(operatingSystem: 'windows'));
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache, platform: FakePlatform(operatingSystem: 'windows'));
cache.includeAllPlatforms = false;
@@ -382,7 +423,24 @@ void main() {
});
testWithoutContext('FontSubset artifacts on macos', () {
final Cache cache = Cache.test();
fakeProcessManager.addCommands(<FakeCommand>[
const FakeCommand(
command: <String>[
'which',
'sysctl'
],
stdout: '/sbin/sysctl',
),
const FakeCommand(
command: <String>[
'sysctl',
'hw.optional.arm64',
],
stdout: 'hw.optional.arm64: 0',
),
]);
final Cache cache = createCache(FakePlatform(operatingSystem: 'macos'));
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache, platform: FakePlatform(operatingSystem: 'macos'));
cache.includeAllPlatforms = false;
@@ -390,23 +448,41 @@ void main() {
});
testWithoutContext('FontSubset artifacts on fuchsia', () {
final Cache cache = Cache.test();
fakeProcessManager.addCommand(unameCommandForX64);
final Cache cache = createCache(FakePlatform(operatingSystem: 'fuchsia'));
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache, platform: FakePlatform(operatingSystem: 'fuchsia'));
cache.includeAllPlatforms = false;
expect(artifacts.getBinaryDirs, throwsToolExit(message: 'Unsupported operating system: fuchsia'));
});
testWithoutContext('FontSubset artifacts for all platforms', () {
final Cache cache = Cache.test();
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache, platform: FakePlatform(operatingSystem: 'fuchsia'));
cache.includeAllPlatforms = true;
testWithoutContext('FontSubset artifacts for all platforms on x64 hosts', () {
fakeProcessManager.addCommand(unameCommandForX64);
expect(artifacts.getBinaryDirs(), <List<String>>[
<String>['darwin-x64', 'darwin-x64/font-subset.zip'],
<String>['linux-x64', 'linux-x64/font-subset.zip'],
<String>['windows-x64', 'windows-x64/font-subset.zip'],
]);
final Cache cache = createCache(FakePlatform(operatingSystem: 'fuchsia'));
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache, platform: FakePlatform(operatingSystem: 'fuchsia'));
cache.includeAllPlatforms = true;
expect(artifacts.getBinaryDirs(), <List<String>>[
<String>['darwin-x64', 'darwin-x64/font-subset.zip'],
<String>['linux-x64', 'linux-x64/font-subset.zip'],
<String>['windows-x64', 'windows-x64/font-subset.zip'],
]);
});
testWithoutContext('FontSubset artifacts for all platforms on arm64 hosts', () {
fakeProcessManager.addCommand(unameCommandForArm64);
final Cache cache = createCache(FakePlatform(operatingSystem: 'fuchsia'));
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache, platform: FakePlatform(operatingSystem: 'fuchsia'));
cache.includeAllPlatforms = true;
expect(artifacts.getBinaryDirs(), <List<String>>[
<String>['darwin-x64', 'darwin-x64/font-subset.zip'], // arm64 macOS hosts are not supported now
<String>['linux-arm64', 'linux-arm64/font-subset.zip'],
<String>['windows-x64', 'windows-x64/font-subset.zip'], // arm64 macOS hosts are not supported now
]);
});
testWithoutContext('macOS desktop artifacts ignore filtering when requested', () {
@@ -444,7 +520,9 @@ void main() {
});
testWithoutContext('Linux desktop artifacts ignore filtering when requested', () {
final Cache cache = Cache.test();
fakeProcessManager.addCommand(unameCommandForX64);
final Cache cache = createCache(FakePlatform(operatingSystem: 'linux'));
final LinuxEngineArtifacts artifacts = LinuxEngineArtifacts(
cache,
platform: FakePlatform(operatingSystem: 'macos'),
@@ -455,17 +533,36 @@ void main() {
expect(artifacts.getBinaryDirs(), isNotEmpty);
});
testWithoutContext('Linux desktop artifacts include profile and release artifacts', () {
final Cache cache = Cache.test();
final LinuxEngineArtifacts artifacts = LinuxEngineArtifacts(
cache,
platform: FakePlatform(operatingSystem: 'linux'),
);
testWithoutContext('Linux desktop artifacts for x64 include profile and release artifacts', () {
fakeProcessManager.addCommand(unameCommandForX64);
expect(artifacts.getBinaryDirs(), containsAll(<Matcher>[
contains(contains('profile')),
contains(contains('release')),
]));
final Cache cache = createCache(FakePlatform(operatingSystem: 'linux'));
final LinuxEngineArtifacts artifacts = LinuxEngineArtifacts(
cache,
platform: FakePlatform(operatingSystem: 'linux'),
);
expect(artifacts.getBinaryDirs(), <List<String>>[
<String>['linux-x64', 'linux-x64/linux-x64-flutter-gtk.zip'],
<String>['linux-x64-profile', 'linux-x64-profile/linux-x64-flutter-gtk.zip'],
<String>['linux-x64-release', 'linux-x64-release/linux-x64-flutter-gtk.zip'],
]);
});
testWithoutContext('Linux desktop artifacts for arm64 include profile and release artifacts', () {
fakeProcessManager.addCommand(unameCommandForArm64);
final Cache cache = createCache(FakePlatform(operatingSystem: 'linux'));
final LinuxEngineArtifacts artifacts = LinuxEngineArtifacts(
cache,
platform: FakePlatform(operatingSystem: 'linux'),
);
expect(artifacts.getBinaryDirs(), <List<String>>[
<String>['linux-arm64', 'linux-arm64/linux-arm64-flutter-gtk.zip'],
<String>['linux-arm64-profile', 'linux-arm64-profile/linux-arm64-flutter-gtk.zip'],
<String>['linux-arm64-release', 'linux-arm64-release/linux-arm64-flutter-gtk.zip'],
]);
});
testWithoutContext('Cache can delete stampfiles of artifacts', () {

View File

@@ -28,7 +28,7 @@ void main() {
testUsingContext('All build commands support null safety options', () {
final List<FlutterCommand> commands = <FlutterCommand>[
BuildWindowsCommand(verboseHelp: false),
BuildLinuxCommand(verboseHelp: false),
BuildLinuxCommand(verboseHelp: false, operatingSystemUtils: globals.os),
BuildMacosCommand(verboseHelp: false),
BuildWebCommand(verboseHelp: false),
BuildApkCommand(verboseHelp: false),

View File

@@ -79,6 +79,7 @@ void main() {
androidWorkflow: AndroidWorkflow(
androidSdk: mockSdk,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
@@ -101,6 +102,7 @@ void main() {
androidWorkflow: AndroidWorkflow(
androidSdk: null,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
@@ -135,6 +137,7 @@ void main() {
androidWorkflow: AndroidWorkflow(
androidSdk: mockSdk,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
final CreateEmulatorResult result = await emulatorManager.createEmulator();
@@ -176,6 +179,7 @@ void main() {
androidWorkflow: AndroidWorkflow(
androidSdk: mockSdk,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
final CreateEmulatorResult result = await emulatorManager.createEmulator();
@@ -212,6 +216,7 @@ void main() {
androidWorkflow: AndroidWorkflow(
androidSdk: mockSdk,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
final CreateEmulatorResult result = await emulatorManager.createEmulator(name: 'test');
@@ -250,6 +255,7 @@ void main() {
androidWorkflow: AndroidWorkflow(
androidSdk: mockSdk,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
final CreateEmulatorResult result = await emulatorManager.createEmulator(name: 'existing-avd-1');
@@ -291,6 +297,7 @@ void main() {
androidWorkflow: AndroidWorkflow(
androidSdk: mockSdk,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
final CreateEmulatorResult result = await emulatorManager.createEmulator();

View File

@@ -839,6 +839,7 @@ void main() {
cache: cache,
fileSystem: fileSystem,
platform: FakePlatform(operatingSystem: 'linux'),
operatingSystemUtils: globals.os,
);
expect(artifacts.getArtifactPath(
Artifact.fuchsiaFlutterRunner,

View File

@@ -53,6 +53,16 @@ void main() {
expect(device.supportsRuntimeMode(BuildMode.jitRelease), false);
});
testWithoutContext('LinuxDevice on arm64 hosts is arm64', () async {
final LinuxDevice deviceArm64Host = LinuxDevice(
processManager: FakeProcessManager.any(),
logger: BufferLogger.test(),
fileSystem: MemoryFileSystem.test(),
operatingSystemUtils: FakeOperatingSystemUtils(hostPlatform: HostPlatform.linux_arm64),
);
expect(await deviceArm64Host.targetPlatform, TargetPlatform.linux_arm64);
});
testWithoutContext('LinuxDevice: no devices listed if platform unsupported', () async {
expect(await LinuxDevices(
fileSystem: MemoryFileSystem.test(),
@@ -159,6 +169,15 @@ FlutterProject setUpFlutterProject(Directory directory) {
class MockLinuxApp extends Mock implements LinuxApp {}
class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
FakeOperatingSystemUtils({
HostPlatform hostPlatform = HostPlatform.linux_x64
}) : _hostPlatform = hostPlatform;
final HostPlatform _hostPlatform;
@override
String get name => 'Linux';
@override
HostPlatform get hostPlatform => _hostPlatform;
}

View File

@@ -90,7 +90,7 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
linux-x64 ${CMAKE_BUILD_TYPE}
${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
VERBATIM
)
''';
@@ -117,7 +117,7 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
linux-x64 ${CMAKE_BUILD_TYPE}
${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
)
''');
@@ -128,6 +128,22 @@ add_custom_command(
expect(cmakeProjectMigration.migrate(), isTrue);
expect(managedCmakeFile.readAsStringSync(), r'''
add_custom_command(
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
${CMAKE_CURRENT_BINARY_DIR}/_phony_
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
VERBATIM
)
''');
expect(testLogger.statusText, contains('add_custom_command() missing VERBATIM or FLUTTER_TARGET_PLATFORM, updating.'));
});
testWithoutContext('is migrated to use FLUTTER_TARGET_PLATFORM', () {
managedCmakeFile.writeAsStringSync(r'''
add_custom_command(
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
${CMAKE_CURRENT_BINARY_DIR}/_phony_
@@ -139,7 +155,25 @@ add_custom_command(
)
''');
expect(testLogger.statusText, contains('add_custom_command() missing VERBATIM, updating.'));
final CmakeCustomCommandMigration cmakeProjectMigration = CmakeCustomCommandMigration(
mockCmakeProject,
testLogger,
);
expect(cmakeProjectMigration.migrate(), isTrue);
expect(managedCmakeFile.readAsStringSync(), r'''
add_custom_command(
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
${CMAKE_CURRENT_BINARY_DIR}/_phony_
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
VERBATIM
)
''');
expect(testLogger.statusText, contains('add_custom_command() missing VERBATIM or FLUTTER_TARGET_PLATFORM, updating.'));
});
});
});

View File

@@ -71,8 +71,8 @@ void main() {
final List<Device> devices = await discoverer.discoverDevices(timeout: const Duration(seconds: 10));
expect(devices, hasLength(1));
});
});
group('startApp', () {
FlutterTesterDevice device;
List<String> logLines;
@@ -106,6 +106,7 @@ void main() {
buildDirectory: 'build',
logger: BufferLogger.test(),
flutterVersion: MockFlutterVersion(),
operatingSystemUtils: FakeOperatingSystemUtils(),
);
logLines = <String>[];
device.getLogReader().logLines.listen(logLines.add);
@@ -169,7 +170,7 @@ Hello!
final LaunchResult result = await device.startApp(app,
mainPath: mainPath,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug)
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
);
expect(result.started, isTrue);
@@ -188,6 +189,7 @@ FlutterTesterDevices setUpFlutterTesterDevices() {
fileSystem: MemoryFileSystem.test(),
config: Config.test(),
flutterVersion: MockFlutterVersion(),
operatingSystemUtils: FakeOperatingSystemUtils(),
);
}

View File

@@ -396,6 +396,9 @@ class FakeCache implements Cache {
return globals.fs.currentDirectory;
}
@override
String getHostPlatformArchName() => 'x64';
@override
File getLicenseFile() {
return globals.fs.currentDirectory.childFile('LICENSE');