compile_testing_protos.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. # Invoked by the Xcode projects to build the protos needed for the unittests.
  3. set -eu
  4. readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/protos"
  5. # Helper for bailing.
  6. die() {
  7. echo "Error: $1"
  8. exit 2
  9. }
  10. # What to do.
  11. case "${ACTION}" in
  12. "")
  13. # Build, fall thru
  14. ;;
  15. "clean")
  16. rm -rf "${OUTPUT_DIR}"
  17. exit 0
  18. ;;
  19. *)
  20. die "Unknown action requested: ${ACTION}"
  21. ;;
  22. esac
  23. # Move to the top of the protobuf directories.
  24. cd "${SRCROOT}/.."
  25. [[ -x src/protoc ]] || \
  26. die "Could not find the protoc binary; make sure you have built it (objectivec/DevTools/full_mac_build.sh -h)."
  27. RUN_PROTOC=no
  28. if [[ ! -d "${OUTPUT_DIR}" ]] ; then
  29. RUN_PROTOC=yes
  30. else
  31. # Find the newest input file (protos, compiler, and this script).
  32. # (these patterns catch some extra stuff, but better to over sample than
  33. # under)
  34. readonly NewestInput=$(find \
  35. src/google/protobuf/*.proto \
  36. objectivec/Tests/*.proto \
  37. src/.libs src/*.la src/protoc \
  38. objectivec/DevTools/compile_testing_protos.sh \
  39. -type f -print0 \
  40. | xargs -0 stat -f "%m %N" \
  41. | sort -n | tail -n1 | cut -f2- -d" ")
  42. # Find the oldest output file.
  43. readonly OldestOutput=$(find \
  44. "${OUTPUT_DIR}" \
  45. -type f -print0 \
  46. | xargs -0 stat -f "%m %N" \
  47. | sort -n -r | tail -n1 | cut -f2- -d" ")
  48. # If the newest input is newer than the oldest output, regenerate.
  49. if [[ "${NewestInput}" -nt "${OldestOutput}" ]] ; then
  50. RUN_PROTOC=yes
  51. fi
  52. fi
  53. if [[ "${RUN_PROTOC}" != "yes" ]] ; then
  54. # Up to date.
  55. exit 0
  56. fi
  57. # Ensure the output dir exists
  58. mkdir -p "${OUTPUT_DIR}/google/protobuf"
  59. CORE_PROTO_FILES=( \
  60. src/google/protobuf/unittest_custom_options.proto \
  61. src/google/protobuf/unittest_enormous_descriptor.proto \
  62. src/google/protobuf/unittest_embed_optimize_for.proto \
  63. src/google/protobuf/unittest_empty.proto \
  64. src/google/protobuf/unittest_import.proto \
  65. src/google/protobuf/unittest_import_lite.proto \
  66. src/google/protobuf/unittest_lite.proto \
  67. src/google/protobuf/unittest_mset.proto \
  68. src/google/protobuf/unittest_no_generic_services.proto \
  69. src/google/protobuf/unittest_optimize_for.proto \
  70. src/google/protobuf/unittest.proto \
  71. src/google/protobuf/unittest_import_public.proto \
  72. src/google/protobuf/unittest_import_public_lite.proto \
  73. src/google/protobuf/unittest_drop_unknown_fields.proto \
  74. src/google/protobuf/unittest_preserve_unknown_enum.proto \
  75. src/google/protobuf/map_lite_unittest.proto \
  76. src/google/protobuf/map_proto2_unittest.proto \
  77. src/google/protobuf/map_unittest.proto \
  78. )
  79. compile_proto() {
  80. src/protoc \
  81. --objc_out="${OUTPUT_DIR}/google/protobuf" \
  82. --proto_path=src/google/protobuf/ \
  83. --proto_path=src \
  84. $*
  85. }
  86. for a_proto in "${CORE_PROTO_FILES[@]}" ; do
  87. compile_proto "${a_proto}"
  88. done
  89. OBJC_PROTO_FILES=( \
  90. objectivec/Tests/unittest_cycle.proto \
  91. objectivec/Tests/unittest_runtime_proto2.proto \
  92. objectivec/Tests/unittest_runtime_proto3.proto \
  93. objectivec/Tests/unittest_objc.proto \
  94. objectivec/Tests/unittest_objc_startup.proto \
  95. )
  96. for a_proto in "${OBJC_PROTO_FILES[@]}" ; do
  97. compile_proto --proto_path="objectivec/Tests" "${a_proto}"
  98. done