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

5
import 'package:meta/meta.dart';
6
import 'package:process/process.dart';
7

8
import '../base/file_system.dart';
9
import '../base/logger.dart';
10
import '../base/os.dart';
11
import '../base/platform.dart';
12
import '../build_info.dart';
13
import '../desktop_device.dart';
14
import '../device.dart';
15
import '../features.dart';
16 17 18
import '../project.dart';
import 'application_package.dart';
import 'build_linux.dart';
19 20 21
import 'linux_workflow.dart';

/// A device that represents a desktop Linux target.
22
class LinuxDevice extends DesktopDevice {
23 24 25
  LinuxDevice({
    @required ProcessManager processManager,
    @required Logger logger,
26
    @required FileSystem fileSystem,
27
    @required OperatingSystemUtils operatingSystemUtils,
28
  }) : super(
29
      'linux',
30 31
      platformType: PlatformType.linux,
      ephemeral: false,
32 33
      logger: logger,
      processManager: processManager,
34
      fileSystem: fileSystem,
35
      operatingSystemUtils: operatingSystemUtils,
36
  );
37 38 39 40 41

  @override
  bool isSupported() => true;

  @override
42
  String get name => 'Linux';
43 44

  @override
45
  Future<TargetPlatform> get targetPlatform async => TargetPlatform.linux_x64;
46 47

  @override
48 49 50
  bool isSupportedForProject(FlutterProject flutterProject) {
    return flutterProject.linux.existsSync();
  }
51 52

  @override
53
  Future<void> buildForDevice(
54
    covariant LinuxApp package, {
55
    String mainPath,
56
    BuildInfo buildInfo,
57
  }) async {
58 59 60 61 62
    await buildLinux(
      FlutterProject.current().linux,
      buildInfo,
      target: mainPath,
    );
63 64 65
  }

  @override
66 67
  String executablePathForDevice(covariant LinuxApp package, BuildMode buildMode) {
    return package.executable(buildMode);
68
  }
69 70 71
}

class LinuxDevices extends PollingDeviceDiscovery {
72 73 74
  LinuxDevices({
    @required Platform platform,
    @required FeatureFlags featureFlags,
75 76 77 78 79
    @required OperatingSystemUtils operatingSystemUtils,
    @required FileSystem fileSystem,
    @required ProcessManager processManager,
    @required Logger logger,
  }) : _platform = platform,
80 81 82 83
       _linuxWorkflow = LinuxWorkflow(
          platform: platform,
          featureFlags: featureFlags,
       ),
84
       _fileSystem = fileSystem,
85
       _logger = logger,
86 87
       _processManager = processManager,
       _operatingSystemUtils = operatingSystemUtils,
88 89 90 91
       super('linux devices');

  final Platform _platform;
  final LinuxWorkflow _linuxWorkflow;
92 93
  final ProcessManager _processManager;
  final Logger _logger;
94
  final FileSystem _fileSystem;
95
  final OperatingSystemUtils _operatingSystemUtils;
96 97

  @override
98
  bool get supportsPlatform => _platform.isLinux;
99 100

  @override
101
  bool get canListAnything => _linuxWorkflow.canListDevices;
102 103

  @override
104
  Future<List<Device>> pollingGetDevices({ Duration timeout }) async {
105 106 107 108
    if (!canListAnything) {
      return const <Device>[];
    }
    return <Device>[
109 110 111
      LinuxDevice(
        logger: _logger,
        processManager: _processManager,
112
        fileSystem: _fileSystem,
113
        operatingSystemUtils: _operatingSystemUtils,
114
      ),
115 116 117 118 119 120
    ];
  }

  @override
  Future<List<String>> getDiagnostics() async => const <String>[];
}