Class: Pod::Generator::CopyResourcesScript
- Inherits:
-
Object
- Object
- Pod::Generator::CopyResourcesScript
- Defined in:
- lib/cocoapods/generator/copy_resources_script.rb
Private Helpers collapse
- EXTERNAL_STRINGS_FILE_MIMINUM_DEPLOYMENT_TARGET =
Returns The minimum deployment target which supports the
--reference-external-strings-file
option for theibtool
command. { :ios => Version.new('6.0'), :osx => Version.new('10.8'), :watchos => Version.new('2.0'), :tvos => Version.new('9.0'), :visionos => Version.new('1.0'), }
- INSTALL_RESOURCES_FUNCTION =
<<EOS #{Pod::Generator::ScriptPhaseConstants::DEFAULT_SCRIPT_PHASE_HEADER} if [ -z ${UNLOCALIZED_RESOURCES_FOLDER_PATH+x} ]; then # If UNLOCALIZED_RESOURCES_FOLDER_PATH is not set, then there's nowhere for us to copy # resources to, so exit 0 (signalling the script phase was successful). exit 0 fi mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt > "$RESOURCES_TO_COPY" XCASSET_FILES=() #{Pod::Generator::ScriptPhaseConstants::RSYNC_PROTECT_TMP_FILES} case "${TARGETED_DEVICE_FAMILY:-}" in 1,2) TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" ;; 1) TARGET_DEVICE_ARGS="--target-device iphone" ;; 2) TARGET_DEVICE_ARGS="--target-device ipad" ;; 3) TARGET_DEVICE_ARGS="--target-device tv" ;; 4) TARGET_DEVICE_ARGS="--target-device watch" ;; *) TARGET_DEVICE_ARGS="--target-device mac" ;; esac install_resource() { if [[ "$1" = /* ]] ; then RESOURCE_PATH="$1" else RESOURCE_PATH="${PODS_ROOT}/$1" fi if [[ ! -e "$RESOURCE_PATH" ]] ; then cat << EOM error: Resource "$RESOURCE_PATH" not found. Run 'pod install' to update the copy resources script. EOM exit 1 fi case $RESOURCE_PATH in *\.storyboard) echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \\"$RESOURCE_PATH\\" .storyboard`.storyboardc $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" || true ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \\"$RESOURCE_PATH\\" .storyboard`.storyboardc" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} ;; *\.xib) echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \\"$RESOURCE_PATH\\" .xib`.nib $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" || true ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \\"$RESOURCE_PATH\\" .xib`.nib" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} ;; *.framework) echo "mkdir -p ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" || true mkdir -p "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" $RESOURCE_PATH ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" || true rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" ;; *.xcdatamodel) echo "xcrun momc \\"$RESOURCE_PATH\\" \\"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH"`.mom\\"" || true xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodel`.mom" ;; *.xcdatamodeld) echo "xcrun momc \\"$RESOURCE_PATH\\" \\"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd\\"" || true xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd" ;; *.xcmappingmodel) echo "xcrun mapc \\"$RESOURCE_PATH\\" \\"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm\\"" || true xcrun mapc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm" ;; *.xcassets) ABSOLUTE_XCASSET_FILE="$RESOURCE_PATH" XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") ;; *) echo "$RESOURCE_PATH" || true echo "$RESOURCE_PATH" >> "$RESOURCES_TO_COPY" ;; esac } EOS
- RSYNC_CALL =
<<EOS mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" fi rm -f "$RESOURCES_TO_COPY" EOS
- XCASSETS_COMPILE =
<<EOS if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "${XCASSET_FILES:-}" ] then # Find all other xcassets (this unfortunately includes those of path pods and other targets). OTHER_XCASSETS=$(find -L "$PWD" -iname "*.xcassets" -type d) while read line; do if [[ $line != "${PODS_ROOT}*" ]]; then XCASSET_FILES+=("$line") fi done <<<"$OTHER_XCASSETS" if [ -z ${ASSETCATALOG_COMPILER_APPICON_NAME+x} ]; then printf "%s\\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" else printf "%s\\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" --app-icon "${ASSETCATALOG_COMPILER_APPICON_NAME}" --output-partial-info-plist "${TARGET_TEMP_DIR}/assetcatalog_generated_info_cocoapods.plist" fi fi EOS
Instance Attribute Summary collapse
-
#platform ⇒ Platform
readonly
The platform of the library for which the copy resources script is needed.
-
#resources_by_config ⇒ Hash{String, Array{String}] A list of files relative to the project pods root, keyed by build configuration.
readonly
HashArray{String] A list of files relative to the project pods root, keyed by build configuration.
Private Helpers collapse
-
#install_resources_function ⇒ String
private
The install resources shell function.
-
#script ⇒ String
private
The contents of the copy resources script.
-
#use_external_strings_file? ⇒ Boolean
private
Whether the external strings file is supported by the
ibtool
according to the deployment target of the platform.
Instance Method Summary collapse
-
#generate ⇒ String
The contents of the copy resources script.
-
#initialize(resources_by_config, platform) ⇒ CopyResourcesScript
constructor
Initialize a new instance.
-
#save_as(pathname) ⇒ void
Saves the resource script to the given pathname.
Constructor Details
#initialize(resources_by_config, platform) ⇒ CopyResourcesScript
Initialize a new instance
22 23 24 25 |
# File 'lib/cocoapods/generator/copy_resources_script.rb', line 22 def initialize(resources_by_config, platform) @resources_by_config = resources_by_config @platform = platform end |
Instance Attribute Details
#platform ⇒ Platform (readonly)
Returns The platform of the library for which the copy resources script is needed.
12 13 14 |
# File 'lib/cocoapods/generator/copy_resources_script.rb', line 12 def platform @platform end |
#resources_by_config ⇒ Hash{String, Array{String}] A list of files relative to the project pods root, keyed by build configuration. (readonly)
Returns HashArray{String] A list of files relative to the project pods root, keyed by build configuration.
7 8 9 |
# File 'lib/cocoapods/generator/copy_resources_script.rb', line 7 def resources_by_config @resources_by_config end |
Instance Method Details
#generate ⇒ String
Returns The contents of the copy resources script.
43 44 45 |
# File 'lib/cocoapods/generator/copy_resources_script.rb', line 43 def generate script end |
#install_resources_function ⇒ String (private)
Returns The install resources shell function.
73 74 75 76 77 78 79 |
# File 'lib/cocoapods/generator/copy_resources_script.rb', line 73 def install_resources_function if use_external_strings_file? INSTALL_RESOURCES_FUNCTION else INSTALL_RESOURCES_FUNCTION.gsub(' --reference-external-strings-file', '') end end |
#save_as(pathname) ⇒ void
This method returns an undefined value.
Saves the resource script to the given pathname.
34 35 36 37 38 39 |
# File 'lib/cocoapods/generator/copy_resources_script.rb', line 34 def save_as(pathname) pathname.open('w') do |file| file.puts(script) end File.chmod(0755, pathname.to_s) end |
#script ⇒ String (private)
Returns The contents of the copy resources script.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cocoapods/generator/copy_resources_script.rb', line 83 def script # Define install function script = install_resources_function # Call function for each configuration-dependent resource resources_by_config.each do |config, resources| unless resources.empty? script += %(if [[ "$CONFIGURATION" == "#{config}" ]]; then\n) resources.each do |resource| script += %( install_resource "#{resource}"\n) end script += "fi\n" end end script += RSYNC_CALL script += XCASSETS_COMPILE script end |
#use_external_strings_file? ⇒ Boolean (private)
Returns Whether the external strings file is supported by the
ibtool
according to the deployment target of the platform.
66 67 68 69 |
# File 'lib/cocoapods/generator/copy_resources_script.rb', line 66 def use_external_strings_file? minimum_deployment_target = EXTERNAL_STRINGS_FILE_MIMINUM_DEPLOYMENT_TARGET[platform.name] platform.deployment_target >= minimum_deployment_target end |