Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions tools/engine_tool/lib/src/gn_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'package:process_runner/process_runner.dart';

import 'build_utils.dart';
import 'environment.dart';
import 'json_utils.dart';
import 'proc_utils.dart';
import 'typed_json.dart';

/// Canonicalized build targets start with this prefix.
const String buildTargetPrefix = '//';
Expand Down Expand Up @@ -86,9 +86,8 @@ Future<Map<String, BuildTarget>> findTargets(
environment.logger
.fatal('gn desc output is malformed $label has no value.');
}
final Map<String, Object?> properties =
targetEntry.value! as Map<String, Object?>;
final String? typeString = getString(properties, 'type');
final JsonObject properties = JsonObject(targetEntry.value! as Map<String, Object?>);
final String? typeString = properties.stringOrNull('type');
if (typeString == null) {
environment.logger.fatal('gn desc is missing target type: $properties');
}
Expand All @@ -97,7 +96,7 @@ Future<Map<String, BuildTarget>> findTargets(
// Target is a type that we don't support.
continue;
}
final bool testOnly = getBool(properties, 'testonly');
final bool testOnly = properties.boolean('testonly');
final List<String> outputs =
await _runGnOutputs(buildDir.path, label, environment);
File? executable;
Expand Down
119 changes: 0 additions & 119 deletions tools/engine_tool/lib/src/json_utils.dart

This file was deleted.

45 changes: 21 additions & 24 deletions tools/engine_tool/lib/src/proc_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math';

import 'package:path/path.dart' as p;
import 'package:process_runner/process_runner.dart';

import 'environment.dart';
import 'json_utils.dart';
import 'logger.dart';
import 'typed_json.dart';
import 'worker_pool.dart';

/// Artifacts from an exited sub-process.
Expand All @@ -33,18 +32,18 @@ final class ProcessArtifacts {

/// Constructs an instance of ProcessArtifacts from serialized JSON text.
factory ProcessArtifacts.fromJson(String serialized) {
final Map<String, dynamic> artifact =
jsonDecode(serialized) as Map<String, dynamic>;
final List<String> errors = <String>[];
final Directory cwd = Directory(stringOfJson(artifact, 'cwd', errors)!);
final List<String> commandLine =
stringListOfJson(artifact, 'commandLine', errors)!;
final int exitCode = intOfJson(artifact, 'exitCode', errors)!;
final String stdout = stringOfJson(artifact, 'stdout', errors)!;
final String stderr = stringOfJson(artifact, 'stderr', errors)!;
final int? pid = intOfJson(artifact, 'pid', errors);
return ProcessArtifacts(cwd, commandLine, exitCode, stdout, stderr,
pid: pid);
final JsonObject artifact = JsonObject.parse(serialized);
return artifact.map((JsonObject json) => ProcessArtifacts(
Directory(json.string('cwd')),
json.stringList('commandLine'),
json.integer('exitCode'),
json.string('stdout'),
json.string('stderr'),
pid: json.integer('pid'),
), onError: (JsonObject source, JsonMapException e) {
throw FormatException('Failed to parse ProcessArtifacts: $e', source.toPrettyString());
},
);
}

/// Constructs an instance of ProcessArtifacts from a file containing JSON.
Expand All @@ -54,16 +53,14 @@ final class ProcessArtifacts {

/// Saves ProcessArtifacts into file.
void save(File file) {
final Map<String, Object> data = <String, Object>{};
if (pid != null) {
data['pid'] = pid!;
}
data['exitCode'] = exitCode;
data['stdout'] = stdout;
data['stderr'] = stderr;
data['cwd'] = cwd.absolute.path;
data['commandLine'] = commandLine;
file.writeAsStringSync(jsonEncodePretty(data));
file.writeAsStringSync(JsonObject(<String, Object?>{
if (pid != null) 'pid': pid,
'exitCode': exitCode,
'stdout': stdout,
'stderr': stderr,
'cwd': cwd.absolute.path,
'commandLine': commandLine,
}).toPrettyString());
}

/// Creates a temporary file and saves the artifacts into it.
Expand Down
19 changes: 8 additions & 11 deletions tools/engine_tool/lib/src/run_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:convert';
import 'package:process_runner/process_runner.dart';

import 'environment.dart';
import 'json_utils.dart';
import 'typed_json.dart';

const String _targetPlatformKey = 'targetPlatform';
const String _nameKey = 'name';
Expand All @@ -17,16 +17,13 @@ const String _idKey = 'id';
class RunTarget {
/// Construct a RunTarget from a JSON map.
factory RunTarget.fromJson(Map<String, Object> map) {
final List<String> errors = <String>[];
final String name = stringOfJson(map, _nameKey, errors)!;
final String id = stringOfJson(map, _idKey, errors)!;
final String targetPlatform =
stringOfJson(map, _targetPlatformKey, errors)!;

if (errors.isNotEmpty) {
throw FormatException('Failed to parse RunTarget: ${errors.join('\n')}');
}
return RunTarget._(name, id, targetPlatform);
return JsonObject(map).map((JsonObject json) => RunTarget._(
json.string(_nameKey),
json.string(_idKey),
json.string(_targetPlatformKey),
), onError: (JsonObject source, JsonMapException e) {
throw FormatException('Failed to parse RunTarget: $e', source.toPrettyString());
});
}

RunTarget._(this.name, this.id, this.targetPlatform);
Expand Down
Loading