-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathlink_config.dart
116 lines (107 loc) · 4.1 KB
/
link_config.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:convert';
import 'dart:io';
import 'package:collection/collection.dart';
import 'package:meta/meta.dart';
import 'package:pub_semver/pub_semver.dart';
import '../args_parser.dart';
import '../json_utils.dart';
import '../model/hook.dart';
import '../utils/map.dart';
import 'architecture.dart';
import 'asset.dart';
import 'build_config.dart';
import 'build_mode.dart';
import 'hook_config.dart';
import 'ios_sdk.dart';
import 'link_mode_preference.dart';
import 'os.dart';
part '../model/link_config.dart';
/// The configuration for a link hook (`hook/link.dart`) invocation.
///
/// It consists of a subset of the fields from the [BuildConfig] already passed
/// to the build hook and the [assets] from the build step.
abstract class LinkConfig implements HookConfig {
/// The list of assets to be linked. These are the assets generated by a
/// `build.dart` script destined for this packages `link.dart`.
Iterable<Asset> get assets;
/// The path to the file containing recorded uses after kernel tree-shaking.
///
/// The file contents can be parsed using `package:record_use`.
@experimental
Uri? get recordedUsagesFile;
/// Generate the [LinkConfig] from the input arguments to the linking script.
factory LinkConfig.fromArguments(List<String> arguments) =>
LinkConfigImpl.fromArguments(arguments);
factory LinkConfig.build({
required Uri outputDirectory,
required Uri outputDirectoryShared,
required String packageName,
required Uri packageRoot,
Architecture? targetArchitecture,
required OS targetOS,
IOSSdk? targetIOSSdk,
int? targetIOSVersion,
int? targetMacOSVersion,
CCompilerConfig? cCompiler,
BuildMode? buildMode,
Iterable<String>? supportedAssetTypes,
int? targetAndroidNdkApi,
required Iterable<Asset> assets,
required LinkModePreference linkModePreference,
bool? dryRun,
Version? version,
}) =>
LinkConfigImpl(
assets: assets.cast(),
outputDirectory: outputDirectory,
outputDirectoryShared: outputDirectoryShared,
packageName: packageName,
packageRoot: packageRoot,
buildMode: buildMode as BuildModeImpl,
cCompiler: cCompiler as CCompilerConfigImpl?,
targetAndroidNdkApi: targetAndroidNdkApi,
targetArchitecture: targetArchitecture as ArchitectureImpl?,
targetIOSSdk: targetIOSSdk as IOSSdkImpl?,
targetOS: targetOS as OSImpl,
targetIOSVersion: targetIOSVersion,
targetMacOSVersion: targetMacOSVersion,
dryRun: dryRun,
linkModePreference: linkModePreference as LinkModePreferenceImpl,
supportedAssetTypes: supportedAssetTypes,
version: version,
);
factory LinkConfig.dryRun({
required Uri outputDirectory,
required Uri outputDirectoryShared,
required String packageName,
required Uri packageRoot,
required OS targetOS,
Iterable<String>? supportedAssetTypes,
required Iterable<Asset> assets,
required LinkModePreference linkModePreference,
Version? version,
}) =>
LinkConfigImpl.dryRun(
assets: assets.cast(),
outputDirectory: outputDirectory,
outputDirectoryShared: outputDirectoryShared,
packageName: packageName,
packageRoot: packageRoot,
targetOS: targetOS as OSImpl,
supportedAssetTypes: supportedAssetTypes,
linkModePreference: linkModePreference as LinkModePreferenceImpl,
version: version,
);
/// The version of [BuildConfig].
///
/// The build config is used in the protocol between the Dart and Flutter SDKs
/// and packages through build hook invocations.
///
/// We're trying to avoid breaking changes. However, in the case that we have
/// to, the major version mismatch between the Dart or Flutter SDK and build
/// hook (`hook/build.dart`) will lead to a nice error message.
static Version get latestVersion => HookConfigImpl.latestVersion;
}