generate_test_protos.sh 1.2 KB

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