build_linux.dart 1.78 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

7
import '../base/analyze_size.dart';
8 9 10
import '../base/common.dart';
import '../build_info.dart';
import '../cache.dart';
11
import '../features.dart';
12
import '../globals.dart' as globals;
13
import '../linux/build_linux.dart';
14 15 16 17 18 19
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 {
20
  BuildLinuxCommand({ bool verboseHelp = false }) {
21
    addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
22 23 24 25 26 27
  }

  @override
  final String name = 'linux';

  @override
28
  bool get hidden => !featureFlags.isLinuxEnabled || !globals.platform.isLinux;
29 30 31 32 33 34 35

  @override
  Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{
    DevelopmentArtifact.linux,
  };

  @override
36
  String get description => 'Build a Linux desktop application.';
37 38 39 40

  @override
  Future<FlutterCommandResult> runCommand() async {
    final BuildInfo buildInfo = getBuildInfo();
41
    final FlutterProject flutterProject = FlutterProject.current();
42 43 44
    if (!featureFlags.isLinuxEnabled) {
      throwToolExit('"build linux" is not currently supported.');
    }
45
    if (!globals.platform.isLinux) {
46 47
      throwToolExit('"build linux" only supported on Linux hosts.');
    }
48 49 50 51 52 53 54
    await buildLinux(
      flutterProject.linux,
      buildInfo,
      target: targetFile,
      sizeAnalyzer: SizeAnalyzer(
        fileSystem: globals.fs,
        logger: globals.logger,
55
        flutterUsage: globals.flutterUsage,
56 57
      ),
    );
58
    return FlutterCommandResult.success();
59 60
  }
}