Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(790)

Side by Side Diff: pkg/front_end/lib/src/fasta/compile_platform.dart

Issue 2710693002: Update compile_platform to not use dartk. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/compile_platform_dartk.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'package:kernel/verifier.dart' show
11 verifyProgram;
12
13 import 'ticker.dart' show
14 Ticker;
15
10 import 'dart:io' show 16 import 'dart:io' show
11 File, 17 exitCode;
12 IOSink;
13 18
14 import 'package:analyzer/src/generated/source.dart' show 19 import 'compiler_command_line.dart' show
15 Source; 20 CompilerCommandLine;
16 21
17 import 'package:analyzer/dart/element/element.dart' show 22 import 'compiler_context.dart' show
18 ExportElement, 23 CompilerContext;
19 LibraryElement;
20
21 import 'package:kernel/kernel.dart' show
22 Repository;
23
24 import 'package:kernel/ast.dart' show
25 Field,
26 Library,
27 Name,
28 Program,
29 StringLiteral;
30
31 import 'package:kernel/binary/ast_to_binary.dart' show
32 BinaryPrinter;
33
34 import 'package:kernel/analyzer/loader.dart' show
35 DartLoader,
36 DartOptions,
37 createDartSdk;
38
39 import 'package:kernel/target/targets.dart' show
40 Target,
41 TargetFlags,
42 getTarget;
43
44 import 'package:kernel/repository.dart' show
45 Repository;
46
47 import 'package:kernel/ast.dart' show
48 Program;
49
50 import 'environment_variable.dart' show
51 EnvironmentVariableDirectory,
52 fileExists;
53 24
54 import 'errors.dart' show 25 import 'errors.dart' show
55 inputError; 26 InputError;
56 27
57 const EnvironmentVariableSdk dartAotSdk = const EnvironmentVariableSdk( 28 import 'kernel/kernel_target.dart' show
58 "DART_AOT_SDK", 29 KernelTarget;
59 "The environment variable 'DART_AOT_SDK' should point to a patched SDK.");
60 30
61 class EnvironmentVariableSdk extends EnvironmentVariableDirectory { 31 import 'dill/dill_target.dart' show
62 const EnvironmentVariableSdk(String name, String what) 32 DillTarget;
63 : super(name, what);
64 33
65 Future<Null> validate(String value) async { 34 import 'translate_uri.dart' show
66 Uri sdk = Uri.base.resolveUri(new Uri.directory(value)); 35 TranslateUri;
67 const String asyncDart = "lib/async/async.dart"; 36
68 if (!await fileExists(sdk, asyncDart)) { 37 import 'ast_kind.dart' show
69 inputError(null, null, 38 AstKind;
70 "The environment variable '$name' has the value '$value', " 39
71 "that's a directory that doesn't contain '$asyncDart'. $what"); 40 Future main(List<String> arguments) async {
72 } 41 Ticker ticker = new Ticker();
73 const String asyncSources = "lib/async/async_sources.gypi"; 42 try {
74 if (await fileExists(sdk, asyncSources)) { 43 await CompilerCommandLine.withGlobalOptions(
75 inputError(null, null, 44 "compile_platform", arguments,
76 "The environment variable '$name' has the value '$value', " 45 (CompilerContext c) => compilePlatform(c, ticker));
77 "that's a directory that contains '$asyncSources', so it isn't a " 46 } on InputError catch (e) {
78 "patched SDK. $what"); 47 exitCode = 1;
79 } 48 print(e.format());
80 return null; 49 return null;
81 } 50 }
82 } 51 }
83 52
84 main(List<String> arguments) async { 53 Future compilePlatform(CompilerContext c, Ticker ticker) async {
85 Uri output = Uri.base.resolveUri(new Uri.file(arguments.single)); 54 ticker.isVerbose = c.options.verbose;
86 DartOptions options = new DartOptions( 55 Uri output = Uri.base.resolveUri(new Uri.file(c.options.arguments[1]));
87 strongMode: false, sdk: await dartAotSdk.value, packagePath: null); 56 Uri patchedSdk =
88 Repository repository = new Repository(); 57 Uri.base.resolveUri(new Uri.file(c.options.arguments[0]));
89 DartLoader loader = new DartLoader(repository, options, null, 58 ticker.logMs("Parsed arguments");
90 ignoreRedirectingFactories: false, 59 if (ticker.isVerbose) {
91 dartSdk: createDartSdk(options.sdk, strongMode: options.strongMode)); 60 print("Compiling $patchedSdk to $output");
92 Target target = getTarget(
93 "vm", new TargetFlags(strongMode: options.strongMode));
94 Program program = loader.loadProgram(
95 Uri.base.resolve("pkg/fasta/test/platform.dart"), target: target);
96 if (loader.errors.isNotEmpty) {
97 inputError(null, null, loader.errors.join("\n"));
98 } 61 }
99 Library mainLibrary = program.mainMethod.enclosingLibrary; 62
100 program.uriToSource.remove(mainLibrary.fileUri); 63 TranslateUri uriTranslator = await TranslateUri.parse(patchedSdk);
101 program = new Program( 64 ticker.logMs("Read packages file");
102 program.libraries.where( 65
103 (Library l) => l.importUri.scheme == "dart").toList(), 66 DillTarget dillTarget = new DillTarget(ticker, uriTranslator);
104 program.uriToSource); 67 KernelTarget kernelTarget = new KernelTarget(
105 target.performModularTransformations(program); 68 dillTarget, uriTranslator, c.uriToSource);
106 target.performGlobalTransformations(program); 69
107 for (LibraryElement analyzerLibrary in loader.libraryElements) { 70 kernelTarget.read(Uri.parse("dart:core"));
108 Library library = loader.getLibraryReference(analyzerLibrary); 71 await dillTarget.writeOutline(null);
109 StringBuffer sb = new StringBuffer(); 72 await kernelTarget.writeOutline(output);
110 if (analyzerLibrary.exports.isNotEmpty) { 73
111 Source source; 74 if (exitCode != 0) return null;
112 int offset; 75 await kernelTarget.writeProgram(output, AstKind.Kernel);
113 for (ExportElement export in analyzerLibrary.exports) { 76 if (c.options.dumpIr) {
114 source ??= export.source; 77 kernelTarget.dumpIr();
115 offset ??= export.nameOffset; 78 }
116 Uri uri = export.exportedLibrary.source.uri; 79 if (c.options.verify) {
117 sb.write("export '"); 80 try {
118 sb.write(uri); 81 verifyProgram(kernelTarget.program);
119 sb.write("'"); 82 ticker.logMs("Verified program");
120 if (export.combinators.isNotEmpty) { 83 } catch (e, s) {
121 sb.write(" "); 84 exitCode = 1;
122 sb.writeAll(export.combinators, " "); 85 print("Verification of program failed: $e");
123 } 86 if (s != null && c.options.verbose) {
124 sb.write(";"); 87 print(s);
125 } 88 }
126 Name exports = new Name("_exports#", library);
127 StringLiteral literal = new StringLiteral("$sb")
128 ..fileOffset = offset;
129 library.addMember(new Field(exports, isStatic: true, isConst: true,
130 initializer: literal, fileUri: "${new Uri.file(source.fullName)}")
131 ..fileOffset = offset);
132 } 89 }
133 } 90 }
134
135 IOSink sink = new File.fromUri(output).openWrite();
136 new BinaryPrinter(sink).writeProgramFile(program);
137 await sink.close();
138 } 91 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/compile_platform_dartk.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698