Class: Pod::Generator::CopyResourcesScript

Inherits:
Object
  • Object
show all
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 the ibtool command.

Returns:

  • (Hash{Symbol=>Version})

    The minimum deployment target which supports the --reference-external-strings-file option for the ibtool 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 =
"\#{Pod::Generator::ScriptPhaseConstants::DEFAULT_SCRIPT_PHASE_HEADER}\nif [ -z ${UNLOCALIZED_RESOURCES_FOLDER_PATH+x} ]; then\n  # If UNLOCALIZED_RESOURCES_FOLDER_PATH is not set, then there's nowhere for us to copy\n  # resources to, so exit 0 (signalling the script phase was successful).\n  exit 0\nfi\n\nmkdir -p \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\"\n\nRESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt\n> \"$RESOURCES_TO_COPY\"\n\nXCASSET_FILES=()\n\n\#{Pod::Generator::ScriptPhaseConstants::RSYNC_PROTECT_TMP_FILES}\ncase \"${TARGETED_DEVICE_FAMILY:-}\" in\n  1,2)\n    TARGET_DEVICE_ARGS=\"--target-device ipad --target-device iphone\"\n    ;;\n  1)\n    TARGET_DEVICE_ARGS=\"--target-device iphone\"\n    ;;\n  2)\n    TARGET_DEVICE_ARGS=\"--target-device ipad\"\n    ;;\n  3)\n    TARGET_DEVICE_ARGS=\"--target-device tv\"\n    ;;\n  4)\n    TARGET_DEVICE_ARGS=\"--target-device watch\"\n    ;;\n  *)\n    TARGET_DEVICE_ARGS=\"--target-device mac\"\n    ;;\nesac\n\ninstall_resource()\n{\n  if [[ \"$1\" = /* ]] ; then\n    RESOURCE_PATH=\"$1\"\n  else\n    RESOURCE_PATH=\"${PODS_ROOT}/$1\"\n  fi\n  if [[ ! -e \"$RESOURCE_PATH\" ]] ; then\n    cat << EOM\nerror: Resource \"$RESOURCE_PATH\" not found. Run 'pod install' to update the copy resources script.\nEOM\n    exit 1\n  fi\n  case $RESOURCE_PATH in\n    *\\.storyboard)\n      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\n      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}\n      ;;\n    *\\.xib)\n      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\n      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}\n      ;;\n    *.framework)\n      echo \"mkdir -p ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}\" || true\n      mkdir -p \"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}\"\n      echo \"rsync --delete -av \"${RSYNC_PROTECT_TMP_FILES[@]}\" $RESOURCE_PATH ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}\" || true\n      rsync --delete -av \"${RSYNC_PROTECT_TMP_FILES[@]}\" \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}\"\n      ;;\n    *.xcdatamodel)\n      echo \"xcrun momc \\\\\"$RESOURCE_PATH\\\\\" \\\\\"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\"`.mom\\\\\"\" || true\n      xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xcdatamodel`.mom\"\n      ;;\n    *.xcdatamodeld)\n      echo \"xcrun momc \\\\\"$RESOURCE_PATH\\\\\" \\\\\"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xcdatamodeld`.momd\\\\\"\" || true\n      xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xcdatamodeld`.momd\"\n      ;;\n    *.xcmappingmodel)\n      echo \"xcrun mapc \\\\\"$RESOURCE_PATH\\\\\" \\\\\"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xcmappingmodel`.cdm\\\\\"\" || true\n      xcrun mapc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xcmappingmodel`.cdm\"\n      ;;\n    *.xcassets)\n      ABSOLUTE_XCASSET_FILE=\"$RESOURCE_PATH\"\n      XCASSET_FILES+=(\"$ABSOLUTE_XCASSET_FILE\")\n      ;;\n    *)\n      echo \"$RESOURCE_PATH\" || true\n      echo \"$RESOURCE_PATH\" >> \"$RESOURCES_TO_COPY\"\n      ;;\n  esac\n}\n"
RSYNC_CALL =
"\nmkdir -p \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\"\nrsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from=\"$RESOURCES_TO_COPY\" / \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\"\nif [[ \"${ACTION}\" == \"install\" ]] && [[ \"${SKIP_INSTALL}\" == \"NO\" ]]; then\n  mkdir -p \"${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\"\n  rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from=\"$RESOURCES_TO_COPY\" / \"${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\"\nfi\nrm -f \"$RESOURCES_TO_COPY\"\n"
XCASSETS_COMPILE =
"\nif [[ -n \"${WRAPPER_EXTENSION}\" ]] && [ \"`xcrun --find actool`\" ] && [ -n \"${XCASSET_FILES:-}\" ]\nthen\n  # Find all other xcassets (this unfortunately includes those of path pods and other targets).\n  OTHER_XCASSETS=$(find -L \"$PWD\" -iname \"*.xcassets\" -type d)\n  while read line; do\n    if [[ $line != \"${PODS_ROOT}*\" ]]; then\n      XCASSET_FILES+=(\"$line\")\n    fi\n  done <<<\"$OTHER_XCASSETS\"\n\n  if [ -z ${ASSETCATALOG_COMPILER_APPICON_NAME+x} ]; then\n    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}\"\n  else\n    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\"\n  fi\nfi\n"

Instance Attribute Summary collapse

Private Helpers collapse

Instance Method Summary collapse

Constructor Details

#initialize(resources_by_config, platform) ⇒ CopyResourcesScript

Initialize a new instance

Parameters:

  • resources_by_config (Hash<String, Array<String>>)

    @see resources_by_config

  • platform (Platform)

    @see platform



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

#platformPlatform (readonly)

Returns The platform of the library for which the copy resources script is needed.

Returns:

  • (Platform)

    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_configHash{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.

Returns:

  • (Hash{String, Array{String}] A list of files relative to the project pods root, keyed by build configuration.)

    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

#generateString

Returns The contents of the copy resources script.

Returns:

  • (String)

    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_functionString (private)

Returns The install resources shell function.

Returns:

  • (String)

    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.

Parameters:

  • pathname (Pathname)

    The path where the copy resources script should be saved.



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

#scriptString (private)

Returns The contents of the copy resources script.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    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