Joshua Haberman | 8b87075 | 2021-05-04 10:19:22 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Adam Cozzette | ed1d744 | 2021-08-06 15:53:14 -0700 | [diff] [blame] | 3 | set -ex |
Joshua Haberman | 8b87075 | 2021-05-04 10:19:22 -0700 | [diff] [blame] | 4 | |
Mike Kruskal | ed5c57a | 2022-08-10 22:51:29 -0700 | [diff] [blame] | 5 | cd `dirname $0`/.. |
Joshua Haberman | 8b87075 | 2021-05-04 10:19:22 -0700 | [diff] [blame] | 6 | |
Mike Kruskal | 01c340d | 2022-09-19 09:50:19 -0700 | [diff] [blame] | 7 | if [[ -z "${PROTOC}" ]]; then |
| 8 | PROTOC=$(pwd)/protoc |
| 9 | fi |
Mike Kruskal | ed5c57a | 2022-08-10 22:51:29 -0700 | [diff] [blame] | 10 | if [ ! -f $PROTOC ]; then |
Mike Kruskal | f0ef44d | 2023-02-02 15:53:04 -0800 | [diff] [blame] | 11 | ${BAZEL:-bazel} $BAZEL_STARTUP_FLAGS build -c opt //:protoc $BAZEL_FLAGS |
Mike Kruskal | ed5c57a | 2022-08-10 22:51:29 -0700 | [diff] [blame] | 12 | PROTOC=$(pwd)/bazel-bin/protoc |
Joshua Haberman | 45e9707 | 2021-05-12 10:42:16 -0700 | [diff] [blame] | 13 | fi |
| 14 | |
Mike Kruskal | ed5c57a | 2022-08-10 22:51:29 -0700 | [diff] [blame] | 15 | if [[ -d php/tmp && -z $(find php/tests/proto $PROTOC -newer php/tmp) ]]; then |
Joshua Haberman | 8b87075 | 2021-05-04 10:19:22 -0700 | [diff] [blame] | 16 | # Generated protos are already present and up to date, so we can skip protoc. |
| 17 | # |
| 18 | # Protoc is very fast, but sometimes it is not available (like if we haven't |
| 19 | # built it in Docker). Skipping it helps us proceed in this case. |
| 20 | echo "Test protos are up-to-date, skipping protoc." |
| 21 | exit 0 |
| 22 | fi |
| 23 | |
Mike Kruskal | ed5c57a | 2022-08-10 22:51:29 -0700 | [diff] [blame] | 24 | rm -rf php/tmp |
| 25 | mkdir -p php/tmp |
Joshua Haberman | 8b87075 | 2021-05-04 10:19:22 -0700 | [diff] [blame] | 26 | |
Joshua Haberman | 45e9707 | 2021-05-12 10:42:16 -0700 | [diff] [blame] | 27 | find php/tests/proto -type f -name "*.proto"| xargs $PROTOC --php_out=php/tmp -Isrc -Iphp/tests |
Joshua Haberman | 8b87075 | 2021-05-04 10:19:22 -0700 | [diff] [blame] | 28 | |
| 29 | if [ "$1" = "--aggregate_metadata" ]; then |
| 30 | # Overwrite some of the files to use aggregation. |
| 31 | AGGREGATED_FILES="tests/proto/test.proto tests/proto/test_include.proto tests/proto/test_import_descriptor_proto.proto" |
Joshua Haberman | 45e9707 | 2021-05-12 10:42:16 -0700 | [diff] [blame] | 32 | $PROTOC --php_out=aggregate_metadata=foo#bar:php/tmp -Isrc -Iphp/tests $AGGREGATED_FILES |
Joshua Haberman | 8b87075 | 2021-05-04 10:19:22 -0700 | [diff] [blame] | 33 | fi |
| 34 | |
| 35 | echo "Generated test protos from tests/proto -> tmp" |