Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-11432] Declarative package description for SwiftPM using Function Builders #4665

Closed
swift-ci opened this issue Sep 7, 2019 · 2 comments

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Sep 7, 2019

Previous ID SR-11432
Radar None
Original Reporter kitasuke (JIRA User)
Type New Feature
Status Closed
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels New Feature
Assignee kitasuke (JIRA)
Priority Medium

md5: 063f185e77f07f6591ed8271b385975c

Issue Description:

Overview

I would like to make a propose to have declarative package description by using function builder as alternative way. I think we can keep current way as it is.

There are pros and cons. This case might not work with function builders because package description has type constraints in the tree structure, but I would love to hear your opinions.

Pros

  • Declarative description

  • More understandable API

Cons

  • Can't have type constraints for all of contents unless we defined function builder for specific types

  • Compiler error is not friendly when we have wrong content at unexpected place

let package = Package(name: "Paper") {
    ProductList {
        Product(name: "tool", type: .static) {
            TargetList {
                Target(name: "tool")
            }
        }
    }
    DependencyList {
        Dependency(
            url: "http://example.com.com/ExamplePackage/ExamplePackage",
            from: "1.2.3"
        )
        Dependency(url: "dev", exact: "1.2.3")
    }
    TargetList {
        Target(name: "tool") {
            TargetDependencyList {
                TargetDependency(name: "Paper")
                TargetDependency(name: "ExamplePackage")
            }
        }
        Target(name: "Paper") {
            TargetDependencyList {
                TargetDependency(name: "Basic")
                Target(name: "Utility")
                Product(name: "AnotherExamplePackage")
            }
        }
    }
}

Here is my rough implementation of the functionality. Encoded data would be interface for current implementation of package description.

https://gist.github.com/kitasuke/ee73934c2eda0f63bbd371b69380c443

With this implementation, description above can be encoded because it conforms to Encodable, so that this can be mapped to existing structure easily. Here is sample encoded output as JSON

{
  "targets": [
    {
      "name": "tool",
      "dependencies": [
        {
          "name": "Paper"
        },
        {
          "name": "ExamplePackage"
        }
      ]
    },
    {
      "name": "Paper",
      "dependencies": [
        {
          "name": "Basic"
        },
        {
          "name": "Utility"
        },
        {
          "name": "AnotherExamplePackage",
          "type": "executable"
        }
      ]
    }
  ],
  "name": "Paper",
  "dependencies": [
    {
      "url": "http://example.com.com/ExamplePackage/ExamplePackage",
      "from": "1.2.3"
    },
    {
      "url": "dev",
      "exact": "1.2.3"
    }
  ],
  "products": [
    {
      "name": "tool",
      "type": "static",
      "targets": [
        {
          "name": "tool"
        }
      ]
    }
  ]
}
@ankitspd
Copy link
Member

ankitspd commented Sep 9, 2019

kitasuke (JIRA User) Thanks for working on this! We should discuss this on the forums so a wider audience can pitch in. Can you post this in the SwiftPM development category: https://forums.swift.org/c/development/SwiftPM

@swift-ci
Copy link
Contributor Author

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants