Reland "Migration: fix generate_resources.dart to use dart compile js."

This is a reland of commit 6abea1381b

Original change's description:
> Migration: fix generate_resources.dart to use `dart compile js`.
>
> This is necessary because the command `dart2js` is no longer present
> in the SDK.
>
> Change-Id: Iea3cf3092bcda6c889c55a51d1b5601773404fb9
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253862
> Reviewed-by: Samuel Rawlins <srawlins@google.com>
> Commit-Queue: Paul Berry <paulberry@google.com>

Change-Id: Ibc25641aca165b578b2c4348ef0b841263298e3c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255740
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry 2022-08-18 20:21:17 +00:00 committed by Commit Bot
parent 9d05e410ad
commit 1f3ff13d98

View file

@ -18,7 +18,7 @@ void main(List<String> args) async {
var argParser = ArgParser()
..addFlag('verify', negatable: false)
..addFlag('dev', negatable: false)
..addOption('dart2js_path')
..addOption('dart_path')
..addFlag('help', negatable: false);
var argResults = argParser.parse(args);
if (argResults['help'] == true) {
@ -45,8 +45,7 @@ Run with '--verify' to validate that the web resource have been regenerated.
if (verify) {
verifyResourcesGDartGenerated();
} else {
await compileWebFrontEnd(
devMode: dev!, dart2jsPath: dart2jsPath(argResults)!);
await compileWebFrontEnd(devMode: dev!, dartPath: dartPath(argResults)!);
print('');
@ -91,9 +90,11 @@ String base64Encode(List<int> bytes) {
}
Future<void> compileWebFrontEnd(
{required bool devMode, required String dart2jsPath}) async {
// dart2js -m -o output source
var process = await Process.start(dart2jsPath, [
{required bool devMode, required String dartPath}) async {
// dart compile js -m -o output source
var process = await Process.start(dartPath, [
'compile',
'js',
devMode ? '-O1' : '-m',
'--no-frequency-based-minification',
'-o',
@ -121,14 +122,12 @@ void createResourcesGDart() {
resourcesFile.writeAsStringSync(content);
}
/// Returns the dart2jsPath, either from [argResults] or the Platform.
String? dart2jsPath(ArgResults argResults) {
if (argResults.wasParsed('dart2js_path')) {
return argResults['dart2js_path'] as String?;
/// Returns the dartPath, either from [argResults] or the Platform.
String? dartPath(ArgResults argResults) {
if (argResults.wasParsed('dart_path')) {
return argResults['dart_path'] as String?;
} else {
var sdkBinDir = path.dirname(Platform.resolvedExecutable);
var dart2jsBinary = Platform.isWindows ? 'dart2js.bat' : 'dart2js';
return path.join(sdkBinDir, dart2jsBinary);
return Platform.resolvedExecutable;
}
}