generate-podspec.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. SUPPORTED_SWIFT_VERSIONS=''
  66. for SPM_PKG_DEF in Package@swift-*.swift; do
  67. SWIFT_VERSION="$(echo "${SPM_PKG_DEF}" | sed -E 's/^Package@swift-([0-9]+\.[0-9]+)\.swift$/\1/g')"
  68. if [[ -n "${SWIFT_VERSION}" ]] && [[ "${SWIFT_VERSION}" != "${SPM_PKG_DEF}" ]]; then
  69. # We add the comma to the end here, since we will add the last version at the end.
  70. SUPPORTED_SWIFT_VERSIONS="${SUPPORTED_SWIFT_VERSIONS}'${SWIFT_VERSION}', "
  71. fi
  72. done
  73. SUPPORTED_SWIFT_VERSIONS="${SUPPORTED_SWIFT_VERSIONS}'$(swift package tools-version | awk -F'.' '{print $1"."$2}')'"
  74. popd > /dev/null
  75. # Verify variables
  76. # ################
  77. echo 'Verifying config...'
  78. if [[ -z "${CURRENT_VERSION}" ]]; then
  79. echo "Could not find MARKETING_VERSION in ${VERSION_XCCONFIG_FILE}!"
  80. exit -1
  81. elif [[ -n "${VERSION_TO_VERIFY}" ]] && [[ "${VERSION_TO_VERIFY}" != "${CURRENT_VERSION}" ]]; then
  82. echo "MARKETING_VERSION in ${VERSION_XCCONFIG_FILE} is ${CURRENT_VERSION}, but ${VERSION_TO_VERIFY} was expected!"
  83. exit -1
  84. fi
  85. if [[ -z "${MACOS_SDK}" ]]; then
  86. echo "Could not find ${MACOS_SDK_CONFIG_VAR} in ${SDKS_XCCONFIG_FILE}!"
  87. exit -1
  88. fi
  89. if [[ -z "${IOS_SDK}" ]]; then
  90. echo "Could not find ${IOS_SDK_CONFIG_VAR} in ${SDKS_XCCONFIG_FILE}!"
  91. exit -1
  92. fi
  93. if [[ -z "${TVOS_SDK}" ]]; then
  94. echo "Could not find ${TVOS_SDK_CONFIG_VAR} in ${SDKS_XCCONFIG_FILE}!"
  95. exit -1
  96. fi
  97. if [[ -z "${WATCHOS_SDK}" ]]; then
  98. echo "Could not find ${WATCHOS_SDK_CONFIG_VAR} in ${SDKS_XCCONFIG_FILE}!"
  99. exit -1
  100. fi
  101. # Generate podspec
  102. # ################
  103. echo "Generating podspec..."
  104. pushd "$(dirname $0)/../" > /dev/null
  105. cat << EOF > ./CocoaLumberjack.podspec
  106. Pod::Spec.new do |s|
  107. s.name = 'CocoaLumberjack'
  108. s.version = '${CURRENT_VERSION}'
  109. s.license = 'BSD'
  110. s.summary = 'A fast & simple, yet powerful & flexible logging framework for macOS, iOS, tvOS and watchOS.'
  111. s.authors = { 'Robbie Hanson' => 'robbiehanson@deusty.com' }
  112. s.homepage = 'https://github.com/CocoaLumberjack/CocoaLumberjack'
  113. s.source = { :git => 'https://github.com/CocoaLumberjack/CocoaLumberjack.git',
  114. :tag => "#{s.version}" }
  115. s.description = 'It is similar in concept to other popular logging frameworks such as log4j, ' \\
  116. 'yet is designed specifically for objective-c, and takes advantage of features ' \\
  117. 'such as multi-threading, grand central dispatch (if available), lockless ' \\
  118. 'atomic operations, and the dynamic nature of the objective-c runtime.'
  119. s.cocoapods_version = '>= 1.7.0'
  120. s.swift_versions = [${SUPPORTED_SWIFT_VERSIONS}]
  121. s.osx.deployment_target = '${MACOS_SDK}'
  122. s.ios.deployment_target = '${IOS_SDK}'
  123. s.tvos.deployment_target = '${TVOS_SDK}'
  124. s.watchos.deployment_target = '${WATCHOS_SDK}'
  125. s.preserve_paths = 'README.md', 'LICENSE', 'CHANGELOG.md'
  126. s.default_subspecs = 'Core'
  127. s.subspec 'Core' do |ss|
  128. ss.source_files = 'Sources/CocoaLumberjack/**/*.{h,m}'
  129. ss.private_header_files = 'Sources/CocoaLumberjack/DD*Internal.{h}'
  130. ss.resources = 'Sources/CocoaLumberjack/PrivacyInfo.xcprivacy'
  131. end
  132. s.subspec 'Swift' do |ss|
  133. ss.dependency 'CocoaLumberjack/Core'
  134. ss.source_files = 'Sources/CocoaLumberjackSwift/**/*.swift', 'Sources/CocoaLumberjackSwiftSupport/include/**/*.{h}'
  135. end
  136. end
  137. EOF
  138. popd > /dev/null