OLD | NEW |
1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
2 import 'dart:io'; | 2 import 'dart:io'; |
3 | 3 |
| 4 import 'package:path/path.dart' as p; |
| 5 |
4 import 'package:dev_compiler/src/compiler/command.dart'; | 6 import 'package:dev_compiler/src/compiler/command.dart'; |
5 | 7 |
6 /// Compiles the packages that the DDC tests use to JS into: | 8 final String scriptDirectory = p.dirname(p.fromUri(Platform.script)); |
| 9 String outputDirectory; |
| 10 |
| 11 /// Compiles the packages that the DDC tests use to JS into the given output |
| 12 /// directory. Usage: |
7 /// | 13 /// |
8 /// gen/codegen_output/pkg/... | 14 /// dart build_pkgs.dart <output_dir> [travis] |
9 /// | 15 /// |
10 /// Assumes the working directory is pkg/dev_compiler. | 16 /// If "travis" is passed, builds the all of the modules tested on Travis. |
11 /// | 17 /// Otherwise, only builds the modules needed by the tests. |
12 /// If no arguments are passed, builds the all of the modules tested on Travis. | |
13 /// If "test" is passed, only builds the modules needed by the tests. | |
14 void main(List<String> arguments) { | 18 void main(List<String> arguments) { |
15 var test = arguments.length == 1 && arguments[0] == 'test'; | 19 var isTravis = arguments.isNotEmpty && arguments.last == "travis"; |
| 20 if (isTravis) arguments.removeLast(); |
16 | 21 |
17 new Directory("gen/codegen_output/pkg").createSync(recursive: true); | 22 if (arguments.length != 1) { |
| 23 print("Usage: dart build_pkgs.dart <output_dir> [travis]"); |
| 24 exit(1); |
| 25 } |
| 26 |
| 27 outputDirectory = arguments[0]; |
| 28 new Directory(outputDirectory).createSync(recursive: true); |
18 | 29 |
19 // Build leaf packages. These have no other package dependencies. | 30 // Build leaf packages. These have no other package dependencies. |
20 | 31 |
21 // Under pkg. | 32 // Under pkg. |
22 compileModule('async_helper'); | 33 compileModule('async_helper'); |
23 compileModule('expect', libs: ['minitest']); | 34 compileModule('expect', libs: ['minitest']); |
24 compileModule('js', libs: ['js_util']); | 35 compileModule('js', libs: ['js_util']); |
25 compileModule('meta'); | 36 compileModule('meta'); |
26 if (!test) { | 37 if (isTravis) { |
27 compileModule('lookup_map'); | 38 compileModule('lookup_map'); |
28 compileModule('microlytics', libs: ['html_channels']); | 39 compileModule('microlytics', libs: ['html_channels']); |
29 compileModule('typed_mock'); | 40 compileModule('typed_mock'); |
30 } | 41 } |
31 | 42 |
32 // Under third_party/pkg. | 43 // Under third_party/pkg. |
33 compileModule('collection'); | 44 compileModule('collection'); |
34 compileModule('matcher'); | 45 compileModule('matcher'); |
35 compileModule('path'); | 46 compileModule('path'); |
36 if (!test) { | 47 if (isTravis) { |
37 compileModule('args', libs: ['command_runner']); | 48 compileModule('args', libs: ['command_runner']); |
38 compileModule('charcode'); | 49 compileModule('charcode'); |
39 compileModule('fixnum'); | 50 compileModule('fixnum'); |
40 compileModule('logging'); | 51 compileModule('logging'); |
41 compileModule('markdown'); | 52 compileModule('markdown'); |
42 compileModule('mime'); | 53 compileModule('mime'); |
43 compileModule('plugin', libs: ['manager']); | 54 compileModule('plugin', libs: ['manager']); |
44 compileModule('typed_data'); | 55 compileModule('typed_data'); |
45 compileModule('usage'); | 56 compileModule('usage'); |
46 compileModule('utf'); | 57 compileModule('utf'); |
47 compileModule('when'); | 58 compileModule('when'); |
48 } | 59 } |
49 | 60 |
50 // Composite packages with dependencies. | 61 // Composite packages with dependencies. |
51 compileModule('stack_trace', deps: ['path']); | 62 compileModule('stack_trace', deps: ['path']); |
52 if (!test) { | 63 if (isTravis) { |
53 compileModule('async', deps: ['collection']); | 64 compileModule('async', deps: ['collection']); |
54 } | 65 } |
55 | 66 |
56 if (test) { | 67 if (!isTravis) { |
57 compileModule('unittest', | 68 compileModule('unittest', |
58 deps: ['matcher', 'path', 'stack_trace'], | 69 deps: ['matcher', 'path', 'stack_trace'], |
59 libs: ['html_config', 'html_individual_config', 'html_enhanced_config'], | 70 libs: ['html_config', 'html_individual_config', 'html_enhanced_config'], |
60 unsafeForceCompile: true); | 71 unsafeForceCompile: true); |
61 } | 72 } |
62 } | 73 } |
63 | 74 |
64 /// Compiles a [module] with a single matching ".dart" library and additional | 75 /// Compiles a [module] with a single matching ".dart" library and additional |
65 /// [libs] and [deps] on other modules. | 76 /// [libs] and [deps] on other modules. |
66 void compileModule(String module, | 77 void compileModule(String module, |
67 {List<String> libs, List<String> deps, bool unsafeForceCompile: false}) { | 78 {List<String> libs, List<String> deps, bool unsafeForceCompile: false}) { |
| 79 var sdkSummary = p.join(scriptDirectory, "../lib/sdk/ddc_sdk.sum"); |
68 var args = [ | 80 var args = [ |
69 '--dart-sdk-summary=lib/sdk/ddc_sdk.sum', | 81 '--dart-sdk-summary=$sdkSummary', |
70 '-ogen/codegen_output/pkg/$module.js' | 82 '-o${outputDirectory}/$module.js' |
71 ]; | 83 ]; |
72 | 84 |
73 // There is always a library that matches the module. | 85 // There is always a library that matches the module. |
74 args.add('package:$module/$module.dart'); | 86 args.add('package:$module/$module.dart'); |
75 | 87 |
76 // Add any additional libraries. | 88 // Add any additional libraries. |
77 if (libs != null) { | 89 if (libs != null) { |
78 for (var lib in libs) { | 90 for (var lib in libs) { |
79 args.add('package:$module/$lib.dart'); | 91 args.add('package:$module/$lib.dart'); |
80 } | 92 } |
81 } | 93 } |
82 | 94 |
83 // Add summaries for any modules this depends on. | 95 // Add summaries for any modules this depends on. |
84 if (deps != null) { | 96 if (deps != null) { |
85 for (var dep in deps) { | 97 for (var dep in deps) { |
86 args.add('-sgen/codegen_output/pkg/$dep.sum'); | 98 args.add('-s${outputDirectory}/$dep.sum'); |
87 } | 99 } |
88 } | 100 } |
89 | 101 |
90 if (unsafeForceCompile) { | 102 if (unsafeForceCompile) { |
91 args.add('--unsafe-force-compile'); | 103 args.add('--unsafe-force-compile'); |
92 } | 104 } |
93 | 105 |
94 // TODO(rnystrom): Hack. DDC has its own forked copy of async_helper that | 106 // TODO(rnystrom): Hack. DDC has its own forked copy of async_helper that |
95 // has a couple of differences from pkg/async_helper. We should unfork them, | 107 // has a couple of differences from pkg/async_helper. We should unfork them, |
96 // but I'm not sure how they'll affect the other non-DDC tests. For now, just | 108 // but I'm not sure how they'll affect the other non-DDC tests. For now, just |
97 // use ours. | 109 // use ours. |
98 if (module == 'async_helper') { | 110 if (module == 'async_helper') { |
99 args.add('--url-mapping=package:async_helper/async_helper.dart,' | 111 args.add('--url-mapping=package:async_helper/async_helper.dart,' + |
100 'test/codegen/async_helper.dart'); | 112 p.join(scriptDirectory, "../test/codegen/async_helper.dart")); |
101 } | 113 } |
102 | 114 |
103 compile(args); | 115 var exitCode = compile(args); |
| 116 if (exitCode != 0) exit(exitCode); |
104 } | 117 } |
OLD | NEW |