[ddc] Migrate ddb script to null safety

Issue: https://github.com/dart-lang/sdk/issues/46617
Change-Id: I34e9c11f6c721ca460a39f0037bf841afb6725f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250352
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
Nicholas Shahan 2022-07-19 22:49:54 +00:00 committed by Commit Bot
parent c19ab3751a
commit a6478ba4c5

View file

@ -3,23 +3,20 @@
// for details. All rights reserved. Use of this source code is governed by a // for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file. // BSD-style license that can be found in the LICENSE file.
// @dart = 2.9 /// Compiles code with DDC and runs the resulting code with either node or
/// chrome.
// ///
// Compiles code with DDC and runs the resulting code with either node or /// The first script supplied should be the one with `main()`.
// chrome. ///
// /// Saves the output in the same directory as the sources for convenient
// The first script supplied should be the one with `main()`. /// inspection, modification or rerunning the code.
//
// Saves the output in the same directory as the sources for convenient
// inspection, modification or rerunning the code.
import 'dart:io'; import 'dart:io';
import 'package:args/args.dart' show ArgParser; import 'package:args/args.dart' show ArgParser;
import 'package:path/path.dart' as p;
import 'package:dev_compiler/src/compiler/module_builder.dart' import 'package:dev_compiler/src/compiler/module_builder.dart'
as module_builder; as module_builder;
import 'package:path/path.dart' as p;
enum NullSafety { strict, weak, disabled } enum NullSafety { strict, weak, disabled }
@ -113,14 +110,14 @@ void main(List<String> args) async {
printUsage(); printUsage();
exit(1); exit(1);
} }
var arch = options['arch'] as String; var arch = options['arch'] as String?;
var debug = options['debug'] as bool || var debug = options['debug'] as bool ||
options['observe'] as bool || options['observe'] as bool ||
options.wasParsed('vm-service-port'); options.wasParsed('vm-service-port');
var summarizeText = options['summarize-text'] as bool; var summarizeText = options['summarize-text'] as bool;
var binary = options['binary'] as String; var binary = options['binary'] as String?;
var experiments = options['enable-experiment'] as List; var experiments = options['enable-experiment'] as List<String>;
var summaries = options['summary'] as List; var summaries = options['summary'] as List<String>;
var port = int.parse(options['port'] as String); var port = int.parse(options['port'] as String);
var mode = options['mode'] as String; var mode = options['mode'] as String;
var compile = mode == 'compile' || mode == 'all'; var compile = mode == 'compile' || mode == 'all';
@ -133,7 +130,7 @@ void main(List<String> args) async {
var weakNullSafetyErrors = options['weak-null-safety-errors'] as bool; var weakNullSafetyErrors = options['weak-null-safety-errors'] as bool;
var canaryFeatures = options['canary'] as bool; var canaryFeatures = options['canary'] as bool;
var entry = p.canonicalize(options.rest.first); var entry = p.canonicalize(options.rest.first);
var out = (options['out'] as String) ?? p.setExtension(entry, '.js'); var out = (options['out'] as String?) ?? p.setExtension(entry, '.js');
var libRoot = p.dirname(entry); var libRoot = p.dirname(entry);
var basename = p.basenameWithoutExtension(entry); var basename = p.basenameWithoutExtension(entry);
var libname = var libname =
@ -180,8 +177,9 @@ void main(List<String> args) async {
var vmServicePort = options.wasParsed('vm-service-port') var vmServicePort = options.wasParsed('vm-service-port')
? '=${options['vm-service-port']}' ? '=${options['vm-service-port']}'
: ''; : '';
var vmOptions = options['compile-vm-options'] as String?;
var args = <String>[ var args = <String>[
...?options['compile-vm-options']?.split(' '), ...?vmOptions?.split(' '),
if (debug) ...[ if (debug) ...[
if (observe) ...[ if (observe) ...[
'--enable-vm-service$vmServicePort', '--enable-vm-service$vmServicePort',
@ -200,10 +198,11 @@ void main(List<String> args) async {
} }
String mod; String mod;
bool chrome = false; var chrome = false;
bool node = false; var node = false;
bool d8 = false; var d8 = false;
switch (options['runtime'] as String) { var runtime = options['runtime'] as String?;
switch (runtime) {
case 'node': case 'node':
node = true; node = true;
mod = 'common'; mod = 'common';
@ -216,6 +215,8 @@ void main(List<String> args) async {
chrome = true; chrome = true;
mod = 'amd'; mod = 'amd';
break; break;
default:
throw Exception('Unexpected runtime: $runtime');
} }
var sdkRoot = p.dirname(p.dirname(ddcPath)); var sdkRoot = p.dirname(p.dirname(ddcPath));
@ -386,14 +387,15 @@ final _resolvedUnames = {
}; };
/// Returns the location of the Dart SDK's build directory. /// Returns the location of the Dart SDK's build directory.
String resolveBuildDir(String sdkRoot, String architecture) { String resolveBuildDir(String sdkRoot, String? architecture) {
String platformString; String platformString;
String archString; String archString;
if (Platform.isMacOS) { if (Platform.isMacOS) {
platformString = 'xcodebuild'; platformString = 'xcodebuild';
String resolvedArchitecture = architecture; var resolvedArchitecture = architecture;
if (architecture == null) { if (architecture == null) {
final uname = Process.runSync('uname', ['-m']).stdout.trim(); var result = Process.runSync('uname', ['-m']).stdout as String;
final uname = result.trim();
resolvedArchitecture = _resolvedUnames[uname] ?? uname; resolvedArchitecture = _resolvedUnames[uname] ?? uname;
} }
if (resolvedArchitecture == 'x64') { if (resolvedArchitecture == 'x64') {