context_runner.dart 12.7 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 6
// @dart = 2.8

7 8
import 'dart:async';

9 10
import 'package:process/process.dart';

11
import 'android/android_builder.dart';
12 13 14
import 'android/android_sdk.dart';
import 'android/android_studio.dart';
import 'android/android_workflow.dart';
15
import 'android/gradle.dart';
16
import 'android/gradle_utils.dart';
17
import 'application_package.dart';
18 19
import 'artifacts.dart';
import 'asset.dart';
20 21
import 'base/config.dart';
import 'base/context.dart';
22
import 'base/error_handling_io.dart';
23 24 25
import 'base/io.dart';
import 'base/logger.dart';
import 'base/os.dart';
26
import 'base/process.dart';
27
import 'base/terminal.dart';
28
import 'base/time.dart';
29
import 'base/user_messages.dart';
30
import 'build_system/build_system.dart';
31
import 'cache.dart';
32
import 'custom_devices/custom_devices_config.dart';
33
import 'dart/pub.dart';
34 35
import 'devfs.dart';
import 'device.dart';
36
import 'devtools_launcher.dart';
37
import 'doctor.dart';
38
import 'emulator.dart';
39
import 'features.dart';
40
import 'flutter_application_package.dart';
41
import 'flutter_cache.dart';
42
import 'flutter_device_manager.dart';
43
import 'flutter_features.dart';
44 45
import 'fuchsia/fuchsia_device.dart' show FuchsiaDeviceTools;
import 'fuchsia/fuchsia_sdk.dart' show FuchsiaSdk, FuchsiaArtifacts;
46
import 'fuchsia/fuchsia_workflow.dart' show FuchsiaWorkflow, fuchsiaWorkflow;
47
import 'globals.dart' as globals;
48
import 'ios/ios_workflow.dart';
49
import 'ios/iproxy.dart';
50 51
import 'ios/simulators.dart';
import 'ios/xcodeproj.dart';
52 53
import 'macos/cocoapods.dart';
import 'macos/cocoapods_validator.dart';
54
import 'macos/macos_workflow.dart';
55
import 'macos/xcdevice.dart';
56
import 'macos/xcode.dart';
57
import 'mdns_discovery.dart';
58
import 'persistent_tool_state.dart';
59
import 'reporting/crash_reporting.dart';
60
import 'reporting/first_run.dart';
61
import 'reporting/reporting.dart';
62
import 'resident_runner.dart';
63
import 'run_hot.dart';
64
import 'runner/local_engine.dart';
65
import 'version.dart';
66
import 'web/workflow.dart';
67
import 'windows/uwptool.dart';
68 69
import 'windows/visual_studio.dart';
import 'windows/visual_studio_validator.dart';
70
import 'windows/windows_workflow.dart';
71

72
Future<T> runInContext<T>(
73
  FutureOr<T> Function() runner, {
74
  Map<Type, Generator> overrides,
75
}) async {
76 77 78 79 80 81 82 83 84

  // Wrap runner with any asynchronous initialization that should run with the
  // overrides and callbacks.
  bool runningOnBot;
  FutureOr<T> runnerWrapper() async {
    runningOnBot = await globals.isRunningOnBot;
    return runner();
  }

85
  return context.run<T>(
86
    name: 'global fallbacks',
87
    body: runnerWrapper,
88 89
    overrides: overrides,
    fallbacks: <Type, Generator>{
90 91
      AndroidBuilder: () => AndroidGradleBuilder(
        logger: globals.logger,
92 93
        processManager: globals.processManager,
        fileSystem: globals.fs,
94
        artifacts: globals.artifacts,
95
        usage: globals.flutterUsage,
96 97
        gradleUtils: globals.gradleUtils,
        platform: globals.platform,
98
      ),
99 100 101 102 103 104 105 106 107 108 109
      AndroidLicenseValidator: () => AndroidLicenseValidator(
        operatingSystemUtils: globals.os,
        platform: globals.platform,
        userMessages: globals.userMessages,
        processManager: globals.processManager,
        androidStudio: globals.androidStudio,
        androidSdk: globals.androidSdk,
        logger: globals.logger,
        fileSystem: globals.fs,
        stdio: globals.stdio,
      ),
110 111
      AndroidSdk: AndroidSdk.locateAndroidSdk,
      AndroidStudio: AndroidStudio.latestValid,
112 113 114 115 116 117 118 119 120
      AndroidValidator: () => AndroidValidator(
        androidStudio: globals.androidStudio,
        androidSdk: globals.androidSdk,
        fileSystem: globals.fs,
        logger: globals.logger,
        platform: globals.platform,
        processManager: globals.processManager,
        userMessages: globals.userMessages,
      ),
121 122
      AndroidWorkflow: () => AndroidWorkflow(
        androidSdk: globals.androidSdk,
123
        featureFlags: featureFlags,
124
        operatingSystemUtils: globals.os,
125
      ),
126
      ApplicationPackageFactory: () => FlutterApplicationPackageFactory(
127 128 129 130 131 132
        userMessages: globals.userMessages,
        processManager: globals.processManager,
        logger: globals.logger,
        fileSystem: globals.fs,
        androidSdk: globals.androidSdk,
      ),
133 134 135 136
      Artifacts: () => CachedArtifacts(
        fileSystem: globals.fs,
        cache: globals.cache,
        platform: globals.platform,
137
        operatingSystemUtils: globals.os,
138
      ),
139 140 141 142
      AssetBundleFactory: () {
        return AssetBundleFactory.defaultInstance(
          logger: globals.logger,
          fileSystem: globals.fs,
143
          platform: globals.platform,
144 145
        );
      },
146
      BuildSystem: () => FlutterBuildSystem(
147 148 149 150
        fileSystem: globals.fs,
        logger: globals.logger,
        platform: globals.platform,
      ),
151
      Cache: () => FlutterCache(
152 153 154
        fileSystem: globals.fs,
        logger: globals.logger,
        platform: globals.platform,
155
        osUtils: globals.os,
156
      ),
157 158 159 160 161 162
      CocoaPods: () => CocoaPods(
        fileSystem: globals.fs,
        processManager: globals.processManager,
        logger: globals.logger,
        platform: globals.platform,
        xcodeProjectInterpreter: globals.xcodeProjectInterpreter,
163
        usage: globals.flutterUsage,
164
      ),
165 166 167 168
      CocoaPodsValidator: () => CocoaPodsValidator(
        globals.cocoaPods,
        globals.userMessages,
      ),
169
      Config: () => Config(
170 171
        Config.kFlutterSettings,
        fileSystem: globals.fs,
172
        logger: globals.logger,
173
        platform: globals.platform,
174
      ),
175 176 177 178 179
      CustomDevicesConfig: () => CustomDevicesConfig(
        fileSystem: globals.fs,
        logger: globals.logger,
        platform: globals.platform
      ),
180 181 182 183 184 185
      CrashReporter: () => CrashReporter(
        fileSystem: globals.fs,
        logger: globals.logger,
        flutterProjectFactory: globals.projectFactory,
        client: globals.httpClientFactory?.call() ?? HttpClient(),
      ),
186
      DevFSConfig: () => DevFSConfig(),
187 188 189 190 191 192 193 194 195 196 197 198 199 200
      DeviceManager: () => FlutterDeviceManager(
        logger: globals.logger,
        processManager: globals.processManager,
        platform: globals.platform,
        androidSdk: globals.androidSdk,
        iosSimulatorUtils: globals.iosSimulatorUtils,
        featureFlags: featureFlags,
        fileSystem: globals.fs,
        iosWorkflow: globals.iosWorkflow,
        artifacts: globals.artifacts,
        flutterVersion: globals.flutterVersion,
        androidWorkflow: androidWorkflow,
        fuchsiaWorkflow: fuchsiaWorkflow,
        xcDevice: globals.xcdevice,
201
        userMessages: globals.userMessages,
202
        windowsWorkflow: windowsWorkflow,
203 204 205 206
        macOSWorkflow: MacOSWorkflow(
          platform: globals.platform,
          featureFlags: featureFlags,
        ),
207
        operatingSystemUtils: globals.os,
208
        terminal: globals.terminal,
209
        customDevicesConfig: globals.customDevicesConfig,
210 211 212 213 214
        uwptool: UwpTool(
          artifacts: globals.artifacts,
          logger: globals.logger,
          processManager: globals.processManager,
        ),
215
      ),
216 217
      DevtoolsLauncher: () => DevtoolsServerLauncher(
        processManager: globals.processManager,
218
        dartExecutable: globals.artifacts.getHostArtifact(HostArtifact.engineDartBinary).path,
219 220
        logger: globals.logger,
      ),
221
      Doctor: () => Doctor(logger: globals.logger),
222
      DoctorValidatorsProvider: () => DoctorValidatorsProvider.defaultInstance,
223 224 225 226 227 228 229
      EmulatorManager: () => EmulatorManager(
        androidSdk: globals.androidSdk,
        processManager: globals.processManager,
        logger: globals.logger,
        fileSystem: globals.fs,
        androidWorkflow: androidWorkflow,
      ),
230 231 232 233 234
      FeatureFlags: () => FlutterFeatureFlags(
        flutterVersion: globals.flutterVersion,
        config: globals.config,
        platform: globals.platform,
      ),
235
      FlutterVersion: () => FlutterVersion(),
236
      FuchsiaArtifacts: () => FuchsiaArtifacts.find(),
237
      FuchsiaDeviceTools: () => FuchsiaDeviceTools(),
238
      FuchsiaSdk: () => FuchsiaSdk(),
239 240 241 242 243
      FuchsiaWorkflow: () => FuchsiaWorkflow(
        featureFlags: featureFlags,
        platform: globals.platform,
        fuchsiaArtifacts: globals.fuchsiaArtifacts,
      ),
244 245 246 247 248 249 250
      GradleUtils: () => GradleUtils(
        fileSystem: globals.fs,
        operatingSystemUtils: globals.os,
        logger: globals.logger,
        platform: globals.platform,
        cache: globals.cache,
      ),
251
      HotRunnerConfig: () => HotRunnerConfig(),
252
      IOSSimulatorUtils: () => IOSSimulatorUtils(
253 254
        logger: globals.logger,
        processManager: globals.processManager,
255 256
        xcode: globals.xcode,
      ),
257 258 259 260 261
      IOSWorkflow: () => IOSWorkflow(
        featureFlags: featureFlags,
        xcode: globals.xcode,
        platform: globals.platform,
      ),
262 263 264 265 266 267 268
      LocalEngineLocator: () => LocalEngineLocator(
        userMessages: userMessages,
        logger: globals.logger,
        platform: globals.platform,
        fileSystem: globals.fs,
        flutterRoot: Cache.flutterRoot,
      ),
269 270 271 272
      Logger: () => globals.platform.isWindows
        ? WindowsStdoutLogger(
            terminal: globals.terminal,
            stdio: globals.stdio,
273
            outputPreferences: globals.outputPreferences,
274 275 276 277
          )
        : StdoutLogger(
            terminal: globals.terminal,
            stdio: globals.stdio,
278
            outputPreferences: globals.outputPreferences,
279
          ),
280 281 282 283
      MacOSWorkflow: () => MacOSWorkflow(
        featureFlags: featureFlags,
        platform: globals.platform,
      ),
284 285 286 287
      MDnsObservatoryDiscovery: () => MDnsObservatoryDiscovery(
        logger: globals.logger,
        flutterUsage: globals.flutterUsage,
      ),
288 289 290 291 292 293
      OperatingSystemUtils: () => OperatingSystemUtils(
        fileSystem: globals.fs,
        logger: globals.logger,
        platform: globals.platform,
        processManager: globals.processManager,
      ),
294 295 296 297 298
      OutputPreferences: () => OutputPreferences(
        wrapText: globals.stdio.hasTerminal ?? false,
        showColor:  globals.platform.stdoutSupportsAnsi,
        stdio: globals.stdio,
      ),
299 300 301 302 303
      PersistentToolState: () => PersistentToolState(
        fileSystem: globals.fs,
        logger: globals.logger,
        platform: globals.platform,
      ),
304
      ProcessInfo: () => ProcessInfo(globals.fs),
305
      ProcessManager: () => ErrorHandlingProcessManager(
306
        delegate: const LocalProcessManager(),
307 308
        platform: globals.platform,
      ),
309 310 311 312
      ProcessUtils: () => ProcessUtils(
        processManager: globals.processManager,
        logger: globals.logger,
      ),
313 314 315 316 317 318 319 320
      Pub: () => Pub(
        fileSystem: globals.fs,
        logger: globals.logger,
        processManager: globals.processManager,
        botDetector: globals.botDetector,
        platform: globals.platform,
        usage: globals.flutterUsage,
      ),
321
      ShutdownHooks: () => ShutdownHooks(logger: globals.logger),
322
      Stdio: () => Stdio(),
323
      SystemClock: () => const SystemClock(),
324 325
      Usage: () => Usage(
        runningOnBot: runningOnBot,
326
        firstRunMessenger: FirstRunMessenger(persistentToolState: globals.persistentToolState),
327
      ),
328
      UserMessages: () => UserMessages(),
329 330 331 332 333 334 335 336 337
      VisualStudioValidator: () => VisualStudioValidator(
        userMessages: globals.userMessages,
        visualStudio: VisualStudio(
          fileSystem: globals.fs,
          platform: globals.platform,
          logger: globals.logger,
          processManager: globals.processManager,
        )
      ),
338 339 340 341
      WebWorkflow: () => WebWorkflow(
        featureFlags: featureFlags,
        platform: globals.platform,
      ),
342 343 344 345
      WindowsWorkflow: () => WindowsWorkflow(
        featureFlags: featureFlags,
        platform: globals.platform,
      ),
346 347 348 349 350
      Xcode: () => Xcode(
        logger: globals.logger,
        processManager: globals.processManager,
        platform: globals.platform,
        fileSystem: globals.fs,
351
        xcodeProjectInterpreter: globals.xcodeProjectInterpreter,
352
      ),
353 354 355
      XCDevice: () => XCDevice(
        processManager: globals.processManager,
        logger: globals.logger,
356 357 358
        artifacts: globals.artifacts,
        cache: globals.cache,
        platform: globals.platform,
359
        xcode: globals.xcode,
360
        iproxy: IProxy(
361 362 363
          iproxyPath: globals.artifacts.getHostArtifact(
            HostArtifact.iproxy,
          ).path,
364 365 366 367
          logger: globals.logger,
          processManager: globals.processManager,
          dyLdLibEntry: globals.cache.dyLdLibEntry,
        ),
368
      ),
369 370 371 372 373
      XcodeProjectInterpreter: () => XcodeProjectInterpreter(
        logger: globals.logger,
        processManager: globals.processManager,
        platform: globals.platform,
        fileSystem: globals.fs,
374
        usage: globals.flutterUsage,
375
      ),
376 377
    },
  );
378
}