Skip to content

Commit

Permalink
[et] Resolve dart_executable as an executable
Browse files Browse the repository at this point in the history
Resolves dart_executable targets, which are `action`s with metadata
specifying `action_type = [ "dart_executable" ]` to
`BuildTargetType.executable`.
  • Loading branch information
cbracken committed Apr 19, 2024
1 parent f4c4e15 commit 4de7330
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tools/engine_tool/lib/src/gn_utils.dart
Expand Up @@ -32,8 +32,13 @@ enum BuildTargetType {
staticLibrary,
}

BuildTargetType? _buildTargetTypeFromString(String type) {
BuildTargetType? _buildTargetTypeFromString(String type, Map<String, Object?>? metadata) {
switch (type) {
case 'action':
if (_getActionType(metadata) == 'dart_executable') {
return BuildTargetType.executable;
}
return null;
case 'executable':
return BuildTargetType.executable;
case 'shared_library':
Expand All @@ -46,6 +51,16 @@ BuildTargetType? _buildTargetTypeFromString(String type) {
}
}

String? _getActionType(Map<String, Object?>? metadata) {
if (metadata != null) {
final List<String>? action_type = getListOfString(metadata, 'action_type');
if (action_type != null && action_type.isNotEmpty) {
return action_type[0];
}
}
return null;
}

// TODO(johnmccutchan): What should we do about source_sets and other
// output-less targets? Also, what about action targets which are kind of
// "internal" build steps? For now we are ignoring them.
Expand Down Expand Up @@ -113,7 +128,8 @@ Future<Map<String, BuildTarget>> findTargets(
if (typeString == null) {
environment.logger.fatal('gn desc is missing target type: $properties');
}
final BuildTargetType? type = _buildTargetTypeFromString(typeString!);
final Map<String, Object?>? metadata = getMap(properties, 'metadata');
final BuildTargetType? type = _buildTargetTypeFromString(typeString!, metadata);
if (type == null) {
// Target is a type that we don't support.
continue;
Expand Down
8 changes: 8 additions & 0 deletions tools/engine_tool/lib/src/json_utils.dart
Expand Up @@ -117,3 +117,11 @@ List<String>? getListOfString(Map<String, Object?> map, String field) {
}
return (map[field]! as List<Object?>).cast<String>();
}

/// Returns the value in map[field] iff it is a Map<String, Object?>. null otherwise.
Map<String, Object?>? getMap(Map<String, Object?> map, String field) {
if (map[field] case final Map<String, Object?> value) {
return value;
}
return null;
}

0 comments on commit 4de7330

Please sign in to comment.