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

Side by Side Diff: tools/testing/dart/compiler_configuration.dart

Issue 2901923003: Replace the configuration map with a typed object. (Closed)
Patch Set: Created 3 years, 7 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 compiler_configuration; 5 import 'dart:io';
6 6
7 import 'dart:io' show Platform; 7 import 'configuration.dart';
8 8 import 'runtime_configuration.dart';
9 import 'runtime_configuration.dart' show RuntimeConfiguration; 9 import 'test_runner.dart';
10 import 'runtime_configuration.dart' show DartPrecompiledAdbRuntimeConfiguration; 10 import 'test_suite.dart';
11 import 'test_runner.dart' show Command, CommandBuilder, CompilationCommand;
12 import 'test_suite.dart' show TestInformation, TestUtils;
13 11
14 List<String> replaceDartFileWith(List<String> list, String replacement) { 12 List<String> replaceDartFileWith(List<String> list, String replacement) {
15 var copy = new List<String>.from(list); 13 var copy = new List<String>.from(list);
16 for (var i = 0; i < copy.length; i++) { 14 for (var i = 0; i < copy.length; i++) {
17 if (copy[i].endsWith(".dart")) { 15 if (copy[i].endsWith(".dart")) {
18 copy[i] = replacement; 16 copy[i] = replacement;
19 } 17 }
20 } 18 }
21 return copy; 19 return copy;
22 } 20 }
(...skipping 17 matching lines...) Expand all
40 return (path == '' || path.endsWith('/')) ? uri : Uri.parse('$uri/'); 38 return (path == '' || path.endsWith('/')) ? uri : Uri.parse('$uri/');
41 } 39 }
42 40
43 abstract class CompilerConfiguration { 41 abstract class CompilerConfiguration {
44 final bool isDebug; 42 final bool isDebug;
45 final bool isChecked; 43 final bool isChecked;
46 final bool isStrong; 44 final bool isStrong;
47 final bool isHostChecked; 45 final bool isHostChecked;
48 final bool useSdk; 46 final bool useSdk;
49 47
50 // TODO(ahe): Remove this constructor and move the switch to
51 // test_options.dart. We probably want to store an instance of
52 // [CompilerConfiguration] in [configuration] there.
53 factory CompilerConfiguration(Map<String, dynamic> configuration) {
54 var compiler = configuration['compiler'] as String;
55
56 // TODO(ahe): Move these booleans into a struction configuration object
57 // which can eventually completely replace the Map-based configuration
58 // object.
59 var isDebug = (configuration['mode'] as String) == 'debug';
60 var isChecked = configuration['checked'] as bool;
61 var isStrong = configuration['strong'] as bool;
62 var isHostChecked = configuration['host_checked'] as bool;
63 var useSdk = configuration['use_sdk'] as bool;
64 var isCsp = configuration['csp'] as bool;
65 var useCps = configuration['cps_ir'] as bool;
66 var useBlobs = configuration['use_blobs'] as bool;
67 var hotReload = configuration['hot_reload'] as bool;
68 var hotReloadRollback = configuration['hot_reload_rollback'] as bool;
69 var useFastStartup = configuration['fast_startup'] as bool;
70 var useKernelInDart2js = configuration['dart2js_with_kernel'] as bool;
71
72 switch (compiler) {
73 case 'dart2analyzer':
74 return new AnalyzerCompilerConfiguration(
75 isDebug: isDebug,
76 isChecked: isChecked,
77 isStrong: isStrong,
78 isHostChecked: isHostChecked,
79 useSdk: useSdk);
80 case 'dart2js':
81 return new Dart2jsCompilerConfiguration(
82 isDebug: isDebug,
83 isChecked: isChecked,
84 isHostChecked: isHostChecked,
85 useCps: useCps,
86 useSdk: useSdk,
87 isCsp: isCsp,
88 useFastStartup: useFastStartup,
89 useKernel: useKernelInDart2js,
90 extraDart2jsOptions:
91 TestUtils.getExtraOptions(configuration, 'dart2js_options'));
92 case 'app_jit':
93 return new AppJitCompilerConfiguration(
94 isDebug: isDebug, isChecked: isChecked);
95 case 'precompiler':
96 return new PrecompilerCompilerConfiguration(
97 isDebug: isDebug,
98 isChecked: isChecked,
99 arch: configuration['arch'] as String,
100 useBlobs: useBlobs,
101 isAndroid: configuration['system'] == 'android');
102 case 'dartk':
103 return new NoneCompilerConfiguration(
104 isDebug: isDebug,
105 isChecked: isChecked,
106 isHostChecked: isHostChecked,
107 useSdk: useSdk,
108 hotReload: hotReload,
109 hotReloadRollback: hotReloadRollback,
110 useDFE: true);
111 case 'dartkp':
112 return new PrecompilerCompilerConfiguration(
113 isDebug: isDebug,
114 isChecked: isChecked,
115 arch: configuration['arch'] as String,
116 useBlobs: useBlobs,
117 isAndroid: configuration['system'] == 'android',
118 useDFE: true);
119 case 'none':
120 return new NoneCompilerConfiguration(
121 isDebug: isDebug,
122 isChecked: isChecked,
123 isHostChecked: isHostChecked,
124 useSdk: useSdk,
125 hotReload: hotReload,
126 hotReloadRollback: hotReloadRollback);
127 default:
128 throw "Unknown compiler '$compiler'";
129 }
130 }
131
132 CompilerConfiguration._subclass( 48 CompilerConfiguration._subclass(
133 {this.isDebug: false, 49 {this.isDebug: false,
134 this.isChecked: false, 50 this.isChecked: false,
135 this.isStrong: false, 51 this.isStrong: false,
136 this.isHostChecked: false, 52 this.isHostChecked: false,
137 this.useSdk: false}); 53 this.useSdk: false});
138 54
139 /// Return a multiplier used to give tests longer time to run. 55 /// A multiplier used to give tests longer time to run.
140 // TODO(ahe): Convert to getter! 56 int get timeoutMultiplier => 1;
141 int computeTimeoutMultiplier() {
142 return 1;
143 }
144 57
145 // TODO(ahe): It shouldn't be necessary to pass [buildDir] to any of these 58 // TODO(ahe): It shouldn't be necessary to pass [buildDir] to any of these
146 // functions. It is fixed for a given configuration. 59 // functions. It is fixed for a given configuration.
147 String computeCompilerPath(String buildDir) { 60 String computeCompilerPath(String buildDir) {
148 throw "Unknown compiler for: $runtimeType"; 61 throw "Unknown compiler for: $runtimeType";
149 } 62 }
150 63
151 bool get hasCompiler => true; 64 bool get hasCompiler => true;
152 65
153 String get executableScriptSuffix => Platform.isWindows ? '.bat' : ''; 66 String get executableScriptSuffix => Platform.isWindows ? '.bat' : '';
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 info, 332 info,
420 vmOptions, 333 vmOptions,
421 sharedOptions, 334 sharedOptions,
422 originalArguments, 335 originalArguments,
423 artifact); 336 artifact);
424 } 337 }
425 338
426 static ComposedCompilerConfiguration createDartKPConfiguration( 339 static ComposedCompilerConfiguration createDartKPConfiguration(
427 {bool isChecked, 340 {bool isChecked,
428 bool isHostChecked, 341 bool isHostChecked,
429 String arch, 342 Architecture arch,
430 bool useBlobs, 343 bool useBlobs,
431 bool isAndroid, 344 bool isAndroid,
432 bool useSdk, 345 bool useSdk,
433 bool verify, 346 bool verify,
434 bool strong, 347 bool strong,
435 bool treeShake}) { 348 bool treeShake}) {
436 return new ComposedCompilerConfiguration([ 349 return new ComposedCompilerConfiguration([
437 // Compile with dartk. 350 // Compile with dartk.
438 new PipelineCommand.runWithGlobalArguments(new DartKCompilerConfiguration( 351 new PipelineCommand.runWithGlobalArguments(new DartKCompilerConfiguration(
439 isChecked: isChecked, 352 isChecked: isChecked,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 bool this.isCsp, 467 bool this.isCsp,
555 bool this.useFastStartup, 468 bool this.useFastStartup,
556 this.useKernel, 469 this.useKernel,
557 this.extraDart2jsOptions}) 470 this.extraDart2jsOptions})
558 : super('dart2js', 471 : super('dart2js',
559 isDebug: isDebug, 472 isDebug: isDebug,
560 isChecked: isChecked, 473 isChecked: isChecked,
561 isHostChecked: isHostChecked, 474 isHostChecked: isHostChecked,
562 useSdk: useSdk); 475 useSdk: useSdk);
563 476
564 int computeTimeoutMultiplier() { 477 int get timeoutMultiplier {
565 int multiplier = 1; 478 var multiplier = 1;
566 if (isDebug) multiplier *= 4; 479 if (isDebug) multiplier *= 4;
567 if (isChecked) multiplier *= 2; 480 if (isChecked) multiplier *= 2;
568 if (isHostChecked) multiplier *= 16; 481 if (isHostChecked) multiplier *= 16;
569 return multiplier; 482 return multiplier;
570 } 483 }
571 484
572 CommandArtifact computeCompilationArtifact( 485 CommandArtifact computeCompilationArtifact(
573 String buildDir, 486 String buildDir,
574 String tempDir, 487 String tempDir,
575 CommandBuilder commandBuilder, 488 CommandBuilder commandBuilder,
(...skipping 18 matching lines...) Expand all
594 ? nativeDirectoryToUri(buildDir).resolve('dart-sdk/') 507 ? nativeDirectoryToUri(buildDir).resolve('dart-sdk/')
595 : nativeDirectoryToUri(TestUtils.dartDir.toNativePath()) 508 : nativeDirectoryToUri(TestUtils.dartDir.toNativePath())
596 .resolve('sdk/'); 509 .resolve('sdk/');
597 Uri preambleDir = sdk.resolve('lib/_internal/js_runtime/lib/preambles/'); 510 Uri preambleDir = sdk.resolve('lib/_internal/js_runtime/lib/preambles/');
598 return runtimeConfiguration.dart2jsPreambles(preambleDir) 511 return runtimeConfiguration.dart2jsPreambles(preambleDir)
599 ..add(artifact.filename); 512 ..add(artifact.filename);
600 } 513 }
601 } 514 }
602 515
603 class PrecompilerCompilerConfiguration extends CompilerConfiguration { 516 class PrecompilerCompilerConfiguration extends CompilerConfiguration {
604 final String arch; 517 final Architecture arch;
605 final bool useBlobs; 518 final bool useBlobs;
606 final bool isAndroid; 519 final bool isAndroid;
607 final bool useDFE; 520 final bool useDFE;
608 521
609 PrecompilerCompilerConfiguration( 522 PrecompilerCompilerConfiguration(
610 {bool isDebug, 523 {bool isDebug,
611 bool isChecked, 524 bool isChecked,
612 this.arch, 525 this.arch,
613 this.useBlobs, 526 this.useBlobs,
614 this.isAndroid, 527 this.isAndroid,
615 this.useDFE: false}) 528 this.useDFE: false})
616 : super._subclass(isDebug: isDebug, isChecked: isChecked); 529 : super._subclass(isDebug: isDebug, isChecked: isChecked);
617 530
618 int computeTimeoutMultiplier() { 531 int get timeoutMultiplier {
619 int multiplier = 2; 532 var multiplier = 2;
620 if (isDebug) multiplier *= 4; 533 if (isDebug) multiplier *= 4;
621 if (isChecked) multiplier *= 2; 534 if (isChecked) multiplier *= 2;
622 return multiplier; 535 return multiplier;
623 } 536 }
624 537
625 CommandArtifact computeCompilationArtifact( 538 CommandArtifact computeCompilationArtifact(
626 String buildDir, 539 String buildDir,
627 String tempDir, 540 String tempDir,
628 CommandBuilder commandBuilder, 541 CommandBuilder commandBuilder,
629 List<String> arguments, 542 List<String> arguments,
(...skipping 12 matching lines...) Expand all
642 } 555 }
643 556
644 CompilationCommand computeCompilationCommand( 557 CompilationCommand computeCompilationCommand(
645 String tempDir, 558 String tempDir,
646 String buildDir, 559 String buildDir,
647 CommandBuilder commandBuilder, 560 CommandBuilder commandBuilder,
648 List<String> arguments, 561 List<String> arguments,
649 Map<String, String> environmentOverrides) { 562 Map<String, String> environmentOverrides) {
650 String exec; 563 String exec;
651 if (isAndroid) { 564 if (isAndroid) {
652 if (arch == "arm") { 565 if (arch == Architecture.arm) {
653 exec = "$buildDir/clang_x86/dart_bootstrap"; 566 exec = "$buildDir/clang_x86/dart_bootstrap";
654 } else if (arch == "arm64") { 567 } else if (arch == Architecture.arm64) {
655 exec = "$buildDir/clang_x64/dart_bootstrap"; 568 exec = "$buildDir/clang_x64/dart_bootstrap";
656 } 569 }
657 } else { 570 } else {
658 exec = "$buildDir/dart_bootstrap"; 571 exec = "$buildDir/dart_bootstrap";
659 } 572 }
660 var args = <String>[]; 573 var args = <String>[];
661 if (useDFE) { 574 if (useDFE) {
662 args.add('--dfe=utils/kernel-service/kernel-service.dart'); 575 args.add('--dfe=utils/kernel-service/kernel-service.dart');
663 args.add('--platform=${buildDir}/patched_sdk/platform.dill'); 576 args.add('--platform=${buildDir}/patched_sdk/platform.dill');
664 } 577 }
665 args.add("--snapshot-kind=app-aot"); 578 args.add("--snapshot-kind=app-aot");
666 if (useBlobs) { 579 if (useBlobs) {
667 args.add("--snapshot=$tempDir/out.aotsnapshot"); 580 args.add("--snapshot=$tempDir/out.aotsnapshot");
668 args.add("--use-blobs"); 581 args.add("--use-blobs");
669 } else { 582 } else {
670 args.add("--snapshot=$tempDir/out.S"); 583 args.add("--snapshot=$tempDir/out.S");
671 } 584 }
672 if (isAndroid && arch == 'arm') { 585 if (isAndroid && arch == Architecture.arm) {
673 args.add('--no-sim-use-hardfp'); 586 args.add('--no-sim-use-hardfp');
674 } 587 }
675 args.addAll(arguments); 588 args.addAll(arguments);
676 589
677 return commandBuilder.getCompilationCommand('precompiler', tempDir, !useSdk, 590 return commandBuilder.getCompilationCommand('precompiler', tempDir, !useSdk,
678 bootstrapDependencies(buildDir), exec, args, environmentOverrides); 591 bootstrapDependencies(buildDir), exec, args, environmentOverrides);
679 } 592 }
680 593
681 CompilationCommand computeAssembleCommand( 594 CompilationCommand computeAssembleCommand(
682 String tempDir, 595 String tempDir,
683 String buildDir, 596 String buildDir,
684 CommandBuilder commandBuilder, 597 CommandBuilder commandBuilder,
685 List arguments, 598 List arguments,
686 Map<String, String> environmentOverrides) { 599 Map<String, String> environmentOverrides) {
687 String cc, shared, ld_flags; 600 String cc, shared, ldFlags;
688 if (isAndroid) { 601 if (isAndroid) {
689 var ndk = "third_party/android_tools/ndk"; 602 var ndk = "third_party/android_tools/ndk";
690 String triple; 603 String triple;
691 if (arch == "arm") { 604 if (arch == Architecture.arm) {
692 triple = "arm-linux-androideabi"; 605 triple = "arm-linux-androideabi";
693 } else if (arch == "arm64") { 606 } else if (arch == Architecture.arm64) {
694 triple = "aarch64-linux-android"; 607 triple = "aarch64-linux-android";
695 } 608 }
696 String host; 609 String host;
697 if (Platform.isLinux) { 610 if (Platform.isLinux) {
698 host = "linux"; 611 host = "linux";
699 } else if (Platform.isMacOS) { 612 } else if (Platform.isMacOS) {
700 host = "darwin"; 613 host = "darwin";
701 } 614 }
702 cc = "$ndk/toolchains/$triple-4.9/prebuilt/$host-x86_64/bin/$triple-gcc"; 615 cc = "$ndk/toolchains/$triple-4.9/prebuilt/$host-x86_64/bin/$triple-gcc";
703 shared = '-shared'; 616 shared = '-shared';
704 } else if (Platform.isLinux) { 617 } else if (Platform.isLinux) {
705 cc = 'gcc'; 618 cc = 'gcc';
706 shared = '-shared'; 619 shared = '-shared';
707 } else if (Platform.isMacOS) { 620 } else if (Platform.isMacOS) {
708 cc = 'clang'; 621 cc = 'clang';
709 shared = '-dynamiclib'; 622 shared = '-dynamiclib';
710 // Tell Mac linker to give up generating eh_frame from dwarf. 623 // Tell Mac linker to give up generating eh_frame from dwarf.
711 ld_flags = '-Wl,-no_compact_unwind'; 624 ldFlags = '-Wl,-no_compact_unwind';
712 } else { 625 } else {
713 throw "Platform not supported: ${Platform.operatingSystem}"; 626 throw "Platform not supported: ${Platform.operatingSystem}";
714 } 627 }
715 628
716 String cc_flags; 629 String ccFlags;
717 if (arch == 'x64') { 630 switch (arch) {
718 cc_flags = "-m64"; 631 case Architecture.x64:
719 } else if (arch == 'simarm64') { 632 case Architecture.simarm64:
720 cc_flags = "-m64"; 633 ccFlags = "-m64";
721 } else if (arch == 'ia32') { 634 break;
722 cc_flags = "-m32"; 635 case Architecture.ia32:
723 } else if (arch == 'simarm') { 636 case Architecture.simarm:
724 cc_flags = "-m32"; 637 case Architecture.simmips:
725 } else if (arch == 'simmips') { 638 ccFlags = "-m32";
726 cc_flags = "-m32"; 639 break;
727 } else if (arch == 'arm') { 640 case Architecture.arm:
728 cc_flags = null; 641 case Architecture.arm64:
729 } else if (arch == 'arm64') { 642 ccFlags = null;
730 cc_flags = null; 643 break;
731 } else if (arch == 'mips') { 644 case Architecture.mips:
732 cc_flags = "-EL"; 645 ccFlags = "-EL";
733 } else { 646 break;
734 throw "Architecture not supported: $arch"; 647 default:
648 throw "Architecture not supported: ${arch.name}";
735 } 649 }
736 650
737 var exec = cc; 651 var exec = cc;
738 var args = <String>[]; 652 var args = <String>[];
739 if (cc_flags != null) args.add(cc_flags); 653 if (ccFlags != null) args.add(ccFlags);
740 if (ld_flags != null) args.add(ld_flags); 654 if (ldFlags != null) args.add(ldFlags);
741 args.add(shared); 655 args.add(shared);
742 args.add('-nostdlib'); 656 args.add('-nostdlib');
743 args.add('-o'); 657 args.add('-o');
744 args.add('$tempDir/out.aotsnapshot'); 658 args.add('$tempDir/out.aotsnapshot');
745 args.add('$tempDir/out.S'); 659 args.add('$tempDir/out.S');
746 660
747 return commandBuilder.getCompilationCommand('assemble', tempDir, !useSdk, 661 return commandBuilder.getCompilationCommand('assemble', tempDir, !useSdk,
748 bootstrapDependencies(buildDir), exec, args, environmentOverrides); 662 bootstrapDependencies(buildDir), exec, args, environmentOverrides);
749 } 663 }
750 664
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 ..addAll(vmOptions) 732 ..addAll(vmOptions)
819 ..addAll(sharedOptions) 733 ..addAll(sharedOptions)
820 ..addAll(originalArguments); 734 ..addAll(originalArguments);
821 } 735 }
822 } 736 }
823 737
824 class AppJitCompilerConfiguration extends CompilerConfiguration { 738 class AppJitCompilerConfiguration extends CompilerConfiguration {
825 AppJitCompilerConfiguration({bool isDebug, bool isChecked}) 739 AppJitCompilerConfiguration({bool isDebug, bool isChecked})
826 : super._subclass(isDebug: isDebug, isChecked: isChecked); 740 : super._subclass(isDebug: isDebug, isChecked: isChecked);
827 741
828 int computeTimeoutMultiplier() { 742 int get timeoutMultiplier {
829 int multiplier = 1; 743 var multiplier = 1;
830 if (isDebug) multiplier *= 2; 744 if (isDebug) multiplier *= 2;
831 if (isChecked) multiplier *= 2; 745 if (isChecked) multiplier *= 2;
832 return multiplier; 746 return multiplier;
833 } 747 }
834 748
835 CommandArtifact computeCompilationArtifact( 749 CommandArtifact computeCompilationArtifact(
836 String buildDir, 750 String buildDir,
837 String tempDir, 751 String tempDir,
838 CommandBuilder commandBuilder, 752 CommandBuilder commandBuilder,
839 List<String> arguments, 753 List<String> arguments,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 bool isStrong, 817 bool isStrong,
904 bool isHostChecked, 818 bool isHostChecked,
905 bool useSdk}) 819 bool useSdk})
906 : super._subclass( 820 : super._subclass(
907 isDebug: isDebug, 821 isDebug: isDebug,
908 isChecked: isChecked, 822 isChecked: isChecked,
909 isStrong: isStrong, 823 isStrong: isStrong,
910 isHostChecked: isHostChecked, 824 isHostChecked: isHostChecked,
911 useSdk: useSdk); 825 useSdk: useSdk);
912 826
913 int computeTimeoutMultiplier() { 827 int get timeoutMultiplier => 4;
914 return 4;
915 }
916 828
917 String computeCompilerPath(String buildDir) { 829 String computeCompilerPath(String buildDir) {
918 var prefix = 'sdk/bin'; 830 var prefix = 'sdk/bin';
919 String suffix = executableScriptSuffix; 831 String suffix = executableScriptSuffix;
920 if (isHostChecked) { 832 if (isHostChecked) {
921 if (useSdk) { 833 if (useSdk) {
922 throw "--host-checked and --use-sdk cannot be used together"; 834 throw "--host-checked and --use-sdk cannot be used together";
923 } 835 }
924 // The script dartanalyzer_developer is not included in the 836 // The script dartanalyzer_developer is not included in the
925 // shipped SDK, that is the script is not installed in 837 // shipped SDK, that is the script is not installed in
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 RuntimeConfiguration runtimeConfiguration, 869 RuntimeConfiguration runtimeConfiguration,
958 String buildDir, 870 String buildDir,
959 TestInformation info, 871 TestInformation info,
960 List<String> vmOptions, 872 List<String> vmOptions,
961 List<String> sharedOptions, 873 List<String> sharedOptions,
962 List<String> originalArguments, 874 List<String> originalArguments,
963 CommandArtifact artifact) { 875 CommandArtifact artifact) {
964 return <String>[]; 876 return <String>[];
965 } 877 }
966 } 878 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698