context_runner.dart 8.07 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 8 9
import 'android/android_sdk.dart';
import 'android/android_studio.dart';
import 'android/android_workflow.dart';
10
import 'android/gradle_utils.dart';
11
import 'application_package.dart';
12 13
import 'artifacts.dart';
import 'asset.dart';
14 15 16 17 18
import 'base/config.dart';
import 'base/context.dart';
import 'base/io.dart';
import 'base/logger.dart';
import 'base/os.dart';
19
import 'base/process.dart';
20
import 'base/time.dart';
21
import 'base/user_messages.dart';
22
import 'build_system/build_system.dart';
23
import 'cache.dart';
24
import 'compile.dart';
25
import 'dart/pub.dart';
26 27 28
import 'devfs.dart';
import 'device.dart';
import 'doctor.dart';
29
import 'emulator.dart';
30
import 'features.dart';
31 32 33
import 'fuchsia/fuchsia_device.dart' show FuchsiaDeviceTools;
import 'fuchsia/fuchsia_sdk.dart' show FuchsiaSdk, FuchsiaArtifacts;
import 'fuchsia/fuchsia_workflow.dart' show FuchsiaWorkflow;
34
import 'globals.dart' as globals;
35 36 37
import 'ios/ios_workflow.dart';
import 'ios/simulators.dart';
import 'ios/xcodeproj.dart';
38 39
import 'macos/cocoapods.dart';
import 'macos/cocoapods_validator.dart';
40
import 'macos/macos_workflow.dart';
41
import 'macos/xcode.dart';
42
import 'mdns_discovery.dart';
43
import 'persistent_tool_state.dart';
44
import 'reporting/reporting.dart';
45 46
import 'run_hot.dart';
import 'version.dart';
47
import 'web/workflow.dart';
48 49
import 'windows/visual_studio.dart';
import 'windows/visual_studio_validator.dart';
50
import 'windows/windows_workflow.dart';
51

52 53
Future<T> runInContext<T>(
  FutureOr<T> runner(), {
54
  Map<Type, Generator> overrides,
55
}) async {
56 57 58 59 60 61 62 63 64

  // 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();
  }

65
  return await context.run<T>(
66
    name: 'global fallbacks',
67
    body: runnerWrapper,
68 69
    overrides: overrides,
    fallbacks: <Type, Generator>{
70
      AndroidLicenseValidator: () => AndroidLicenseValidator(),
71 72
      AndroidSdk: AndroidSdk.locateAndroidSdk,
      AndroidStudio: AndroidStudio.latestValid,
73 74 75 76 77 78 79 80 81
      AndroidValidator: () => AndroidValidator(
        androidStudio: globals.androidStudio,
        androidSdk: globals.androidSdk,
        fileSystem: globals.fs,
        logger: globals.logger,
        platform: globals.platform,
        processManager: globals.processManager,
        userMessages: globals.userMessages,
      ),
82 83 84
      AndroidWorkflow: () => AndroidWorkflow(
        androidSdk: globals.androidSdk,
      ),
85
      ApplicationPackageFactory: () => ApplicationPackageFactory(),
86 87 88 89 90
      Artifacts: () => CachedArtifacts(
        fileSystem: globals.fs,
        cache: globals.cache,
        platform: globals.platform,
      ),
91
      AssetBundleFactory: () => AssetBundleFactory.defaultInstance,
92
      BuildSystem: () => FlutterBuildSystem(
93 94 95 96
        fileSystem: globals.fs,
        logger: globals.logger,
        platform: globals.platform,
      ),
97 98 99 100 101
      Cache: () => Cache(
        fileSystem: globals.fs,
        logger: globals.logger,
        platform: globals.platform,
      ),
102 103 104 105 106 107 108 109
      CocoaPods: () => CocoaPods(
        fileSystem: globals.fs,
        processManager: globals.processManager,
        logger: globals.logger,
        platform: globals.platform,
        xcodeProjectInterpreter: globals.xcodeProjectInterpreter,
        timeoutConfiguration: timeoutConfiguration,
      ),
110 111 112 113
      CocoaPodsValidator: () => CocoaPodsValidator(
        globals.cocoaPods,
        globals.userMessages,
      ),
114
      Config: () => Config(
115 116
        Config.kFlutterSettings,
        fileSystem: globals.fs,
117
        logger: globals.logger,
118
        platform: globals.platform,
119
      ),
120 121 122 123 124 125
      CrashReporter: () => CrashReporter(
        fileSystem: globals.fs,
        logger: globals.logger,
        flutterProjectFactory: globals.projectFactory,
        client: globals.httpClientFactory?.call() ?? HttpClient(),
      ),
126 127
      DevFSConfig: () => DevFSConfig(),
      DeviceManager: () => DeviceManager(),
128
      Doctor: () => Doctor(logger: globals.logger),
129
      DoctorValidatorsProvider: () => DoctorValidatorsProvider.defaultInstance,
130 131 132 133 134 135 136
      EmulatorManager: () => EmulatorManager(
        androidSdk: globals.androidSdk,
        processManager: globals.processManager,
        logger: globals.logger,
        fileSystem: globals.fs,
        androidWorkflow: androidWorkflow,
      ),
137
      FeatureFlags: () => const FeatureFlags(),
138
      FlutterVersion: () => FlutterVersion(const SystemClock()),
139
      FuchsiaArtifacts: () => FuchsiaArtifacts.find(),
140
      FuchsiaDeviceTools: () => FuchsiaDeviceTools(),
141 142
      FuchsiaSdk: () => FuchsiaSdk(),
      FuchsiaWorkflow: () => FuchsiaWorkflow(),
143
      GradleUtils: () => GradleUtils(),
144
      HotRunnerConfig: () => HotRunnerConfig(),
145
      IOSSimulatorUtils: () => IOSSimulatorUtils(
146 147
        logger: globals.logger,
        processManager: globals.processManager,
148 149
        xcode: globals.xcode,
      ),
150
      IOSWorkflow: () => const IOSWorkflow(),
151
      KernelCompilerFactory: () => const KernelCompilerFactory(),
152 153 154 155
      Logger: () => globals.platform.isWindows
        ? WindowsStdoutLogger(
            terminal: globals.terminal,
            stdio: globals.stdio,
156
            outputPreferences: globals.outputPreferences,
157 158 159 160 161
            timeoutConfiguration: timeoutConfiguration,
          )
        : StdoutLogger(
            terminal: globals.terminal,
            stdio: globals.stdio,
162
            outputPreferences: globals.outputPreferences,
163 164
            timeoutConfiguration: timeoutConfiguration,
          ),
165
      MacOSWorkflow: () => const MacOSWorkflow(),
166
      MDnsObservatoryDiscovery: () => MDnsObservatoryDiscovery(),
167 168 169 170 171 172
      OperatingSystemUtils: () => OperatingSystemUtils(
        fileSystem: globals.fs,
        logger: globals.logger,
        platform: globals.platform,
        processManager: globals.processManager,
      ),
173 174 175 176 177
      PersistentToolState: () => PersistentToolState(
        fileSystem: globals.fs,
        logger: globals.logger,
        platform: globals.platform,
      ),
178
      ProcessInfo: () => ProcessInfo(),
179 180 181 182
      ProcessUtils: () => ProcessUtils(
        processManager: globals.processManager,
        logger: globals.logger,
      ),
183 184 185 186 187 188 189 190
      Pub: () => Pub(
        fileSystem: globals.fs,
        logger: globals.logger,
        processManager: globals.processManager,
        botDetector: globals.botDetector,
        platform: globals.platform,
        usage: globals.flutterUsage,
      ),
191
      ShutdownHooks: () => ShutdownHooks(logger: globals.logger),
192
      Stdio: () => Stdio(),
193
      SystemClock: () => const SystemClock(),
194
      TimeoutConfiguration: () => const TimeoutConfiguration(),
195 196 197
      Usage: () => Usage(
        runningOnBot: runningOnBot,
      ),
198
      UserMessages: () => UserMessages(),
199 200 201 202 203 204 205 206 207
      VisualStudioValidator: () => VisualStudioValidator(
        userMessages: globals.userMessages,
        visualStudio: VisualStudio(
          fileSystem: globals.fs,
          platform: globals.platform,
          logger: globals.logger,
          processManager: globals.processManager,
        )
      ),
208 209 210 211
      WebWorkflow: () => WebWorkflow(
        featureFlags: featureFlags,
        platform: globals.platform,
      ),
212
      WindowsWorkflow: () => const WindowsWorkflow(),
213 214 215 216 217
      Xcode: () => Xcode(
        logger: globals.logger,
        processManager: globals.processManager,
        platform: globals.platform,
        fileSystem: globals.fs,
218
        xcodeProjectInterpreter: globals.xcodeProjectInterpreter,
219
      ),
220 221 222
      XCDevice: () => XCDevice(
        processManager: globals.processManager,
        logger: globals.logger,
223 224 225
        artifacts: globals.artifacts,
        cache: globals.cache,
        platform: globals.platform,
226 227
        xcode: globals.xcode,
      ),
228 229 230 231 232 233
      XcodeProjectInterpreter: () => XcodeProjectInterpreter(
        logger: globals.logger,
        processManager: globals.processManager,
        platform: globals.platform,
        fileSystem: globals.fs,
        terminal: globals.terminal,
234
        usage: globals.flutterUsage,
235
      ),
236 237
    },
  );
238
}