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

Side by Side Diff: pkg/front_end/test/fasta/shaker_test.dart

Issue 2919003003: Reapply "Use backend targets to run Kernel transformations in Fasta" (Closed)
Patch Set: Follow dartanalyzer suggestions Created 3 years, 6 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
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 /// Tests basic functionality of the API tree-shaker. 5 /// Tests basic functionality of the API tree-shaker.
6 /// 6 ///
7 /// Each input file is built and tree-shaken, then we check that the set of 7 /// Each input file is built and tree-shaken, then we check that the set of
8 /// libraries, classes, and members that are retained match those declared in an 8 /// libraries, classes, and members that are retained match those declared in an
9 /// expectations file. 9 /// expectations file.
10 /// 10 ///
(...skipping 15 matching lines...) Expand all
26 import 'package:front_end/src/fasta/kernel/kernel_target.dart' 26 import 'package:front_end/src/fasta/kernel/kernel_target.dart'
27 show KernelTarget; 27 show KernelTarget;
28 import 'package:front_end/src/fasta/kernel/verifier.dart' show verifyProgram; 28 import 'package:front_end/src/fasta/kernel/verifier.dart' show verifyProgram;
29 import 'package:front_end/src/fasta/testing/kernel_chain.dart' show runDiff; 29 import 'package:front_end/src/fasta/testing/kernel_chain.dart' show runDiff;
30 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'; 30 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart';
31 import 'package:front_end/src/fasta/ticker.dart' show Ticker; 31 import 'package:front_end/src/fasta/ticker.dart' show Ticker;
32 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; 32 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri;
33 import 'package:front_end/src/fasta/util/relativize.dart' show relativizeUri; 33 import 'package:front_end/src/fasta/util/relativize.dart' show relativizeUri;
34 import 'package:kernel/ast.dart' show Program; 34 import 'package:kernel/ast.dart' show Program;
35 import 'package:kernel/kernel.dart' show loadProgramFromBytes; 35 import 'package:kernel/kernel.dart' show loadProgramFromBytes;
36 import 'package:kernel/target/targets.dart' show TargetFlags;
36 import 'package:testing/testing.dart' 37 import 'package:testing/testing.dart'
37 show Chain, ChainContext, ExpectationSet, Result, Step, TestDescription; 38 show Chain, ChainContext, ExpectationSet, Result, Step, TestDescription;
38 import 'testing/suite.dart'; 39 import 'testing/suite.dart';
39 40
40 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); 41 main(List<String> arguments) => runMe(arguments, createContext, "testing.json");
41 42
42 Future<TreeShakerContext> createContext( 43 Future<TreeShakerContext> createContext(
43 Chain suite, Map<String, String> environment) { 44 Chain suite, Map<String, String> environment) {
44 return TreeShakerContext.create(environment); 45 return TreeShakerContext.create(environment);
45 } 46 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 class BuildProgram 89 class BuildProgram
89 extends Step<TestDescription, _IntermediateData, TreeShakerContext> { 90 extends Step<TestDescription, _IntermediateData, TreeShakerContext> {
90 const BuildProgram(); 91 const BuildProgram();
91 String get name => "build program"; 92 String get name => "build program";
92 Future<Result<_IntermediateData>> run( 93 Future<Result<_IntermediateData>> run(
93 TestDescription description, TreeShakerContext context) async { 94 TestDescription description, TreeShakerContext context) async {
94 try { 95 try {
95 var platformOutline = context.loadPlatformOutline(); 96 var platformOutline = context.loadPlatformOutline();
96 platformOutline.unbindCanonicalNames(); 97 platformOutline.unbindCanonicalNames();
97 var dillTarget = new DillTarget( 98 var dillTarget = new DillTarget(
98 new Ticker(isVerbose: false), context.uriTranslator, "vm"); 99 new Ticker(isVerbose: false), context.uriTranslator, "vm_fasta",
100 flags: new TargetFlags(strongMode: false));
99 dillTarget.loader.appendLibraries(platformOutline); 101 dillTarget.loader.appendLibraries(platformOutline);
100 var sourceTarget = new KernelTarget(PhysicalFileSystem.instance, 102 var sourceTarget = new KernelTarget(
101 dillTarget, context.uriTranslator, false); 103 PhysicalFileSystem.instance, dillTarget, context.uriTranslator);
102 await dillTarget.buildOutlines(); 104 await dillTarget.buildOutlines();
103 105
104 var inputUri = description.uri; 106 var inputUri = description.uri;
105 107
106 /// We treat the lib.dart library as a special dependency that was 108 /// We treat the lib.dart library as a special dependency that was
107 /// previously built. To do so, we build it and append it back to the 109 /// previously built. To do so, we build it and append it back to the
108 /// dillTarget before building the actual test. 110 /// dillTarget before building the actual test.
109 var libUri = inputUri.resolve('lib/lib.dart'); 111 var libUri = inputUri.resolve('lib/lib.dart');
110 sourceTarget.read(libUri); 112 sourceTarget.read(libUri);
111 dillTarget.loader.appendLibraries( 113 dillTarget.loader.appendLibraries(
112 await sourceTarget.buildOutlines(), (uri) => uri == libUri); 114 await sourceTarget.buildOutlines(), (uri) => uri == libUri);
113 115
114 /// This new KernelTarget contains only sources from the test without 116 /// This new KernelTarget contains only sources from the test without
115 /// lib.dart. 117 /// lib.dart.
116 sourceTarget = new KernelTarget(PhysicalFileSystem.instance, dillTarget, 118 sourceTarget = new KernelTarget(
117 context.uriTranslator, false); 119 PhysicalFileSystem.instance, dillTarget, context.uriTranslator);
118 120
119 await dillTarget.buildOutlines(); 121 await dillTarget.buildOutlines();
120 sourceTarget.read(inputUri); 122 sourceTarget.read(inputUri);
121 var contents = new File.fromUri(inputUri).readAsStringSync(); 123 var contents = new File.fromUri(inputUri).readAsStringSync();
122 var showCoreLibraries = contents.contains("@@SHOW_CORE_LIBRARIES@@"); 124 var showCoreLibraries = contents.contains("@@SHOW_CORE_LIBRARIES@@");
123 125
124 await sourceTarget.buildOutlines(); 126 await sourceTarget.buildOutlines();
125 // Note: We run the tree-shaker as a separate step on this suite to be 127 // Note: We run the tree-shaker as a separate step on this suite to be
126 // able to specify what libraries to tree shake (by default only the code 128 // able to specify what libraries to tree shake (by default only the code
127 // in the dillTarget gets tree-shaken). We could apply the tree-shaker 129 // in the dillTarget gets tree-shaken). We could apply the tree-shaker
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 """ 234 """
233 Please create file ${expectedFile.path} with this content: 235 Please create file ${expectedFile.path} with this content:
234 $buffer"""); 236 $buffer""");
235 } 237 }
236 } 238 }
237 } 239 }
238 240
239 /// A special library used only to test the shaker. The suite above will 241 /// A special library used only to test the shaker. The suite above will
240 /// tree-shake the contents of this library. 242 /// tree-shake the contents of this library.
241 const _specialLibraryPath = 'pkg/front_end/testcases/shaker/lib/lib.dart'; 243 const _specialLibraryPath = 'pkg/front_end/testcases/shaker/lib/lib.dart';
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698