gen_snapshot: fix Platform.operatingSystem issue (#213)
This change fixes an issue that `Platform.operatingSystem` returns Android on x64 hosts and when cross-building for arm64 targets on x64 hosts. To fix the issue, use the gen_snapshot of linux and elinux instead of Android's one. Fixed https://github.com/sony/flutter-elinux/issues/212 Signed-off-by: Hidenori Matsubayashi <[email protected]>
This commit is contained in:
@@ -88,12 +88,11 @@ class BuildPackageCommand extends BuildSubCommand
|
|||||||
@override
|
@override
|
||||||
Future<Set<DevelopmentArtifact>> get requiredArtifacts async =>
|
Future<Set<DevelopmentArtifact>> get requiredArtifacts async =>
|
||||||
<DevelopmentArtifact>{
|
<DevelopmentArtifact>{
|
||||||
// Use gensnapshot for Arm64 Linux when the host is arm64 because
|
// Use gen_snapshot of the arm64 linux-desktop when self-building
|
||||||
// the artifacts for arm64 host don't support self-building now.
|
// on arm64 hosts. This is because elinux's artifacts for arm64
|
||||||
|
// doesn't support self-build as of now.
|
||||||
if (_getCurrentHostPlatformArchName() == 'arm64')
|
if (_getCurrentHostPlatformArchName() == 'arm64')
|
||||||
DevelopmentArtifact.linux,
|
DevelopmentArtifact.linux,
|
||||||
if (_getCurrentHostPlatformArchName() == 'x64')
|
|
||||||
DevelopmentArtifact.androidGenSnapshot,
|
|
||||||
ELinuxDevelopmentArtifact.elinux,
|
ELinuxDevelopmentArtifact.elinux,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -18,12 +18,11 @@ class ELinuxRunCommand extends RunCommand
|
|||||||
@override
|
@override
|
||||||
Future<Set<DevelopmentArtifact>> get requiredArtifacts async =>
|
Future<Set<DevelopmentArtifact>> get requiredArtifacts async =>
|
||||||
<DevelopmentArtifact>{
|
<DevelopmentArtifact>{
|
||||||
// Use gensnapshot for Arm64 Linux when the host is arm64 because
|
// Use gen_snapshot of the arm64 linux-desktop when self-building
|
||||||
// the artifacts for arm64 host don't support self-building now.
|
// on arm64 hosts. This is because elinux's artifacts for arm64
|
||||||
|
// doesn't support self-build as of now.
|
||||||
if (_getCurrentHostPlatformArchName() == 'arm64')
|
if (_getCurrentHostPlatformArchName() == 'arm64')
|
||||||
DevelopmentArtifact.linux,
|
DevelopmentArtifact.linux,
|
||||||
if (_getCurrentHostPlatformArchName() == 'x64')
|
|
||||||
DevelopmentArtifact.androidGenSnapshot,
|
|
||||||
ELinuxDevelopmentArtifact.elinux,
|
ELinuxDevelopmentArtifact.elinux,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -34,16 +34,19 @@ class ELinuxArtifacts extends CachedArtifacts {
|
|||||||
BuildMode? mode,
|
BuildMode? mode,
|
||||||
EnvironmentType? environmentType,
|
EnvironmentType? environmentType,
|
||||||
}) {
|
}) {
|
||||||
|
final HostPlatform hostPlatform = getCurrentHostPlatform();
|
||||||
|
|
||||||
|
// Use elinux-*-*/linux-x64/gen_snapshot only when the host pc is x64 arch.
|
||||||
|
// The other causes use linux-desktop's one.
|
||||||
if (artifact == Artifact.genSnapshot &&
|
if (artifact == Artifact.genSnapshot &&
|
||||||
|
hostPlatform == HostPlatform.linux_x64 &&
|
||||||
platform != null &&
|
platform != null &&
|
||||||
getNameForTargetPlatform(platform).startsWith('android')) {
|
getNameForTargetPlatform(platform).startsWith('linux')) {
|
||||||
assert(mode != null, 'Need to specify a build mode.');
|
assert(mode != null, 'Need to specify a build mode.');
|
||||||
assert(mode != BuildMode.debug,
|
assert(mode != BuildMode.debug,
|
||||||
'Artifact $artifact only available in non-debug mode.');
|
'Artifact $artifact only available in non-debug mode.');
|
||||||
|
|
||||||
final String arch = _getArchForTargetPlatform(platform);
|
final String arch = _getArchForTargetPlatform(platform);
|
||||||
final HostPlatform hostPlatform = getCurrentHostPlatform();
|
|
||||||
assert(hostPlatform != HostPlatform.linux_arm64,
|
|
||||||
'Artifact $artifact not available on Linux arm64.');
|
|
||||||
return _getEngineArtifactsDirectory(arch, mode!)
|
return _getEngineArtifactsDirectory(arch, mode!)
|
||||||
.childDirectory(getNameForHostPlatform(hostPlatform))
|
.childDirectory(getNameForHostPlatform(hostPlatform))
|
||||||
.childFile('gen_snapshot')
|
.childFile('gen_snapshot')
|
||||||
@@ -53,10 +56,10 @@ class ELinuxArtifacts extends CachedArtifacts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _getArchForTargetPlatform(TargetPlatform platform) {
|
String _getArchForTargetPlatform(TargetPlatform platform) {
|
||||||
if (platform == TargetPlatform.android_arm64) {
|
if (platform == TargetPlatform.linux_x64) {
|
||||||
return 'arm64';
|
|
||||||
} else {
|
|
||||||
return 'x64';
|
return 'x64';
|
||||||
|
} else {
|
||||||
|
return 'arm64';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-19
@@ -12,7 +12,6 @@ import 'package:flutter_tools/src/android/gradle.dart';
|
|||||||
import 'package:flutter_tools/src/base/analyze_size.dart';
|
import 'package:flutter_tools/src/base/analyze_size.dart';
|
||||||
import 'package:flutter_tools/src/base/common.dart';
|
import 'package:flutter_tools/src/base/common.dart';
|
||||||
import 'package:flutter_tools/src/base/logger.dart';
|
import 'package:flutter_tools/src/base/logger.dart';
|
||||||
import 'package:flutter_tools/src/base/os.dart';
|
|
||||||
import 'package:flutter_tools/src/build_info.dart';
|
import 'package:flutter_tools/src/build_info.dart';
|
||||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||||
import 'package:flutter_tools/src/cache.dart';
|
import 'package:flutter_tools/src/cache.dart';
|
||||||
@@ -179,22 +178,11 @@ class ELinuxBuilder {
|
|||||||
|
|
||||||
/// See: [getTargetPlatformForName] in `build_info.dart`
|
/// See: [getTargetPlatformForName] in `build_info.dart`
|
||||||
TargetPlatform _getTargetPlatformForArch(String arch) {
|
TargetPlatform _getTargetPlatformForArch(String arch) {
|
||||||
final String hostArch = _getCurrentHostPlatformArchName();
|
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
// Use gensnapshot for Arm64 Linux when the host is arm64 because
|
return TargetPlatform.linux_arm64;
|
||||||
// the artifacts for arm64 host don't support self-building now.
|
|
||||||
if (hostArch == 'arm64') {
|
|
||||||
return TargetPlatform.linux_arm64;
|
|
||||||
}
|
|
||||||
return TargetPlatform.android_arm64;
|
|
||||||
default:
|
default:
|
||||||
// Use gensnapshot for Arm64 Linux when the host is arm64 because
|
return TargetPlatform.linux_x64;
|
||||||
// the artifacts for arm64 host don't support self-building now.
|
|
||||||
if (hostArch == 'arm64') {
|
|
||||||
return TargetPlatform.linux_x64;
|
|
||||||
}
|
|
||||||
return TargetPlatform.android_x64;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,8 +199,3 @@ String _getTargetPlatformPlatformName(TargetPlatform targetPlatform) {
|
|||||||
return 'android-x64';
|
return 'android-x64';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _getCurrentHostPlatformArchName() {
|
|
||||||
final HostPlatform hostPlatform = getCurrentHostPlatform();
|
|
||||||
return hostPlatform.platformName;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user