aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/build_rules
diff options
context:
space:
mode:
authorGravatar Julio Merino <jmmv@google.com>2016-02-22 19:27:18 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-02-23 13:08:29 +0000
commit19e995368f7a72aab9175136f6608d8c8672204c (patch)
tree0fb91f081a0e37426eff7f9c3b54c7d4d59354fc /tools/build_rules
parent443c730fd1cdc8ae229c95823f9d7059aedb139f (diff)
Allow preprocessing proto files before compiling them in gensrcjar.sh.
-- MOS_MIGRATED_REVID=115250659
Diffstat (limited to 'tools/build_rules')
-rwxr-xr-xtools/build_rules/gensrcjar.sh17
1 files changed, 15 insertions, 2 deletions
diff --git a/tools/build_rules/gensrcjar.sh b/tools/build_rules/gensrcjar.sh
index 365aaa86e3..b94408a703 100755
--- a/tools/build_rules/gensrcjar.sh
+++ b/tools/build_rules/gensrcjar.sh
@@ -18,7 +18,10 @@
# We use environment variables instead of positional arguments or flags for
# clarity in the caller .bzl file and for simplicity of processing. There is no
# need to implement a full-blown argument parser for this simple script.
-INPUT_VARS="JAR OUTPUT PROTO_COMPILER SOURCE"
+INPUT_VARS="JAR OUTPUT PREPROCESSOR PROTO_COMPILER SOURCE"
+
+# Now set defaults for optional input variables.
+: "${PREPROCESSOR:=cat}"
# Basename of the script for error reporting purposes.
PROGRAM_NAME="${0##*/}"
@@ -52,7 +55,17 @@ main() {
rm -rf "${proto_output}"
mkdir -p "${proto_output}"
- "${PROTO_COMPILER}" --java_out="${proto_output}" "${SOURCE}" \
+ # Apply desired preprocessing to the input proto file. For this to work, we
+ # must maintain the name of the original .proto file or else the generated
+ # classes in the JAR file would have an invalid name.
+ local processed_dir="${OUTPUT}.preprocessed"
+ rm -rf "${processed_dir}"
+ mkdir -p "${processed_dir}"
+ local processed_source="${processed_dir}/$(basename "${SOURCE}")"
+ "${PREPROCESSOR}" <"${SOURCE}" >"${processed_source}" \
+ || err "Preprocessor ${PREPROCESSOR} failed"
+
+ "${PROTO_COMPILER}" --java_out="${proto_output}" "${processed_source}" \
|| err "proto_compiler failed"
find "${proto_output}" -exec touch -t "${TIMESTAMP}" '{}' \; \
|| err "Failed to reset timestamps"