[swift-evolution] [swift-build-dev] Proposal: SwiftPM Target Access Control

Anders Bertelrud anders at apple.com
Wed Jul 13 10:57:24 CDT 2016


Thanks for taking the initiative for this, Ankit.  It's a very welcome improvement.

Comments inline.

On 2016-07-12, at 11.15, Ankit Agarwal via swift-build-dev <swift-build-dev at swift.org> wrote:
> To mark a target as exported/public I propose PackageDescription's Target gains a flags property which would be a Set of the following Flag enum declared inside Target class:
> 
> public enum Flag {
>     /// Makes the target public or "exported" for other packages to use.
>     case public
> }
> The Flag enum will be flexible in case we need to add more attributes in future as opposed to a boolean property to mark the public nature of the target.
> 
I would prefer that this be a boolean parameter rather than a generic `flags` parameter, since it makes the manifest read more naturally, and, importantly, is no less extensible than an enum.  Additional parameters with default values can as easily be added as more enum cases can, and in either case, a manifest written to assume the existence of `public` will be equally incompatible with older versions of the package manager.

So, for example:

let package = Package(
   name: "FooLibrary",
   targets: [
       Target(name: "FooLibrary", public: true),
       Target(name: "SampleCLI", dependencies: ["FooLibrary"]),
   ])
> We can keep some obvious defaults for targets which can be implicitly public for e.g. 
> 
> Package has only one target.
> Target with same name as package.
I'm a bit wary of magic here.  I think it would be clearer to have the manifest declare what is public and what is not.  With magic naming conventions it's too easy to accidentally change semantics just by renaming a target.
> I propose that enum Target.Dependency gains a new case External(package: String, target: String) to declare dependency on an external package's target.
> 
Since it's the same fundamental kind of dependency in either case, would it be better to have `package` be an optional parameter to Target?

So that `Target(name: "Foo")` is local but `Target(name: "Foo", package: "Bar")` external?  That would seem more logical.

Anders


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160713/67576b9f/attachment.html>


More information about the swift-evolution mailing list