Actually... it can indeed happen when you have a remote package dependency but it specifies a local dependency path. You might wonder why that would ever happen, but I've run into this several times.
The best workaround that I've found is to use an environment variable to switch from the local to the remote at build time as needed:
Examples/SwiftXChess/SwiftXChessOpenings/Package.swift
- let useLocal = ProcessInfo.processInfo.environment["SWIFTXDEV"] != nil
- let swiftXState = useLocal
- ? Package.Dependency.package(
- name: "SwiftXState",
- path: "../../.."
- )
- : .package(url: repo, from: swiftXMinVersion)
Then below:
Examples/SwiftXChess/SwiftXChessOpenings/Package.swift
- dependencies: [
- .package(url: "https://github.com/chesskit-app/chesskit-swift", from: "0.17.0"),
- swiftXState,
(using the swiftXState global variable in the dependencies: array)
Note: if you're using Xcode, then you have to take non-obvious steps to get ProcessInfo in your Package.swift to actually see any env vars. Because it certainly doesn't read them from your Scheme or .xcproj build settings env vars. No no... and it doesn't even read them from your shell .*rc or .profile, etc.
The only solution that I've found is to jerry-rig launchctl:
launchctl setenv MY_VAR "my value"
... then quit and reopen Xcode.
If you need it to be persistent for your user login on your Mac, you can make a .plist like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.jon.env</string>
<key>ProgramArguments</key>
<array>
<string>/bin/launchctl</string>
<string>setenv</string>
<string>MY_VAR</string>
<string>my value</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
... and save that into ~/Library/LaunchAgents/com.makeXcodePlayNiceWithSPM.env.plist
Then of course the first time you add this, do the following raindance to avoid having to reboot/relog your Mac:
launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.makeXcodePlayNiceWithSPM.env.plist
launchctl kickstart -k gui/$UID/com.makeXcodePlayNiceWithSPM.env.plist
... then quit and reopen Xcode, and tattoo onto your left arm what you have done so that later you can actually remember how to disable that env var when needed.
(If anyone knows a better way to make Xcode's SPM see env vars via ProcessInfo, certainly let me know. There has to be a better way... right?) ![]()