@@ -29,18 +29,26 @@ import 'json_utils.dart';
2929/// `'bin/<name>.dart'` .
3030/// - `supported_platforms` (`List<String>` , optional): Host operating systems on
3131/// which the extension can run (normalized to lowercase, e.g., `'linux'` ,
32- /// `'macos'` , `'windows'` ). When omitted or empty, [supportsHostPlatform]
33- /// imposes no static host platform filter before spawning.
34- /// - `services` (`List<String>` , optional): RPC service namespaces implemented
32+ /// `'macos'` , `'windows'` ). Platform-agnostic extensions omit this field to
33+ /// run on all host platforms (when omitted or empty, [supportsHostPlatform]
34+ /// imposes no static host platform filter before spawning). Extensions with
35+ /// host-specific native tools or dependencies must explicitly declare their
36+ /// supported host operating systems.
37+ /// - `services` (`List<String>` , required): RPC service namespaces implemented
3538/// by the extension (e.g., `'diagnostics'` , `'config'` , `'template'` ,
36- /// `'device'` , `'build'` ).
37- /// - `build_targets` (`List<String>` , optional): Static top-level `flutter build`
38- /// subcommand target names contributed by the extension.
39- /// - `templates` (`List<String>` , optional): Custom project template names
40- /// contributed by the extension.
39+ /// `'device'` , `'build'` ). Required, non-empty. Entries are lowercase service
40+ /// namespace identifiers matching known tool services (`'build'` ,
41+ /// `'device'` , `'template'` , `'config'` , `'diagnostics'` , `'clean'` ,
42+ /// `'artifacts'` ).
43+ /// - `build_targets` (`List<String>` , optional): Lowercase kebab-case
44+ /// subcommand target names contributed to `flutter build` (e.g.
45+ /// `'custom-target'` ).
46+ /// - `templates` (`List<String>` , optional): Lowercase kebab-case template
47+ /// names contributed to `flutter create -t` (e.g. `'custom-app'` ).
4148/// - `platforms` (`List<String>` , optional): Custom target platform identifiers
42- /// supported for `flutter create --platforms=<platform>` . Each entry must
43- /// match `^[a-z][a-z0-9_]*$` .
49+ /// supported for `flutter create --platforms=<platform>` . Each entry must be
50+ /// a lowercase snake_case identifier starting with a letter and containing
51+ /// only lowercase letters, digits, and underscores (e.g. `'custom_os'` ).
4452///
4553/// ### Example `extension/flutter_tools/config.yaml`
4654///
@@ -72,10 +80,11 @@ final class ExtensionPackageConfig {
7280 String ? entrypoint,
7381 Iterable <String > platforms = const < String > {},
7482 this .protocolVersion = currentProtocolVersion,
75- Iterable <String > services = const < String > {} ,
83+ required Iterable <String > services,
7684 Iterable <String > supportedPlatforms = const < String > {},
7785 Iterable <String > templates = const < String > {},
78- }) : entrypoint = _validateEntrypoint (entrypoint ?? 'bin/$name .dart' ),
86+ }) : assert (services.isNotEmpty),
87+ entrypoint = _validateEntrypoint (entrypoint ?? 'bin/$name .dart' ),
7988 supportedPlatforms = Set <String >.unmodifiable (
8089 supportedPlatforms.map ((String p) => p.toLowerCase ()),
8190 ),
@@ -84,11 +93,10 @@ final class ExtensionPackageConfig {
8493 templates = Set <String >.unmodifiable (templates),
8594 platforms = _validatePlatforms (platforms);
8695
87- /// Parses an [ExtensionPackageConfig] from a decoded YAML or JSON [map] .
96+ /// Parses an [ExtensionPackageConfig] from a decoded YAML or JSON [json] map .
8897 ///
8998 /// Throws a [FormatException] if required fields are missing or invalid.
90- factory ExtensionPackageConfig .fromMap (Map <Object ?, Object ?> map, {String ? packageName}) {
91- final Map <String , Object ?> json = map.cast <String , Object ?>();
99+ factory ExtensionPackageConfig .fromMap (Map <String , Object ?> json, {String ? packageName}) {
92100 final String rawName = packageName != null && json[nameKey] == null
93101 ? packageName
94102 : json.requiredField <String >(nameKey);
@@ -112,15 +120,22 @@ final class ExtensionPackageConfig {
112120 final String ? rawEntrypoint = json.nullableField <String >(entrypointKey);
113121 final String entrypoint = _validateEntrypoint (rawEntrypoint ?? 'bin/$name .dart' );
114122
123+ final Set <String > services = json.stringSet (servicesKey, rejectEmpty: true );
124+ if (services.isEmpty) {
125+ throw const FormatException (
126+ 'Extension config.yaml must specify a non-empty list of services for "$servicesKey ".' ,
127+ );
128+ }
129+
115130 return ExtensionPackageConfig (
116131 name: name,
117132 protocolVersion: protocolVersion,
118133 entrypoint: entrypoint,
119- supportedPlatforms: _parseStringSet ( json, supportedPlatformsKey ),
120- services: _parseStringSet (json, servicesKey) ,
121- buildTargets: _parseStringSet ( json, buildTargetsKey ),
122- templates: _parseStringSet ( json, templatesKey ),
123- platforms: _parseStringSet ( json, platformsKey ),
134+ supportedPlatforms: json. stringSet (supportedPlatformsKey, rejectEmpty : true ),
135+ services: services ,
136+ buildTargets: json. stringSet (buildTargetsKey, rejectEmpty : true ),
137+ templates: json. stringSet (templatesKey, rejectEmpty : true ),
138+ platforms: json. stringSet (platformsKey, rejectEmpty : true ),
124139 );
125140 }
126141
@@ -224,27 +239,15 @@ final class ExtensionPackageConfig {
224239 final String trimmed = platform.trim ();
225240 if (! _platformIdentifierPattern.hasMatch (trimmed)) {
226241 throw FormatException (
227- 'Extension config.yaml "$platformsKey " entries must be valid lowercase identifiers, '
228- 'got: "$platform ".' ,
242+ 'Extension config.yaml "$platformsKey " entries must be lowercase snake_case identifiers '
243+ 'starting with a letter (e.g. "custom_os"), got: "$platform ".' ,
229244 );
230245 }
231246 validated.add (trimmed);
232247 }
233248 return Set <String >.unmodifiable (validated);
234249 }
235250
236- static Set <String > _parseStringSet (Map <String , Object ?> json, String fieldName) {
237- return < String > {
238- for (final String item in json.stringIterable (fieldName))
239- if (item.trim ().isNotEmpty)
240- item.trim ()
241- else
242- throw FormatException (
243- 'Extension config.yaml "$fieldName " entries must be non-empty strings, got: "$item ".' ,
244- ),
245- };
246- }
247-
248251 static const SetEquality <String > _stringSetEquality = SetEquality <String >();
249252
250253 @override
0 commit comments