OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /** | 5 /** |
6 * Tools for generating code in analyzer and analysis server. | 6 * Tools for generating code in analyzer and analysis server. |
7 */ | 7 */ |
8 library analyzer.src.codegen.tools; | 8 library analyzer.src.codegen.tools; |
9 | 9 |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 * Replace the [output] with the correct contents. [pkgPath] is the path to | 279 * Replace the [output] with the correct contents. [pkgPath] is the path to |
280 * the current package. | 280 * the current package. |
281 */ | 281 */ |
282 void generate(String pkgPath); | 282 void generate(String pkgPath); |
283 | 283 |
284 /** | 284 /** |
285 * Get a [FileSystemEntity] representing the output file or directory. | 285 * Get a [FileSystemEntity] representing the output file or directory. |
286 * [pkgPath] is the path to the current package. | 286 * [pkgPath] is the path to the current package. |
287 */ | 287 */ |
288 FileSystemEntity output(String pkgPath); | 288 FileSystemEntity output(String pkgPath); |
| 289 |
| 290 /** |
| 291 * Check that all of the [targets] are up to date. If they are not, print |
| 292 * out a message instructing the user to regenerate them, and exit with a |
| 293 * nonzero error code. |
| 294 * |
| 295 * [pkgPath] is the path to the current package. [generatorRelPath] is the |
| 296 * path to a .dart script the user may use to regenerate the targets. |
| 297 * |
| 298 * To avoid mistakes when run on Windows, [generatorRelPath] always uses |
| 299 * POSIX directory separators. |
| 300 */ |
| 301 static void checkAll(String pkgPath, String generatorRelPath, |
| 302 Iterable<GeneratedContent> targets) { |
| 303 bool generateNeeded = false; |
| 304 for (GeneratedContent target in targets) { |
| 305 if (!target.check(pkgPath)) { |
| 306 print( |
| 307 '${target.output(pkgPath).absolute} does not have expected contents.
'); |
| 308 generateNeeded = true; |
| 309 } |
| 310 } |
| 311 if (generateNeeded) { |
| 312 print('Please regenerate using:'); |
| 313 String executable = Platform.executable; |
| 314 String packageRoot = ''; |
| 315 if (Platform.packageRoot.isNotEmpty) { |
| 316 packageRoot = ' --package-root=${Platform.packageRoot}'; |
| 317 } |
| 318 String generateScript = |
| 319 join(pkgPath, joinAll(posix.split(generatorRelPath))); |
| 320 print(' $executable$packageRoot $generateScript'); |
| 321 exit(1); |
| 322 } else { |
| 323 print('All generated files up to date.'); |
| 324 } |
| 325 } |
| 326 |
| 327 /** |
| 328 * Regenerate all of the [targets]. [pkgPath] is the path to the current |
| 329 * package. |
| 330 */ |
| 331 static void generateAll(String pkgPath, Iterable<GeneratedContent> targets) { |
| 332 for (GeneratedContent target in targets) { |
| 333 target.generate(pkgPath); |
| 334 } |
| 335 } |
289 } | 336 } |
290 | 337 |
291 /** | 338 /** |
292 * Class representing a single output directory (either generated code or | 339 * Class representing a single output directory (either generated code or |
293 * generated HTML). No other content should exist in the directory. | 340 * generated HTML). No other content should exist in the directory. |
294 */ | 341 */ |
295 class GeneratedDirectory extends GeneratedContent { | 342 class GeneratedDirectory extends GeneratedContent { |
296 /** | 343 /** |
297 * The path to the directory that will have the generated content. | 344 * The path to the directory that will have the generated content. |
298 */ | 345 */ |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 if (lines.last.isEmpty) { | 598 if (lines.last.isEmpty) { |
552 lines.removeLast(); | 599 lines.removeLast(); |
553 buffer.add(new dom.Text(lines.join('\n$indent') + '\n')); | 600 buffer.add(new dom.Text(lines.join('\n$indent') + '\n')); |
554 indentNeeded = true; | 601 indentNeeded = true; |
555 } else { | 602 } else { |
556 buffer.add(new dom.Text(lines.join('\n$indent'))); | 603 buffer.add(new dom.Text(lines.join('\n$indent'))); |
557 indentNeeded = false; | 604 indentNeeded = false; |
558 } | 605 } |
559 } | 606 } |
560 } | 607 } |
OLD | NEW |