chen3feng / blade-build

Blade is a powerful build system from Tencent, supports many mainstream programming languages, such as C/C++, java, scala, python, protobuf...
Other
2.05k stars 497 forks source link

Change protobuf java plugin output directory #1011

Closed WindLeeWT closed 1 year ago

WindLeeWT commented 1 year ago

When generating java files from protobuf, blade automatically adds target directory as output directory as below:

thirdparty/protobuf/bin/x86_64/protoc-2.5.0 --proto_path=. -I=thirdparty --java_out=build64_release/`dirname java/com/gdt/log_process/wx_log_convertor/conf.proto` java/com/gdt/log_process/wx_log_convertor/conf.proto

However, when we're going to insert some custom code by use of insertion points mechanism, it reports error whatever path we give to plugin output path:

[2/6] thirdparty/protobuf/bin/x86_64/protoc-2.5.0 --proto_path=. -I=thirdparty --java_out=build64_release/`dirname java/com/gdt/log_process/wx_log_convertor/conf.proto` --plugin=protoc-gen-java_field_tracking=thirdparty/protobuf/bin/plugin/governance/java_field_tracking_generator --java_field_tracking_out=build64_release java/com/gdt/log_process/wx_log_convertor/conf.proto
FAILED: build64_release/java/com/gdt/log_process/wx_log_convertor/com/gdt/log_process/wx_log_convertor/Conf.java 
thirdparty/protobuf/bin/x86_64/protoc-2.5.0 --proto_path=. -I=thirdparty --java_out=build64_release/`dirname java/com/gdt/log_process/wx_log_convertor/conf.proto` --plugin=protoc-gen-java_field_tracking=thirdparty/protobuf/bin/plugin/governance/java_field_tracking_generator --java_field_tracking_out=build64_release java/com/gdt/log_process/wx_log_convertor/conf.proto
com/gdt/log_process/wx_log_convertor/Conf.java: Tried to insert into file that doesn't exist.

Checking related code in protoc from the error message, we see that there are two stages here:

  1. protoc generates native java code as before with some insertion points inside. The output location is build64_release/dirname java/com/gdt/log_process/wx_log_convertor/conf.proto denoted by dir1
  2. protoc inserts custom code generated by the plugin. It searches for the output source from output location --java_field_tracking_out=... denote by dir2

It seems dir1 and dir2 should be the same, otherwise protoc complain that Tried to insert into file that doesn't exist.