| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart' | 9 import 'package:analyzer/analyzer.dart' |
| 10 show | 10 show |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 void main(List<String> args) { | 22 void main(List<String> args) { |
| 23 // Parse flags. | 23 // Parse flags. |
| 24 var parser = new ArgParser() | 24 var parser = new ArgParser() |
| 25 ..addOption('out', | 25 ..addOption('out', |
| 26 help: 'Output file (defaults to "out.js")', | 26 help: 'Output file (defaults to "out.js")', |
| 27 abbr: 'o', | 27 abbr: 'o', |
| 28 defaultsTo: 'out.js') | 28 defaultsTo: 'out.js') |
| 29 ..addFlag('unsafe-force-compile', | 29 ..addFlag('unsafe-force-compile', |
| 30 help: 'Generate code with undefined behavior', negatable: false) | 30 help: 'Generate code with undefined behavior', negatable: false) |
| 31 ..addFlag('emit-metadata', |
| 32 help: 'Preserve annotations in generated code', negatable: false) |
| 31 ..addOption('package-root', | 33 ..addOption('package-root', |
| 32 help: 'Directory containing packages', | 34 help: 'Directory containing packages', |
| 33 abbr: 'p', | 35 abbr: 'p', |
| 34 defaultsTo: 'packages/') | 36 defaultsTo: 'packages/') |
| 35 ..addFlag('log', help: 'Show individual build commands') | 37 ..addFlag('log', help: 'Show individual build commands') |
| 36 ..addOption('tmp', | 38 ..addOption('tmp', |
| 37 help: | 39 help: |
| 38 'Directory for temporary artifacts (defaults to a system tmp directo
ry)'); | 40 'Directory for temporary artifacts (defaults to a system tmp directo
ry)'); |
| 39 | 41 |
| 40 var options = parser.parse(args); | 42 var options = parser.parse(args); |
| 41 if (options.rest.length != 1) { | 43 if (options.rest.length != 1) { |
| 42 throw 'Expected a single dart entrypoint.'; | 44 throw 'Expected a single dart entrypoint.'; |
| 43 } | 45 } |
| 44 var entry = options.rest.first; | 46 var entry = options.rest.first; |
| 45 var outfile = options['out'] as String; | 47 var outfile = options['out'] as String; |
| 46 var packageRoot = options['package-root'] as String; | 48 var packageRoot = options['package-root'] as String; |
| 47 var unsafe = options['unsafe-force-compile'] as bool; | 49 var unsafe = options['unsafe-force-compile'] as bool; |
| 48 var log = options['log'] as bool; | 50 var log = options['log'] as bool; |
| 49 var tmp = options['tmp'] as String; | 51 var tmp = options['tmp'] as String; |
| 52 var metadata = options['emit-metadata'] as bool; |
| 50 | 53 |
| 51 // Build an invocation to dartdevc | 54 // Build an invocation to dartdevc |
| 52 var dartPath = Platform.resolvedExecutable; | 55 var dartPath = Platform.resolvedExecutable; |
| 53 var ddcPath = path.dirname(path.dirname(Platform.script.toFilePath())); | 56 var ddcPath = path.dirname(path.dirname(Platform.script.toFilePath())); |
| 54 var template = [ | 57 var template = [ |
| 55 '$ddcPath/bin/dartdevc.dart', | 58 '$ddcPath/bin/dartdevc.dart', |
| 56 '--no-source-map', // Invalid as we're just concatenating files below | 59 '--modules=legacy', // TODO(vsm): Change this to use common format. |
| 60 '--single-out-file', |
| 61 '--inline-source-map', |
| 57 '-p', | 62 '-p', |
| 58 packageRoot | 63 packageRoot |
| 59 ]; | 64 ]; |
| 65 if (metadata) { |
| 66 template.add('--emit-metadata'); |
| 67 } |
| 60 if (unsafe) { | 68 if (unsafe) { |
| 61 template.add('--unsafe-force-compile'); | 69 template.add('--unsafe-force-compile'); |
| 62 } | 70 } |
| 63 | 71 |
| 64 // Compute the transitive closure | 72 // Compute the transitive closure |
| 65 var total = new Stopwatch()..start(); | 73 var total = new Stopwatch()..start(); |
| 66 var partial = new Stopwatch()..start(); | 74 var partial = new Stopwatch()..start(); |
| 67 | 75 |
| 68 // TODO(vsm): We're using the analyzer just to compute the import/export/part | 76 // TODO(vsm): We're using the analyzer just to compute the import/export/part |
| 69 // dependence graph. This is expensive. Is there a lighterweight way to do | 77 // dependence graph. This is expensive. Is there a lighterweight way to do |
| 70 // this? | 78 // this? |
| 71 transitiveFiles(entry, Directory.current.path, packageRoot); | 79 transitiveFiles(entry, Directory.current.path, packageRoot); |
| 72 orderModules(); | 80 orderModules(); |
| 73 computeTransitiveDependences(); | 81 computeTransitiveDependences(); |
| 74 | 82 |
| 75 var graphTime = partial.elapsedMilliseconds / 1000; | 83 var graphTime = partial.elapsedMilliseconds / 1000; |
| 76 print('Computed global build graph in $graphTime seconds'); | 84 print('Computed global build graph in $graphTime seconds'); |
| 77 | 85 |
| 78 // Prepend Dart runtime files to the output | 86 // Prepend Dart runtime files to the output |
| 79 var out = new File(outfile); | 87 var out = new File(outfile); |
| 80 var dartLibrary = | 88 var dartLibrary = |
| 81 new File(path.join(ddcPath, 'lib', 'runtime', 'dart_library.js')) | 89 new File(path.join(ddcPath, 'lib', 'js', 'legacy', 'dart_library.js')) |
| 82 .readAsStringSync(); | 90 .readAsStringSync(); |
| 83 out.writeAsStringSync(dartLibrary); | 91 out.writeAsStringSync(dartLibrary); |
| 84 var dartSdk = new File(path.join(ddcPath, 'lib', 'runtime', 'dart_sdk.js')) | 92 var dartSdk = |
| 85 .readAsStringSync(); | 93 new File(path.join(ddcPath, 'lib', 'js', 'legacy', 'dart_sdk.js')) |
| 94 .readAsStringSync(); |
| 86 out.writeAsStringSync(dartSdk, mode: FileMode.APPEND); | 95 out.writeAsStringSync(dartSdk, mode: FileMode.APPEND); |
| 87 | 96 |
| 88 // Linearize module concatenation for deterministic output | 97 // Linearize module concatenation for deterministic output |
| 89 var last = new Future.value(); | 98 var last = new Future.value(); |
| 90 for (var module in orderedModules) { | 99 for (var module in orderedModules) { |
| 91 linearizerMap[module] = last; | 100 linearizerMap[module] = last; |
| 92 var completer = new Completer(); | 101 var completer = new Completer(); |
| 93 completerMap[module] = completer; | 102 completerMap[module] = completer; |
| 94 last = completer.future; | 103 last = completer.future; |
| 95 } | 104 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 var uri = _resolveDirective(d); | 280 var uri = _resolveDirective(d); |
| 272 processDependence(entryPoint, canonicalize(uri, entryDir)); | 281 processDependence(entryPoint, canonicalize(uri, entryDir)); |
| 273 transitiveFiles(uri, entryDir, packageRoot); | 282 transitiveFiles(uri, entryDir, packageRoot); |
| 274 } else if (d is PartDirective) { | 283 } else if (d is PartDirective) { |
| 275 var uri = _resolveDirective(d); | 284 var uri = _resolveDirective(d); |
| 276 processFile(canonicalize(uri, entryDir)); | 285 processFile(canonicalize(uri, entryDir)); |
| 277 } | 286 } |
| 278 } | 287 } |
| 279 } | 288 } |
| 280 } | 289 } |
| OLD | NEW |