diff --git a/CHANGELOG.md b/CHANGELOG.md index 77acb24f..d3bc5afe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,7 @@ _None._ ### New Features -_None._ +- `install_swiftpm_dependencies`: Add optional flag to exit non-zero if the `Package.resolved` is not current [#141] ### Bug Fixes diff --git a/bin/install_swiftpm_dependencies b/bin/install_swiftpm_dependencies index 1159215a..7f133742 100755 --- a/bin/install_swiftpm_dependencies +++ b/bin/install_swiftpm_dependencies @@ -1,38 +1,89 @@ #!/bin/bash -eu print_usage() { - echo "Usage:" - echo " Using the \`Package.resolved\` of an Xcode \`.xworkspace\`:" - echo " ${0##*/} --workspace PATH" - echo " Using the \`Package.resolved\` of an Xcode \`.xcodeproj\`:" - echo " ${0##*/} --project PATH" - echo " Using the \`Package.resolved\` at the root, managed by \`swift package\` instead of Xcode:" - echo " ${0##*/} --use-spm" + cat <&2 @@ -109,16 +160,27 @@ if [[ -d "${XCWORKSPACE_PATH}" ]]; then # (despite the help page of `xcodebuild` suggesting that it should work without `-scheme`). Since the dependency resolution doesn't really depend on the scheme # and we don't want to have to provide or guess it, using `-list` instead stops making `xcodebuild` complain about `-workspace` not being used in conjunction # with `-scheme` (even if in practice we don't care about the scheme list it returns) - xcodebuild -workspace "${XCWORKSPACE_PATH}" -resolvePackageDependencies -onlyUsePackageVersionsFromResolvedFile -list + xcodebuild -workspace "${XCWORKSPACE_PATH}" -resolvePackageDependencies -skipPackageUpdates -list elif [[ -d "${XCODEPROJ_PATH}" ]]; then echo "~~~ Resolving Swift Packages with \`xcodebuild\`" echo "Using -project \"${XCODEPROJ_PATH}\"" - xcodebuild -project "${XCODEPROJ_PATH}" -resolvePackageDependencies -onlyUsePackageVersionsFromResolvedFile + xcodebuild -project "${XCODEPROJ_PATH}" -resolvePackageDependencies -skipPackageUpdates elif [[ "${USE_SPM}" == "true" ]]; then echo "~~~ Resolving packages with \`swift package\`" swift package resolve fi +# If STRICT_PACKAGE_CHECK is enabled, check to see if the `Package.resolved` has uncommitted changes +if [[ "$STRICT_PACKAGE_CHECK" == "true" ]]; then + CHANGES=$(git status --porcelain -- "$PACKAGE_RESOLVED_LOCATION") + + if [[ -n "$CHANGES" ]]; then + echo "Uncommitted changes detected in $PACKAGE_RESOLVED_LOCATION:" + echo "$CHANGES" + exit 1 + fi +fi + # `checkouts` can be removed because the system can quickly generate them # instead of needing to download them in the cache each time. #