blob: 5c65fb38ab6b2c05f0d7c081f9ec0e94e9d74fb0 [file] [log] [blame]
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import '../base/analyze_size.dart';
import '../base/common.dart';
import '../base/os.dart';
import '../build_info.dart';
import '../cache.dart';
import '../features.dart';
import '../globals_null_migrated.dart' as globals;
import '../linux/build_linux.dart';
import '../project.dart';
import '../runner/flutter_command.dart' show FlutterCommandResult;
import 'build.dart';
/// A command to build a linux desktop target through a build shell script.
class BuildLinuxCommand extends BuildSubCommand {
@required OperatingSystemUtils operatingSystemUtils,
bool verboseHelp = false,
}) : _operatingSystemUtils = operatingSystemUtils {
addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
final String defaultTargetPlatform =
(_operatingSystemUtils.hostPlatform == HostPlatform.linux_arm64) ?
'linux-arm64' : 'linux-x64';
defaultsTo: defaultTargetPlatform,
allowed: <String>['linux-arm64', 'linux-x64'],
help: 'The target platform for which the app is compiled.',
defaultsTo: '/',
help: 'The root filesystem path of target platform for which '
'the app is compiled. This option is valid only '
'if the current host and target architectures are different.',
final OperatingSystemUtils _operatingSystemUtils;
final String name = 'linux';
bool get hidden => !featureFlags.isLinuxEnabled || !globals.platform.isLinux;
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{
String get description => 'Build a Linux desktop application.';
Future<FlutterCommandResult> runCommand() async {
final BuildInfo buildInfo = await getBuildInfo();
final FlutterProject flutterProject = FlutterProject.current();
final TargetPlatform targetPlatform =
final bool needCrossBuild =
!= getNameForTargetPlatformArch(targetPlatform);
if (!featureFlags.isLinuxEnabled) {
throwToolExit('"build linux" is not currently supported. To enable, run "flutter config --enable-linux-desktop".');
if (!globals.platform.isLinux) {
throwToolExit('"build linux" only supported on Linux hosts.');
// Cross-building for x64 targets on arm64 hosts is not supported.
if (_operatingSystemUtils.hostPlatform != HostPlatform.linux_x64 &&
targetPlatform != TargetPlatform.linux_arm64) {
throwToolExit('"cross-building" only supported on Linux x64 hosts.');
// TODO(fujino):
if (_operatingSystemUtils.hostPlatform == HostPlatform.linux_x64 &&
targetPlatform == TargetPlatform.linux_arm64) {
'Cross-build from Linux x64 host to Linux arm64 target is not currently supported.');
await buildLinux(
target: targetFile,
sizeAnalyzer: SizeAnalyzer(
fileSystem: globals.fs,
logger: globals.logger,
flutterUsage: globals.flutterUsage,
needCrossBuild: needCrossBuild,
targetPlatform: targetPlatform,
targetSysroot: stringArg('target-sysroot'),
return FlutterCommandResult.success();