generate-podspec.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/bin/bash
  2. set -euo pipefail
  3. SCRIPT_NAME="$(basename $0)"
  4. # Functions
  5. # #########
  6. # Arg1: Mode (full, usage_only). Defaults to 'full'.
  7. print_usage() {
  8. echo "Usage: ${SCRIPT_NAME} [VERSION]"
  9. if [[ "${1:-full}" == 'full' ]]; then
  10. echo ''
  11. echo 'Generates the podspec file for the current project.'
  12. echo 'Platform requirements (min SDKs), version are read from the xcconfig files.'
  13. echo 'If called with VERSION, the script verifies that the current MARKETING_VERSION in the xcconfig matches VERSION.'
  14. echo ''
  15. echo 'Examples:'
  16. echo "$ ${SCRIPT_NAME} # Gemerates podspec without verifying the MARKETING_VERSION against a given constant."
  17. echo "$ ${SCRIPT_NAME} 1.2.3 # Generates podspec and verifies that MARKETING_VERSION is 1.2.3."
  18. fi
  19. }
  20. # Arg1: Config variable name
  21. # Arg2: Config value pattern (regex) - must escape forward slashes (used as sed separator)
  22. # Arg3: Config file path
  23. read_config_var() {
  24. sed -nE "s/^ *${1} *= *(${2}) *$/\1/p" "${3}"
  25. return $?
  26. }
  27. # Parse arguments
  28. # ###############
  29. VERSION_TO_VERIFY=''
  30. if [[ $# -gt 0 ]]; then
  31. if [[ $# -eq 1 ]]; then
  32. if [[ $1 == '--help' ]] || [[ $1 == '-h' ]]; then
  33. print_usage 'full'
  34. exit 0
  35. fi
  36. VERSION_TO_VERIFY="$1"
  37. else
  38. echo 'Invalid number of arguments!'
  39. echo 'For more information use --help.'
  40. echo ''
  41. print_usage 'usage_only'
  42. exit -1
  43. fi
  44. fi
  45. # Define variables
  46. # ################
  47. SHARED_XCCONFIG_FILE='./Configs/Module-Shared.xcconfig'
  48. # We define separate vars here in case we ever split it up.
  49. VERSION_XCCONFIG_FILE="${SHARED_XCCONFIG_FILE}"
  50. SDKS_XCCONFIG_FILE="${SHARED_XCCONFIG_FILE}"
  51. VERSION_CONFIG_VAR='MARKETING_VERSION'
  52. MACOS_SDK_CONFIG_VAR='MACOSX_DEPLOYMENT_TARGET'
  53. IOS_SDK_CONFIG_VAR='IPHONEOS_DEPLOYMENT_TARGET'
  54. TVOS_SDK_CONFIG_VAR='TVOS_DEPLOYMENT_TARGET'
  55. WATCHOS_SDK_CONFIG_VAR='WATCHOS_DEPLOYMENT_TARGET'
  56. # Read files
  57. # ##########
  58. echo 'Reading config...'
  59. pushd "$(dirname $0)/../" > /dev/null
  60. CURRENT_VERSION="$(read_config_var "${VERSION_CONFIG_VAR}" '[0-9]+\.[0-9]+\.[0-9]+' "${VERSION_XCCONFIG_FILE}")"
  61. MACOS_SDK="$(read_config_var "${MACOS_SDK_CONFIG_VAR}" '[0-9]+\.[0-9]+' "${SDKS_XCCONFIG_FILE}")"
  62. IOS_SDK="$(read_config_var "${IOS_SDK_CONFIG_VAR}" '[0-9]+\.[0-9]+' "${SDKS_XCCONFIG_FILE}")"
  63. TVOS_SDK="$(read_config_var "${TVOS_SDK_CONFIG_VAR}" '[0-9]+\.[0-9]+' "${SDKS_XCCONFIG_FILE}")"
  64. WATCHOS_SDK="$(read_config_var "${WATCHOS_SDK_CONFIG_VAR}" '[0-9]+\.[0-9]+' "${SDKS_XCCONFIG_FILE}")"
  65. popd > /dev/null
  66. # Verify variables
  67. # ################
  68. echo 'Verifying config...'
  69. if [[ -z "${CURRENT_VERSION}" ]]; then
  70. echo "Could not find MARKETING_VERSION in ${VERSION_XCCONFIG_FILE}!"
  71. exit -1
  72. elif [[ -n "${VERSION_TO_VERIFY}" ]] && [[ "${VERSION_TO_VERIFY}" != "${CURRENT_VERSION}" ]]; then
  73. echo "MARKETING_VERSION in ${VERSION_XCCONFIG_FILE} is ${CURRENT_VERSION}, but ${VERSION_TO_VERIFY} was expected!"
  74. exit -1
  75. fi
  76. if [[ -z "${MACOS_SDK}" ]]; then
  77. echo "Could not find ${MACOS_SDK_CONFIG_VAR} in ${SDKS_XCCONFIG_FILE}!"
  78. exit -1
  79. fi
  80. if [[ -z "${IOS_SDK}" ]]; then
  81. echo "Could not find ${IOS_SDK_CONFIG_VAR} in ${SDKS_XCCONFIG_FILE}!"
  82. exit -1
  83. fi
  84. if [[ -z "${TVOS_SDK}" ]]; then
  85. echo "Could not find ${TVOS_SDK_CONFIG_VAR} in ${SDKS_XCCONFIG_FILE}!"
  86. exit -1
  87. fi
  88. if [[ -z "${WATCHOS_SDK}" ]]; then
  89. echo "Could not find ${WATCHOS_SDK_CONFIG_VAR} in ${SDKS_XCCONFIG_FILE}!"
  90. exit -1
  91. fi
  92. # Generate podspec
  93. # ################
  94. echo "Generating podspec..."
  95. pushd "$(dirname $0)/../" > /dev/null
  96. cat << EOF > ./CocoaLumberjack.podspec
  97. Pod::Spec.new do |s|
  98. s.name = 'CocoaLumberjack'
  99. s.version = '${CURRENT_VERSION}'
  100. s.license = 'BSD'
  101. s.summary = 'A fast & simple, yet powerful & flexible logging framework for macOS, iOS, tvOS and watchOS.'
  102. s.authors = { 'Robbie Hanson' => 'robbiehanson@deusty.com' }
  103. s.homepage = 'https://github.com/CocoaLumberjack/CocoaLumberjack'
  104. s.source = { :git => 'https://github.com/CocoaLumberjack/CocoaLumberjack.git',
  105. :tag => "#{s.version}" }
  106. s.description = 'It is similar in concept to other popular logging frameworks such as log4j, ' \\
  107. 'yet is designed specifically for objective-c, and takes advantage of features ' \\
  108. 'such as multi-threading, grand central dispatch (if available), lockless ' \\
  109. 'atomic operations, and the dynamic nature of the objective-c runtime.'
  110. s.cocoapods_version = '>= 1.7.0'
  111. s.swift_versions = ['5.5', '5.6', '5.7', '5.8']
  112. s.osx.deployment_target = '${MACOS_SDK}'
  113. s.ios.deployment_target = '${IOS_SDK}'
  114. s.tvos.deployment_target = '${TVOS_SDK}'
  115. s.watchos.deployment_target = '${WATCHOS_SDK}'
  116. s.preserve_paths = 'README.md', 'LICENSE', 'CHANGELOG.md'
  117. s.default_subspecs = 'Core'
  118. s.subspec 'Core' do |ss|
  119. ss.source_files = 'Sources/CocoaLumberjack/**/*.{h,m}'
  120. ss.private_header_files = 'Sources/CocoaLumberjack/DD*Internal.{h}'
  121. end
  122. s.subspec 'Swift' do |ss|
  123. ss.dependency 'CocoaLumberjack/Core'
  124. ss.source_files = 'Sources/CocoaLumberjackSwift/**/*.swift', 'Sources/CocoaLumberjackSwiftSupport/include/**/*.{h}'
  125. end
  126. end
  127. EOF
  128. popd > /dev/null