| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library build_dart; | 5 library build_dart; |
| 6 | 6 |
| 7 import "dart:io"; | 7 import "dart:io"; |
| 8 import "package:args/args.dart"; | 8 import "package:args/args.dart"; |
| 9 | 9 |
| 10 bool cleanBuild; | 10 bool cleanBuild; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 // Return a non-zero code to indicate a build failure. | 36 // Return a non-zero code to indicate a build failure. |
| 37 //exit(1); | 37 //exit(1); |
| 38 } | 38 } |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * Handle --changed, --removed, --clean, --full, and --help command-line args. | 41 * Handle --changed, --removed, --clean, --full, and --help command-line args. |
| 42 */ | 42 */ |
| 43 void processArgs(List<String> arguments) { | 43 void processArgs(List<String> arguments) { |
| 44 var parser = new ArgParser(); | 44 var parser = new ArgParser(); |
| 45 parser.addOption("changed", help: "the file has changed since the last build", | 45 parser.addOption("changed", |
| 46 allowMultiple: true); | 46 help: "the file has changed since the last build", allowMultiple: true); |
| 47 parser.addOption("removed", help: "the file was removed since the last build", | 47 parser.addOption("removed", |
| 48 allowMultiple: true); | 48 help: "the file was removed since the last build", allowMultiple: true); |
| 49 parser.addFlag("clean", negatable: false, help: "remove any build artifacts"); | 49 parser.addFlag("clean", negatable: false, help: "remove any build artifacts"); |
| 50 parser.addFlag("full", negatable: false, help: "perform a full build"); | 50 parser.addFlag("full", negatable: false, help: "perform a full build"); |
| 51 parser.addFlag("machine", | 51 parser.addFlag("machine", |
| 52 negatable: false, help: "produce warnings in a machine parseable format"); | 52 negatable: false, help: "produce warnings in a machine parseable format"); |
| 53 parser.addFlag("help", negatable: false, help: "display this help and exit"); | 53 parser.addFlag("help", negatable: false, help: "display this help and exit"); |
| 54 | 54 |
| 55 var args = parser.parse(arguments); | 55 var args = parser.parse(arguments); |
| 56 | 56 |
| 57 if (args["help"]) { | 57 if (args["help"]) { |
| 58 print(parser.getUsage()); | 58 print(parser.getUsage()); |
| 59 exit(0); | 59 exit(0); |
| 60 } | 60 } |
| 61 | 61 |
| 62 changedFiles = args["changed"]; | 62 changedFiles = args["changed"]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 78 }); | 78 }); |
| 79 } | 79 } |
| 80 | 80 |
| 81 /** | 81 /** |
| 82 * Recursively scan the current directory looking for .foo files to process. | 82 * Recursively scan the current directory looking for .foo files to process. |
| 83 */ | 83 */ |
| 84 void handleFullBuild() { | 84 void handleFullBuild() { |
| 85 var files = <String>[]; | 85 var files = <String>[]; |
| 86 | 86 |
| 87 Directory.current.list(recursive: true).listen((entity) { | 87 Directory.current.list(recursive: true).listen((entity) { |
| 88 if (entity is File) { | 88 if (entity is File) { |
| 89 files.add((entity as File).resolveSymbolicLinksSync()); | 89 files.add((entity as File).resolveSymbolicLinksSync()); |
| 90 } | 90 } |
| 91 }, | 91 }, onDone: () => handleChangedFiles(files)); |
| 92 onDone: () => handleChangedFiles(files)); | |
| 93 } | 92 } |
| 94 | 93 |
| 95 /** | 94 /** |
| 96 * Process the given list of changed files. | 95 * Process the given list of changed files. |
| 97 */ | 96 */ |
| 98 void handleChangedFiles(List<String> files) { | 97 void handleChangedFiles(List<String> files) { |
| 99 files.forEach(_processFile); | 98 files.forEach(_processFile); |
| 100 } | 99 } |
| 101 | 100 |
| 102 /** | 101 /** |
| 103 * Process the given list of removed files. | 102 * Process the given list of removed files. |
| 104 */ | 103 */ |
| 105 void handleRemovedFiles(List<String> files) { | 104 void handleRemovedFiles(List<String> files) {} |
| 106 | |
| 107 } | |
| 108 | 105 |
| 109 /** | 106 /** |
| 110 * Convert a .foo file to a .foobar file. | 107 * Convert a .foo file to a .foobar file. |
| 111 */ | 108 */ |
| 112 void _processFile(String arg) { | 109 void _processFile(String arg) { |
| 113 if (arg.endsWith(".foo")) { | 110 if (arg.endsWith(".foo")) { |
| 114 print("processing: ${arg}"); | 111 print("processing: ${arg}"); |
| 115 | 112 |
| 116 File file = new File(arg); | 113 File file = new File(arg); |
| 117 | 114 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 146 } |
| 150 | 147 |
| 151 /** | 148 /** |
| 152 * If this file is a generated file (based on the extension), delete it. | 149 * If this file is a generated file (based on the extension), delete it. |
| 153 */ | 150 */ |
| 154 void _maybeClean(File file) { | 151 void _maybeClean(File file) { |
| 155 if (file.path.endsWith(".foobar")) { | 152 if (file.path.endsWith(".foobar")) { |
| 156 file.delete(); | 153 file.delete(); |
| 157 } | 154 } |
| 158 } | 155 } |
| OLD | NEW |