Skip to content

Commit 429d582

Browse files
committed
Clean up build scripts and formatter config
- build-framework.sh: collapse the 8 duplicated per-platform blocks into a loop over a platform table; add a trap that cleans temp dirs on any exit; quote paths and pass xcodebuild args via an array; drop dead code (BASE_PWD, no-op final cd, commented-out zip). 118 -> 61 lines, same output. - swiftformat.sh: stop overriding .swiftformat with contradictory/deprecated CLI flags (--self remove vs config's insert, deprecated --wrapelements); just run swiftformat over the given path (default: the repo). - .swiftformat: replace deprecated rule names sortedImports -> sortImports and specifiers -> modifierOrder. - generate-contributors-list.sh: fix copy-paste SwiftNIO header (drop stale LICENSE.txt / "SwiftNIO project authors" references). Verified: refactored build loop produces a valid xcframework for the installed platforms incl. the space-containing Mac Catalyst destination; swiftformat runs with no deprecation warnings.
1 parent eccabb5 commit 429d582

4 files changed

Lines changed: 59 additions & 118 deletions

File tree

‎.swiftformat‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333

3434
# rules
3535

36-
--rules indent, braces, isEmpty, redundantBreak, blankLinesAroundMark, blankLinesAtEndOfScope, blankLinesBetweenScopes, consecutiveBlankLines, consecutiveSpaces, duplicateImports, elseOnSameLine, leadingDelimiters, redundantBreak, redundantExtensionACL, redundantFileprivate, redundantGet, redundantInit, redundantLet, redundantNilInit, redundantObjc, redundantParens, redundantPattern, redundantRawValues, redundantReturn, redundantSelf, redundantVoidReturnType, semicolons, sortedImports, spaceAroundBraces, spaceAroundBrackets, spaceAroundComments, spaceAroundGenerics, spaceAroundOperators, spaceAroundParens, spaceInsideBraces, spaceInsideBrackets, specifiers, strongOutlets, strongifiedSelf, todos, void, wrapArguments, yodaConditions, trailingSpace
36+
--rules indent, braces, isEmpty, redundantBreak, blankLinesAroundMark, blankLinesAtEndOfScope, blankLinesBetweenScopes, consecutiveBlankLines, consecutiveSpaces, duplicateImports, elseOnSameLine, leadingDelimiters, redundantBreak, redundantExtensionACL, redundantFileprivate, redundantGet, redundantInit, redundantLet, redundantNilInit, redundantObjc, redundantParens, redundantPattern, redundantRawValues, redundantReturn, redundantSelf, redundantVoidReturnType, semicolons, sortImports, spaceAroundBraces, spaceAroundBrackets, spaceAroundComments, spaceAroundGenerics, spaceAroundOperators, spaceAroundParens, spaceInsideBraces, spaceInsideBrackets, modifierOrder, strongOutlets, strongifiedSelf, todos, void, wrapArguments, yodaConditions, trailingSpace

‎scripts/build-framework.sh‎

Lines changed: 53 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,61 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -euo pipefail
44

5-
BASE_PWD="$PWD"
65
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
7-
OUTPUT_DIR=$( mktemp -d )
8-
COMMON_SETUP="-project ${SCRIPT_DIR}/../CryptoSwift.xcodeproj -scheme CryptoSwift -configuration Release -quiet SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
9-
10-
# macOS
11-
DERIVED_DATA_PATH=$( mktemp -d )
12-
xcrun xcodebuild build \
13-
$COMMON_SETUP \
14-
-derivedDataPath "${DERIVED_DATA_PATH}" \
15-
-destination 'generic/platform=macOS'
16-
17-
mkdir -p "${OUTPUT_DIR}/macos"
18-
ditto "${DERIVED_DATA_PATH}/Build/Products/Release/CryptoSwift.framework" "${OUTPUT_DIR}/macos/CryptoSwift.framework"
19-
rm -rf "${DERIVED_DATA_PATH}"
20-
21-
# macOS Catalyst
22-
DERIVED_DATA_PATH=$( mktemp -d )
23-
xcrun xcodebuild build \
24-
$COMMON_SETUP \
25-
-derivedDataPath "${DERIVED_DATA_PATH}" \
26-
-destination 'generic/platform=macOS,variant=Mac Catalyst'
27-
28-
mkdir -p "${OUTPUT_DIR}/maccatalyst"
29-
ditto "${DERIVED_DATA_PATH}/Build/Products/Release-maccatalyst/CryptoSwift.framework" "${OUTPUT_DIR}/maccatalyst/CryptoSwift.framework"
30-
rm -rf "${DERIVED_DATA_PATH}"
31-
32-
# iOS
33-
DERIVED_DATA_PATH=$( mktemp -d )
34-
xcrun xcodebuild build \
35-
$COMMON_SETUP \
36-
-derivedDataPath "${DERIVED_DATA_PATH}" \
37-
-destination 'generic/platform=iOS'
38-
39-
mkdir -p "${OUTPUT_DIR}/iphoneos"
40-
ditto "${DERIVED_DATA_PATH}/Build/Products/Release-iphoneos/CryptoSwift.framework" "${OUTPUT_DIR}/iphoneos/CryptoSwift.framework"
41-
rm -rf "${DERIVED_DATA_PATH}"
42-
43-
# iOS Simulator
44-
DERIVED_DATA_PATH=$( mktemp -d )
45-
xcrun xcodebuild build \
46-
$COMMON_SETUP \
47-
-derivedDataPath "${DERIVED_DATA_PATH}" \
48-
-destination 'generic/platform=iOS Simulator'
49-
50-
mkdir -p "${OUTPUT_DIR}/iphonesimulator"
51-
ditto "${DERIVED_DATA_PATH}/Build/Products/Release-iphonesimulator/CryptoSwift.framework" "${OUTPUT_DIR}/iphonesimulator/CryptoSwift.framework"
52-
rm -rf "${DERIVED_DATA_PATH}"
53-
54-
# tvOS
55-
DERIVED_DATA_PATH=$( mktemp -d )
56-
xcrun xcodebuild build \
57-
$COMMON_SETUP \
58-
-derivedDataPath "${DERIVED_DATA_PATH}" \
59-
-destination 'generic/platform=tvOS'
60-
61-
mkdir -p "${OUTPUT_DIR}/appletvos"
62-
ditto "${DERIVED_DATA_PATH}/Build/Products/Release-appletvos/CryptoSwift.framework" "${OUTPUT_DIR}/appletvos/CryptoSwift.framework"
63-
rm -rf "${DERIVED_DATA_PATH}"
64-
65-
# tvOS Simulator
66-
DERIVED_DATA_PATH=$( mktemp -d )
67-
xcrun xcodebuild build \
68-
$COMMON_SETUP \
69-
-derivedDataPath "${DERIVED_DATA_PATH}" \
70-
-destination 'generic/platform=tvOS Simulator'
71-
72-
mkdir -p "${OUTPUT_DIR}/appletvsimulator"
73-
ditto "${DERIVED_DATA_PATH}/Build/Products/Release-appletvsimulator/CryptoSwift.framework" "${OUTPUT_DIR}/appletvsimulator/CryptoSwift.framework"
74-
rm -rf "${DERIVED_DATA_PATH}"
75-
76-
# watchOS
77-
DERIVED_DATA_PATH=$( mktemp -d )
78-
xcrun xcodebuild build \
79-
$COMMON_SETUP \
80-
-derivedDataPath "${DERIVED_DATA_PATH}" \
81-
-destination 'generic/platform=watchOS'
82-
83-
mkdir -p "${OUTPUT_DIR}/watchos"
84-
ditto "${DERIVED_DATA_PATH}/Build/Products/Release-watchos/CryptoSwift.framework" "${OUTPUT_DIR}/watchos/CryptoSwift.framework"
85-
rm -rf "${DERIVED_DATA_PATH}"
86-
87-
# watchOS Simulator
88-
DERIVED_DATA_PATH=$( mktemp -d )
89-
xcrun xcodebuild build \
90-
$COMMON_SETUP \
91-
-derivedDataPath "${DERIVED_DATA_PATH}" \
92-
-destination 'generic/platform=watchOS Simulator'
93-
94-
mkdir -p "${OUTPUT_DIR}/watchsimulator"
95-
ditto "${DERIVED_DATA_PATH}/Build/Products/Release-watchsimulator/CryptoSwift.framework" "${OUTPUT_DIR}/watchsimulator/CryptoSwift.framework"
96-
rm -rf "${DERIVED_DATA_PATH}"
6+
PROJECT="${SCRIPT_DIR}/../CryptoSwift.xcodeproj"
7+
XCFRAMEWORK="${SCRIPT_DIR}/../CryptoSwift.xcframework"
8+
OUTPUT_DIR="$( mktemp -d )"
9+
DERIVED_DATA_PATH=""
10+
11+
# Clean up temporary build output on any exit (success or failure).
12+
trap 'rm -rf "${OUTPUT_DIR}" "${DERIVED_DATA_PATH}"' EXIT
13+
14+
COMMON_SETUP=(
15+
-project "${PROJECT}"
16+
-scheme CryptoSwift
17+
-configuration Release
18+
-quiet
19+
SKIP_INSTALL=NO
20+
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
21+
)
22+
23+
# destination | Build/Products subdirectory | output slice directory
24+
PLATFORMS=(
25+
"generic/platform=macOS|Release|macos"
26+
"generic/platform=macOS,variant=Mac Catalyst|Release-maccatalyst|maccatalyst"
27+
"generic/platform=iOS|Release-iphoneos|iphoneos"
28+
"generic/platform=iOS Simulator|Release-iphonesimulator|iphonesimulator"
29+
"generic/platform=tvOS|Release-appletvos|appletvos"
30+
"generic/platform=tvOS Simulator|Release-appletvsimulator|appletvsimulator"
31+
"generic/platform=watchOS|Release-watchos|watchos"
32+
"generic/platform=watchOS Simulator|Release-watchsimulator|watchsimulator"
33+
)
34+
35+
frameworks=()
36+
for entry in "${PLATFORMS[@]}"; do
37+
IFS='|' read -r destination products_subdir slice <<< "${entry}"
38+
39+
DERIVED_DATA_PATH="$( mktemp -d )"
40+
xcrun xcodebuild build \
41+
"${COMMON_SETUP[@]}" \
42+
-derivedDataPath "${DERIVED_DATA_PATH}" \
43+
-destination "${destination}"
44+
45+
mkdir -p "${OUTPUT_DIR}/${slice}"
46+
ditto \
47+
"${DERIVED_DATA_PATH}/Build/Products/${products_subdir}/CryptoSwift.framework" \
48+
"${OUTPUT_DIR}/${slice}/CryptoSwift.framework"
49+
rm -rf "${DERIVED_DATA_PATH}"
50+
DERIVED_DATA_PATH=""
51+
52+
frameworks+=(-framework "${OUTPUT_DIR}/${slice}/CryptoSwift.framework")
53+
done
9754

9855
# XCFRAMEWORK
99-
rm -rf ${SCRIPT_DIR}/../CryptoSwift.xcframework
56+
rm -rf "${XCFRAMEWORK}"
10057
xcrun xcodebuild -quiet -create-xcframework \
101-
-framework "${OUTPUT_DIR}/iphoneos/CryptoSwift.framework" \
102-
-framework "${OUTPUT_DIR}/iphonesimulator/CryptoSwift.framework" \
103-
-framework "${OUTPUT_DIR}/appletvos/CryptoSwift.framework" \
104-
-framework "${OUTPUT_DIR}/appletvsimulator/CryptoSwift.framework" \
105-
-framework "${OUTPUT_DIR}/watchos/CryptoSwift.framework" \
106-
-framework "${OUTPUT_DIR}/watchsimulator/CryptoSwift.framework" \
107-
-framework "${OUTPUT_DIR}/macos/CryptoSwift.framework" \
108-
-framework "${OUTPUT_DIR}/maccatalyst/CryptoSwift.framework" \
109-
-output ${SCRIPT_DIR}/../CryptoSwift.xcframework
110-
111-
# pushd ${OUTPUT_DIR}
112-
# xcrun zip --symlinks -r -o ${BASE_PWD}/CryptoSwift.xcframework.zip CryptoSwift.xcframework
113-
# popd
114-
115-
echo "✔️ CryptoSwift.xcframework"
116-
echo ${OUTPUT_DIR}
58+
"${frameworks[@]}" \
59+
-output "${XCFRAMEWORK}"
11760

118-
rm -rf ${OUTPUT_DIR}
119-
cd ${BASE_PWD}
61+
echo "✔️ ${XCFRAMEWORK}"

‎scripts/generate-contributors-list.sh‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#!/bin/bash
22
##===----------------------------------------------------------------------===##
33
##
4-
## This source file is part of the SwiftNIO open source project
5-
##
4+
## Adapted from the SwiftNIO open source project.
65
## Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
76
## Licensed under Apache License v2.0
87
##
9-
## See LICENSE.txt for license information
10-
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
11-
##
128
## SPDX-License-Identifier: Apache-2.0
139
##
1410
##===----------------------------------------------------------------------===##

‎scripts/swiftformat.sh‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
#!/bin/bash
2+
set -euo pipefail
23

3-
swiftformat --hexliteralcase lowercase --hexgrouping none --ranges nospace --wrapelements beforefirst --self remove $1
4+
# Formatting rules live in .swiftformat (read automatically by swiftformat).
5+
# Format the given path, or the whole repository if none is provided.
6+
swiftformat "${1:-.}"

0 commit comments

Comments
 (0)