Skip to content

Commit 33c0251

Browse files
authored
[hooks] [code_assets] Add lint public_member_api_docs (#2353)
1 parent 289967a commit 33c0251

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+308
-29
lines changed

pkgs/code_assets/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.19.4
2+
3+
* Add doc comments to all public members.
4+
15
## 0.19.3
26

37
* Mark this package as in preview.

pkgs/code_assets/analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ linter:
1414
rules:
1515
- avoid_positional_boolean_parameters
1616
- dangling_library_doc_comments
17+
- public_member_api_docs
1718
- prefer_const_declarations
1819
- prefer_expression_function_bodies
1920
- prefer_final_in_for_each

pkgs/code_assets/lib/src/code_assets/architecture.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ final class Architecture {
8888
static final Architecture current = _abiToArch[Abi.current()]!;
8989
}
9090

91+
/// Extension methods for [Architecture] to convert to and from the syntax.
9192
extension ArchitectureSyntaxExtension on Architecture {
9293
static final _toSyntax = {
9394
for (final item in Architecture.values)
@@ -98,8 +99,10 @@ extension ArchitectureSyntaxExtension on Architecture {
9899
for (var entry in _toSyntax.entries) entry.value: entry.key,
99100
};
100101

102+
/// Converts this [Architecture] to its corresponding [ArchitectureSyntax].
101103
ArchitectureSyntax toSyntax() => _toSyntax[this]!;
102104

105+
/// Converts an [ArchitectureSyntax] to its corresponding [Architecture].
103106
static Architecture fromSyntax(ArchitectureSyntax syntax) =>
104107
switch (_fromSyntax[syntax]) {
105108
null => throw FormatException(

pkgs/code_assets/lib/src/code_assets/c_compiler_config.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ final class CCompilerConfig {
7373
/// The configuration provided in [CCompilerConfig.windows] when
7474
/// [CodeConfig.targetOS] is [OS.windows].
7575
final class WindowsCCompilerConfig {
76+
/// The configuration for the Windows Developer Command Prompt.
7677
final DeveloperCommandPrompt? developerCommandPrompt;
7778

79+
/// Constructs a new [WindowsCCompilerConfig].
7880
WindowsCCompilerConfig({this.developerCommandPrompt});
7981
}
8082

@@ -107,17 +109,23 @@ final class DeveloperCommandPrompt {
107109
/// script name does not.
108110
final List<String> arguments;
109111

112+
/// Constructs a new [DeveloperCommandPrompt].
110113
DeveloperCommandPrompt({required this.script, required this.arguments});
111114
}
112115

116+
/// Extension methods for [CCompilerConfig] to convert to and from the syntax
117+
/// model.
113118
extension CCompilerConfigSyntaxExtension on CCompilerConfig {
119+
/// Converts this [CCompilerConfig] to its corresponding
120+
/// [CCompilerConfigSyntax].
114121
CCompilerConfigSyntax toSyntax() => CCompilerConfigSyntax(
115122
ar: archiver,
116123
cc: compiler,
117124
ld: linker,
118125
windows: _windows?.toSyntax(),
119126
);
120127

128+
/// Converts a [CCompilerConfigSyntax] to its corresponding [CCompilerConfig].
121129
static CCompilerConfig fromSyntax(CCompilerConfigSyntax cCompiler) =>
122130
CCompilerConfig(
123131
archiver: cCompiler.ar,
@@ -132,10 +140,15 @@ extension CCompilerConfigSyntaxExtension on CCompilerConfig {
132140
);
133141
}
134142

143+
/// Extension methods for [WindowsCCompilerConfig] to convert to and from the
144+
/// syntax model.
135145
extension WindowsCCompilerConfigSyntaxExtension on WindowsCCompilerConfig {
146+
/// Converts this [WindowsCCompilerConfig] to its corresponding
147+
/// [WindowsSyntax].
136148
WindowsSyntax toSyntax() =>
137149
WindowsSyntax(developerCommandPrompt: developerCommandPrompt?.toSyntax());
138150

151+
/// Converts a [WindowsSyntax] to its corresponding [WindowsCCompilerConfig].
139152
static WindowsCCompilerConfig fromSyntax(WindowsSyntax windows) =>
140153
WindowsCCompilerConfig(
141154
developerCommandPrompt: switch (windows.developerCommandPrompt) {
@@ -145,10 +158,16 @@ extension WindowsCCompilerConfigSyntaxExtension on WindowsCCompilerConfig {
145158
);
146159
}
147160

161+
/// Extension methods for [DeveloperCommandPrompt] to convert to and from the
162+
/// syntax model.
148163
extension DeveloperCommandPromptSyntaxExtension on DeveloperCommandPrompt {
164+
/// Converts this [DeveloperCommandPrompt] to its corresponding
165+
/// [DeveloperCommandPromptSyntax].
149166
DeveloperCommandPromptSyntax toSyntax() =>
150167
DeveloperCommandPromptSyntax(script: script, arguments: arguments);
151168

169+
/// Converts a [DeveloperCommandPromptSyntax] to its corresponding
170+
/// [DeveloperCommandPrompt].
152171
static DeveloperCommandPrompt fromSyntax(DeveloperCommandPromptSyntax dcp) =>
153172
DeveloperCommandPrompt(script: dcp.script, arguments: dcp.arguments);
154173
}

pkgs/code_assets/lib/src/code_assets/code_asset.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ final class CodeAsset {
8484

8585
CodeAsset._({required this.id, required this.linkMode, required this.file});
8686

87+
/// Creates a [CodeAsset] from an [EncodedAsset].
8788
factory CodeAsset.fromEncoded(EncodedAsset asset) {
8889
assert(asset.isCodeAsset);
8990
final syntaxNode = NativeCodeAssetEncodingSyntax.fromJson(
@@ -97,6 +98,7 @@ final class CodeAsset {
9798
);
9899
}
99100

101+
/// Creates a copy of this [CodeAsset] with the given fields replaced.
100102
CodeAsset copyWith({LinkMode? linkMode, String? id, Uri? file}) =>
101103
CodeAsset._(
102104
id: id ?? this.id,
@@ -115,6 +117,7 @@ final class CodeAsset {
115117
@override
116118
int get hashCode => Object.hash(id, linkMode, file);
117119

120+
/// Encodes this [CodeAsset] into an [EncodedAsset].
118121
EncodedAsset encode() {
119122
final encoding = NativeCodeAssetEncodingSyntax(
120123
file: file,
@@ -125,16 +128,22 @@ final class CodeAsset {
125128
}
126129
}
127130

131+
/// Extension for identifying the type of a [CodeAsset].
128132
extension CodeAssetType on CodeAsset {
133+
/// The type identifier for [CodeAsset]s in a hook input or output.
129134
static const String type = NativeCodeAssetNewSyntax.typeValue;
130135
}
131136

132137
/// Methods on [EncodedAsset] for [CodeAsset]s.
133138
extension EncodedCodeAsset on EncodedAsset {
139+
/// Whether this [EncodedAsset] represents a [CodeAsset].
134140
bool get isCodeAsset => type == CodeAssetType.type;
141+
142+
/// Converts this [EncodedAsset] to a [CodeAsset].
135143
CodeAsset get asCodeAsset => CodeAsset.fromEncoded(this);
136144
}
137145

146+
/// Provides OS-specific library naming conventions.
138147
extension OSLibraryNaming on OS {
139148
/// The default dynamic library file name on this os.
140149
String dylibFileName(String name) {

pkgs/code_assets/lib/src/code_assets/config.dart

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,29 @@ extension HookConfigCodeConfig on HookConfig {
1818
/// Code asset specific configuration.
1919
CodeConfig get code => CodeConfig._fromJson(json, path);
2020

21+
/// Whether the hook invoker (e.g. the Dart or Flutter SDK) expects this
22+
/// hook to build code assets.
2123
bool get buildCodeAssets => buildAssetTypes.contains(CodeAssetType.type);
2224
}
2325

2426
/// Extension to the [LinkInput] providing access to configuration specific to
2527
/// code assets as well as code asset inputs to the linker (only available if
2628
/// code assets are supported).
2729
extension LinkInputCodeAssets on LinkInputAssets {
28-
// Returns the code assets that were sent to this linker.
29-
//
30-
// NOTE: If the linker implementation depends on the contents of the files the
31-
// code assets refer (e.g. looks at static archives and links them) then the
32-
// linker script has to add those files as dependencies via
33-
// [LinkOutput.addDependency] to ensure the linker script will be re-run if
34-
// the content of the files changes.
30+
/// The [CodeAsset]s in this [LinkInputAssets.encodedAssets].
31+
///
32+
/// NOTE: If the linker implementation depends on the contents of the files
33+
/// the code assets refer (e.g. looks at static archives and links them) then
34+
/// the linker script has to add those files as dependencies via
35+
/// [HookOutputBuilder.addDependencies] to ensure the linker script will be
36+
/// re-run if the content of the files changes.
3537
Iterable<CodeAsset> get code =>
3638
encodedAssets.where((e) => e.isCodeAsset).map(CodeAsset.fromEncoded);
3739
}
3840

3941
/// The configuration for [CodeAsset]s in [HookConfig].
42+
///
43+
/// Available via [HookConfigCodeConfig.code].
4044
final class CodeConfig {
4145
final CodeConfigSyntax _syntax;
4246

@@ -53,6 +57,7 @@ final class CodeConfig {
5357
Architecture get targetArchitecture =>
5458
ArchitectureSyntaxExtension.fromSyntax(_syntax.targetArchitecture);
5559

60+
/// The preferred link for [CodeAsset]s.
5661
LinkModePreference get linkModePreference =>
5762
LinkModePreferenceSyntaxExtension.fromSyntax(_syntax.linkModePreference);
5863

@@ -101,6 +106,7 @@ final class IOSCodeConfig {
101106
/// The lowest iOS version that the compiled code will be compatible with.
102107
int get targetVersion => _syntax.targetVersion;
103108

109+
/// Constructs a new [IOSCodeConfig].
104110
IOSCodeConfig({required IOSSdk targetSdk, required int targetVersion})
105111
: _syntax = IOSCodeConfigSyntax(
106112
targetSdk: targetSdk.type,
@@ -119,6 +125,7 @@ final class AndroidCodeConfig {
119125
/// compatible with.
120126
int get targetNdkApi => _syntax.targetNdkApi;
121127

128+
/// Constructs a new [AndroidCodeConfig].
122129
AndroidCodeConfig({required int targetNdkApi})
123130
: _syntax = AndroidCodeConfigSyntax(targetNdkApi: targetNdkApi);
124131
}
@@ -133,6 +140,7 @@ final class MacOSCodeConfig {
133140
/// The lowest MacOS version that the compiled code will be compatible with.
134141
int get targetVersion => _syntax.targetVersion;
135142

143+
/// Constructs a new [MacOSCodeConfig].
136144
MacOSCodeConfig({required int targetVersion})
137145
: _syntax = MacOSCodeConfigSyntax(targetVersion: targetVersion);
138146
}
@@ -145,6 +153,7 @@ extension BuildOutputAssetsBuilderCode on BuildOutputAssetsBuilder {
145153

146154
/// Extension on [BuildOutputBuilder] to add [CodeAsset]s.
147155
final class BuildOutputCodeAssetBuilder {
156+
/// Provides access to emitting code assets.
148157
final BuildOutputAssetsBuilder _output;
149158

150159
BuildOutputCodeAssetBuilder._(this._output);
@@ -185,6 +194,8 @@ final class LinkOutputCodeAssetBuilder {
185194

186195
/// Extension to initialize code specific configuration on link/build inputs.
187196
extension CodeAssetBuildInputBuilder on HookConfigBuilder {
197+
/// Sets up the code asset specific configuration for a build or link hook
198+
/// input.
188199
void setupCode({
189200
required Architecture targetArchitecture,
190201
required OS targetOS,
@@ -229,19 +240,30 @@ extension LinkOutputCodeAssets on LinkOutputAssets {
229240
.toList();
230241
}
231242

243+
/// Extension methods for [MacOSCodeConfig] to convert to and from the syntax
244+
/// model.
232245
extension MacOSCodeConfigSyntaxExtension on MacOSCodeConfig {
246+
/// Converts this [MacOSCodeConfig] to its corresponding
247+
/// [MacOSCodeConfigSyntax].
233248
MacOSCodeConfigSyntax toSyntax() =>
234249
MacOSCodeConfigSyntax(targetVersion: targetVersion);
235250
}
236251

252+
/// Extension methods for [IOSCodeConfig] to convert to and from the syntax
253+
/// model.
237254
extension IOSCodeConfigSyntaxExtension on IOSCodeConfig {
255+
/// Converts this [IOSCodeConfig] to its corresponding [IOSCodeConfigSyntax].
238256
IOSCodeConfigSyntax toSyntax() => IOSCodeConfigSyntax(
239257
targetSdk: targetSdk.type,
240258
targetVersion: targetVersion,
241259
);
242260
}
243261

262+
/// Extension methods for [AndroidCodeConfig] to convert to and from the syntax
263+
/// model.
244264
extension AndroidCodeConfigSyntaxExtension on AndroidCodeConfig {
265+
/// Converts this [AndroidCodeConfig] to its corresponding
266+
/// [AndroidCodeConfigSyntax].
245267
AndroidCodeConfigSyntax toSyntax() =>
246268
AndroidCodeConfigSyntax(targetNdkApi: targetNdkApi);
247269
}

pkgs/code_assets/lib/src/code_assets/extension.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,34 @@ import 'validation.dart';
1515
/// The protocol extension for the `hook/build.dart` and `hook/link.dart`
1616
/// with [CodeAsset]s and [CodeConfig].
1717
final class CodeAssetExtension implements ProtocolExtension {
18+
/// The architecture to build for.
1819
final Architecture targetArchitecture;
20+
21+
/// The operating system to build for.
1922
final OS targetOS;
23+
24+
/// The preferred link mode.
2025
final LinkModePreference linkModePreference;
26+
27+
/// Optional C compiler configuration.
2128
final CCompilerConfig? cCompiler;
29+
30+
/// Optional Android specific configuration.
31+
///
32+
/// Required if [targetOS] is [OS.android].
2233
final AndroidCodeConfig? android;
34+
35+
/// Optional iOS specific configuration.
36+
///
37+
/// Required if [targetOS] is [OS.iOS].
2338
final IOSCodeConfig? iOS;
39+
40+
/// Optional macOS specific configuration.
41+
///
42+
/// Required if [targetOS] is [OS.macOS].
2443
final MacOSCodeConfig? macOS;
2544

45+
/// Constructs a [CodeAssetExtension].
2646
CodeAssetExtension({
2747
required this.targetArchitecture,
2848
required this.targetOS,

pkgs/code_assets/lib/src/code_assets/ios_sdk.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import 'config.dart';
66

77
/// The iOS SDK (device or simulator) in [IOSCodeConfig.targetSdk].
88
final class IOSSdk {
9+
/// The type of this [IOSSdk].
10+
///
11+
/// A string such as `iphoneos` or `iphonesimulator`.
912
final String type;
1013

1114
const IOSSdk._(this.type);

pkgs/code_assets/lib/src/code_assets/link_mode.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ abstract final class LinkMode {
3434
Map<String, Object?> toJson() => toSyntax().json;
3535
}
3636

37+
/// Extension methods for [LinkMode] to convert to and from the syntax model.
3738
extension LinkModeSyntaxExtension on LinkMode {
39+
/// Converts this [LinkMode] to its corresponding [LinkModeSyntax]
40+
/// representation.
3841
LinkModeSyntax toSyntax() => switch (this) {
3942
StaticLinking() => StaticLinkModeSyntax(),
4043
LookupInProcess() => DynamicLoadingProcessLinkModeSyntax(),
@@ -46,6 +49,8 @@ extension LinkModeSyntaxExtension on LinkMode {
4649
_ => throw UnimplementedError('The link mode "$this" is not known'),
4750
};
4851

52+
/// Converts a [LinkModeSyntax] to its corresponding [LinkMode]
53+
/// representation.
4954
static LinkMode fromSyntax(LinkModeSyntax linkMode) => switch (linkMode) {
5055
_ when linkMode.isStaticLinkMode => StaticLinking(),
5156
_ when linkMode.isDynamicLoadingProcessLinkMode => LookupInProcess(),
@@ -86,6 +91,7 @@ final class DynamicLoadingBundled extends DynamicLoading {
8691

8792
static final DynamicLoadingBundled _singleton = DynamicLoadingBundled._();
8893

94+
/// Returns the singleton instance of [DynamicLoadingBundled].
8995
factory DynamicLoadingBundled() => _singleton;
9096

9197
@override
@@ -100,9 +106,10 @@ final class DynamicLoadingBundled extends DynamicLoading {
100106
/// At runtime, the dynamic library will be loaded and the symbols will be
101107
/// looked up in this dynamic library.
102108
final class DynamicLoadingSystem extends DynamicLoading {
103-
/// The [Uri] of the
109+
/// The [Uri] of the dynamic library on the system.
104110
final Uri uri;
105111

112+
/// Constructs a [DynamicLoadingSystem] with the given [uri].
106113
DynamicLoadingSystem(this.uri) : super._();
107114

108115
static const _typeValue = 'dynamic_loading_system';
@@ -127,6 +134,7 @@ final class LookupInProcess extends DynamicLoading {
127134

128135
static final LookupInProcess _singleton = LookupInProcess._();
129136

137+
/// Returns the singleton instance of [LookupInProcess].
130138
factory LookupInProcess() => _singleton;
131139

132140
@override
@@ -142,6 +150,7 @@ final class LookupInExecutable extends DynamicLoading {
142150

143151
static final LookupInExecutable _singleton = LookupInExecutable._();
144152

153+
/// Returns the singleton instance of [LookupInExecutable].
145154
factory LookupInExecutable() => _singleton;
146155

147156
@override
@@ -160,6 +169,8 @@ final class LookupInExecutable extends DynamicLoading {
160169
// TODO(https://github.com/dart-lang/sdk/issues/49418): Support static linking.
161170
final class StaticLinking extends LinkMode {
162171
const StaticLinking._() : super._();
172+
173+
/// Returns the singleton instance of [StaticLinking].
163174
factory StaticLinking() => _singleton;
164175

165176
static const StaticLinking _singleton = StaticLinking._();

0 commit comments

Comments
 (0)