Created
October 25, 2022 11:46
-
-
Save prenaux/2b1e0a8199533556a15123207d93d2cf to your computer and use it in GitHub Desktop.
ham rules to generate Protoc C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ProtocToCpp TARGET : input.proto ; | |
| rule ProtocToCpp { | |
| local genDir = _pb ; | |
| local input = [ FGristFiles $(2) ] ; | |
| local cpp = [ FGristFiles [ FDirName $(input:D) $(genDir) $(input:B).pb.cc ] ] ; | |
| local h = [ FGristFiles [ FDirName $(input:D) $(genDir) $(input:B).pb.h ] ] ; | |
| local outDir = [ FGetAbsolutePath [ FDirName $(input:D) $(genDir) ] ] ; | |
| ProtocRun_ $(cpp) $(h) : $(input) : $(genDir) : $(outDir) ; | |
| DEPENDS protoc-to-cpp : $(cpp) $(h) ; | |
| NOTFILE protoc-to-cpp ; | |
| return [ FDirName $(genDir) $(input:BS=.pb.cc) ] ; | |
| } | |
| # ProtocToRun_ OUTPUTS : INPUT : GEN_DIR : OUT_DIR ; | |
| rule ProtocRun_ { | |
| DEPENDS $(<) : $(>) ; | |
| INPUT_PROTO on $(<) = $(2) ; | |
| GEN_DIR on $(<) = $(3) ; | |
| OUT_DIR on $(<) = $(4) ; | |
| return $(1) ; | |
| } | |
| actions ProtocRun_ { | |
| . "$HAM_HOME/bin/ham-bash-lib.sh" | |
| mkdir -p "$(OUT_DIR)" | |
| cd "$(INPUT_PROTO:D)" | |
| protoc --cpp_out="$(OUT_DIR)" "$(INPUT_PROTO:BS)" | |
| # Prepend clang-format off & remove trailing whitespace | |
| echo "// clang-format off" > "_tmp_trimmed.cc" | |
| sed -E 's/[[:space:]]*$//' "$(OUT_DIR)/$(INPUT_PROTO:BS=).pb.cc" >> "_tmp_trimmed.cc" | |
| mv "_tmp_trimmed.cc" "$(OUT_DIR)/$(INPUT_PROTO:BS=).pb.cc" | |
| # Prepend clang-format off & remove trailing whitespace | |
| echo "// clang-format off" > "_tmp_trimmed.h" | |
| sed -E 's/[[:space:]]*$//' "$(OUT_DIR)/$(INPUT_PROTO:BS=).pb.h" >> "_tmp_trimmed.h" | |
| mv "_tmp_trimmed.h" "$(OUT_DIR)/$(INPUT_PROTO:BS=).pb.h" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment