| OLD | NEW | 
|---|
| 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 import 'dart:io'; | 5 import 'dart:io'; | 
| 6 import 'package:analyzer/src/generated/source.dart' show Source; | 6 import 'package:analyzer/src/generated/source.dart' show Source; | 
| 7 import 'package:analyzer/src/summary/package_bundle_reader.dart' | 7 import 'package:analyzer/src/summary/package_bundle_reader.dart' | 
| 8     show InSummarySource; | 8     show InSummarySource; | 
| 9 import 'package:args/args.dart' show ArgParser, ArgResults; | 9 import 'package:args/args.dart' show ArgParser, ArgResults; | 
| 10 import 'package:args/command_runner.dart' show UsageException; | 10 import 'package:args/command_runner.dart' show UsageException; | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 74     dartdevc arguments: ${args.join(' ')} | 74     dartdevc arguments: ${args.join(' ')} | 
| 75     dart --version: ${Platform.version} | 75     dart --version: ${Platform.version} | 
| 76 ``` | 76 ``` | 
| 77 $error | 77 $error | 
| 78 $stackTrace | 78 $stackTrace | 
| 79 ```'''); | 79 ```'''); | 
| 80     return 70; | 80     return 70; | 
| 81   } | 81   } | 
| 82 } | 82 } | 
| 83 | 83 | 
|  | 84 bool _changed(List<int> list1, List<int> list2) { | 
|  | 85   var length = list1.length; | 
|  | 86   if (length != list2.length) return true; | 
|  | 87   for (var i = 0; i < length; ++i) { | 
|  | 88     if (list1[i] != list2[i]) return true; | 
|  | 89   } | 
|  | 90   return false; | 
|  | 91 } | 
|  | 92 | 
| 84 void _compile(ArgResults argResults, void printFn(Object obj)) { | 93 void _compile(ArgResults argResults, void printFn(Object obj)) { | 
| 85   var compiler = | 94   var compiler = | 
| 86       new ModuleCompiler(new AnalyzerOptions.fromArguments(argResults)); | 95       new ModuleCompiler(new AnalyzerOptions.fromArguments(argResults)); | 
| 87   var compilerOpts = new CompilerOptions.fromArguments(argResults); | 96   var compilerOpts = new CompilerOptions.fromArguments(argResults); | 
| 88   if (argResults['help']) { | 97   if (argResults['help']) { | 
| 89     printFn(_usageMessage); | 98     printFn(_usageMessage); | 
| 90     return; | 99     return; | 
| 91   } | 100   } | 
| 92   var outPaths = argResults['out'] as List<String>; | 101   var outPaths = argResults['out'] as List<String>; | 
| 93   var moduleFormats = parseModuleFormatOption(argResults); | 102   var moduleFormats = parseModuleFormatOption(argResults); | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 143 | 152 | 
| 144   if (!module.isValid) throw new CompileErrorException(); | 153   if (!module.isValid) throw new CompileErrorException(); | 
| 145 | 154 | 
| 146   // Write JS file, as well as source map and summary (if requested). | 155   // Write JS file, as well as source map and summary (if requested). | 
| 147   for (var i = 0; i < outPaths.length; i++) { | 156   for (var i = 0; i < outPaths.length; i++) { | 
| 148     var outPath = outPaths[i]; | 157     var outPath = outPaths[i]; | 
| 149     module.writeCodeSync(moduleFormats[i], singleOutFile, outPath); | 158     module.writeCodeSync(moduleFormats[i], singleOutFile, outPath); | 
| 150     if (module.summaryBytes != null) { | 159     if (module.summaryBytes != null) { | 
| 151       var summaryPath = | 160       var summaryPath = | 
| 152           path.withoutExtension(outPath) + '.${compilerOpts.summaryExtension}'; | 161           path.withoutExtension(outPath) + '.${compilerOpts.summaryExtension}'; | 
| 153       new File(summaryPath).writeAsBytesSync(module.summaryBytes); | 162       // Only overwrite if summary changed.  This plays better with timestamp | 
|  | 163       // based build systems. | 
|  | 164       var file = new File(summaryPath); | 
|  | 165       if (!file.existsSync() || | 
|  | 166           _changed(file.readAsBytesSync(), module.summaryBytes)) { | 
|  | 167         file.writeAsBytesSync(module.summaryBytes); | 
|  | 168       } | 
| 154     } | 169     } | 
| 155   } | 170   } | 
| 156 } | 171 } | 
| 157 | 172 | 
| 158 String _moduleForLibrary( | 173 String _moduleForLibrary( | 
| 159     String moduleRoot, Source source, CompilerOptions compilerOpts) { | 174     String moduleRoot, Source source, CompilerOptions compilerOpts) { | 
| 160   if (source is InSummarySource) { | 175   if (source is InSummarySource) { | 
| 161     var summaryPath = source.summaryPath; | 176     var summaryPath = source.summaryPath; | 
| 162     var ext = '.${compilerOpts.summaryExtension}'; | 177     var ext = '.${compilerOpts.summaryExtension}'; | 
| 163     if (path.isWithin(moduleRoot, summaryPath) && summaryPath.endsWith(ext)) { | 178     if (path.isWithin(moduleRoot, summaryPath) && summaryPath.endsWith(ext)) { | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 182     '\n\n${_argParser.usage}'; | 197     '\n\n${_argParser.usage}'; | 
| 183 | 198 | 
| 184 void _usageException(String message) { | 199 void _usageException(String message) { | 
| 185   throw new UsageException(message, _usageMessage); | 200   throw new UsageException(message, _usageMessage); | 
| 186 } | 201 } | 
| 187 | 202 | 
| 188 /// Thrown when the input source code has errors. | 203 /// Thrown when the input source code has errors. | 
| 189 class CompileErrorException implements Exception { | 204 class CompileErrorException implements Exception { | 
| 190   toString() => '\nPlease fix all errors before compiling (warnings are okay).'; | 205   toString() => '\nPlease fix all errors before compiling (warnings are okay).'; | 
| 191 } | 206 } | 
| OLD | NEW | 
|---|