Skip to content

Commit 7098122

Browse files
committed
Updated caching logic for Swift 4 (taking into account Package.resolved)
1 parent c922e69 commit 7098122

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ bx app env-set <app_name> SWIFT_BUILD_DIR_CACHE true
367367
bx app restage <app_name>
368368
```
369369
370-
Note that if at some point you change the contents of your `Package.swift` or `Package.pins` file, the buildpack will automatically refetch the dependencies and update the cache accordingly. Also, if you do not initially push a `Package.pins` file along with your application and you are using Swift 3.1 (or a later version), a new `Package.pins` file will be generated. It is recommended that you always push a `Package.pins` file along with your application (if using Swift 3.1 or later).
370+
Note that if at some point you change the contents of your `Package.swift` or `Package.resolved` (or `Package.pins` for older versions of Swift) file, the buildpack will automatically refetch the dependencies and update the cache accordingly. Also, if you do not initially push a `Package.resolved` file along with your application and you are using Swift 4.0 (or a later version), a new `Package.resolved` file will be generated. It is recommended that you always push a `Package.resolved` file along with your application (if using Swift 4.0 or later).
371371
372372
### Debugging
373373

bin/compile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ source $BP_DIR/compile-extensions/lib/common
4343
# Check environment support
4444
$BP_DIR/compile-extensions/bin/check_stack_support
4545
# Load convenience functions like status(), echo(), and indent()
46-
source $BP_DIR/lib/common.sh
46+
source ${BP_DIR}/lib/common.sh
4747
# Load caching functions
4848
source ${BP_DIR}/lib/cache.sh
4949
# Load app management extension

lib/cache.sh

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# limitations under the License.
1515
##
1616

17+
# Load convenience functions like status(), echo(), and indent()
18+
source ${BP_DIR}/lib/common.sh
19+
1720
create_swift_signature() {
1821
echo "$(swift --version)"
1922
}
@@ -22,19 +25,27 @@ create_package_signature() {
2225
echo "$(cat $BUILD_DIR/Package.swift)"
2326
}
2427

25-
create_pins_signature() {
26-
# Older versions of Swift do not use a Package.pins file
27-
if test -f $BUILD_DIR/Package.pins; then
28-
echo "$(cat $BUILD_DIR/Package.pins)"
28+
create_dependencies_signature() {
29+
if [ $(is_swift_version_greater_or_equal_to 4.0) == "true" ]; then
30+
if test -f $BUILD_DIR/Package.resolved; then
31+
echo "$(cat $BUILD_DIR/Package.resolved)"
32+
else
33+
echo ""
34+
fi
2935
else
30-
echo ""
36+
# Versions before Swift 3.1 do not use a Package.pins file
37+
if test -f $BUILD_DIR/Package.pins; then
38+
echo "$(cat $BUILD_DIR/Package.pins)"
39+
else
40+
echo ""
41+
fi
3142
fi
3243
}
3344

3445
save_signatures() {
3546
echo "$(create_swift_signature)" > $CACHE_DIR/swift/.swift-signature
3647
echo "$(create_package_signature)" > $CACHE_DIR/swift/.package-signature
37-
echo "$(create_pins_signature)" > $CACHE_DIR/swift/.pins-signature
48+
echo "$(create_dependencies_signature)" > $CACHE_DIR/swift/.dependencies-signature
3849
}
3950

4051
load_swift_signature() {
@@ -45,8 +56,8 @@ load_packages_signature() {
4556
load_signature ".package-signature"
4657
}
4758

48-
load_pins_signature() {
49-
load_signature ".pins-signature"
59+
load_dependencies_signature() {
60+
load_signature ".dependencies-signature"
5061
}
5162

5263
load_signature() {
@@ -65,8 +76,8 @@ get_cache_status() {
6576
echo "new swift signature"
6677
elif [ "$(create_package_signature)" != "$(load_packages_signature)" ]; then
6778
echo "new package signature"
68-
elif [[ ! -z "$(create_pins_signature)" ]] && [ "$(create_pins_signature)" != "$(load_pins_signature)" ]; then
69-
echo "new pins signature"
79+
elif [[ ! -z "$(create_dependencies_signature)" ]] && [ "$(create_dependencies_signature)" != "$(load_dependencies_signature)" ]; then
80+
echo "new dependencies signature"
7081
else
7182
echo "valid"
7283
fi

0 commit comments

Comments
 (0)