| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library fasta.compile_platform; | 5 library fasta.compile_platform; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 Future; | 8 Future; |
| 9 | 9 |
| 10 import 'dart:io' show | 10 import 'dart:io' show |
| 11 File, | 11 File, |
| 12 IOSink; | 12 IOSink; |
| 13 | 13 |
| 14 import 'package:analyzer/src/generated/source.dart' show | 14 import 'package:analyzer/src/generated/source.dart' show |
| 15 Source; | 15 Source; |
| 16 | 16 |
| 17 import 'package:analyzer/dart/element/element.dart' show | 17 import 'package:analyzer/dart/element/element.dart' show |
| 18 ExportElement, | 18 ExportElement, |
| 19 LibraryElement; | 19 LibraryElement; |
| 20 | 20 |
| 21 import 'package:kernel/kernel.dart' show | |
| 22 Repository; | |
| 23 | |
| 24 import 'package:kernel/ast.dart' show | 21 import 'package:kernel/ast.dart' show |
| 25 Field, | 22 Field, |
| 26 Library, | 23 Library, |
| 27 Name, | 24 Name, |
| 28 Program, | 25 Program, |
| 29 StringLiteral; | 26 StringLiteral; |
| 30 | 27 |
| 31 import 'package:kernel/binary/ast_to_binary.dart' show | 28 import 'package:kernel/binary/ast_to_binary.dart' show |
| 32 BinaryPrinter; | 29 BinaryPrinter; |
| 33 | 30 |
| 34 import 'package:kernel/analyzer/loader.dart' show | 31 import 'package:kernel/analyzer/loader.dart' show |
| 35 DartLoader, | 32 DartLoader, |
| 36 DartOptions, | 33 DartOptions, |
| 37 createDartSdk; | 34 createDartSdk; |
| 38 | 35 |
| 39 import 'package:kernel/target/targets.dart' show | 36 import 'package:kernel/target/targets.dart' show |
| 40 Target, | 37 Target, |
| 41 TargetFlags, | 38 TargetFlags, |
| 42 getTarget; | 39 getTarget; |
| 43 | 40 |
| 44 import 'package:kernel/repository.dart' show | |
| 45 Repository; | |
| 46 | |
| 47 import 'package:kernel/ast.dart' show | 41 import 'package:kernel/ast.dart' show |
| 48 Program; | 42 Program; |
| 49 | 43 |
| 50 import 'environment_variable.dart' show | 44 import 'environment_variable.dart' show |
| 51 EnvironmentVariableDirectory, | 45 EnvironmentVariableDirectory, |
| 52 fileExists; | 46 fileExists; |
| 53 | 47 |
| 54 import 'errors.dart' show | 48 import 'errors.dart' show |
| 55 inputError; | 49 inputError; |
| 56 | 50 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 78 "patched SDK. $what"); | 72 "patched SDK. $what"); |
| 79 } | 73 } |
| 80 return null; | 74 return null; |
| 81 } | 75 } |
| 82 } | 76 } |
| 83 | 77 |
| 84 main(List<String> arguments) async { | 78 main(List<String> arguments) async { |
| 85 Uri output = Uri.base.resolveUri(new Uri.file(arguments.single)); | 79 Uri output = Uri.base.resolveUri(new Uri.file(arguments.single)); |
| 86 DartOptions options = new DartOptions( | 80 DartOptions options = new DartOptions( |
| 87 strongMode: false, sdk: await dartAotSdk.value, packagePath: null); | 81 strongMode: false, sdk: await dartAotSdk.value, packagePath: null); |
| 88 Repository repository = new Repository(); | 82 Program program = new Program(); |
| 89 DartLoader loader = new DartLoader(repository, options, null, | 83 DartLoader loader = new DartLoader(program, options, null, |
| 90 ignoreRedirectingFactories: false, | 84 ignoreRedirectingFactories: false, |
| 91 dartSdk: createDartSdk(options.sdk, strongMode: options.strongMode)); | 85 dartSdk: createDartSdk(options.sdk, strongMode: options.strongMode)); |
| 92 Target target = getTarget( | 86 Target target = getTarget( |
| 93 "vm", new TargetFlags(strongMode: options.strongMode)); | 87 "vm", new TargetFlags(strongMode: options.strongMode)); |
| 94 Program program = loader.loadProgram( | 88 loader.loadProgram( |
| 95 Uri.base.resolve("pkg/fasta/test/platform.dart"), target: target); | 89 Uri.base.resolve("pkg/fasta/test/platform.dart"), target: target); |
| 96 if (loader.errors.isNotEmpty) { | 90 if (loader.errors.isNotEmpty) { |
| 97 inputError(null, null, loader.errors.join("\n")); | 91 inputError(null, null, loader.errors.join("\n")); |
| 98 } | 92 } |
| 99 Library mainLibrary = program.mainMethod.enclosingLibrary; | 93 Library mainLibrary = program.mainMethod.enclosingLibrary; |
| 100 program.uriToSource.remove(mainLibrary.fileUri); | 94 program.uriToSource.remove(mainLibrary.fileUri); |
| 101 program = new Program( | 95 program = new Program( |
| 102 program.libraries.where( | 96 program.libraries.where( |
| 103 (Library l) => l.importUri.scheme == "dart").toList(), | 97 (Library l) => l.importUri.scheme == "dart").toList(), |
| 104 program.uriToSource); | 98 program.uriToSource); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 129 library.addMember(new Field(exports, isStatic: true, isConst: true, | 123 library.addMember(new Field(exports, isStatic: true, isConst: true, |
| 130 initializer: literal, fileUri: "${new Uri.file(source.fullName)}") | 124 initializer: literal, fileUri: "${new Uri.file(source.fullName)}") |
| 131 ..fileOffset = offset); | 125 ..fileOffset = offset); |
| 132 } | 126 } |
| 133 } | 127 } |
| 134 | 128 |
| 135 IOSink sink = new File.fromUri(output).openWrite(); | 129 IOSink sink = new File.fromUri(output).openWrite(); |
| 136 new BinaryPrinter(sink).writeProgramFile(program); | 130 new BinaryPrinter(sink).writeProgramFile(program); |
| 137 await sink.close(); | 131 await sink.close(); |
| 138 } | 132 } |
| OLD | NEW |