[swift-build-dev] [swift-dev] Right list?
erica at ericasadun.com
Fri Feb 26 11:30:32 CST 2016
> On Feb 19, 2016, at 5:50 PM, Max Howell <max.howell at apple.com> wrote:
> Yes, we should probably take this to swift-build-dev.
>> I'd like to add a Package property to namespace packages by origin,
> Some namespacing will certainly be required, the sooner the better.
> I was hoping to namespace with github username where possible, it’s mxcl’s PromiseKit after all.
>> and to add aliases in Swift for renaming imports.
> With namespacing we probably wouldn’t need this solution, which would be more ideal, eg:
> import Foo
> Now you have two Foo, so any package that uses both must be specific:
> import mxcl.Foo
> import erica.Foo
> Provided they are compiled such that the build system knows the namespaces at all times, we should be good. It’s only the user who doesn’t need to know at all times.
Following up on this.
I first brought this topic up on swift-dev, and was pointed to swift-build-dev.
Having spent considerable time messing up my Swift packages by giving them ridiculously obvious names like SwiftString and SwiftCollections, I realized that namespacing would be a solution for disambiguating conflicts. import SwiftString is insufficient when several packages are named SwiftString.
When you have two identically named packages, the module imports need to distinguish both the sources as well as references defined per package. Although SwiftPM finds packages using git URLs and module names, I do not believe that origin is addressable or usable. Plus, throughout the lifetime of a package, that origin could potentially move from, for example, GitHub to Bitbucket.
I suggest using some kind of origin key for differentiation. The simplest solutions for these include reverse domain names (basically a company/source identifier), git URLs (the current location of the repo), Github/Bitbucket user names (which are similar to a company/source identifier but more subject to updates over time).
Of these, I’d recommend reverse domain for the following reasons:
They are relatively short
They are already well established for Apple app distribution
They do not rely on a web address that may change should the repo move
They are less likely to conflict with user names across repo hosts
I’d imagine a package declaration that looks something like this:
let package = Package(
In the case of name conflicts instead of importing SwiftString, you’d prefix an origin:
Ideally, you could further alias these to shorten symbol disambiguation:
import org.sadun.SwiftString as SadunStrings
import com.foobar.SwiftString as FoobarStrings
// Unique to only one package, no name conflict
// name collision disambiguation
I'm interested in hearing any feedback and thoughts about whether this is possible and what I could do to help further this idea.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-build-dev