diff options
author | Kai Dohmen <psykai1993@googlemail.com> | 2020-09-10 11:53:51 +0200 |
---|---|---|
committer | Kai Dohmen <psykai1993@googlemail.com> | 2020-09-16 14:17:31 +0000 |
commit | 627c870fd097f41635864be740f71bf1901f2f63 (patch) | |
tree | e03b0557b5d09f33dd3daed002804fe7dea384b2 /share | |
parent | 355a66dddef76b2f0244294af7bfc296d072ec43 (diff) |
Add protobuf.nanopb module
nanopb is a protobuffer implementation aimed for usage on
microcontrollers. It uses its own generator scripts which are applied as
a protoc-plugin.
Generalized the doPrepare function to use the generator as a plugin.
Change-Id: I43549f709f3cdff23c7bed84659636d18ea5fcf8
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'share')
-rw-r--r-- | share/qbs/modules/protobuf/cpp/protobufcpp.qbs | 5 | ||||
-rw-r--r-- | share/qbs/modules/protobuf/nanopb/nanopb.qbs | 78 | ||||
-rw-r--r-- | share/qbs/modules/protobuf/protobuf.js | 32 |
3 files changed, 86 insertions, 29 deletions
diff --git a/share/qbs/modules/protobuf/cpp/protobufcpp.qbs b/share/qbs/modules/protobuf/cpp/protobufcpp.qbs index bd3d94929..0b2ae1f35 100644 --- a/share/qbs/modules/protobuf/cpp/protobufcpp.qbs +++ b/share/qbs/modules/protobuf/cpp/protobufcpp.qbs @@ -72,8 +72,9 @@ ProtobufBase { var result = HelperFunctions.doPrepare( input.protobuf.cpp, product, input, outputs, "cpp"); if (input.fileTags.contains("protobuf.grpc")) { - result = ModUtils.concatAll(result, HelperFunctions.doPrepareGrpc( - input.protobuf.cpp, product, input, outputs, "cpp")); + result = ModUtils.concatAll(result, HelperFunctions.doPrepare( + input.protobuf.cpp, product, input, outputs, "grpc", + "protoc-gen-grpc=" + input.protobuf.cpp.grpcPluginPath)); } return result; } diff --git a/share/qbs/modules/protobuf/nanopb/nanopb.qbs b/share/qbs/modules/protobuf/nanopb/nanopb.qbs new file mode 100644 index 000000000..0dcfbb142 --- /dev/null +++ b/share/qbs/modules/protobuf/nanopb/nanopb.qbs @@ -0,0 +1,78 @@ +import qbs +import qbs.File +import qbs.FileInfo +import qbs.Probes +import qbs.ModUtils +import "../protobufbase.qbs" as ProtobufBase +import "../protobuf.js" as HelperFunctions + +ProtobufBase { + property string includePath: includeProbe.path + property string libraryPath: libraryProbe.path + property string pluginPath: pluginProbe.path + property string _plugin: "protoc-gen-nanopb=" + + FileInfo.joinPaths(pluginPath, "protoc-gen-nanopb") + + Depends { name: "cpp" } + + cpp.libraryPaths: { + var result = []; + if (libraryPath) + result.push(libraryPath); + return result; + } + cpp.dynamicLibraries: "protobuf-nanopb" + cpp.includePaths: { + var result = [_outputDir]; + if (includePath) + result.push(includePath); + return result; + } + + Rule { + inputs: ["protobuf.input"] + outputFileTags: ["hpp", "cpp"] + outputArtifacts: { + var outputDir = HelperFunctions.getOutputDir(input.protobuf.nanopb, input); + var result = [ + HelperFunctions.cppArtifact(outputDir, input, "hpp", ".pb.h"), + HelperFunctions.cppArtifact(outputDir, input, "cpp", ".pb.c") + ]; + + return result; + } + + prepare: { + var result = HelperFunctions.doPrepare( + input.protobuf.nanopb, product, input, outputs, "nanopb", + input.protobuf.nanopb._plugin); + return result; + } + } + + Probes.IncludeProbe { + id: includeProbe + names: ["pb.h", "pb_encode.h", "pb_decode.h", "pb_common.h"] + } + + Probes.LibraryProbe { + id: libraryProbe + names: "protobuf-nanopb" + } + + Probes.BinaryProbe { + id: pluginProbe + names: "protoc-gen-nanopb" + } + + validate: { + HelperFunctions.validateCompiler(compilerName, compilerPath); + + if (!HelperFunctions.checkPath(includePath)) + throw "Can't find nanopb protobuf include files. Please set the includePath property."; + if (!HelperFunctions.checkPath(libraryPath)) + throw "Can't find nanopb protobuf library. Please set the libraryPath property."; + if (!HelperFunctions.checkPath(pluginPath)) + throw "Can't find nanopb protobuf plugin. Please set the pluginPath property."; + } +} diff --git a/share/qbs/modules/protobuf/protobuf.js b/share/qbs/modules/protobuf/protobuf.js index 6a3950850..976a92d7c 100644 --- a/share/qbs/modules/protobuf/protobuf.js +++ b/share/qbs/modules/protobuf/protobuf.js @@ -92,37 +92,15 @@ function objcArtifact(outputDir, input, tag, suffix) { } } -function doPrepare(module, product, input, outputs, lang) +function doPrepare(module, product, input, outputs, generator, plugin) { var outputDir = module._outputDir; var args = []; - args.push("--" + lang + "_out", outputDir); + if (!!plugin) + args.push("--plugin=" + plugin) - var importPaths = module.importPaths; - if (importPaths.length === 0) - importPaths = [FileInfo.path(input.filePath)]; - importPaths.forEach(function(path) { - if (!FileInfo.isAbsolutePath(path)) - path = FileInfo.joinPaths(product.sourceDirectory, path); - args.push("--proto_path", path); - }); - - args.push(input.filePath); - - var cmd = new Command(module.compilerPath, args); - cmd.highlight = "codegen"; - cmd.description = "generating " + lang + " files for " + input.fileName; - return [cmd]; -} - -function doPrepareGrpc(module, product, input, outputs, lang) -{ - var outputDir = module._outputDir; - var args = []; - - args.push("--grpc_out", outputDir); - args.push("--plugin=protoc-gen-grpc=" + module.grpcPluginPath); + args.push("--" + generator + "_out", outputDir); var importPaths = module.importPaths; if (importPaths.length === 0) @@ -137,6 +115,6 @@ function doPrepareGrpc(module, product, input, outputs, lang) var cmd = new Command(module.compilerPath, args); cmd.highlight = "codegen"; - cmd.description = "generating " + lang + " files for " + input.fileName; + cmd.description = "generating " + generator + " files for " + input.fileName; return [cmd]; } |