-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optionaly fail install_swiftpm_dependencies when Package.resolved
is not current
#141
base: trunk
Are you sure you want to change the base?
Changes from all commits
eef5afe
b05c9bc
6018d40
89390a5
6650ecc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <<EOF | ||
Usage: | ||
Install SwiftPM dependencies using the \`Package.resolved\` file: | ||
|
||
1. For an Xcode \`.xcworkspace\`: | ||
${0##*/} --workspace PATH [--strict-package-check] | ||
|
||
2. For an Xcode \`.xcodeproj\`: | ||
${0##*/} --project PATH [--strict-package-check] | ||
|
||
3. For a Swift package managed by \`swift package\` instead of Xcode: | ||
${0##*/} --use-spm [--strict-package-check] | ||
|
||
4. Default behavior (Attept to find an appropriate workspace, project, or swift package): | ||
${0##*/} [--strict-package-check] | ||
|
||
Options: | ||
--workspace PATH Specify the path to the Xcode workspace. | ||
--project PATH Specify the path to the Xcode project. | ||
--use-spm Use the Swift package manager at the root. | ||
--strict-package-check Fail the installation if the \`Package.resolved\` file has uncommitted changes or is out of date. | ||
If specified more than once, the last value will be used. | ||
|
||
Examples: | ||
Install dependencies for an Xcode workspace: | ||
${0##*/} --workspace MyApp.xcworkspace | ||
|
||
Install dependencies with strict package check: | ||
${0##*/} --project MyApp.xcodeproj --strict-package-check | ||
|
||
Install dependencies for a Swift package at the root: | ||
${0##*/} --use-spm | ||
EOF | ||
} | ||
|
||
# Parse input parameters | ||
XCWORKSPACE_PATH= | ||
XCODEPROJ_PATH= | ||
USE_SPM=false | ||
|
||
case ${1:-} in | ||
--workspace) | ||
XCWORKSPACE_PATH="${2:?you need to provide a value after the --workspace option}" | ||
shift; shift | ||
;; | ||
--project) | ||
XCODEPROJ_PATH=${2:?you need to provide a value after the --project option} | ||
shift; shift | ||
;; | ||
--use-spm) | ||
USE_SPM=true | ||
shift | ||
;; | ||
-h|--help) | ||
print_usage | ||
exit 0 | ||
;; | ||
esac | ||
STRICT_PACKAGE_CHECK=false | ||
|
||
# Track the number of targets found in the arguments | ||
TARGET_COUNT=0 | ||
Comment on lines
+45
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems this variable is now completely unused (I'm guessing it was initially introduced as an attempt to detect argument conflicts but then you switched to test for |
||
|
||
while [[ $# -gt 0 ]]; do | ||
case ${1:-} in | ||
--workspace) | ||
if [[ -n $XCWORKSPACE_PATH || -n $XCODEPROJ_PATH || $USE_SPM == "true" ]]; then | ||
echo "Error: only one target can be used: --workspace, --project, or --use-spm" | ||
exit 1 | ||
fi | ||
Comment on lines
+51
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we couldn't DRY this check in a dedicated local function, e.g. function check_options_conflicts() {
if [[ -n $XCWORKSPACE_PATH || -n $XCODEPROJ_PATH || $USE_SPM == "true" ]]; then
echo "Error: only one mode can be used: --workspace, --project, or --use-spm"
exit 1
fi
} Then you'd simply call I also changed the wording from "target" to "mode" as I felt that the word "target" was confusing (I initially thought you meant it as in "Xcode targets" and That being said. since we'll end up removing the |
||
XCWORKSPACE_PATH="${2:?you need to provide a value after the --workspace option}" | ||
TARGET_COUNT=$((TARGET_COUNT + 1)) | ||
shift; shift | ||
;; | ||
--project) | ||
if [[ -n $XCWORKSPACE_PATH || -n $XCODEPROJ_PATH || $USE_SPM == "true" ]]; then | ||
echo "Error: only one target can be used: --workspace, --project, or --use-spm" | ||
exit 1 | ||
fi | ||
XCODEPROJ_PATH=${2:?you need to provide a value after the --project option} | ||
TARGET_COUNT=$((TARGET_COUNT + 1)) | ||
shift; shift | ||
;; | ||
--use-spm) | ||
if [[ -n $XCWORKSPACE_PATH || -n $XCODEPROJ_PATH || $USE_SPM == "true" ]]; then | ||
echo "Error: only one target can be used: --workspace, --project, or --use-spm" | ||
exit 1 | ||
fi | ||
USE_SPM=true | ||
TARGET_COUNT=$((TARGET_COUNT + 1)) | ||
shift | ||
;; | ||
--strict-package-check) | ||
STRICT_PACKAGE_CHECK="true" | ||
shift | ||
;; | ||
-h|--help) | ||
print_usage | ||
exit 0 | ||
;; | ||
esac | ||
done | ||
|
||
if [[ "$#" -gt 0 ]]; then | ||
echo "Unexpected extra arguments: $*" >&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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not entirely sure that this functions equivalently for existing use cases. Here's the problem:
If The descriptions of these flags in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing this flag for this case seems dicey to me. And now that I know about the Dangerfile plugin to check this (thank you), this PR seems like a risky place to handle this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of According to the
One of the important aspect of this helper running on our CI builds is that we don't want CI to risk updating any of the local packages used by the build, and instead want to ensure that it will only install the exact same set of packages, with the exact version being locked in the In a way, So TL;DR: I'd advice keeping Using |
||
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 | ||
Comment on lines
-116
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed above, this change should be reverted |
||
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 | ||
|
||
Comment on lines
+173
to
+183
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the discussion above that we want idempotence on CI, using |
||
# `checkouts` can be removed because the system can quickly generate them | ||
# instead of needing to download them in the cache each time. | ||
# | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.