Browse Source

Merge pull request #1793 from pherl/javalite

Add a javalite plugin.
Jisi Liu 9 years ago
parent
commit
0c011c4c3c
2 changed files with 38 additions and 1 deletions
  1. 4 1
      src/Makefile.am
  2. 34 0
      src/google/protobuf/compiler/java/java_lite_main.cc

+ 4 - 1
src/Makefile.am

@@ -472,9 +472,11 @@ libprotoc_la_SOURCES =                                         \
   google/protobuf/compiler/csharp/csharp_wrapper_field.cc      \
   google/protobuf/compiler/csharp/csharp_wrapper_field.cc      \
   google/protobuf/compiler/csharp/csharp_wrapper_field.h
   google/protobuf/compiler/csharp/csharp_wrapper_field.h
 
 
-bin_PROGRAMS = protoc
+bin_PROGRAMS = protoc protoc-gen-javalite
 protoc_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la
 protoc_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la
 protoc_SOURCES = google/protobuf/compiler/main.cc
 protoc_SOURCES = google/protobuf/compiler/main.cc
+protoc_gen_javalite_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la
+protoc_gen_javalite_SOURCES = google/protobuf/compiler/java/java_lite_main.cc
 
 
 # Tests ==============================================================
 # Tests ==============================================================
 
 
@@ -677,6 +679,7 @@ COMMON_TEST_SOURCES =                                          \
 
 
 check_PROGRAMS = protoc protobuf-test protobuf-lazy-descriptor-test \
 check_PROGRAMS = protoc protobuf-test protobuf-lazy-descriptor-test \
                  protobuf-lite-test test_plugin protobuf-lite-arena-test \
                  protobuf-lite-test test_plugin protobuf-lite-arena-test \
+								 protoc-gen-javalite \
                  $(GZCHECKPROGRAMS)
                  $(GZCHECKPROGRAMS)
 protobuf_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \
 protobuf_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \
                       ../gmock/gtest/lib/libgtest.la              \
                       ../gmock/gtest/lib/libgtest.la              \

+ 34 - 0
src/google/protobuf/compiler/java/java_lite_main.cc

@@ -0,0 +1,34 @@
+#include <google/protobuf/compiler/code_generator.h>
+#include <google/protobuf/compiler/java/java_generator.h>
+#include <google/protobuf/compiler/plugin.h>
+
+namespace google {
+namespace protobuf {
+namespace compiler {
+namespace java {
+
+class JavaLiteGenerator : public CodeGenerator {
+ public:
+  JavaLiteGenerator() {}
+  ~JavaLiteGenerator() {}
+  bool Generate(const FileDescriptor* file,
+                const string& parameter,
+                GeneratorContext* context,
+                string* error) const {
+    // Only pass 'lite' as the generator parameter.
+    return generator_.Generate(file, "lite", context, error);
+  }
+ private:
+  JavaGenerator generator_;
+  GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaLiteGenerator);
+};
+
+}  // namespace java
+}  // namespace compiler
+}  // namespace protobuf
+}  // namespace google
+
+int main(int argc, char* argv[]) {
+  google::protobuf::compiler::java::JavaLiteGenerator generator;
+  return google::protobuf::compiler::PluginMain(argc, argv, &generator);
+}