swift-package-override is a tool to assist with performing ad-hoc Swift package dependency version overrides against Swift packages and Xcode projects. In an Xcode based development workflow, you can drag and drop local checkouts of a specific version of a package dependency to override it. swift-package-override provides a way to apply these kind of overrides which can be used in automated test workflows.
cdinto the root directory of the project to have a Swift package dependency override applied uponswift-package-override set foo v1.2.3to apply an override for packagefoo- Perform testing
swift-package-override checkto verify overrides in effect during testing
For full usage information, run swift-package-override help
Package overrides are specified as a string of package name and git ref pairs separated by spaces.
For example:
foo v1.2.3 bar my_branch baz 46cbda4118e4cae48ad45e1cd7353b9f1674d91e qux? v5.6.7
- Package
foowill have an override set using Git tagv1.2.3 - Package
barwill have an override set using Git branchmy_branch - Package
bazwill have an override set using Git commit46cbda4118e4cae48ad45e1cd7353b9f1674d91e - Package
quxwill have an optional override set using Git tagv5.6.7
Attempts to override a package which is not present as a dependency of the project will cause swift-package-override to return an error. If an optional override is specified, then the absence of a dependency is only treated as a warning.
swift-package-override is configured using configuration files in a .swiftpm_override directory at the root level of a project:
├── .swiftpm_override
│ ├── config
│ └── projects
Configuration opions are set as POSIX sh variable assignments. E.g.
SWIFTPM_OVERRIDE_CONFIG__VERSION=1
SWIFTPM_OVERRIDE_CONFIG__VERSION must be set to 1, indicating the version of the configuration conventions being used.
SWIFTPM_OVERRIDE_CONFIG__PACKAGE_DIR is used to identify the directory which contains the Package.swift file containing the project Swift package dependencies. By default, the Package.swift file is expected to be found in the root level of the project. If it is located in a sub directory/package, it should be configured here.
SWIFTPM_OVERRIDE_CONFIG__BUILD_DIR is used to specify a custom build directory (normally .build) produced by execution of swift commands. It must be set to perform package override verification using the check command, after execution of a build or test swift command.
SWIFTPM_OVERRIDE_CONFIG__DERIVEDDATA_DIR is used to specify a custom derived data directory produced by execution of xcodebuild commands. It must be set to perform package override verification using the check command, after execution of a build or test xcodebuild command.
SWIFTPM_OVERRIDE_CONFIG__CREATE_PACKAGE_WORKSPACE is disabled by default. Enable it by setting a value of 1. This is required for Swift package based projects which do not have Xcode project or workspaces, but which have builds/tests performed against them using xcodebuild.
SWIFTPM_OVERRIDE_CONFIG__CREATE_CHECKOUTS_SYMLINK is disabled by default. Enable it by setting a value of 1. This is is required for use of swift-package-override with Tuist and dependencies are defined using the Tuist/Package.swift file. If package dependencies are specified using a Package.swift file in a different location, this option can be left as disabled.
SWIFTPM_OVERRIDE_CONFIG__SET_ENV_VAR must be set to the name of the environment variable which should contain the list of package overrides (as package name, Git ref pairs separated by spaces) set-env-var and status-env-var commands.
SWIFTPM_OVERRIDE_CONFIG__PROJECT_IMPORT_ON_OVERRIDE is enabled by default. If it is disabled, Xcode projects or workspaces listed in .swiftpm_override/projects will not have package overrides imported into them when swift-package-override set or set-env-var commands are run. This is useful for projects which are performing Xcode project or workspace generation using separate tools (e.g. XcodeGen, or Tuist). After Xcode project or workspace generation has been performed using another tool, an explicit project import can be performed using swift-package-override project-import.
This file should contain the paths to xcodeproj bundles which should have package overrides applied to them. Each path should be followed by a LF.