Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
a793c09b
Commit
a793c09b
authored
Jan 14, 2014
by
Max Cai
Committed by
Gerrit Code Review
Jan 14, 2014
Browse files
Options
Browse Files
Download
Plain Diff
Merge "Allow whitespace in nano codegen options."
parents
0eecf0b8
bc8eec3d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
30 deletions
+46
-30
Android.mk
Android.mk
+3
-1
README.txt
java/README.txt
+6
-7
javanano_generator.cc
src/google/protobuf/compiler/javanano/javanano_generator.cc
+37
-22
No files found.
Android.mk
View file @
a793c09b
...
@@ -374,6 +374,8 @@ LOCAL_SRC_FILES := \
...
@@ -374,6 +374,8 @@ LOCAL_SRC_FILES := \
LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/src
LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/src
LOCAL_PROTO_JAVA_OUTPUT_PARAMS := java_package=$(LOCAL_PATH)/src/google/protobuf/unittest_import_nano.proto|com.google.protobuf.nano,java_outer_classname=$(LOCAL_PATH)/src/google/protobuf/unittest_import_nano.proto|UnittestImportNano
LOCAL_PROTO_JAVA_OUTPUT_PARAMS := \
java_package = $(LOCAL_PATH)/src/google/protobuf/unittest_import_nano.proto|com.google.protobuf.nano, \
java_outer_classname = $(LOCAL_PATH)/src/google/protobuf/unittest_import_nano.proto|UnittestImportNano
include $(BUILD_STATIC_JAVA_LIBRARY)
include $(BUILD_STATIC_JAVA_LIBRARY)
java/README.txt
View file @
a793c09b
...
@@ -580,9 +580,9 @@ To use nano protobufs within the Android repo:
...
@@ -580,9 +580,9 @@ To use nano protobufs within the Android repo:
LOCAL_STATIC_JAVA_LIBRARIES variable, so you don't need to.
LOCAL_STATIC_JAVA_LIBRARIES variable, so you don't need to.
- Set 'LOCAL_PROTO_JAVA_OUTPUT_PARAMS := ...' in your local .mk file
- Set 'LOCAL_PROTO_JAVA_OUTPUT_PARAMS := ...' in your local .mk file
for any command-line options you need. Use commas to join multiple
for any command-line options you need. Use commas to join multiple
options.
Write all options on the same line; avoid backslash-newline
options.
In the nano flavor only, whitespace surrounding the option
or '+=', because they will introduce spaces in the middle of you
r
names and values are ignored, so you can use backslash-newline o
r
options and the generator is not prepared to handle them
.
'+=' to structure your make files nicely
.
- The options will be applied to *all* proto files in LOCAL_SRC_FILES
- The options will be applied to *all* proto files in LOCAL_SRC_FILES
when you build a Java library or package. In case different options
when you build a Java library or package. In case different options
are needed for different proto files, build separate Java libraries
are needed for different proto files, build separate Java libraries
...
@@ -603,10 +603,9 @@ To use nano protobufs outside of Android repo:
...
@@ -603,10 +603,9 @@ To use nano protobufs outside of Android repo:
- Invoke with --javanano_out, e.g.:
- Invoke with --javanano_out, e.g.:
./protoc '--javanano_out=\
./protoc '--javanano_out=\
java_package=src/proto/simple-data.proto|my_package,\
java_package=src/proto/simple-data.proto|my_package,\
java_outer_classname=src/proto/simple-data.proto|OuterName:\
java_outer_classname=src/proto/simple-data.proto|OuterName\
.' src/proto/simple-data.proto
:.' src/proto/simple-data.proto
Contributing to nano:
Contributing to nano:
...
...
src/google/protobuf/compiler/javanano/javanano_generator.cc
View file @
a793c09b
...
@@ -46,6 +46,19 @@ namespace protobuf {
...
@@ -46,6 +46,19 @@ namespace protobuf {
namespace
compiler
{
namespace
compiler
{
namespace
javanano
{
namespace
javanano
{
namespace
{
string
TrimString
(
const
string
&
s
)
{
string
::
size_type
start
=
s
.
find_first_not_of
(
"
\n\r\t
"
);
if
(
start
==
string
::
npos
)
{
return
""
;
}
string
::
size_type
end
=
s
.
find_last_not_of
(
"
\n\r\t
"
)
+
1
;
return
s
.
substr
(
start
,
end
-
start
);
}
}
// namespace
void
UpdateParamsRecursively
(
Params
&
params
,
void
UpdateParamsRecursively
(
Params
&
params
,
const
FileDescriptor
*
file
)
{
const
FileDescriptor
*
file
)
{
// Add any parameters for this file
// Add any parameters for this file
...
@@ -93,42 +106,44 @@ bool JavaNanoGenerator::Generate(const FileDescriptor* file,
...
@@ -93,42 +106,44 @@ bool JavaNanoGenerator::Generate(const FileDescriptor* file,
// Replace any existing options with ones from command line
// Replace any existing options with ones from command line
for
(
int
i
=
0
;
i
<
options
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
options
.
size
();
i
++
)
{
if
(
options
[
i
].
first
==
"output_list_file"
)
{
string
option_name
=
TrimString
(
options
[
i
].
first
);
output_list_file
=
options
[
i
].
second
;
string
option_value
=
TrimString
(
options
[
i
].
second
);
}
else
if
(
options
[
i
].
first
==
"java_package"
)
{
if
(
option_name
==
"output_list_file"
)
{
output_list_file
=
option_value
;
}
else
if
(
option_name
==
"java_package"
)
{
vector
<
string
>
parts
;
vector
<
string
>
parts
;
SplitStringUsing
(
option
s
[
i
].
second
,
"|"
,
&
parts
);
SplitStringUsing
(
option
_value
,
"|"
,
&
parts
);
if
(
parts
.
size
()
!=
2
)
{
if
(
parts
.
size
()
!=
2
)
{
*
error
=
"Bad java_package, expecting filename|PackageName found '"
*
error
=
"Bad java_package, expecting filename|PackageName found '"
+
option
s
[
i
].
second
+
"'"
;
+
option
_value
+
"'"
;
return
false
;
return
false
;
}
}
params
.
set_java_package
(
parts
[
0
],
parts
[
1
]);
params
.
set_java_package
(
parts
[
0
],
parts
[
1
]);
}
else
if
(
option
s
[
i
].
first
==
"java_outer_classname"
)
{
}
else
if
(
option
_name
==
"java_outer_classname"
)
{
vector
<
string
>
parts
;
vector
<
string
>
parts
;
SplitStringUsing
(
option
s
[
i
].
second
,
"|"
,
&
parts
);
SplitStringUsing
(
option
_value
,
"|"
,
&
parts
);
if
(
parts
.
size
()
!=
2
)
{
if
(
parts
.
size
()
!=
2
)
{
*
error
=
"Bad java_outer_classname, "
*
error
=
"Bad java_outer_classname, "
"expecting filename|ClassName found '"
"expecting filename|ClassName found '"
+
option
s
[
i
].
second
+
"'"
;
+
option
_value
+
"'"
;
return
false
;
return
false
;
}
}
params
.
set_java_outer_classname
(
parts
[
0
],
parts
[
1
]);
params
.
set_java_outer_classname
(
parts
[
0
],
parts
[
1
]);
}
else
if
(
option
s
[
i
].
first
==
"store_unknown_fields"
)
{
}
else
if
(
option
_name
==
"store_unknown_fields"
)
{
params
.
set_store_unknown_fields
(
option
s
[
i
].
second
==
"true"
);
params
.
set_store_unknown_fields
(
option
_value
==
"true"
);
}
else
if
(
option
s
[
i
].
first
==
"java_multiple_files"
)
{
}
else
if
(
option
_name
==
"java_multiple_files"
)
{
params
.
set_override_java_multiple_files
(
option
s
[
i
].
second
==
"true"
);
params
.
set_override_java_multiple_files
(
option
_value
==
"true"
);
}
else
if
(
option
s
[
i
].
first
==
"java_nano_generate_has"
)
{
}
else
if
(
option
_name
==
"java_nano_generate_has"
)
{
params
.
set_generate_has
(
option
s
[
i
].
second
==
"true"
);
params
.
set_generate_has
(
option
_value
==
"true"
);
}
else
if
(
option
s
[
i
].
first
==
"enum_style"
)
{
}
else
if
(
option
_name
==
"enum_style"
)
{
params
.
set_java_enum_style
(
option
s
[
i
].
second
==
"java"
);
params
.
set_java_enum_style
(
option
_value
==
"java"
);
}
else
if
(
option
s
[
i
].
first
==
"optional_field_style"
)
{
}
else
if
(
option
_name
==
"optional_field_style"
)
{
params
.
set_optional_field_accessors
(
option
s
[
i
].
second
==
"accessors"
);
params
.
set_optional_field_accessors
(
option
_value
==
"accessors"
);
params
.
set_use_reference_types_for_primitives
(
option
s
[
i
].
second
==
"reftypes"
);
params
.
set_use_reference_types_for_primitives
(
option
_value
==
"reftypes"
);
}
else
if
(
option
s
[
i
].
first
==
"generate_equals"
)
{
}
else
if
(
option
_name
==
"generate_equals"
)
{
params
.
set_generate_equals
(
option
s
[
i
].
second
==
"true"
);
params
.
set_generate_equals
(
option
_value
==
"true"
);
}
else
{
}
else
{
*
error
=
"Ignore unknown javanano generator option: "
+
option
s
[
i
].
first
;
*
error
=
"Ignore unknown javanano generator option: "
+
option
_name
;
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment