compile_testing_protos.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_arena.proto
  61. src/google/protobuf/unittest_custom_options.proto
  62. src/google/protobuf/unittest_enormous_descriptor.proto
  63. src/google/protobuf/unittest_embed_optimize_for.proto
  64. src/google/protobuf/unittest_empty.proto
  65. src/google/protobuf/unittest_import.proto
  66. src/google/protobuf/unittest_import_lite.proto
  67. src/google/protobuf/unittest_lite.proto
  68. src/google/protobuf/unittest_mset.proto
  69. src/google/protobuf/unittest_mset_wire_format.proto
  70. src/google/protobuf/unittest_no_arena.proto
  71. src/google/protobuf/unittest_no_arena_import.proto
  72. src/google/protobuf/unittest_no_generic_services.proto
  73. src/google/protobuf/unittest_optimize_for.proto
  74. src/google/protobuf/unittest.proto
  75. src/google/protobuf/unittest_import_public.proto
  76. src/google/protobuf/unittest_import_public_lite.proto
  77. src/google/protobuf/unittest_drop_unknown_fields.proto
  78. src/google/protobuf/unittest_preserve_unknown_enum.proto
  79. src/google/protobuf/map_lite_unittest.proto
  80. src/google/protobuf/map_proto2_unittest.proto
  81. src/google/protobuf/map_unittest.proto
  82. )
  83. # The unittest_custom_options.proto extends the messages in descriptor.proto
  84. # so we build it in to test extending in general. The library doesn't provide
  85. # a descriptor as it doesn't use the classes/enums.
  86. CORE_PROTO_FILES+=(
  87. src/google/protobuf/descriptor.proto
  88. )
  89. compile_proto() {
  90. src/protoc \
  91. --objc_out="${OUTPUT_DIR}/google/protobuf" \
  92. --proto_path=src/google/protobuf/ \
  93. --proto_path=src \
  94. $*
  95. }
  96. for a_proto in "${CORE_PROTO_FILES[@]}" ; do
  97. compile_proto "${a_proto}"
  98. done
  99. OBJC_PROTO_FILES=(
  100. objectivec/Tests/unittest_cycle.proto
  101. objectivec/Tests/unittest_runtime_proto2.proto
  102. objectivec/Tests/unittest_runtime_proto3.proto
  103. objectivec/Tests/unittest_objc.proto
  104. objectivec/Tests/unittest_objc_startup.proto
  105. )
  106. for a_proto in "${OBJC_PROTO_FILES[@]}" ; do
  107. compile_proto --proto_path="objectivec/Tests" "${a_proto}"
  108. done