Explorar o código

Merged in bugfix/PROTO-58-header-guards-generated-with-slash (pull request #25)

Bart Hertog %!s(int64=5) %!d(string=hai) anos
pai
achega
4cfafd85ef

+ 2 - 0
build_test.sh

@@ -37,6 +37,8 @@ protoc --plugin=protoc-gen-eams=protoc-gen-eams -I./test/proto --eams_out=./buil
 protoc --plugin=protoc-gen-eams=protoc-gen-eams -I./test/proto --eams_out=./build/EAMS ./test/proto/repeated_fields.proto
 protoc --plugin=protoc-gen-eams=protoc-gen-eams -I./test/proto --eams_out=./build/EAMS ./test/proto/oneof_fields.proto
 protoc --plugin=protoc-gen-eams=protoc-gen-eams -I./test/proto --eams_out=./build/EAMS ./test/proto/include_other_files.proto
+# Delibertly do not manually generate file_to_include.proto and subfolder/file_to_include_from_subfolder.proto 
+# to test the automatic generation of files from including them in include_other_files.proto.
 protoc --plugin=protoc-gen-eams=protoc-gen-eams -I./test/proto --eams_out=./build/EAMS ./test/proto/string_bytes.proto
 
 # For validation and testing generate the same message using python

+ 4 - 3
generator/protoc-gen-eams.py

@@ -297,7 +297,8 @@ def generate_code(request, respones):
 
         enums_generator = generate_enums(proto_file.enum_type)
 
-        filename_str = os.path.splitext(proto_file.name)[0]
+        filename_with_folder = os.path.splitext(proto_file.name)[0]
+        filename_without_folder = os.path.basename(filename_with_folder)
 
         imported_dependencies = []
         if proto_file.dependency:
@@ -308,7 +309,7 @@ def generate_code(request, respones):
             namespace_names = proto_file.package.split(".")
 
         try:
-            file_str = template.render(filename=filename_str, namespaces=namespace_names,
+            file_str = template.render(filename=filename_without_folder, namespaces=namespace_names,
                                        messages=messages_array[number_of_processed_msg:],
                                        enums=enums_generator, dependencies=imported_dependencies)
 
@@ -327,7 +328,7 @@ def generate_code(request, respones):
         else:
             number_of_processed_msg = len(messages_array)
             f = respones.file.add()
-            f.name = filename_str + ".h"
+            f.name = filename_with_folder + ".h"
             f.content = file_str
 
 

+ 5 - 0
test/proto/include_other_files.proto

@@ -38,8 +38,13 @@ import "file_to_include.proto";
 // Import something with variable length
 import "repeated_fields.proto";
 
+// Import something from a subfolder.
+import "subfolder/file_to_include_from_subfolder.proto";
+
+
 message IncludedMessages {
   some.external.lib.CommonStates  state = 1;
   some.external.lib.CommonMessage msg   = 2;
   repeated_fields rf  = 3;
+  other_folder_msg sub_msg = 4;
 }

+ 38 - 0
test/proto/subfolder/file_to_include_from_subfolder.proto

@@ -0,0 +1,38 @@
+/*
+ *  Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+ *
+ *  This file is part of Embedded Proto.
+ *
+ *  Embedded Proto is open source software: you can redistribute it and/or 
+ *  modify it under the terms of the GNU General Public License as published 
+ *  by the Free Software Foundation, version 3 of the license.
+ *
+ *  Embedded Proto  is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+ *
+ *  For commercial and closed source application please visit:
+ *  <https://EmbeddedProto.com/license/>.
+ *
+ *  Embedded AMS B.V.
+ *  Info:
+ *    info at EmbeddedProto dot com
+ *
+ *  Postal address:
+ *    Johan Huizingalaan 763a
+ *    1066 VH, Amsterdam
+ *    the Netherlands
+ */
+
+// This file is used to test including other proto files particular from a subfolder.
+
+syntax = "proto3";
+
+message other_folder_msg {
+  int32 val = 1;
+}
+