From 2d53b57a019b6589948328a34c5a6099de583c3a Mon Sep 17 00:00:00 2001 From: Brandon McAnsh Date: Tue, 25 Aug 2026 14:13:06 -0400 Subject: [PATCH] feat(api): build the contract packages from local checkouts Trying a proto change meant publishing a version and a tag for it, because FlipcashAPI pins both contract packages exactly. Setting FLIPCASH_PROTO_LOCAL to the directory holding the two client checkouts swaps the pinned dependencies for path dependencies. An environment variable rather than an edit to this file, for two reasons: the switch has to survive worktrees, where a relative path to a sibling checkout does not, and a manifest nobody edits is one nobody can commit in local mode. CI never sets the variable, so release builds resolve the pins. Verified with swift build against local ocp-client-protocol and flipcash2-client-protocol checkouts, including a message added to a proto and brought in with sync-protos.sh --local. --- FlipcashAPI/Package.swift | 40 +++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/FlipcashAPI/Package.swift b/FlipcashAPI/Package.swift index ebadc5f7e..8c52e70fd 100644 --- a/FlipcashAPI/Package.swift +++ b/FlipcashAPI/Package.swift @@ -2,6 +2,41 @@ // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription +import Foundation + +// The contract packages are normally consumed at a pinned version, which means trying a +// proto change would mean publishing one. Set FLIPCASH_PROTO_LOCAL to the directory that +// holds ocp-client-protocol/ and flipcash2-client-protocol/ to build against those +// checkouts instead: +// +// export FLIPCASH_PROTO_LOCAL=~/dev/bmcreations/code +// xed . +// +// Xcode inherits the environment of whatever launched it, so it has to be started from a +// shell that exported the variable rather than from the Dock. SwiftPM re-evaluates this +// manifest when the variable changes, so switching back needs no clean. +// +// Local mode drops the two contract entries from the tracked workspace Package.resolved. +// That is noise rather than a version change, since the pins below are exact, but restore it +// before committing: +// +// git checkout -- Code.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +// +// Unset is the committed state, and CI never sets it, so release builds always resolve the +// pinned version below. +let protoLocalRoot = ProcessInfo.processInfo.environment["FLIPCASH_PROTO_LOCAL"] + .map { ($0 as NSString).expandingTildeInPath } + .flatMap { $0.isEmpty ? nil : $0 } + +let contractDependencies: [Package.Dependency] = protoLocalRoot.map { root in + [ + .package(path: "\(root)/ocp-client-protocol"), + .package(path: "\(root)/flipcash2-client-protocol"), + ] +} ?? [ + .package(url: "https://github.com/code-payments/ocp-client-protocol", exact: "0.1.0"), + .package(url: "https://github.com/code-payments/flipcash2-client-protocol", exact: "0.1.0"), +] let package = Package( name: "FlipcashAPI", @@ -14,10 +49,7 @@ let package = Package( targets: ["FlipcashAPI"] ), ], - dependencies: [ - .package(url: "https://github.com/code-payments/ocp-client-protocol", exact: "0.1.0"), - .package(url: "https://github.com/code-payments/flipcash2-client-protocol", exact: "0.1.0"), - ], + dependencies: contractDependencies, targets: [ .target( name: "FlipcashAPI",