xref: /aosp_15_r20/external/protobuf/php/generate_test_protos.sh (revision 1b3f573f81763fcece89efc2b6a5209149e44ab8)
1*1b3f573fSAndroid Build Coastguard Worker#!/bin/bash
2*1b3f573fSAndroid Build Coastguard Worker
3*1b3f573fSAndroid Build Coastguard Workerset -ex
4*1b3f573fSAndroid Build Coastguard Worker
5*1b3f573fSAndroid Build Coastguard Workercd `dirname $0`
6*1b3f573fSAndroid Build Coastguard Worker
7*1b3f573fSAndroid Build Coastguard Workerif ../src/protoc --help > /dev/null; then
8*1b3f573fSAndroid Build Coastguard Worker  PROTOC=src/protoc
9*1b3f573fSAndroid Build Coastguard Workerelse
10*1b3f573fSAndroid Build Coastguard Worker  # Bazel seems to be creating a problematic symlink in
11*1b3f573fSAndroid Build Coastguard Worker  # _build/out/external/com_google_protobuf, so we remove the _build directory
12*1b3f573fSAndroid Build Coastguard Worker  # before building protoc.
13*1b3f573fSAndroid Build Coastguard Worker  (cd .. && bazel build -c opt :protoc)
14*1b3f573fSAndroid Build Coastguard Worker  PROTOC=bazel-bin/protoc
15*1b3f573fSAndroid Build Coastguard Workerfi
16*1b3f573fSAndroid Build Coastguard Worker
17*1b3f573fSAndroid Build Coastguard Workerif [[ -d tmp && -z $(find tests/proto ../$PROTOC -newer tmp) ]]; then
18*1b3f573fSAndroid Build Coastguard Worker  # Generated protos are already present and up to date, so we can skip protoc.
19*1b3f573fSAndroid Build Coastguard Worker  #
20*1b3f573fSAndroid Build Coastguard Worker  # Protoc is very fast, but sometimes it is not available (like if we haven't
21*1b3f573fSAndroid Build Coastguard Worker  # built it in Docker). Skipping it helps us proceed in this case.
22*1b3f573fSAndroid Build Coastguard Worker  echo "Test protos are up-to-date, skipping protoc."
23*1b3f573fSAndroid Build Coastguard Worker  exit 0
24*1b3f573fSAndroid Build Coastguard Workerfi
25*1b3f573fSAndroid Build Coastguard Worker
26*1b3f573fSAndroid Build Coastguard Workerrm -rf tmp
27*1b3f573fSAndroid Build Coastguard Workermkdir -p tmp
28*1b3f573fSAndroid Build Coastguard Worker
29*1b3f573fSAndroid Build Coastguard Workercd ..
30*1b3f573fSAndroid Build Coastguard Workerfind php/tests/proto -type f -name "*.proto"| xargs $PROTOC --php_out=php/tmp -Isrc -Iphp/tests
31*1b3f573fSAndroid Build Coastguard Worker
32*1b3f573fSAndroid Build Coastguard Workerif [ "$1" = "--aggregate_metadata" ]; then
33*1b3f573fSAndroid Build Coastguard Worker  # Overwrite some of the files to use aggregation.
34*1b3f573fSAndroid Build Coastguard Worker  AGGREGATED_FILES="tests/proto/test.proto tests/proto/test_include.proto tests/proto/test_import_descriptor_proto.proto"
35*1b3f573fSAndroid Build Coastguard Worker  $PROTOC --php_out=aggregate_metadata=foo#bar:php/tmp -Isrc -Iphp/tests $AGGREGATED_FILES
36*1b3f573fSAndroid Build Coastguard Workerfi
37*1b3f573fSAndroid Build Coastguard Worker
38*1b3f573fSAndroid Build Coastguard Workerecho "Generated test protos from tests/proto -> tmp"
39