| 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 code generation. | 6 * Tools for code generation. |
| 7 */ | 7 */ |
| 8 library codegen.tools; | 8 library 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 */ | 279 */ |
| 280 @override | 280 @override |
| 281 bool check() { | 281 bool check() { |
| 282 Map<String, FileContentsComputer> map = directoryContentsComputer(); | 282 Map<String, FileContentsComputer> map = directoryContentsComputer(); |
| 283 try { | 283 try { |
| 284 for (String file in map.keys) { | 284 for (String file in map.keys) { |
| 285 FileContentsComputer fileContentsComputer = map[file]; | 285 FileContentsComputer fileContentsComputer = map[file]; |
| 286 String expectedContents = fileContentsComputer(); | 286 String expectedContents = fileContentsComputer(); |
| 287 File outputFile = | 287 File outputFile = |
| 288 new File(joinAll(posix.split(posix.join(outputDirPath, file)))); | 288 new File(joinAll(posix.split(posix.join(outputDirPath, file)))); |
| 289 if (expectedContents != outputFile.readAsStringSync()) { | 289 String actualContents = outputFile.readAsStringSync(); |
| 290 // Normalize Windows line endings to Unix line endings so that the |
| 291 // comparison doesn't fail on Windows. |
| 292 actualContents = actualContents.replaceAll('\r\n', '\n'); |
| 293 if (expectedContents != actualContents) { |
| 290 return false; | 294 return false; |
| 291 } | 295 } |
| 292 } | 296 } |
| 293 int nonHiddenFileCount = 0; | 297 int nonHiddenFileCount = 0; |
| 294 outputFile.listSync(recursive: false, followLinks: false).forEach( | 298 outputFile.listSync(recursive: false, followLinks: false).forEach( |
| 295 (FileSystemEntity fileSystemEntity) { | 299 (FileSystemEntity fileSystemEntity) { |
| 296 if (fileSystemEntity is File && | 300 if (fileSystemEntity is File && |
| 297 !basename(fileSystemEntity.path).startsWith('.')) { | 301 !basename(fileSystemEntity.path).startsWith('.')) { |
| 298 nonHiddenFileCount++; | 302 nonHiddenFileCount++; |
| 299 } | 303 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 File get outputFile => new File(joinAll(posix.split(outputPath))); | 367 File get outputFile => new File(joinAll(posix.split(outputPath))); |
| 364 | 368 |
| 365 /** | 369 /** |
| 366 * Check whether the file has the correct contents, and return true if it | 370 * Check whether the file has the correct contents, and return true if it |
| 367 * does. | 371 * does. |
| 368 */ | 372 */ |
| 369 @override | 373 @override |
| 370 bool check() { | 374 bool check() { |
| 371 String expectedContents = computeContents(); | 375 String expectedContents = computeContents(); |
| 372 try { | 376 try { |
| 373 return expectedContents == outputFile.readAsStringSync(); | 377 String actualContents = outputFile.readAsStringSync(); |
| 378 // Normalize Windows line endings to Unix line endings so that the |
| 379 // comparison doesn't fail on Windows. |
| 380 actualContents = actualContents.replaceAll('\r\n', '\n'); |
| 381 return expectedContents == actualContents; |
| 374 } catch (e) { | 382 } catch (e) { |
| 375 // There was a problem reading the file (most likely because it didn't | 383 // There was a problem reading the file (most likely because it didn't |
| 376 // exist). Treat that the same as if the file doesn't have the expected | 384 // exist). Treat that the same as if the file doesn't have the expected |
| 377 // contents. | 385 // contents. |
| 378 return false; | 386 return false; |
| 379 } | 387 } |
| 380 } | 388 } |
| 381 | 389 |
| 382 /** | 390 /** |
| 383 * Replace the file with the correct contents. [spec] is the "tool/spec" | 391 * Replace the file with the correct contents. [spec] is the "tool/spec" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 if (lines.last.isEmpty) { | 530 if (lines.last.isEmpty) { |
| 523 lines.removeLast(); | 531 lines.removeLast(); |
| 524 buffer.add(new dom.Text(lines.join('\n$indent') + '\n')); | 532 buffer.add(new dom.Text(lines.join('\n$indent') + '\n')); |
| 525 indentNeeded = true; | 533 indentNeeded = true; |
| 526 } else { | 534 } else { |
| 527 buffer.add(new dom.Text(lines.join('\n$indent'))); | 535 buffer.add(new dom.Text(lines.join('\n$indent'))); |
| 528 indentNeeded = false; | 536 indentNeeded = false; |
| 529 } | 537 } |
| 530 } | 538 } |
| 531 } | 539 } |
| OLD | NEW |