OLD | NEW |
1 import 'dart:io'; | 1 import 'dart:io'; |
2 import 'package:args/args.dart'; | 2 import 'package:args/args.dart'; |
3 import 'package:analyzer/src/services/formatter_impl.dart'; | 3 import 'package:analyzer/src/services/formatter_impl.dart'; |
4 import 'package:async_await/async_await.dart' as async_await; | 4 import 'package:async_await/async_await.dart' as async_await; |
5 import 'package:path/path.dart' as p; | 5 import 'package:path/path.dart' as p; |
6 final sourceDir = p.dirname(p.dirname(p.fromUri(Platform.script))); | 6 final sourceDir = p.dirname(p.dirname(p.fromUri(Platform.script))); |
7 final sourceUrl = p.toUri(sourceDir).toString(); | 7 final sourceUrl = p.toUri(sourceDir).toString(); |
8 final generatedDir = p.join(p.dirname(sourceDir), 'pub_generated'); | 8 final generatedDir = p.join(p.dirname(sourceDir), 'pub_generated'); |
9 bool hadFailure = false; | 9 bool hadFailure = false; |
10 bool verbose = false; | 10 bool verbose = false; |
(...skipping 14 matching lines...) Expand all Loading... |
25 'Unexpected arguments: ${rest.skip(1).join(" ")}.'); | 25 'Unexpected arguments: ${rest.skip(1).join(" ")}.'); |
26 } | 26 } |
27 buildDir = rest.first; | 27 buildDir = rest.first; |
28 } on FormatException catch (ex) { | 28 } on FormatException catch (ex) { |
29 stderr.writeln(ex); | 29 stderr.writeln(ex); |
30 stderr.writeln(); | 30 stderr.writeln(); |
31 stderr.writeln( | 31 stderr.writeln( |
32 "Usage: dart async_compile.dart [--verbose] [--force] <build dir>"); | 32 "Usage: dart async_compile.dart [--verbose] [--force] <build dir>"); |
33 exit(64); | 33 exit(64); |
34 } | 34 } |
35 var result = Process.runSync( | 35 var currentCommit = _getCurrentCommit(); |
36 "git", | |
37 ["rev-parse", "HEAD"], | |
38 workingDirectory: p.join(sourceDir, "../../../../third_party/pkg/async_awa
it")); | |
39 if (result.exitCode != 0) { | |
40 stderr.writeln("Could not get Git revision of async_await compiler."); | |
41 exit(1); | |
42 } | |
43 var currentCommit = result.stdout.trim(); | |
44 var readmePath = p.join(generatedDir, "README.md"); | 36 var readmePath = p.join(generatedDir, "README.md"); |
45 var lastCommit; | 37 var lastCommit; |
46 var readme = new File(readmePath).readAsStringSync(); | 38 var readme = new File(readmePath).readAsStringSync(); |
47 var match = _commitPattern.firstMatch(readme); | 39 var match = _commitPattern.firstMatch(readme); |
48 if (match == null) { | 40 if (match == null) { |
49 stderr.writeln("Could not find compiler commit hash in README.md."); | 41 stderr.writeln("Could not find compiler commit hash in README.md."); |
50 exit(1); | 42 exit(1); |
51 } | 43 } |
52 lastCommit = match[0]; | 44 lastCommit = match[0]; |
53 var numFiles = 0; | 45 var numFiles = 0; |
(...skipping 26 matching lines...) Expand all Loading... |
80 } | 72 } |
81 if (currentCommit != lastCommit) { | 73 if (currentCommit != lastCommit) { |
82 readme = readme.replaceAll(_commitPattern, currentCommit); | 74 readme = readme.replaceAll(_commitPattern, currentCommit); |
83 _writeFile(readmePath, readme); | 75 _writeFile(readmePath, readme); |
84 if (verbose) print("Updated README.md"); | 76 if (verbose) print("Updated README.md"); |
85 } | 77 } |
86 if (numCompiled > 0) _generateSnapshot(buildDir); | 78 if (numCompiled > 0) _generateSnapshot(buildDir); |
87 if (verbose) print("Compiled $numCompiled out of $numFiles files"); | 79 if (verbose) print("Compiled $numCompiled out of $numFiles files"); |
88 if (hadFailure) exit(1); | 80 if (hadFailure) exit(1); |
89 } | 81 } |
| 82 String _getCurrentCommit() { |
| 83 var command = "git"; |
| 84 var args = ["rev-parse", "HEAD"]; |
| 85 if (Platform.operatingSystem == "windows") { |
| 86 command = "cmd"; |
| 87 args = ["/c", "git"]..addAll(args); |
| 88 } |
| 89 var result = Process.runSync( |
| 90 command, |
| 91 args, |
| 92 workingDirectory: p.join(sourceDir, "../../../../third_party/pkg/async_awa
it")); |
| 93 if (result.exitCode != 0) { |
| 94 stderr.writeln("Could not get Git revision of async_await compiler."); |
| 95 exit(1); |
| 96 } |
| 97 return result.stdout.trim(); |
| 98 } |
90 void _compile(String sourcePath, String source, String destPath) { | 99 void _compile(String sourcePath, String source, String destPath) { |
91 var destDir = new Directory(p.dirname(destPath)); | 100 var destDir = new Directory(p.dirname(destPath)); |
92 destDir.createSync(recursive: true); | 101 destDir.createSync(recursive: true); |
93 source = _translateAsyncAwait(sourcePath, source); | 102 source = _translateAsyncAwait(sourcePath, source); |
94 if (source != null) source = _fixDart2jsImports(sourcePath, source, destPath); | 103 if (source != null) source = _fixDart2jsImports(sourcePath, source, destPath); |
95 if (source == null) { | 104 if (source == null) { |
96 _deleteFile(destPath); | 105 _deleteFile(destPath); |
97 } else { | 106 } else { |
98 _writeFile(destPath, source); | 107 _writeFile(destPath, source); |
99 } | 108 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 void _deleteFile(String path) { | 146 void _deleteFile(String path) { |
138 try { | 147 try { |
139 new File(path).deleteSync(); | 148 new File(path).deleteSync(); |
140 } on IOException catch (ex) {} | 149 } on IOException catch (ex) {} |
141 } | 150 } |
142 void _writeFile(String path, String contents) { | 151 void _writeFile(String path, String contents) { |
143 try { | 152 try { |
144 new File(path).writeAsStringSync(contents); | 153 new File(path).writeAsStringSync(contents); |
145 } on IOException catch (ex) {} | 154 } on IOException catch (ex) {} |
146 } | 155 } |
OLD | NEW |