Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: lib/protobuf/plugin/ProtocGenDart.dart

Issue 10595002: Protocol Buffer runtime library and 'protoc' plugin (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Work around http://code.google.com/p/dart/issues/detail?id=3806 Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/protobuf/plugin/ProtocException.dart ('k') | lib/protobuf/plugin/README » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env dart
2 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file.
5
6 #import("../runtime/Protobuf.dart");
7 #import("dart:io");
8 #source("protoc/descriptor.pb.dart");
9 #source("protoc/plugin.pb.dart");
10 #source("CodeGenerator.dart");
11 #source("DartFile.dart");
12 #source("DartHelpers.dart");
13 #source("EnumGenerator.dart");
14 #source("ExtensionGenerator.dart");
15 #source("IndentingWriter.dart");
16 #source("MessageGenerator.dart");
17 #source("ProtobufField.dart");
18 #source("ProtocException.dart");
19 #source("ProtoGenDartConfig.dart");
20 #source("Writer.dart");
21
22 final String DISABLE_STREAMS_FLAG = "disable_streams";
23
24 void main() {
25 var config = parseOptions();
26 if (config === null || !config.valid) {
27 usage();
28 } else {
29 CodeGenerator cg = new CodeGenerator(config, stdin, stdout, stderr);
30 cg.generate();
31 }
32 }
33
34 void err(String s) {
35 stderr.write("$s\n".charCodes());
36 }
37
38 void usage() {
39 err("Usage: protoc-gen-dart [--out=OUTDIR] [--parameter=PARAM] "
40 "PROTO_FILES < DESCRIPTORS");
41 err("--out=OUTDIR output directory (as passed to the --foo_out");
42 err(" parameterif omitted, the current directory should");
43 err(" be used.");
44 err("--parameter=PARAM gives the generator param, if any was provided.");
45 err(" Some generators accept extra parameters. You can");
46 err(" specify this parameter on the command-line by");
47 err(" placing it before the output directory, separated");
48 err(" by a colon (protoc --dart_out=disable_streams:out).");
49 err(" PROTO_FILES The PROTO_FILES list the .proto files which");
50 err(" were given on the compiler command-line; these");
51 err(" are the files for which the plugin is expected");
52 err(" to generate output code.");
53 err(" DESCRIPTORS Finally, DESCRIPTORS is an encoded");
54 err(" FileDescriptorSet as defined in descriptor.proto");
55 err(" This is piped to the plugin's stdin.");
56 }
57
58 final String OUT_CL_PARAM = "--out";
59 final String PARAMETER_CL_PARAM = "--parameter";
60
61 ProtocGenDartConfig parseOptions([ProtocGenDartConfig config = null]) {
62 Options opts = new Options();
63 ProtocGenDartConfig _config = config !== null ? config
64 : new ProtocGenDartConfig();
65 try {
66 for (int i = 0; i < opts.arguments.length; i++) {
67 if (opts.arguments[i].startsWith(OUT_CL_PARAM)) {
68 if(opts.arguments[i].length > OUT_CL_PARAM.length + 1) {
69 _config.out = opts.arguments[i].substring(OUT_CL_PARAM.length + 1);
70 }
71 } else if (opts.arguments[i].startsWith(PARAMETER_CL_PARAM)) {
72 if(opts.arguments[i].length > PARAMETER_CL_PARAM.length + 1) {
73 _config.parameter =
74 opts.arguments[i].substring(PARAMETER_CL_PARAM.length + 1);
75 }
76 continue;
77 } else {
78 if (opts.arguments[i].startsWith("-")) {
79 _config.valid = false;
80 } else {
81 _config.protoFiles.add(opts.arguments[i]);
82 }
83 }
84 }
85 return _config;
86 } catch (FileIOException e) {
87 err(e.message);
88 }
89 }
90
OLDNEW
« no previous file with comments | « lib/protobuf/plugin/ProtocException.dart ('k') | lib/protobuf/plugin/README » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698