[英]protoc custom plugin erroring out with Program not found or is not executable
I am trying to build a custom protoc plugin to generate custom output from.proto files.我正在尝试构建一个自定义 protoc 插件来生成自定义 output from.proto 文件。 I literally copied java file containing CodeGenerator from protoc custom plugin as a starting point and renamed it.我从 protoc自定义插件中复制了包含 CodeGenerator 的 java 文件作为起点并将其重命名。 I also followed executable and created.sh file.我还关注了可执行文件和 created.sh 文件。 The content of my shell script is as follows.我的shell脚本内容如下。
I also add the PATH variable value and output of the plugin execution.我还添加了插件执行的 PATH 变量值和 output。 Can someone point me where I am going wrong with this?有人可以指出我哪里出了问题吗? The shell script runs fine separately executing the main method shell 脚本运行良好,分别执行 main 方法
If that is your entire example.sh
, it won't work because it doesn't have a "hashbang" line identifying the script interpreter.如果那是您的整个example.sh
,它将不起作用,因为它没有标识脚本解释器的“hashbang”行。
It should be something like:它应该是这样的:
#!/bin/bash
set -e
java cp ...
I think that's likely your problem because I tried running protoc
and specifying an plug-in in the same way you did, and it worked as long as the plug-in was actually executable on its own.我认为这可能是您的问题,因为我尝试以与您相同的方式运行protoc
并指定插件,并且只要插件实际上可以自行执行,它就可以工作。
how about using absolute path of example.sh?使用example.sh的绝对路径怎么样? protoc working directory may not be current folder. protoc 工作目录可能不是当前文件夹。
The protoc
error messaging is a little cryptic here. protoc
错误消息在这里有点神秘。 You have 3 options for providing a plugin to protoc
:您有 3 个选项可以为protoc
提供插件:
$PATH
following the protoc-gen-$NAME
format. $PATH
中遵循protoc-gen-$NAME
格式的插件。 This will be automatically picked up.这将被自动拾取。$PATH
.不符合上述命名约定的插件,但在您的$PATH
中可用。 This can be executed with the --plugin=$some-nonconventional-name
.这可以使用--plugin=$some-nonconventional-name
来执行。$PATH
.不在您的$PATH
中的插件。 This requires suppling an absolute path or relative path (from the current working directory) to the executable.这需要为可执行文件提供绝对路径或相对路径(从当前工作目录)。 This is executed with --plugin=proto-gen-$any-name-you-want=$path-to-executable
这是使用--plugin=proto-gen-$any-name-you-want=$path-to-executable
Expanding on 3 above.扩展上面的3。 If you create a file example-plugin
:如果您创建一个文件example-plugin
:
#!/bin/bash
echo "Example Plugin Running!"
You'll then want to make sure it's executable:然后,您需要确保它是可执行的:
chmod +x ./example-plugin
We need an output directory, let's make one:我们需要一个 output 目录,我们来做一个:
mdkir plugin-output
We need a .proto
file.我们需要一个.proto
文件。 Find one and name it anything you like, like MyProto.proto
找到一个并将其命名为您喜欢的任何名称,例如MyProto.proto
Let's pick an arbitrary name for this plugin.让我们为这个插件选择一个任意名称。 We can call it foo
.我们可以称之为foo
。
Then you'll execute it with protoc
as follows:然后你将使用protoc
执行它,如下所示:
protoc --plugin=protoc-gen-foo=$PATH_TO_EXAMPLE_PLUGIN --foo_output=./plugin-output MyProto.proto
You should see something like:您应该会看到如下内容:
--foo_out: protoc-gen-foo: Plugin output is unparseable: Example Plugin Running!\n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.