Different versions per swift version in Portfile

Andrew Udvare audvare at gmail.com
Mon May 24 19:15:27 UTC 2021


> On 2021-05-24, at 13:27, 조성빈 <goranmoomin at daum.net> wrote:
> 
> I’m trying to write my first Portfile for the swift-format tool.
> 
> I’m referencing the xcodes port as an example of a Swift port.
> 
> The problem here is that the version of the tool must be synced with the local swift version.
> For example, release 0.50400.0 is compatible with Swift 5.4, 0.50300.0 is compatible with Swift 5.3, etc…
> 
> My questions:
> 	• Is it right to give if conditions on the swift version to differentiate versions?

You probably want to do this by having subports or having separate ports for each version. Subports are easier to maintain as its in one file and can share and inherit variables from a top level. In each subport, change the version and distfile being pulled in. Example, with GitHub PortGroup:

# Latest version gets no suffix
github.setup apple swift-format 0.50400.0

subport ${name}52 {  # name swift-format
  github.setup apple swift-format 0.50200.1
}

> Would executing different version statements on every if branch be sufficient?


Generally ports don't try to make install-time assumptions on behalf of the user. The user has to pick the correct version to install. This is especially because none of the port's configure, build, etc phases will execute when the packaged is installed via a pre-built tarball.

Subport use in the kubectl port: https://github.com/macports/macports-ports/blob/c382ef7da2db4cef7a087edbf0d75647f4c708aa/sysutils/kubectl/Portfile#L24

> 	• If 1. is correct, is there a variable for me to test with?

You could test with $xcodeversion prior to building/installation. For example in a swift-format53 (where 53 indicates Swift 5.3 compatibility requiring Xcode 12) port:

subport ${name}53 {  # name swift-format
  if {[vercmp $xcodeversion 12] < 0} {
    ui_error "${name} @${version} Xcode 12 or later."
    return -code error "incompatible Xcode version"
  }
}

> 	• If 1. is incorrect, how should I provide different versions? Would just providing the version only for the latest swift the right choice?

This would probably be acceptable to most users of Swift. Most users want to stay up-to-date with it. Having the flexibility there for those supporting older platforms would still be appreciated.

-- 
Andrew


More information about the macports-users mailing list