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; |
11 bool fullBuild; | 11 bool fullBuild; |
12 bool useMachineInterface; | 12 bool useMachineInterface; |
13 | 13 |
14 List<String> changedFiles; | 14 List<String> changedFiles; |
15 List<String> removedFiles; | 15 List<String> removedFiles; |
16 | 16 |
17 /** | 17 /** |
18 * If the file is named 'build.dart' and is placed in the root directory of a | 18 * If the file is named 'build.dart' and is placed in the root directory of a |
19 * project or in a directory containing a pubspec.yaml file, then the Editor | 19 * project or in a directory containing a pubspec.yaml file, then the Editor |
20 * will automatically invoke that file whenever a file in that project changes. | 20 * will automatically invoke that file whenever a file in that project changes. |
21 * See the source code of [processArgs] for information about the legal command | 21 * See the source code of [processArgs] for information about the legal command |
22 * line options. | 22 * line options. |
23 */ | 23 */ |
24 void main() { | 24 void main(List<String> arguments) { |
25 processArgs(); | 25 processArgs(arguments); |
26 | 26 |
27 if (cleanBuild) { | 27 if (cleanBuild) { |
28 handleCleanCommand(); | 28 handleCleanCommand(); |
29 } else if (fullBuild) { | 29 } else if (fullBuild) { |
30 handleFullBuild(); | 30 handleFullBuild(); |
31 } else { | 31 } else { |
32 handleChangedFiles(changedFiles); | 32 handleChangedFiles(changedFiles); |
33 handleRemovedFiles(removedFiles); | 33 handleRemovedFiles(removedFiles); |
34 } | 34 } |
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() { | 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", help: "the file has changed since the last build", |
46 allowMultiple: true); | 46 allowMultiple: true); |
47 parser.addOption("removed", help: "the file was removed since the last build", | 47 parser.addOption("removed", help: "the file was removed since the last build", |
48 allowMultiple: true); | 48 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(new Options().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"]; |
63 removedFiles = args["removed"]; | 63 removedFiles = args["removed"]; |
64 | 64 |
65 useMachineInterface = args["machine"]; | 65 useMachineInterface = args["machine"]; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 149 } |
150 | 150 |
151 /** | 151 /** |
152 * If this file is a generated file (based on the extension), delete it. | 152 * If this file is a generated file (based on the extension), delete it. |
153 */ | 153 */ |
154 void _maybeClean(File file) { | 154 void _maybeClean(File file) { |
155 if (file.path.endsWith(".foobar")) { | 155 if (file.path.endsWith(".foobar")) { |
156 file.delete(); | 156 file.delete(); |
157 } | 157 } |
158 } | 158 } |
OLD | NEW |