8000 Improve dSYM handling for XCFrameworks by amorde · Pull Request #9540 · CocoaPods/CocoaPods · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve dSYM handling for XCFrameworks #9540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
* Also apply Xcode 11 `XCTUnwrap` fix to library and framework targets that weakly link `XCTest`.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#9518](https://github.com/CocoaPods/CocoaPods/pull/9518)

* Fix dSYM handling for XCFrameworks.
[Eric Amorde](https://github.com/amorde)
[#9530](https://github.com/CocoaPods/CocoaPods/issues/9530)


## 1.9.0.beta.3 (2020-02-04)
Expand Down
34 changes: 26 additions & 8 deletions lib/cocoapods/generator/embed_frameworks_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,27 +129,29 @@ def script
# Copies and strips a vendored dSYM
install_dsym() {
local source="$1"
warn_missing_arch=${2:-true}
if [ -r "$source" ]; then
# Copy the dSYM into a the targets temp dir.
# Copy the dSYM into the targets temp dir.
echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \\"- CVS/\\" --filter \\"- .svn/\\" --filter \\"- .git/\\" --filter \\"- .hg/\\" --filter \\"- Headers\\" --filter \\"- PrivateHeaders\\" --filter \\"- Modules\\" \\"${source}\\" \\"${DERIVED_FILES_DIR}\\""
rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${DERIVED_FILES_DIR}"

local basename
basename="$(basename -s .framework.dSYM "$source")"
binary="${DERIVED_FILES_DIR}/${basename}.framework.dSYM/Contents/Resources/DWARF/${basename}"
basename="$(basename -s .dSYM "$source")"
binary_name="$(ls "$source/Contents/Resources/DWARF")"
binary="${DERIVED_FILES_DIR}/${basename}.dSYM/Contents/Resources/DWARF/${binary_name}"

# Strip invalid architectures so "fat" simulator / device frameworks work on device
if [[ "$(file "$binary")" == *"Mach-O "*"dSYM companion"* ]]; then
strip_invalid_archs "$binary"
strip_invalid_archs "$binary" "$warn_missing_arch"
fi

if [[ $STRIP_BINARY_RETVAL == 1 ]]; then
# Move the stripped file into its final destination.
echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \\"- CVS/\\" --filter \\"- .svn/\\" --filter \\"- .git/\\" --filter \\"- .hg/\\" --filter \\"- Headers\\" --filter \\"- PrivateHeaders\\" --filter \\"- Modules\\" \\"${DERIVED_FILES_DIR}/${basename}.framework.dSYM\\" \\"${DWARF_DSYM_FOLDER_PATH}\\""
rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${DERIVED_FILES_DIR}/${basename}.framework.dSYM" "${DWARF_DSYM_FOLDER_PATH}"
rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${DERIVED_FILES_DIR}/${basename}.dSYM" "${DWARF_DSYM_FOLDER_PATH}"
else
# The dSYM was not stripped at all, in this case touch a fake folder so the input/output paths from Xcode do not reexecute this script because the file is missing.
touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.framework.dSYM"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the expected format for vendored frameworks, but since xcframeworks will have many dSYM files they must be named differently

touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.dSYM"
fi
fi
}
Expand Down Expand Up @@ -180,13 +182,16 @@ def script
# Strip invalid architectures
strip_invalid_archs() {
binary="$1"
warn_missing_arch=${2:-true}
# Get architectures for current target binary
binary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)"
# Intersect them with the architectures we are building for
intersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\\n' | sort | uniq -d)"
# If there are no archs supported by this binary then warn the user
if [[ -z "$intersected_archs" ]]; then
echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)."
if [[ "$warn_missing_arch" == "true" ]]; then
echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)."
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for xcframeworks, it's possible for a dSYM to be excluded completely due to archs not matching. this isn't an error, since there are multiple dSYMs instead of 1

fi
STRIP_BINARY_RETVAL=0
return
fi
Expand All @@ -212,7 +217,8 @@ def script
install_framework "$artifact"
;;
*.dSYM)
install_dsym "$artifact"
# Suppress arch warnings since XCFrameworks will include many dSYM files
install_dsym "$artifact" "false"
;;
*.bcsymbolmap)
install_bcsymbolmap "$artifact"
Expand Down Expand Up @@ -259,6 +265,18 @@ def script
SH
script
end

# @param [Xcode::FrameworkPaths] framework_path
# the framework path containing the dSYM
#
# @return [String, Nil] the name of the dSYM binary, if found
#
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
end
end
end
33 changes: 21 additions & 12 deletions lib/cocoapods/generator/prepare_artifacts_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def script

install_xcframework() {
local basepath="$1"
local embed="$2"
local dsym_folder="$2"
local embed="$3"
shift
local paths=("$@")

Expand Down Expand Up @@ -165,6 +166,17 @@ def script
fi

install_framework "$basepath/$target_path" "$embed"

< 8000 /td>
if [[ -z "$dsym_folder" || ! -d "$dsym_folder" ]]; then
return
fi

dsyms=($(ls "$dsym_folder"))

local target_dsym=""
for i in ${!dsyms[@]}; do
install_artifact "$dsym_folder/${dsyms[$i]}" "$CONFIGURATION_BUILD_DIR" "true"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the prepare step, we now copy all dsyms and filter out the ones we need inside the Embed Frameworks script

done
}

SH
Expand All @@ -186,12 +198,6 @@ def script
args = install_xcframework_args(xcframework.path, static_slices, true)
contents_by_config[config] << %( install_xcframework #{args}\n)
end

dsyms = PrepareArtifactsScript.dsym_paths(xcframework.path)
dsyms.each do |path|
source = shell_escape("${PODS_ROOT}/#{path.relative_path_from(sandbox_root)}")
contents_by_config[config] << %( install_artifact #{source} "${TARGET_BUILD_DIR}" "true"\n)
end
end
end

Expand All @@ -215,6 +221,12 @@ def shell_escape(value)

def install_xcframework_args(root, slices, static)
args = [shell_escape("${PODS_ROOT}/#{root.relative_path_from(sandbox_root)}")]
dsym_folder_arg = if (dsym_folder = PrepareArtifactsScript.dsym_folder(root))
shell_escape("${PODS_ROOT}/#{dsym_folder.relative_path_from(sandbox_root)}")
else
'""'
end
args << dsym_folder_arg
embed = static ? 'false' : 'true'
args << shell_escape(embed)
slices.each do |slice|
Expand All @@ -229,14 +241,11 @@ class << self
#
# @return [Array<Pathname>] all found .dSYM paths
#
def dsym_paths(xcframework_path)
def dsym_folder(xcframework_path)
basename = File.basename(xcframework_path, '.xcframework')
dsym_basename = basename + '.dSYMs'
path = xcframework_path.dirname + dsym_basename
return [] unless File.directory?(path)

pattern = path + '*.dSYM'
Dir.glob(pattern).map { |s| Pathname.new(s) }
Pathname.new(path) if File.directory?(path)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/cocoapods-integration-specs
Submodule cocoapods-integration-specs updated 32 files
+14 −8 install_custom_module_map/after/Pods/Target Support Files/Pods-Example/Pods-Example-frameworks.sh
+14 −8 install_custom_module_name/after/Pods/Target Support Files/Pods-Example/Pods-Example-frameworks.sh
+14 −8 install_framework_resources/after/Pods/Target Support Files/Pods-SampleApp/Pods-SampleApp-frameworks.sh
+14 −8 ...l_header_mappings_dir/after/Pods/Target Support Files/Pods-OtherSampleApp/Pods-OtherSampleApp-frameworks.sh
+14 −8 ...er_mappings_dir_macos/after/Pods/Target Support Files/Pods-OtherSampleApp/Pods-OtherSampleApp-frameworks.sh
+14 −8 install_multiple_test_specs/after/Pods/Target Support Files/HostedTestLib/HostedTestLib-App-frameworks.sh
+14 −8 ...ll_multiple_test_specs/after/Pods/Target Support Files/HostedTestLib/HostedTestLib-AppWithDep-frameworks.sh
+14 −8 ...ltiple_test_specs/after/Pods/Target Support Files/HostedTestLib/HostedTestLib-Unit-UnitTests3-frameworks.sh
+14 −8 ...ltiple_test_specs/after/Pods/Target Support Files/HostedTestLib/HostedTestLib-Unit-UnitTests4-frameworks.sh
+14 −8 ...s/after/Pods/Target Support Files/Pods-InstallMultipleTestSpecs/Pods-InstallMultipleTestSpecs-frameworks.sh
+14 −8 install_multiple_test_specs/after/Pods/Target Support Files/Pods-Other/Pods-Other-frameworks.sh
+14 −8 install_multiple_test_specs/after/Pods/Target Support Files/TestLib/TestLib-App-frameworks.sh
+14 −8 install_multiple_test_specs/after/Pods/Target Support Files/TestLib/TestLib-Unit-UnitTests1-frameworks.sh
+14 −8 install_multiple_test_specs/after/Pods/Target Support Files/TestLib/TestLib-Unit-UnitTests2-frameworks.sh
+14 −8 install_search_paths_inheritance/after/Pods/Target Support Files/Pods-App/Pods-App-frameworks.sh
+14 −8 install_search_paths_inheritance/after/Pods/Target Support Files/Pods-Test/Pods-Test-frameworks.sh
+14 −8 ...et Support Files/CustomModuleMapPod-framework-iOS/CustomModuleMapPod-framework-iOS-Unit-Tests-frameworks.sh
+14 −8 ...upport Files/CustomModuleMapPod-framework-macOS/CustomModuleMapPod-framework-macOS-Unit-Tests-frameworks.sh
+14 −8 ...ules/after/Pods/Target Support Files/MixedPod-framework-iOS/MixedPod-framework-iOS-Unit-Tests-frameworks.sh
+14 −8 .../after/Pods/Target Support Files/MixedPod-framework-macOS/MixedPod-framework-macOS-Unit-Tests-frameworks.sh
+14 −8 ...odules/after/Pods/Target Support Files/ObjCPod-framework-iOS/ObjCPod-framework-iOS-Unit-Tests-frameworks.sh
+14 −8 ...es/after/Pods/Target Support Files/ObjCPod-framework-macOS/ObjCPod-framework-macOS-Unit-Tests-frameworks.sh
+14 −8 ...get Support Files/Pods-Abstract Target-iOS Pods-Dynamic/Pods-Abstract Target-iOS Pods-Dynamic-frameworks.sh
+14 −8 ...Support Files/Pods-Abstract Target-macOS Pods-Dynamic/Pods-Abstract Target-macOS Pods-Dynamic-frameworks.sh
+14 −8 ...ules/after/Pods/Target Support Files/SwiftPod-framework-iOS/SwiftPod-framework-iOS-Unit-Tests-frameworks.sh
+14 −8 .../after/Pods/Target Support Files/SwiftPod-framework-macOS/SwiftPod-framework-macOS-Unit-Tests-frameworks.sh
+14 −8 install_subspecs/after/Pods/Target Support Files/Pods-OS X App/Pods-OS X App-frameworks.sh
+14 −8 install_vendored_dynamic_framework/after/Pods/Target Support Files/Pods-SampleApp/Pods-SampleApp-frameworks.sh
+15 −3 install_vendored_xcframework/after/Pods/Target Support Files/BananaLib/BananaLib-Unit-Tests-artifacts.sh
+14 −8 install_vendored_xcframework/after/Pods/Target Support Files/BananaLib/BananaLib-Unit-Tests-frameworks.sh
+15 −3 ...mework/after/Pods/Target Support Files/Pods-XCFrameworkIntegration/Pods-XCFrameworkIntegration-artifacts.sh
+14 −8 ...ework/after/Pods/Target Support Files/Pods-XCFrameworkIntegration/Pods-XCFrameworkIntegration-frameworks.sh
24 changes: 10 additions & 14 deletions spec/unit/generator/prepare_artifacts_script_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Pod
generator = PrepareArtifactsScript.new({ 'Debug' => [xcframework] }, temporary_sandbox.root, Platform.ios)
generator.send(:script).should.include <<-SH.strip_heredoc
if [[ "$CONFIGURATION" == "Debug" ]]; then
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "true" "ios-armv7_arm64/CoconutLib.framework" "ios-i386_x86_64-simulator/CoconutLib.framework"
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "" "true" "ios-armv7_arm64/CoconutLib.framework" "ios-i386_x86_64-simulator/CoconutLib.framework"
fi
SH
end
Expand All @@ -17,25 +17,25 @@ module Pod
generator = PrepareArtifactsScript.new({ 'Debug' => [xcframework] }, temporary_sandbox.root, Platform.macos)
generator.send(:script).should.include <<-SH.strip_heredoc
if [[ "$CONFIGURATION" == "Debug" ]]; then
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "true" "macos-x86_64/CoconutLib.framework"
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "" "true" "macos-x86_64/CoconutLib.framework"
fi
SH
generator = PrepareArtifactsScript.new({ 'Debug' => [xcframework] }, temporary_sandbox.root, Platform.ios)
generator.send(:script).should.include <<-SH.strip_heredoc
if [[ "$CONFIGURATION" == "Debug" ]]; then
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "true" "ios-armv7_arm64/CoconutLib.framework" "ios-i386_x86_64-simulator/CoconutLib.framework"
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "" "true" "ios-armv7_arm64/CoconutLib.framework" "ios-i386_x86_64-simulator/CoconutLib.framework"
fi
SH
generator = PrepareArtifactsScript.new({ 'Debug' => [xcframework] }, temporary_sandbox.root, Platform.watchos)
generator.send(:script).should.include <<-SH.strip_heredoc
if [[ "$CONFIGURATION" == "Debug" ]]; then
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "true" "watchos-i386-simulator/CoconutLib.framework" "watchos-armv7k_arm64_32/CoconutLib.framework"
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "" "true" "watchos-i386-simulator/CoconutLib.framework" "watchos-armv7k_arm64_32/CoconutLib.framework"
fi
SH
generator = PrepareArtifactsScript.new({ 'Debug' => [xcframework] }, temporary_sandbox.root, Platform.tvos)
generator.send(:script).should.include <<-SH.strip_heredoc
if [[ "$CONFIGURATION" == "Debug" ]]; then
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "true" "tvos-x86_64-simulator/CoconutLib.framework" "tvos-arm64/CoconutLib.framework"
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "" "true" "tvos-x86_64-simulator/CoconutLib.framework" "tvos-arm64/CoconutLib.framework"
fi
SH
end
Expand All @@ -47,25 +47,21 @@ module Pod
# Second argument to `install_xcframework` is a boolean indicating whether to embed the framework
generator.send(:script).should.include <<-SH.strip_heredoc
if [[ "$CONFIGURATION" == "Debug" ]]; then
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "false" "ios-armv7_arm64/CoconutLib.framework" "ios-i386_x86_64-simulator/CoconutLib.framework"
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "" "false" "ios-armv7_arm64/CoconutLib.framework" "ios-i386_x86_64-simulator/CoconutLib.framework"
fi
SH
end

it 'installs dSYMs if found' do
xcframework = Xcode::XCFramework.new(fixture('CoconutLib.xcframework'))
dsym_path = xcframework.path.dirname + 'CoconutLib.dSYMs'
PrepareArtifactsScript.stubs(:dsym_paths).returns([
dsym_path + 'A.dSYM',
dsym_path + 'B.dSYM',
])
PrepareArtifactsScript.stubs(:dsym_folder).returns(dsym_path)
generator = PrepareArtifactsScript.new({ 'Debug' => [xcframework] }, temporary_sandbox.root, Platform.ios)
results = generator.generate
results.should.include <<-SH.strip_heredoc
install_artifact "${PODS_ROOT}/../../spec/fixtures/CoconutLib.dSYMs/A.dSYM" "${TARGET_BUILD_DIR}" "true"
SH
results.should.include <<-SH.strip_heredoc
install_artifact "${PODS_ROOT}/../../spec/fixtures/CoconutLib.dSYMs/B.dSYM" "${TARGET_BUILD_DIR}" "true"
if [[ "$CONFIGURATION" == "Debug" ]]; then
install_xcframework "${PODS_ROOT}/../../spec/fixtures/CoconutLib.xcframework" "${PODS_ROOT}/../../spec/fixtures/CoconutLib.dSYMs" "true" "ios-armv7_arm64/CoconutLib.framework" "ios-i386_x86_64-simulator/CoconutLib.framework"
fi
SH
end
end
Expand Down
0