protoc custom plugin erroring out with Program not found or is not executable

671 Views Asked by At

I am trying to build a custom protoc plugin to generate custom output from .proto files. I literally copied java file containing CodeGenerator from protoc custom plugin as a starting point and renamed it. I also followed executable and created .sh file. The content of my shell script is as follows.

example.sh

I also add the PATH variable value and output of the plugin execution. Can someone point me where I am going wrong with this? The shell script runs fine separately executing the main method

enter image description here

3

There are 3 best solutions below

0
On

how about using absolute path of example.sh? protoc working directory may not be current folder.

0
On

If that is your entire example.sh, it won't work because it doesn't have a "hashbang" line identifying the script interpreter.

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.

0
On

The protoc error messaging is a little cryptic here. You have 3 options for providing a plugin to protoc:

  1. A plugin in your $PATH following the protoc-gen-$NAME format. This will be automatically picked up.
  2. A plugin not conforming to the above naming convention, but available in your $PATH. This can be executed with the --plugin=$some-nonconventional-name.
  3. A plugin not in your $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

Expanding on 3 above. If you create a file 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:

mdkir plugin-output

We need a .proto file. Find one and name it anything you like, like MyProto.proto

Let's pick an arbitrary name for this plugin. We can call it foo.

Then you'll execute it with protoc as follows:

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