Class: Pod::Generator::EmbedFrameworksScript

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/generator/embed_frameworks_script.rb

Instance Attribute Summary collapse

Private Helpers collapse

Instance Method Summary collapse

Constructor Details

#initialize(frameworks_by_config, xcframeworks_by_config) ⇒ EmbedFrameworksScript

Returns a new instance of EmbedFrameworksScript.

Parameters:



22
23
24
25
# File 'lib/cocoapods/generator/embed_frameworks_script.rb', line 22

def initialize(frameworks_by_config, xcframeworks_by_config)
  @frameworks_by_config = frameworks_by_config
  @xcframeworks_by_config = xcframeworks_by_config
end

Instance Attribute Details

#frameworks_by_configHash{String => Array<FrameworkPaths>} (readonly)

Returns Multiple lists of frameworks per configuration.

Returns:

  • (Hash{String => Array<FrameworkPaths>})

    Multiple lists of frameworks per configuration.



9
10
11
# File 'lib/cocoapods/generator/embed_frameworks_script.rb', line 9

def frameworks_by_config
  @frameworks_by_config
end

#xcframeworks_by_configHash{String => Array<XCFrameworkPaths>} (readonly)

Returns Multiple lists of frameworks per configuration.

Returns:

  • (Hash{String => Array<XCFrameworkPaths>})

    Multiple lists of frameworks per configuration.



14
15
16
# File 'lib/cocoapods/generator/embed_frameworks_script.rb', line 14

def xcframeworks_by_config
  @xcframeworks_by_config
end

Instance Method Details

#dsym_binary_name(framework_path) ⇒ String, Nil (private)

Returns the name of the dSYM binary, if found.

Parameters:

Returns:

  • (String, Nil)

    the name of the dSYM binary, if found



188
189
190
191
192
193
# File 'lib/cocoapods/generator/embed_frameworks_script.rb', line 188

def dsym_binary_name(framework_path)
  return nil if framework_path.dsym_path.nil?
  if (path = Pathname.glob(framework_path.dsym_path.join('Contents/Resources/DWARF', '**/*')).first)
    File.basename(path)
  end
end

#generateString

Returns The contents of the embed frameworks script.

Returns:

  • (String)

    The contents of the embed frameworks script.



43
44
45
# File 'lib/cocoapods/generator/embed_frameworks_script.rb', line 43

def generate
  script
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 embed frameworks script should be saved.



34
35
36
37
38
39
# File 'lib/cocoapods/generator/embed_frameworks_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 embed frameworks script.

Returns:

  • (String)

    The contents of the embed frameworks script.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/cocoapods/generator/embed_frameworks_script.rb', line 53

def script
  script = "\#{Pod::Generator::ScriptPhaseConstants::DEFAULT_SCRIPT_PHASE_HEADER}\nif [ -z ${FRAMEWORKS_FOLDER_PATH+x} ]; then\n  # If FRAMEWORKS_FOLDER_PATH is not set, then there's nowhere for us to copy\n  # frameworks to, so exit 0 (signalling the script phase was successful).\n  exit 0\nfi\n\necho \"mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}\"\nmkdir -p \"${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}\"\n\nCOCOAPODS_PARALLEL_CODE_SIGN=\"${COCOAPODS_PARALLEL_CODE_SIGN:-false}\"\nSWIFT_STDLIB_PATH=\"${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}\"\nBCSYMBOLMAP_DIR=\"BCSymbolMaps\"\n\n\n\#{Pod::Generator::ScriptPhaseConstants::RSYNC_PROTECT_TMP_FILES}\n# Copies and strips a vendored framework\ninstall_framework()\n{\n  if [ -r \"${BUILT_PRODUCTS_DIR}/$1\" ]; then\n    local source=\"${BUILT_PRODUCTS_DIR}/$1\"\n  elif [ -r \"${BUILT_PRODUCTS_DIR}/$(basename \"$1\")\" ]; then\n    local source=\"${BUILT_PRODUCTS_DIR}/$(basename \"$1\")\"\n  elif [ -r \"$1\" ]; then\n    local source=\"$1\"\n  fi\n\n  local destination=\"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}\"\n\n  if [ -L \"${source}\" ]; then\n    echo \"Symlinked...\"\n    source=\"$(readlink -f \"${source}\")\"\n  fi\n\n  if [ -d \"${source}/${BCSYMBOLMAP_DIR}\" ]; then\n    # Locate and install any .bcsymbolmaps if present, and remove them from the .framework before the framework is copied\n    find \"${source}/${BCSYMBOLMAP_DIR}\" -name \"*.bcsymbolmap\"|while read f; do\necho \"Installing $f\"\ninstall_bcsymbolmap \"$f\" \"$destination\"\nrm \"$f\"\n    done\n    rmdir \"${source}/${BCSYMBOLMAP_DIR}\"\n  fi\n\n  # Use filter instead of exclude so missing patterns don't throw errors.\n  echo \"rsync --delete -av \"${RSYNC_PROTECT_TMP_FILES[@]}\" --links --filter \\\\\"- CVS/\\\\\" --filter \\\\\"- .svn/\\\\\" --filter \\\\\"- .git/\\\\\" --filter \\\\\"- .hg/\\\\\" --filter \\\\\"- Headers\\\\\" --filter \\\\\"- PrivateHeaders\\\\\" --filter \\\\\"- Modules\\\\\" \\\\\"${source}\\\\\" \\\\\"${destination}\\\\\"\"\n  rsync --delete -av \"${RSYNC_PROTECT_TMP_FILES[@]}\" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"\n\n  local basename\n  basename=\"$(basename -s .framework \"$1\")\"\n  binary=\"${destination}/${basename}.framework/${basename}\"\n\n  if ! [ -r \"$binary\" ]; then\n    binary=\"${destination}/${basename}\"\n  elif [ -L \"${binary}\" ]; then\n    echo \"Destination binary is symlinked...\"\n    dirname=\"$(dirname \"${binary}\")\"\n    binary=\"${dirname}/$(readlink \"${binary}\")\"\n  fi\n\n  # Strip invalid architectures so \"fat\" simulator / device frameworks work on device\n  if [[ \"$(file \"$binary\")\" == *\"dynamically linked shared library\"* ]]; then\n    strip_invalid_archs \"$binary\"\n  fi\n\n  # Resign the code if required by the build settings to avoid unstable apps\n  code_sign_if_enabled \"${destination}/$(basename \"$1\")\"\n\n  # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7.\n  if [ \"${XCODE_VERSION_MAJOR}\" -lt 7 ]; then\n    local swift_runtime_libs\n    swift_runtime_libs=$(xcrun otool -LX \"$binary\" | grep --color=never @rpath/libswift | sed -E s/@rpath\\\\\\\\/\\\\(.+dylib\\\\).*/\\\\\\\\1/g | uniq -u)\n    for lib in $swift_runtime_libs; do\necho \"rsync -auv \\\\\"${SWIFT_STDLIB_PATH}/${lib}\\\\\" \\\\\"${destination}\\\\\"\"\nrsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"\ncode_sign_if_enabled \"${destination}/${lib}\"\n    done\n  fi\n}\n\#{Pod::Generator::ScriptPhaseConstants::INSTALL_DSYM_METHOD}\n\#{Pod::Generator::ScriptPhaseConstants::STRIP_INVALID_ARCHITECTURES_METHOD}\n\#{Pod::Generator::ScriptPhaseConstants::INSTALL_BCSYMBOLMAP_METHOD}\n# Signs a framework with the provided identity\ncode_sign_if_enabled() {\n  if [ -n \"${EXPANDED_CODE_SIGN_IDENTITY:-}\" -a \"${CODE_SIGNING_REQUIRED:-}\" != \"NO\" -a \"${CODE_SIGNING_ALLOWED}\" != \"NO\" ]; then\n    # Use the current code_sign_identity\n    echo \"Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}\"\n    local code_sign_cmd=\"/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS:-} --preserve-metadata=identifier,entitlements '$1'\"\n\n    if [ \"${COCOAPODS_PARALLEL_CODE_SIGN}\" == \"true\" ]; then\ncode_sign_cmd=\"$code_sign_cmd &\"\n    fi\n    echo \"$code_sign_cmd\"\n    eval \"$code_sign_cmd\"\n  fi\n}\n  SH\n  contents_by_config = Hash.new do |hash, key|\n    hash[key] = ''\n  end\n  frameworks_by_config.each do |config, frameworks|\n    frameworks.each do |framework|\n      contents_by_config[config] << %(  install_framework \"\#{framework.source_path}\"\\n)\n    end\n  end\n  xcframeworks_by_config.each do |config, xcframeworks|\n    xcframeworks.select { |xcf| xcf.build_type.dynamic_framework? }.each do |xcframework|\n      target_name = xcframework.target_name\n      name = xcframework.name\n      contents_by_config[config] << %(  install_framework \"\#{Target::BuildSettings::XCFRAMEWORKS_BUILD_DIR_VARIABLE}/\#{target_name}/\#{name}.framework\"\\n)\n    end\n  end\n  script << \"\\n\" unless contents_by_config.empty?\n  contents_by_config.keys.sort.each do |config|\n    contents = contents_by_config[config]\n    next if contents.empty?\n    script << %(if [[ \"$CONFIGURATION\" == \"\#{config}\" ]]; then\\n)\n    script << contents\n    script << \"fi\\n\"\n  end\n  script << <<-SH.strip_heredoc\n  if [ \"${COCOAPODS_PARALLEL_CODE_SIGN}\" == \"true\" ]; then\n    wait\n  fi\n  SH\n  script\nend\n".strip_heredoc