| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Command line tool to run the checker on a Dart program. | 5 /// Command line tool to run the checker on a Dart program. |
| 6 library ddc.devc; | 6 library ddc.devc; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 var dartInputFile = path.join(path.dirname(inputFile), url); | 74 var dartInputFile = path.join(path.dirname(inputFile), url); |
| 75 | 75 |
| 76 if (!new File(dartInputFile).existsSync()) { | 76 if (!new File(dartInputFile).existsSync()) { |
| 77 _log.severe(mainScriptTag.sourceSpan.message( | 77 _log.severe(mainScriptTag.sourceSpan.message( |
| 78 'Script file $dartInputFile not found', | 78 'Script file $dartInputFile not found', |
| 79 color: options.useColors ? colorOf('error') : false)); | 79 color: options.useColors ? colorOf('error') : false)); |
| 80 return _earlyErrorResult; | 80 return _earlyErrorResult; |
| 81 } | 81 } |
| 82 | 82 |
| 83 var results = _compileDart(dartInputFile, resolver, options, reporter); | 83 var results = _compileDart(dartInputFile, resolver, options, reporter, |
| 84 new Uri.file(path.absolute(inputFile))); |
| 84 if (results.failure && !options.forceCompile) return results; | 85 if (results.failure && !options.forceCompile) return results; |
| 85 | 86 |
| 86 if (options.outputDir != null) { | 87 if (options.outputDir != null) { |
| 87 generateEntryHtml(inputFile, options, results, doc); | 88 generateEntryHtml(inputFile, options, results, doc); |
| 88 } | 89 } |
| 89 return results; | 90 return results; |
| 90 } | 91 } |
| 91 | 92 |
| 92 CheckerResults _compileDart( | 93 CheckerResults _compileDart( |
| 93 String inputFile, TypeResolver resolver, CompilerOptions options, | 94 String inputFile, TypeResolver resolver, CompilerOptions options, |
| 94 [CheckerReporter reporter]) { | 95 [CheckerReporter reporter, Uri htmlUri]) { |
| 95 Uri uri; | 96 Uri uri; |
| 96 if (inputFile.startsWith('dart:') || inputFile.startsWith('package:')) { | 97 if (inputFile.startsWith('dart:') || inputFile.startsWith('package:')) { |
| 97 uri = Uri.parse(inputFile); | 98 uri = Uri.parse(inputFile); |
| 98 } else { | 99 } else { |
| 99 uri = new Uri.file(path.absolute(inputFile)); | 100 uri = new Uri.file(path.absolute(inputFile)); |
| 100 } | 101 } |
| 101 | 102 var codegenRoot = htmlUri != null ? htmlUri : uri; |
| 102 if (reporter == null) { | 103 if (reporter == null) { |
| 103 reporter = options.dumpInfo | 104 reporter = options.dumpInfo |
| 104 ? new SummaryReporter() | 105 ? new SummaryReporter() |
| 105 : new LogReporter(options.useColors); | 106 : new LogReporter(options.useColors); |
| 106 } | 107 } |
| 107 | 108 |
| 108 var libraries = <LibraryInfo>[]; | 109 var libraries = <LibraryInfo>[]; |
| 109 var rules = new RestrictedRules(resolver.context.typeProvider, reporter, | 110 var rules = new RestrictedRules(resolver.context.typeProvider, reporter, |
| 110 options: options); | 111 options: options); |
| 111 var codeChecker = new CodeChecker(rules, reporter, options); | 112 var codeChecker = new CodeChecker(rules, reporter, options); |
| 112 var generators = <CodeGenerator>[]; | 113 var generators = <CodeGenerator>[]; |
| 113 if (options.dumpSrcDir != null) { | 114 if (options.dumpSrcDir != null) { |
| 114 generators | 115 generators.add(new EmptyDartGenerator( |
| 115 .add(new EmptyDartGenerator(options.dumpSrcDir, uri, rules, options)); | 116 options.dumpSrcDir, codegenRoot, rules, options)); |
| 116 } | 117 } |
| 117 var outputDir = options.outputDir; | 118 var outputDir = options.outputDir; |
| 118 if (outputDir != null) { | 119 if (outputDir != null) { |
| 119 var cg = options.outputDart | 120 var cg = options.outputDart |
| 120 ? new DartGenerator(outputDir, uri, rules, options) | 121 ? new DartGenerator(outputDir, codegenRoot, rules, options) |
| 121 : new JSGenerator(outputDir, uri, rules, options); | 122 : new JSGenerator(outputDir, codegenRoot, rules, options); |
| 122 generators.add(cg); | 123 generators.add(cg); |
| 123 } | 124 } |
| 124 | 125 |
| 125 bool failure = false; | 126 bool failure = false; |
| 126 var rootSource = resolver.findSource(uri); | 127 var rootSource = resolver.findSource(uri); |
| 127 // TODO(sigmund): switch to use synchronous codegen? | 128 // TODO(sigmund): switch to use synchronous codegen? |
| 128 for (var source in reachableSources(rootSource, resolver.context)) { | 129 for (var source in reachableSources(rootSource, resolver.context)) { |
| 129 var entryUnit = resolver.context.resolveCompilationUnit2(source, source); | 130 var entryUnit = resolver.context.resolveCompilationUnit2(source, source); |
| 130 var lib = entryUnit.element.enclosingElement; | 131 var lib = entryUnit.element.enclosingElement; |
| 131 if (!options.checkSdk && lib.isInSdk) continue; | 132 if (!options.checkSdk && lib.isInSdk) continue; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 if (options.dumpInfoFile != null) { | 164 if (options.dumpInfoFile != null) { |
| 164 new File(options.dumpInfoFile) | 165 new File(options.dumpInfoFile) |
| 165 .writeAsStringSync(JSON.encode(reporter.result.toJsonMap())); | 166 .writeAsStringSync(JSON.encode(reporter.result.toJsonMap())); |
| 166 } | 167 } |
| 167 } | 168 } |
| 168 return new CheckerResults(libraries, rules, failure || options.forceCompile); | 169 return new CheckerResults(libraries, rules, failure || options.forceCompile); |
| 169 } | 170 } |
| 170 | 171 |
| 171 final _log = new Logger('ddc'); | 172 final _log = new Logger('ddc'); |
| 172 final _earlyErrorResult = new CheckerResults(const [], null, true); | 173 final _earlyErrorResult = new CheckerResults(const [], null, true); |
| OLD | NEW |