mirror of
https://github.com/dart-lang/sdk
synced 2024-10-02 23:49:17 +00:00
Discontinue dart2native (use dart compile)
TEST=Existing tests updated to use dart compile Change-Id: Ia3478069df2354a3bf057fedae0f1eea9415de95 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210241 Commit-Queue: Michael Thomsen <mit@google.com> Reviewed-by: Devon Carew <devoncarew@google.com> Reviewed-by: Tess Strickland <sstrickl@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com>
This commit is contained in:
parent
0c165830b8
commit
6c5fb84716
|
@ -1,131 +0,0 @@
|
|||
#!/usr/bin/env dart
|
||||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
||||
// 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.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:dart2native/generate.dart';
|
||||
import 'package:front_end/src/api_prototype/compiler_options.dart'
|
||||
show Verbosity;
|
||||
|
||||
void printUsage(final ArgParser parser) {
|
||||
print('''
|
||||
Usage: dart2native <main-dart-file> [<options>]
|
||||
|
||||
Generates an executable or an AOT snapshot from <main-dart-file>.
|
||||
''');
|
||||
print(parser.usage);
|
||||
}
|
||||
|
||||
Future<void> main(List<String> args) async {
|
||||
// If we're outputting to a terminal, wrap usage text to that width.
|
||||
int? outputLineWidth;
|
||||
try {
|
||||
outputLineWidth = stdout.terminalColumns;
|
||||
} catch (_) {/* Ignore. */}
|
||||
|
||||
final ArgParser parser = ArgParser(usageLineLength: outputLineWidth)
|
||||
..addMultiOption('define', abbr: 'D', valueHelp: 'key=value', help: '''
|
||||
Define an environment declaration. To specify multiple declarations, use multiple options or use commas to separate key-value pairs.
|
||||
E.g.: dart2native -Da=1,b=2 main.dart''')
|
||||
..addFlag('enable-asserts',
|
||||
negatable: false, help: 'Enable assert statements.')
|
||||
..addMultiOption(
|
||||
'extra-gen-snapshot-options',
|
||||
help: 'Pass additional options to gen_snapshot.',
|
||||
hide: true,
|
||||
valueHelp: 'opt1,opt2,...',
|
||||
)
|
||||
..addFlag('help',
|
||||
abbr: 'h', negatable: false, help: 'Display this help message.')
|
||||
..addOption(
|
||||
'output-kind',
|
||||
abbr: 'k',
|
||||
allowed: ['aot', 'exe'],
|
||||
allowedHelp: {
|
||||
'aot': 'Generate an AOT snapshot.',
|
||||
'exe': 'Generate a standalone executable.',
|
||||
},
|
||||
defaultsTo: 'exe',
|
||||
valueHelp: 'aot|exe',
|
||||
)
|
||||
..addOption('output', abbr: 'o', valueHelp: 'path', help: '''
|
||||
Set the output filename. <path> can be relative or absolute.
|
||||
E.g.: dart2native main.dart -o ../bin/my_app.exe
|
||||
''')
|
||||
..addOption('packages', abbr: 'p', valueHelp: 'path', help: '''
|
||||
Get package locations from the specified file instead of .packages. <path> can be relative or absolute.
|
||||
E.g.: dart2native --packages=/tmp/pkgs main.dart
|
||||
''')
|
||||
..addOption('save-debugging-info', abbr: 'S', valueHelp: 'path', help: '''
|
||||
Remove debugging information from the output and save it separately to the specified file. <path> can be relative or absolute.
|
||||
''')
|
||||
..addOption('enable-experiment',
|
||||
defaultsTo: '', valueHelp: 'feature', hide: true, help: '''
|
||||
Comma separated list of experimental features.
|
||||
''')
|
||||
..addFlag('sound-null-safety',
|
||||
help: 'Respect the nullability of types at runtime.', defaultsTo: null)
|
||||
..addFlag('verbose',
|
||||
abbr: 'v', negatable: false, help: 'Show verbose output.')
|
||||
..addOption(
|
||||
'verbosity',
|
||||
defaultsTo: Verbosity.defaultValue,
|
||||
help: '''
|
||||
Sets the verbosity level used for filtering messages during compilation.
|
||||
''',
|
||||
allowed: Verbosity.allowedValues,
|
||||
allowedHelp: Verbosity.allowedValuesHelp,
|
||||
);
|
||||
|
||||
ArgResults parsedArgs;
|
||||
try {
|
||||
parsedArgs = parser.parse(args);
|
||||
} on FormatException catch (e) {
|
||||
stderr.writeln('Error: ${e.message}');
|
||||
await stderr.flush();
|
||||
printUsage(parser);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (parsedArgs['help']) {
|
||||
printUsage(parser);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (parsedArgs.rest.length != 1) {
|
||||
printUsage(parser);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
final String sourceFile = parsedArgs.rest[0];
|
||||
if (!FileSystemEntity.isFileSync(sourceFile)) {
|
||||
stderr.writeln(
|
||||
'"$sourceFile" is not a file. See \'--help\' for more information.');
|
||||
await stderr.flush();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
await generateNative(
|
||||
kind: parsedArgs['output-kind'],
|
||||
sourceFile: sourceFile,
|
||||
outputFile: parsedArgs['output'],
|
||||
debugFile: parsedArgs['save-debugging-info'],
|
||||
packages: parsedArgs['packages'],
|
||||
defines: parsedArgs['define'],
|
||||
enableExperiment: parsedArgs['enable-experiment'],
|
||||
enableAsserts: parsedArgs['enable-asserts'],
|
||||
soundNullSafety: parsedArgs['sound-null-safety'],
|
||||
verbose: parsedArgs['verbose'],
|
||||
verbosity: parsedArgs['verbosity'],
|
||||
extraOptions: parsedArgs['extra-gen-snapshot-options']);
|
||||
} catch (e) {
|
||||
stderr.writeln('Failed to generate native files:');
|
||||
stderr.writeln(e);
|
||||
await stderr.flush();
|
||||
exit(1);
|
||||
}
|
||||
}
|
|
@ -10,9 +10,6 @@ executables:
|
|||
dart2native:
|
||||
|
||||
dependencies:
|
||||
args: ^1.4.0
|
||||
front_end:
|
||||
path: ../front_end
|
||||
path: any
|
||||
|
||||
dev_dependencies:
|
||||
|
|
|
@ -239,7 +239,13 @@ For example: dart compile $commandName --packages=/tmp/pkgs main.dart''')
|
|||
defaultsTo: null)
|
||||
..addOption('save-debugging-info', abbr: 'S', valueHelp: 'path', help: '''
|
||||
Remove debugging information from the output and save it separately to the specified file.
|
||||
<path> can be relative or absolute.''');
|
||||
<path> can be relative or absolute.''')
|
||||
..addMultiOption(
|
||||
'extra-gen-snapshot-options',
|
||||
help: 'Pass additional options to gen_snapshot.',
|
||||
hide: true,
|
||||
valueHelp: 'opt1,opt2,...',
|
||||
);
|
||||
|
||||
addExperimentalFlags(argParser, verbose);
|
||||
}
|
||||
|
@ -277,6 +283,7 @@ Remove debugging information from the output and save it separately to the speci
|
|||
debugFile: argResults['save-debugging-info'],
|
||||
verbose: verbose,
|
||||
verbosity: argResults['verbosity'],
|
||||
extraOptions: argResults['extra-gen-snapshot-options'],
|
||||
);
|
||||
return 0;
|
||||
} catch (e) {
|
||||
|
|
|
@ -32,7 +32,7 @@ translated output.
|
|||
|
||||
```dart
|
||||
@pragma('vm:prefer-inline')
|
||||
bar() => throw null;
|
||||
bar() => throw Null;
|
||||
|
||||
@pragma('vm:never-inline')
|
||||
foo() => bar();
|
||||
|
@ -44,24 +44,18 @@ Now we run the following commands:
|
|||
|
||||
```bash
|
||||
# Make sure that we have the native_stack_traces package.
|
||||
$ pub get native_stack_traces
|
||||
$ pub global activate native_stack_traces
|
||||
$ dart pub global activate native_stack_traces
|
||||
|
||||
# We compile the example program, removing the source location information
|
||||
# from the snapshot and saving the debugging information into throws.debug.
|
||||
$ dart2native -k aot -S throws.debug -o throws.aotsnapshot throws.dart
|
||||
$ dart compile exe -S throws.debug throws.dart
|
||||
|
||||
# Run the program, saving the error output to throws.err.
|
||||
$ dartaotruntime throws.aotsnapshot 2>throws.err
|
||||
$ ./throws.exe 2>throws.err
|
||||
|
||||
# Using the saved debugging information, we can translate the stack trace
|
||||
# contained in throws.err to its symbolic form.
|
||||
$ pub global run native_stack_traces:decode translate -d throws.debug -i throws.err
|
||||
|
||||
# We can also just pipe the output of running the program directly into
|
||||
# the utility.
|
||||
$ dartaotruntime throws.aotsnapshot |& \
|
||||
pub global run native_stack_traces:decode translate -d throws.debug
|
||||
$ dart pub global run native_stack_traces:decode translate -d throws.debug -i throws.err
|
||||
```
|
||||
|
||||
## Features and bugs
|
||||
|
|
|
@ -8,16 +8,15 @@ import 'dart:io';
|
|||
import 'package:path/path.dart' as path;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
final dart2native = () {
|
||||
final dartCompile = () {
|
||||
final sdkBin = path.dirname(Platform.executable);
|
||||
final dart2native =
|
||||
path.join(sdkBin, Platform.isWindows ? 'dart2native.bat' : 'dart2native');
|
||||
final dartCmd = path.join(sdkBin, Platform.isWindows ? 'dart.bat' : 'dart');
|
||||
|
||||
if (!File(dart2native).existsSync()) {
|
||||
throw 'Failed to locate dart2native in the SDK';
|
||||
if (!File(dartCmd).existsSync()) {
|
||||
throw 'Failed to locate `dart` in the SDK';
|
||||
}
|
||||
|
||||
return path.canonicalize(dart2native);
|
||||
return path.canonicalize(dartCmd);
|
||||
}();
|
||||
|
||||
class AotSnapshot {
|
||||
|
@ -61,6 +60,8 @@ void main(List<String> args) => input.main(args);
|
|||
];
|
||||
|
||||
final args = [
|
||||
'compile',
|
||||
'exe',
|
||||
'-o',
|
||||
snapshot.outputBinary,
|
||||
'--packages=$packages',
|
||||
|
@ -69,12 +70,12 @@ void main(List<String> args) => input.main(args);
|
|||
];
|
||||
|
||||
// Compile input.dart to native and output instruction sizes.
|
||||
final result = await Process.run(dart2native, args);
|
||||
final result = await Process.run(dartCompile, args);
|
||||
|
||||
expect(result.exitCode, equals(0), reason: '''
|
||||
Compilation completed with exit code ${result.exitCode}.
|
||||
|
||||
Command line: $dart2native ${args.join(' ')}
|
||||
Command line: $dartCompile ${args.join(' ')}
|
||||
|
||||
stdout: ${result.stdout}
|
||||
stderr: ${result.stderr}
|
||||
|
|
56
sdk/BUILD.gn
56
sdk/BUILD.gn
|
@ -37,7 +37,6 @@ declare_args() {
|
|||
# ......dartaotruntime or dartaotruntime.exe (executable)
|
||||
# ......dartdoc
|
||||
# ......dartfmt
|
||||
# ......dart2native (if not on ia32)
|
||||
# ......dart2js
|
||||
# ......dartanalyzer
|
||||
# ......dartdevc
|
||||
|
@ -46,7 +45,6 @@ declare_args() {
|
|||
# ......snapshots/
|
||||
# ........analysis_server.dart.snapshot
|
||||
# ........dart2js.dart.snapshot
|
||||
# ........dart2native.dart.snapshot (if not on ia32)
|
||||
# ........dartanalyzer.dart.snapshot
|
||||
# ........dartdev.dart.snapshot
|
||||
# ........dartdev.dill
|
||||
|
@ -147,12 +145,6 @@ _platform_sdk_snapshots = [
|
|||
"../utils/pub",
|
||||
],
|
||||
]
|
||||
if (dart_target_arch != "ia32") {
|
||||
_platform_sdk_snapshots += [ [
|
||||
"dart2native",
|
||||
"../utils/dart2native:generate_dart2native_snapshot",
|
||||
] ]
|
||||
}
|
||||
if (create_kernel_service_snapshot) {
|
||||
_platform_sdk_snapshots += [ [
|
||||
"kernel-service",
|
||||
|
@ -270,8 +262,8 @@ foreach(library, _full_sdk_libraries) {
|
|||
{
|
||||
target = "copy_${library}_library"
|
||||
visibility = [
|
||||
":copy_platform_sdk_libraries",
|
||||
":copy_full_sdk_libraries",
|
||||
":copy_platform_sdk_libraries",
|
||||
]
|
||||
source = "lib/$library"
|
||||
dest = "$root_out_dir/$dart_sdk_output/lib/$library"
|
||||
|
@ -328,7 +320,7 @@ if (target_os != current_os && target_os == "fuchsia") {
|
|||
}
|
||||
|
||||
copy("copy_dartaotruntime") {
|
||||
visibility = [ ":copy_dart2native" ]
|
||||
visibility = [ ":group_dart2native" ]
|
||||
deps = [ "../runtime/bin:dart_precompiled_runtime_product" ]
|
||||
src_dir = get_label_info("../runtime/bin:dart_precompiled_runtime_product",
|
||||
"root_out_dir")
|
||||
|
@ -341,7 +333,7 @@ copy("copy_dartaotruntime") {
|
|||
}
|
||||
|
||||
copy("copy_gen_snapshot") {
|
||||
visibility = [ ":copy_dart2native" ]
|
||||
visibility = [ ":group_dart2native" ]
|
||||
deps = [ "../runtime/bin:gen_snapshot_product" ]
|
||||
src_dir =
|
||||
get_label_info("../runtime/bin:gen_snapshot_product", "root_out_dir")
|
||||
|
@ -352,7 +344,7 @@ copy("copy_gen_snapshot") {
|
|||
}
|
||||
|
||||
copy("copy_vm_platform_strong_product") {
|
||||
visibility = [ ":copy_dart2native" ]
|
||||
visibility = [ ":group_dart2native" ]
|
||||
deps = [ "../runtime/vm:vm_platform_product" ]
|
||||
src_dir = get_label_info("../runtime/vm:vm_platform_product", "root_out_dir")
|
||||
sources = [ "$src_dir/vm_platform_strong_product.dill" ]
|
||||
|
@ -360,27 +352,21 @@ copy("copy_vm_platform_strong_product") {
|
|||
[ "$root_out_dir/$dart_sdk_output/lib/_internal/{{source_file_part}}" ]
|
||||
}
|
||||
|
||||
copy("copy_dart2native") {
|
||||
copy("copy_gen_kernel_snapshot") {
|
||||
visibility = [ ":group_dart2native" ]
|
||||
deps = [ "../utils/gen_kernel" ]
|
||||
sources = [ "$root_gen_dir/gen_kernel.dart.snapshot" ]
|
||||
outputs =
|
||||
[ "$root_out_dir/$dart_sdk_output/bin/snapshots/{{source_file_part}}" ]
|
||||
}
|
||||
|
||||
group("group_dart2native") {
|
||||
deps = [
|
||||
":copy_dartaotruntime",
|
||||
":copy_gen_kernel_snapshot",
|
||||
":copy_gen_snapshot",
|
||||
":copy_vm_platform_strong_product",
|
||||
]
|
||||
ext = ""
|
||||
if (is_win) {
|
||||
ext = ".bat"
|
||||
}
|
||||
sources = [ "bin/dart2native$ext" ]
|
||||
outputs = [ "$root_out_dir/$dart_sdk_output/bin/{{source_file_part}}" ]
|
||||
}
|
||||
|
||||
copy("copy_gen_kernel_snapshot") {
|
||||
visibility = [ ":copy_dart2native" ]
|
||||
deps = [ "../utils/gen_kernel" ]
|
||||
sources = [ "$root_gen_dir/gen_kernel.dart.snapshot" ]
|
||||
outputs =
|
||||
[ "$root_out_dir/$dart_sdk_output/bin/snapshots/{{source_file_part}}" ]
|
||||
}
|
||||
|
||||
# A template for copying the things in _platform_sdk_scripts and
|
||||
|
@ -394,8 +380,8 @@ template("copy_sdk_script") {
|
|||
}
|
||||
copy(target_name) {
|
||||
visibility = [
|
||||
":copy_platform_sdk_scripts",
|
||||
":copy_full_sdk_scripts",
|
||||
":copy_platform_sdk_scripts",
|
||||
]
|
||||
sources = [ "bin/${name}_sdk$ext" ]
|
||||
outputs = [ "$root_out_dir/$dart_sdk_output/bin/$name$ext" ]
|
||||
|
@ -411,8 +397,8 @@ foreach(sdk_script, _full_sdk_scripts) {
|
|||
foreach(script, _scripts) {
|
||||
copy("copy_${script}_script") {
|
||||
visibility = [
|
||||
":copy_platform_sdk_scripts",
|
||||
":copy_full_sdk_scripts",
|
||||
":copy_platform_sdk_scripts",
|
||||
]
|
||||
ext = ""
|
||||
if (is_win) {
|
||||
|
@ -458,8 +444,8 @@ foreach(snapshot, _full_sdk_snapshots) {
|
|||
}
|
||||
copy("copy_${snapshot[0]}_snapshot") {
|
||||
visibility = [
|
||||
":copy_platform_sdk_snapshots",
|
||||
":copy_full_sdk_snapshots",
|
||||
":copy_platform_sdk_snapshots",
|
||||
]
|
||||
deps = [ snapshot[1] ]
|
||||
sources = [ "$root/${snapshot[0]}.dart.snapshot" ]
|
||||
|
@ -695,8 +681,8 @@ group("copy_platform_sdk_libraries") {
|
|||
# This is the main rule to copy libraries in _full_sdk_libraries to lib/
|
||||
group("copy_full_sdk_libraries") {
|
||||
visibility = [
|
||||
":create_full_sdk",
|
||||
":copy_libraries",
|
||||
":create_full_sdk",
|
||||
]
|
||||
public_deps = []
|
||||
foreach(library, _full_sdk_libraries) {
|
||||
|
@ -796,8 +782,8 @@ copy("copy_api_readme") {
|
|||
# Parts common to both platform and full SDKs.
|
||||
group("create_common_sdk") {
|
||||
visibility = [
|
||||
":create_sdk",
|
||||
":create_platform_sdk",
|
||||
":create_sdk",
|
||||
]
|
||||
public_deps = [
|
||||
":copy_analysis_summaries",
|
||||
|
@ -818,17 +804,17 @@ group("create_common_sdk") {
|
|||
]
|
||||
|
||||
# We do not support AOT on ia32 and should therefore not add the
|
||||
# dart2native script (since there is no AOT compiler/runtime available)
|
||||
# dart native compilation files (since there is no AOT compiler/runtime available)
|
||||
if (dart_target_arch != "ia32") {
|
||||
public_deps += [ ":copy_dart2native" ]
|
||||
public_deps += [ ":group_dart2native" ]
|
||||
}
|
||||
}
|
||||
|
||||
# Parts specific to the platform SDK.
|
||||
group("_create_platform_sdk") {
|
||||
visibility = [
|
||||
":create_sdk",
|
||||
":create_platform_sdk",
|
||||
":create_sdk",
|
||||
]
|
||||
public_deps = [
|
||||
":copy_platform_sdk_libraries",
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
||||
# 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.
|
||||
|
||||
# Run dart2native.dart.snapshot on the Dart VM
|
||||
|
||||
echo "Warning: 'dart2native' is deprecated. Please use 'dart compile exe'." 1>&2
|
||||
|
||||
function follow_links() {
|
||||
file="$1"
|
||||
while [ -h "$file" ]; do
|
||||
# On Mac OS, readlink -f doesn't work.
|
||||
file="$(readlink "$file")"
|
||||
done
|
||||
echo "$file"
|
||||
}
|
||||
|
||||
# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
|
||||
PROG_NAME="$(follow_links "$BASH_SOURCE")"
|
||||
|
||||
# Handle the case where dart-sdk/bin has been symlinked to.
|
||||
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
|
||||
SNAPSHOTS_DIR="${BIN_DIR}/snapshots"
|
||||
DART="$BIN_DIR/dart"
|
||||
|
||||
exec "$DART" "${SNAPSHOTS_DIR}/dart2native.dart.snapshot" "$@"
|
|
@ -1,45 +0,0 @@
|
|||
@echo off
|
||||
REM Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
||||
REM for details. All rights reserved. Use of this source code is governed by a
|
||||
REM BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
echo Warning: 'dart2native' is deprecated. Please use 'dart compile exe'. 1>&2
|
||||
|
||||
setlocal
|
||||
rem Handle the case where dart-sdk/bin has been symlinked to.
|
||||
set DIR_NAME_WITH_SLASH=%~dp0
|
||||
set DIR_NAME=%DIR_NAME_WITH_SLASH:~0,-1%%
|
||||
call :follow_links "%DIR_NAME%", RETURNED_BIN_DIR
|
||||
rem Get rid of surrounding quotes.
|
||||
for %%i in ("%RETURNED_BIN_DIR%") do set BIN_DIR=%%~fi
|
||||
|
||||
set DART=%BIN_DIR%\dart
|
||||
|
||||
"%DART%" "%BIN_DIR%\snapshots\dart2native.dart.snapshot" %*
|
||||
|
||||
endlocal
|
||||
|
||||
exit /b %errorlevel%
|
||||
|
||||
rem Follow the symbolic links (junctions points) using `dir to determine the
|
||||
rem canonical path. Output with a link looks something like this
|
||||
rem
|
||||
rem 01/03/2013 10:11 PM <JUNCTION> abc def
|
||||
rem [c:\dart_bleeding\dart-repo.9\dart\out\ReleaseIA32\dart-sdk]
|
||||
rem
|
||||
rem So in the output of 'dir /a:l "targetdir"' we are looking for a filename
|
||||
rem surrounded by right angle bracket and left square bracket. Once we get
|
||||
rem the filename, which is name of the link, we recursively follow that.
|
||||
:follow_links
|
||||
setlocal
|
||||
for %%i in (%1) do set result=%%~fi
|
||||
set current=
|
||||
for /f "usebackq tokens=2 delims=[]" %%i in (`dir /a:l "%~dp1" 2^>nul ^
|
||||
^| %SystemRoot%\System32\find.exe "> %~n1 [" 2^>nul`) do (
|
||||
set current=%%i
|
||||
)
|
||||
if not "%current%"=="" call :follow_links "%current%", result
|
||||
endlocal & set %~2=%result%
|
||||
goto :eof
|
||||
|
||||
:end
|
Loading…
Reference in a new issue