Skip to content

Commit

Permalink
Embed third-party dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
testableapple committed Oct 19, 2023
1 parent 5c84fb1 commit 0e4d80d
Show file tree
Hide file tree
Showing 107 changed files with 13,366 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .slather.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ ignore:
- "**/*_Mock.swift"
- "**/*_Vendor.swift"
- "**/Generated/*.swift"
- "Sources/StreamChatSwiftUI/StreamNuke"
- "Sources/StreamChatSwiftUI/StreamSwiftyGif"
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MAKEFLAGS += --silent

update_dependencies:
echo "👉 Updating Nuke"
make update_nuke version=11.3.1
echo "👉 Updating SwiftyGif"
make update_swiftygif version=5.4.2

update_nuke: check_version_parameter
./Scripts/updateDependency.sh $(version) Dependencies/Nuke Sources/StreamChatSwiftUI/StreamNuke Sources
./Scripts/removePublicDeclarations.sh Sources/StreamChatSwiftUI/StreamNuke

update_swiftygif: check_version_parameter
./Scripts/updateDependency.sh $(version) Dependencies/SwiftyGif Sources/StreamChatSwiftUI/StreamSwiftyGif SwiftyGif
./Scripts/removePublicDeclarations.sh Sources/StreamChatSwiftUI/StreamSwiftyGif

check_version_parameter:
@if [ "$(version)" = "" ]; then\
echo "❌ Missing version parameter"; \
exit 1;\
fi
66 changes: 66 additions & 0 deletions Scripts/removePublicDeclarations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
#
# Usage: ./removePublicDeclarations.sh Sources/StreamNuke
#
# This script would iterate over the files on a particular directory, and perform basic replacement operations.
# It heavily relies on 'sed':
# sed -i '<backup-file-extension>' -e 's/<original-string>/<replacement>/g' <file>
# ^
# Passing empty string prevents the creation of backup files

args=("$@")
directory=$1

replaceDeclaration() {
original=$1
replacement=$2
file=$3
`sed -i '' -e "s/$original/$replacement/g" $file`
}

files=`find $directory -name "*.swift"`
for f in $files
do
replaceDeclaration 'public internal(set) ' '' $f
replaceDeclaration 'open ' '' $f
replaceDeclaration 'public ' '' $f

# Nuke
if [[ $directory == *"Nuke"* ]]; then
replaceDeclaration 'var log' 'var nukeLog' $f
replaceDeclaration 'log =' 'nukeLog =' $f
replaceDeclaration 'log: log' 'log: nukeLog' $f
replaceDeclaration 'signpost(log' 'signpost(nukeLog' $f
replaceDeclaration ' Cache(' ' NukeCache(' $f
replaceDeclaration ' Cache<' ' NukeCache<' $f
replaceDeclaration ' Image?' ' NukeImage?' $f
replaceDeclaration ' Image(' ' NukeImage(' $f
replaceDeclaration 'struct Image:' 'struct NukeImage:' $f
replaceDeclaration 'extension Image {' 'extension NukeImage {' $f
replaceDeclaration 'Content == Image' 'Content == NukeImage' $f
replaceDeclaration ' VideoPlayerView' ' NukeVideoPlayerView' $f
replaceDeclaration 'typealias Color' 'typealias NukeColor' $f
replaceDeclaration 'extension Color' 'extension NukeColor' $f
replaceDeclaration 'AssetType' 'NukeAssetType' $f
replaceDeclaration 'typealias ImageRequest = Nuke.ImageRequest' '' $f
replaceDeclaration 'typealias ImageResponse = Nuke.ImageResponse' '' $f
replaceDeclaration 'typealias ImagePipeline = Nuke.ImagePipeline' '' $f
replaceDeclaration 'typealias ImageContainer = Nuke.ImageContainer' '' $f
replaceDeclaration 'open class ' '' $f
replaceDeclaration 'import Nuke' '' $f

# Remove Cancellable interface duplicate
if [[ $f == *"DataLoader"* && `head -10 $f` == *"protocol Cancellable"* ]]; then
`sed -i '' -e '7,11d' $f`
fi

# Rename files
if [[ $f == *"Caching/Cache.swift" ]]; then
new_f="${f/Cache.swift/NukeCache.swift}"
mv "$f" "$new_f"
elif [[ $f == *"NukeUI/VideoPlayerView.swift" ]]; then
new_f="${f/VideoPlayerView.swift/NukeVideoPlayerView.swift}"
mv "$f" "$new_f"
fi
fi
done
51 changes: 51 additions & 0 deletions Scripts/removeUnneededSymbols.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
#
# Usage: ./removeUnneededSymbols.sh StreamChatSwiftUI ./Products
#
# Creating an xcframework for StreamChatSwiftUI generates a .bcsymbolmap file for itself, and one for
# each of its dependencies too (eg. StreamChat). That means that we will end up having something like:
#
# -> StreamChatSwiftUI/BCSymbolMaps/
# <UUID-StreamChatSwiftUI>.bcsymbolmap
# <UUID-StreamChat>.bcsymbolmap
#
# When adding both StreamChat and StreamChatSwiftUI to an app, it will throw an error when trying to compile
# saying that there are multiple executions producing the same file (<UUID-StreamChat>.bcsymbolmap).
#
# This script will remove duplicated .bcsymbolmap in the generated xcframeworks.
# If we countinue with the same example, it will leave it as follows:
#
# -> StreamChatSwiftUI/BCSymbolMaps/
# <UUID-StreamChatSwiftUI>.bcsymbolmap
#
# Each xcframework only contains its symbols now.

args=("$@")
library=$1
output_directory=$2

function removeUnneededSymbols() {
arch=$1
path="$output_directory/$library.xcframework/$arch/BCSymbolMaps"
cd $path

# Looking for [...]/DerivedSources/[LIBRARY-NAME]_vers.c
regex="(\/DerivedSources\/)([a-zA-Z_]*)(_vers.c)"
files="*.bcsymbolmap"
for f in $files
do
text=`head -10 $f`
[[ $text =~ $regex ]]
library_match="${BASH_REMATCH[2]}"
if [[ $library_match != $library ]]
then
echo "→ Removing uneeded 'bcsymbolmap' from $library-$arch: $library_match - $f"
rm $f
fi
done

cd - >/dev/null
}

removeUnneededSymbols "ios-arm64"
removeUnneededSymbols "ios-arm64_x86_64-simulator"
2 changes: 1 addition & 1 deletion Scripts/run-linter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail
echo -e "👉 Running SwiftFormat Linting"

echo -e "👉 Linting Sources..."
mint run swiftformat --lint --config .swiftformat Sources --exclude **/Generated
mint run swiftformat --lint --config .swiftformat Sources --exclude **/Generated,Sources/StreamChatUI/StreamNuke,Sources/StreamChatUI/StreamSwiftyGif
echo -e "👉 Linting Tests..."
mint run swiftformat --lint --config .swiftformat StreamChatSwiftUITests
echo -e "👉 Linting DemoApp..."
Expand Down
60 changes: 60 additions & 0 deletions Scripts/updateDependency.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
#
# Usage: ./updateDependency.sh 10.3.3 Dependencies/Nuke Sources/StreamNuke Sources
#
# This script gets the source code of a dependency of a given library, and copies it to our codebase

ensure_clean_git () {
if !(git diff-index --quiet HEAD)
then
echo "→ Seems like git is not clean in $dependency_directory. Please make sure it is clean, and run it again"
exit 1
fi
}

args=("$@")
version=$1
dependency_directory=$2
output_directory=$3
sources_directory=$4

dependency_url=""

if [[ $dependency_directory == *"Nuke"* ]]; then
dependency_url="[email protected]:kean/Nuke.git"
elif [[ $dependency_directory == *"SwiftyGif"* ]]; then
dependency_url="[email protected]:kirualex/SwiftyGif.git"
else
echo "→ Unknown dependency at $dependency_directory"
exit 1
fi

if ! [[ -d "$dependency_directory" ]]; then
echo "$dependency_directory does not exist in your filesystem. Cloning the repo"
git clone $dependency_url $dependency_directory
fi

cd $dependency_directory

ensure_clean_git

git fetch --tags
git checkout $version

ensure_clean_git

cd -

echo "→ Copying source files"
rm -rf $output_directory
mkdir $output_directory
cp -r "$dependency_directory/$sources_directory/." $output_directory


for f in `find $output_directory -type f \( -iname \*.h -o -iname \*.plist \)`
do
echo "→ Removing $f"
rm $f
done

rm -rf $dependency_directory
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//

import Combine
import Nuke
import StreamChat
import SwiftUI

Expand Down Expand Up @@ -163,7 +162,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {

@objc
private func didReceiveMemoryWarning() {
Nuke.ImageCache.shared.removeAll()
ImageCache.shared.removeAll()
messageCachingUtils.clearCache()
}

Expand Down Expand Up @@ -511,7 +510,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
messageCachingUtils.clearCache()
if messageController == nil {
utils.channelControllerFactory.clearCurrentController()
Nuke.ImageCache.shared.trim(toCost: utils.messageListConfig.cacheSizeOnChatDismiss)
ImageCache.shared.trim(toCost: utils.messageListConfig.cacheSizeOnChatDismiss)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ private struct ZoomableScrollViewImpl<Content: View>: UIViewControllerRepresenta
updateConstraintsCancellable = scrollView.publisher(for: \.bounds).map(\.size).removeDuplicates()
.sink { [unowned self] _ in
view.setNeedsUpdateConstraints()
}
doubleTapCancellable = doubleTap.sink { [unowned self] in handleDoubleTap() }
} as! any Cancellable // FIXME
doubleTapCancellable = doubleTap.sink { [unowned self] in handleDoubleTap() } as! any Cancellable // FIXME
}

func update(content: Content, doubleTap: AnyPublisher<Void, Never>) {
coordinator.hostingController.rootView = content
scrollView.setNeedsUpdateConstraints()
doubleTapCancellable = doubleTap.sink { [unowned self] in handleDoubleTap() }
doubleTapCancellable = doubleTap.sink { [unowned self] in handleDoubleTap() } as! any Cancellable // FIXME
}

func handleDoubleTap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Copyright © 2023 Stream.io Inc. All rights reserved.
//

import Nuke
import NukeUI
import StreamChat
import SwiftUI

Expand Down Expand Up @@ -106,7 +104,7 @@ struct LazyGiphyView: View {
var body: some View {
LazyImage(imageURL: source) { state in
if let imageContainer = state.imageContainer {
Image(imageContainer)
NukeImage(imageContainer)
} else if state.error != nil {
Color(.secondarySystemBackground)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Copyright © 2023 Stream.io Inc. All rights reserved.
//

import Nuke
import NukeUI
import StreamChat
import SwiftUI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Copyright © 2023 Stream.io Inc. All rights reserved.
//

import Nuke
import NukeUI
import StreamChat
import SwiftUI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Copyright © 2023 Stream.io Inc. All rights reserved.
//

import NukeUI
import StreamChat
import SwiftUI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//

import AVKit
import Nuke
import NukeUI
import StreamChat
import SwiftUI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Copyright © 2023 Stream.io Inc. All rights reserved.
//

import Nuke
import NukeUI
import StreamChat
import SwiftUI

Expand Down
Loading

0 comments on commit 0e4d80d

Please sign in to comment.