Quantcast
Channel: Package Manager - Swift Forums
Viewing all articles
Browse latest Browse all 167

How to iterate through set of exact dependency versions for swift package using command line?

$
0
0

Hi! I'm maintaining a macros library with the following dependency on swift-syntax:

let dependencies: [Package.Dependency] = [
  .package(url: "https://github.com/apple/swift-syntax.git", "509.0.0"..<"600.0.0"),
]

My goal is to iterate through those supported versions and run my unit tests against each one. Here is what that ends up looking like when I try validating my package "manually" across versions by-hand:

let dependencies: [Package.Dependency] = [
  //  .package(url: "https://github.com/apple/swift-syntax.git", "509.0.0"..<"600.0.0"),
  //  .package(url: "https://github.com/apple/swift-syntax.git", exact: "510.0.2"),
  //  .package(url: "https://github.com/apple/swift-syntax.git", exact: "510.0.1"),
  //  .package(url: "https://github.com/apple/swift-syntax.git", exact: "510.0.0"),
  //  .package(url: "https://github.com/apple/swift-syntax.git", exact: "509.1.1"),
  //  .package(url: "https://github.com/apple/swift-syntax.git", exact: "509.1.0"),
  //  .package(url: "https://github.com/apple/swift-syntax.git", exact: "509.0.2"),
  //  .package(url: "https://github.com/apple/swift-syntax.git", exact: "509.0.1"),
  .package(url: "https://github.com/apple/swift-syntax.git", exact: "509.0.0"),
]

Ehh… not great. My preference would be to somehow "override" the dependency through the command-line (and then write a script that iterates through those options for me before a clean test build).

I attempted to try and pass a flag through to Xswiftc:

//  swift build -Xswiftc -DSWIFT_SYNTAX_509_0_0

#if SWIFT_SYNTAX_509_0_0

let dependencies: [Package.Dependency] = [
  .package(url: "https://github.com/apple/swift-syntax.git", exact: "509.0.0"),
]

//  swift build -Xswiftc -DSWIFT_SYNTAX_509_0_1

#elseif SWIFT_SYNTAX_509_0_1

let dependencies: [Package.Dependency] = [
  .package(url: "https://github.com/apple/swift-syntax.git", exact: "509.0.1"),
]

#else

...

#endif

But it looks like it is a known issue that these flags are meant for forwarding to targets and are not accessible to SwiftPM while the package itself is constructed.[1][2]

It sounds like using environment variables (which are available to SwiftPM) might be a legit workaround… but I'm also open to any other modern patterns the community might know about. Does anyone have a repo or an example for doing something along these lines? Thanks!


  1. Compiler flags in Package.swift ↩︎

  2. Passing compilation flags to local Swift packages ↩︎

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 167

Trending Articles