diff options
| author | ruki <[email protected]> | 2020-06-13 10:12:41 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-06-13 10:12:41 +0800 |
| commit | 9636ff2d67111f584a1a4a8e995e672940f3a8b7 (patch) | |
| tree | 32107c46de527cd1b25c41ba3f55d4a6bedf407b | |
| parent | b0dbf85198909ffdcdd086c94ce429a81626a01f (diff) | |
add proto rootdir
| -rw-r--r-- | tests/projects/c++/protobuf/src/subdir/test2.proto | 8 | ||||
| -rw-r--r-- | tests/projects/c++/protobuf/src/test.proto | 2 | ||||
| -rw-r--r-- | tests/projects/c++/protobuf/xmake.lua | 15 | ||||
| -rw-r--r-- | tests/projects/c/protobuf/xmake.lua | 13 | ||||
| -rw-r--r-- | xmake/rules/protobuf/proto.lua | 20 |
5 files changed, 29 insertions, 29 deletions
diff --git a/tests/projects/c++/protobuf/src/subdir/test2.proto b/tests/projects/c++/protobuf/src/subdir/test2.proto new file mode 100644 index 000000000..811cdac3e --- /dev/null +++ b/tests/projects/c++/protobuf/src/subdir/test2.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +package test2; +message TestCase2 { + string name2 = 4; +} +message Test2 { + repeated TestCase2 case2 = 1; +} diff --git a/tests/projects/c++/protobuf/src/test.proto b/tests/projects/c++/protobuf/src/test.proto index 0f129ea13..0f580b87a 100644 --- a/tests/projects/c++/protobuf/src/test.proto +++ b/tests/projects/c++/protobuf/src/test.proto @@ -1,8 +1,10 @@ syntax = "proto3"; +import "subdir/test2.proto"; package test; message TestCase { string name = 4; } message Test { repeated TestCase case = 1; + repeated test2.TestCase2 case2 = 2; } diff --git a/tests/projects/c++/protobuf/xmake.lua b/tests/projects/c++/protobuf/xmake.lua index ee65ee71f..04bed4fb0 100644 --- a/tests/projects/c++/protobuf/xmake.lua +++ b/tests/projects/c++/protobuf/xmake.lua @@ -1,23 +1,10 @@ - --- add rules: debug and release add_rules("mode.debug", "mode.release") - --- add protobuf add_requires("protobuf-cpp") --- add target target("test") - - -- set kind set_kind("binary") - - -- set languages set_languages("c++11") - - -- add packages add_packages("protobuf-cpp") - - -- add files add_files("src/*.cpp") - add_files("src/*.proto", {rules = "protobuf.cpp"}) + add_files("src/**.proto", {rules = "protobuf.cpp", proto_rootdir = "src"}) diff --git a/tests/projects/c/protobuf/xmake.lua b/tests/projects/c/protobuf/xmake.lua index b32af856c..86e154439 100644 --- a/tests/projects/c/protobuf/xmake.lua +++ b/tests/projects/c/protobuf/xmake.lua @@ -1,20 +1,9 @@ - --- add rules: debug and release add_rules("mode.debug", "mode.release") - --- add protobuf add_requires("protobuf-c") --- add target target("test") - - -- set kind set_kind("binary") - - -- add packages add_packages("protobuf-c") - - -- add files add_files("src/*.c") - add_files("src/**.proto", {rules = "protobuf.c"}) + add_files("src/**.proto", {rules = "protobuf.c", proto_rootdir = "src"}) diff --git a/xmake/rules/protobuf/proto.lua b/xmake/rules/protobuf/proto.lua index b7ad10eae..6b4c887c1 100644 --- a/xmake/rules/protobuf/proto.lua +++ b/xmake/rules/protobuf/proto.lua @@ -52,10 +52,15 @@ function main(target, sourcekind, sourcefile_proto, opt) protoc = assert(target:data(sourcekind == "cxx" and "protobuf.protoc" or "protobuf.protoc-c"), "protoc not found!") -- get c/c++ source file for protobuf + local prefixdir + local fileconfig = target:fileconfig(sourcefile_proto) + if fileconfig then + prefixdir = fileconfig.proto_rootdir + end local rootdir = path.join(target:autogendir(), "rules", "protobuf") local filename = path.basename(sourcefile_proto) .. ".pb" .. (sourcekind == "cxx" and ".cc" or "-c.c") local sourcefile_cx = target:autogenfile(sourcefile_proto, {rootdir = rootdir, filename = filename}) - local sourcefile_dir = path.directory(sourcefile_cx) + local sourcefile_dir = prefixdir and path.join(rootdir, prefixdir) or path.directory(sourcefile_cx) -- add includedirs target:add("includedirs", sourcefile_dir) @@ -94,8 +99,17 @@ function main(target, sourcekind, sourcefile_proto, opt) os.mkdir(sourcefile_dir) end - -- compile protobuf - os.vrunv(protoc, {sourcefile_proto, "-I" .. os.args(path.directory(sourcefile_proto)), (sourcekind == "cxx" and "--cpp_out=" or "--c_out=") .. sourcefile_dir}) + -- get compilation flags + local argv = {sourcefile_proto} + if prefixdir then + table.insert(argv, "-I" .. prefixdir) + else + table.insert(argv, "-I" .. path.directory(sourcefile_proto)) + end + table.insert(argv, (sourcekind == "cxx" and "--cpp_out=" or "--c_out=") .. sourcefile_dir) + + -- do compile + os.vrunv(protoc, argv) -- trace if option.get("verbose") then |
