Skip to content

Commit

Permalink
Update create-xcframework.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
atdrendel committed Mar 20, 2024
1 parent a60b3ff commit c48fb3c
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 84 deletions.
79 changes: 72 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,73 @@
# DiffMatchPatchObjC

.archives
*.xcframework
*.xcframework.zip
*.xcframework.zip.checksum

# from https://github.com/github/gitignore/blob/master/Swift.gitignore

.env

.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc

# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata

## Other
*.xccheckout
*.moved-aside
*.xcuserstate
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
.build/
.swiftpm/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md

fastlane/report.xml
fastlane/screenshots
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ let package = Package(
.library(
name: "DiffMatchPatchObjC",
type: .dynamic,
targets: ["DiffMatchPatchObjC"]),
targets: ["DiffMatchPatchObjC"]
),
],
targets: [
.target(
Expand All @@ -16,6 +17,7 @@ let package = Package(
),
.testTarget(
name: "DiffMatchPatchObjCTests",
dependencies: ["DiffMatchPatchObjC"]),
dependencies: ["DiffMatchPatchObjC"]
),
]
)
74 changes: 35 additions & 39 deletions Tests/DiffMatchPatchObjCTests/DiffMatchPatchObjCTests.swift
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
import XCTest
@testable import DiffMatchPatchObjC
import XCTest

final class DiffMatchPatchObjCTests: XCTestCase {
func testDiffMatchPatch() throws {
repeat {
autoreleasepool {
let old = """
Buy:
* Milk
* Fresh bread
* Eggs (6)
""".trimmingCharacters(in: .whitespacesAndNewlines)

let new = """
To buy:
* Milk
* Fresh bread (x2)
* Eggs (6)
""".trimmingCharacters(in: .whitespacesAndNewlines)

let base = """
Buy:
* Milk
* Fresh bread
* Eggs (10)
""".trimmingCharacters(in: .whitespacesAndNewlines)

let expected = """
To buy:
* Milk
* Fresh bread (x2)
* Eggs (10)
""".trimmingCharacters(in: .whitespacesAndNewlines)

let merged = threeWayMerge(old: old, new: new, base: base)
XCTAssertEqual(merged, expected)
}
} while true
let old = """
Buy:
* Milk
* Fresh bread
* Eggs (6)
""".trimmingCharacters(in: .whitespacesAndNewlines)

let new = """
To buy:
* Milk
* Fresh bread (x2)
* Eggs (6)
""".trimmingCharacters(in: .whitespacesAndNewlines)

let base = """
Buy:
* Milk
* Fresh bread
* Eggs (10)
""".trimmingCharacters(in: .whitespacesAndNewlines)

let expected = """
To buy:
* Milk
* Fresh bread (x2)
* Eggs (10)
""".trimmingCharacters(in: .whitespacesAndNewlines)

let merged = threeWayMerge(old: old, new: new, base: base)
XCTAssertEqual(merged, expected)
}
}

Expand Down
77 changes: 41 additions & 36 deletions bin/create-xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

set -e

NAME="DiffMatchPatchObjC"

function get_project_dir() {
SELF=`realpath $0`
DIR=`dirname $SELF`
Expand All @@ -15,71 +13,78 @@ function get_version() {
}

function deletePreviousArtifacts() {
find . -type f -name "$NAME*.xcframework" -exec rm {} +
find . -type f -name "$NAME*.xcframework.zip" -exec rm {} +
find . -type f -name "$NAME*.xcframework.zip.checksum" -exec rm {} +
find . -type f -name "$1*.xcframework" -exec rm {} +
find . -type f -name "$1*.xcframework.zip" -exec rm {} +
find . -type f -name "$1*.xcframework.zip.checksum" -exec rm {} +
rm -rf .archives
}

function buildFramework() {
xcodebuild archive \
-workspace $NAME \
-scheme $NAME \
-destination "$1" \
-archivePath "$2" \
-scheme $1 \
-destination "$2" \
-archivePath "$3" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
}

function builtFrameworkPathForArchive() {
realpath "$1/.archives/$2/Products/usr/local/lib/$3.framework"
}

function dsymSymbolsPathForArchive() {
realpath "$1/.archives/$2/dSYMs/$3.framework.dSYM"
}

function createXCFramework() {
xcodebuild \
-create-xcframework \
-framework ".archives/$NAME-iOS.xcarchive/Products/Library/Frameworks/CWasm3.framework" \
-debug-symbols "$1/.archives/$NAME-iOS.xcarchive/BCSymbolMaps/9EDFC8DD-15A8-39FB-B396-190B0F458495.bcsymbolmap" \
-debug-symbols "$1/.archives/$NAME-iOS.xcarchive/dSYMs/$NAME.framework.dSYM" \
-framework ".archives/$NAME-iOS-Simulator.xcarchive/Products/Library/Frameworks/$NAME.framework" \
-debug-symbols "$1/.archives/$NAME-iOS-Simulator.xcarchive/dSYMs/$NAME.framework.dSYM" \
-framework ".archives/$NAME-macOS-Catalyst.xcarchive/Products/Library/Frameworks/$NAME.framework" \
-debug-symbols "$1/.archives/$NAME-macOS-Catalyst.xcarchive/dSYMs/$NAME.framework.dSYM" \
-framework ".archives/$NAME-macOS.xcarchive/Products/Library/Frameworks/$NAME.framework" \
-debug-symbols "$1/.archives/$NAME-macOS.xcarchive/dSYMs/$NAME.framework.dSYM" \
-output CWasm3.xcframework
-framework "$(builtFrameworkPathForArchive $1 $2-iOS.xcarchive $2)" \
-debug-symbols "$(dsymSymbolsPathForArchive $1 $2-iOS.xcarchive $2)" \
-framework "$(builtFrameworkPathForArchive $1 $2-iOS-Simulator.xcarchive $2)" \
-debug-symbols "$(dsymSymbolsPathForArchive $1 $2-iOS-Simulator.xcarchive $2)" \
-framework "$(builtFrameworkPathForArchive $1 $2-macOS-Catalyst.xcarchive $2)" \
-debug-symbols "$(dsymSymbolsPathForArchive $1 $2-macOS-Catalyst.xcarchive $2)" \
-framework "$(builtFrameworkPathForArchive $1 $2-macOS.xcarchive $2)" \
-debug-symbols "$(dsymSymbolsPathForArchive $1 $2-macOS.xcarchive $2)" \
-output "$2.xcframework"
}

function zipXCFramework() {
ditto -c -k --sequesterRsrc --keepParent "$NAME.xcframework" "$1"
ditto -c -k --sequesterRsrc --keepParent "$1.xcframework" "$2"
}

function createChecksum() {
CHECKSUM=`swift package compute-checksum $1`
local checksum=`swift package compute-checksum $1`

echo "$CHECKSUM" > "$1.checksum"
echo "$checksum" > "$1.checksum"

echo ""
echo "🔒 $(swift package compute-checksum $1)"
}

VERSION="$(get_version)"
name="DiffMatchPatchObjC"
version="$(get_version)"

if [ -z "$VERSION" ]; then
if [ -z "$version" ]; then
echo "❌️ Version must be set"
exit -1
fi

PROJECT_DIR="$(get_project_dir)"
pushd "$PROJECT_DIR" &>/dev/null
project_dir="$(get_project_dir)"
pushd "$project_dir" &>/dev/null

deletePreviousArtifacts
deletePreviousArtifacts "$name"
mkdir .archives

buildFramework "generic/platform=iOS" ".archives/$NAME-iOS"
buildFramework "generic/platform=iOS Simulator" ".archives/$NAME-iOS-Simulator"
buildFramework "generic/platform=macOS,variant=Mac Catalyst" ".archives/$NAME-macOS-Catalyst"
buildFramework "generic/platform=macOS" ".archives/$NAME-macOS"
createXCFramework $PROJECT_DIR
ZIP_NAME="$NAME-$VERSION.xcframework.zip"
zipXCFramework $ZIP_NAME
createChecksum $ZIP_NAME
rm -rf "$NAME.xcframework"
buildFramework "$name" "generic/platform=iOS" ".archives/$name-iOS"
buildFramework "$name" "generic/platform=iOS Simulator" ".archives/$name-iOS-Simulator"
buildFramework "$name" "generic/platform=macOS,variant=Mac Catalyst" ".archives/$name-macOS-Catalyst"
buildFramework "$name" "generic/platform=macOS" ".archives/$name-macOS"
createXCFramework "$project_dir" "$name"
zip_name="$name-$version.xcframework.zip"
zipXCFramework "$name" "$zip_name"
createChecksum "$zip_name"
rm -rf "$name.xcframework"

popd &>/dev/null

0 comments on commit c48fb3c

Please sign in to comment.