compile_testing_protos.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/bin/bash -eu
  2. # Invoked by the Xcode projects to build the protos needed for the unittests.
  3. readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/protos"
  4. # -----------------------------------------------------------------------------
  5. # Helper for bailing.
  6. die() {
  7. echo "Error: $1"
  8. exit 2
  9. }
  10. # -----------------------------------------------------------------------------
  11. # What to do.
  12. case "${ACTION}" in
  13. "")
  14. # Build, fall thru
  15. ;;
  16. "clean")
  17. rm -rf "${OUTPUT_DIR}"
  18. exit 0
  19. ;;
  20. *)
  21. die "Unknown action requested: ${ACTION}"
  22. ;;
  23. esac
  24. # -----------------------------------------------------------------------------
  25. # Ensure the output dir exists
  26. mkdir -p "${OUTPUT_DIR}/google/protobuf"
  27. # -----------------------------------------------------------------------------
  28. # Move to the top of the protobuf directories and ensure there is a protoc
  29. # binary to use.
  30. cd "${SRCROOT}/.."
  31. [[ -x src/protoc ]] || \
  32. die "Could not find the protoc binary; make sure you have built it (objectivec/DevTools/full_mac_build.sh -h)."
  33. # -----------------------------------------------------------------------------
  34. # See the compiler or proto files have changed.
  35. RUN_PROTOC=no
  36. if [[ ! -d "${OUTPUT_DIR}" ]] ; then
  37. RUN_PROTOC=yes
  38. else
  39. # Find the newest input file (protos, compiler, and this script).
  40. # (these patterns catch some extra stuff, but better to over sample than
  41. # under)
  42. readonly NewestInput=$(find \
  43. src/google/protobuf/*.proto \
  44. objectivec/Tests/*.proto \
  45. src/.libs src/*.la src/protoc \
  46. objectivec/DevTools/compile_testing_protos.sh \
  47. -type f -print0 \
  48. | xargs -0 stat -f "%m %N" \
  49. | sort -n | tail -n1 | cut -f2- -d" ")
  50. # Find the oldest output file.
  51. readonly OldestOutput=$(find \
  52. "${OUTPUT_DIR}" \
  53. -type f -name "*pbobjc.[hm]" -print0 \
  54. | xargs -0 stat -f "%m %N" \
  55. | sort -n -r | tail -n1 | cut -f2- -d" ")
  56. # If the newest input is newer than the oldest output, regenerate.
  57. if [[ "${NewestInput}" -nt "${OldestOutput}" ]] ; then
  58. RUN_PROTOC=yes
  59. fi
  60. fi
  61. if [[ "${RUN_PROTOC}" != "yes" ]] ; then
  62. # Up to date.
  63. exit 0
  64. fi
  65. # -----------------------------------------------------------------------------
  66. # Prune out all the files from previous generations to ensure we only have
  67. # current ones.
  68. find "${OUTPUT_DIR}" \
  69. -type f -name "*pbobjc.[hm]" -print0 \
  70. | xargs -0 rm -rf
  71. # -----------------------------------------------------------------------------
  72. # Helper to invoke protoc
  73. compile_protos() {
  74. src/protoc \
  75. --objc_out="${OUTPUT_DIR}/google/protobuf" \
  76. --proto_path=src/google/protobuf/ \
  77. --proto_path=src \
  78. "$@"
  79. }
  80. # -----------------------------------------------------------------------------
  81. # Generate most of the proto files that exist in the C++ src tree. Several
  82. # are used in the tests, but the extra don't hurt in that they ensure ObjC
  83. # sources can be generated from them.
  84. CORE_PROTO_FILES=(
  85. src/google/protobuf/any_test.proto
  86. src/google/protobuf/unittest_arena.proto
  87. src/google/protobuf/unittest_custom_options.proto
  88. src/google/protobuf/unittest_enormous_descriptor.proto
  89. src/google/protobuf/unittest_embed_optimize_for.proto
  90. src/google/protobuf/unittest_empty.proto
  91. src/google/protobuf/unittest_import.proto
  92. src/google/protobuf/unittest_import_lite.proto
  93. src/google/protobuf/unittest_lite.proto
  94. src/google/protobuf/unittest_mset.proto
  95. src/google/protobuf/unittest_mset_wire_format.proto
  96. src/google/protobuf/unittest_no_arena.proto
  97. src/google/protobuf/unittest_no_arena_import.proto
  98. src/google/protobuf/unittest_no_generic_services.proto
  99. src/google/protobuf/unittest_optimize_for.proto
  100. src/google/protobuf/unittest.proto
  101. src/google/protobuf/unittest_import_public.proto
  102. src/google/protobuf/unittest_import_public_lite.proto
  103. src/google/protobuf/unittest_drop_unknown_fields.proto
  104. src/google/protobuf/unittest_preserve_unknown_enum.proto
  105. src/google/protobuf/map_lite_unittest.proto
  106. src/google/protobuf/map_proto2_unittest.proto
  107. src/google/protobuf/map_unittest.proto
  108. # The unittest_custom_options.proto extends the messages in descriptor.proto
  109. # so we build it in to test extending in general. The library doesn't provide
  110. # a descriptor as it doesn't use the classes/enums.
  111. src/google/protobuf/descriptor.proto
  112. )
  113. # Note: there is overlap in package.Message names between some of the test
  114. # files, so they can't be generated all at once. This works because the overlap
  115. # isn't linked into a single binary.
  116. for a_proto in "${CORE_PROTO_FILES[@]}" ; do
  117. compile_protos "${a_proto}"
  118. done
  119. # -----------------------------------------------------------------------------
  120. # Generate the Objective C specific testing protos.
  121. compile_protos \
  122. --proto_path="objectivec/Tests" \
  123. objectivec/Tests/unittest_cycle.proto \
  124. objectivec/Tests/unittest_deprecated.proto \
  125. objectivec/Tests/unittest_deprecated_file.proto \
  126. objectivec/Tests/unittest_extension_chain_a.proto \
  127. objectivec/Tests/unittest_extension_chain_b.proto \
  128. objectivec/Tests/unittest_extension_chain_c.proto \
  129. objectivec/Tests/unittest_extension_chain_d.proto \
  130. objectivec/Tests/unittest_extension_chain_e.proto \
  131. objectivec/Tests/unittest_extension_chain_f.proto \
  132. objectivec/Tests/unittest_extension_chain_g.proto \
  133. objectivec/Tests/unittest_runtime_proto2.proto \
  134. objectivec/Tests/unittest_runtime_proto3.proto \
  135. objectivec/Tests/unittest_objc.proto \
  136. objectivec/Tests/unittest_objc_startup.proto