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

Preliminary support for target dependency condition #23

Merged
merged 2 commits into from
Jun 27, 2023

Conversation

jonasrottmann
Copy link
Contributor

@jonasrottmann jonasrottmann commented Jun 15, 2023

Hey, I've made some preliminary changes to address issue #22. Although I'm uncertain if this is the optimal approach, and whether parsing the actual condition is even necessary. I noticed that .target dependency conditions are not parsed either. Furthermore, this change doesn't impact visualisation. I haven't included any tests yet, but I'm open to iterating on this 🙂

Based on this example Package.swift

// swift-tools-version: 5.8
import PackageDescription

let package = Package(
    name: "My Package",
    platforms: [
        .iOS(.v16)
    ],
    dependencies: [
        .package(url: "https://hello.world/package", from: "0.0.0")
    ],
    targets: [
        .target(
            name: "MyTarget",
            dependencies: [
                .product(
                    name: "Package",
                    package: "package",
                    condition: .when(platforms: [.iOS])
                ),
                .target(
                    name: "MyLibraryTarget", 
                    condition: .when(platforms: [.iOS])
                )
            ]
        )
    ]
)

I looked at the swift package dump-package output:

...
"dependencies" : [
  {
    "product" : [
      "Package",
      "package",
      null,
      {
        "platformNames" : [
          "ios"
        ]
      }
    ]
  },
  {
    "target" : [
      "MyLibraryTarget",
      {
        "platformNames" : [
          "ios"
        ]
      }
    ]
  }
],
...

@simonbs
Copy link
Owner

simonbs commented Jun 26, 2023

Hey @jonasrottmann and sorry for the late reply. The last couple of weeks have been quite busy 😊

These changes seem fine to me and I'd be happy to merge the PR. Would you mind adding a unit test that covers this first?

@jonasrottmann
Copy link
Contributor Author

Hey, no worries 🙂 I added a iOS platform condition to a dependency in example-package-b.json so PackageSwiftFileParserLiveTests.testParsesDependencies would come across it. I wanted to avoid the hassle of adding an entire new example package JSON 🤔 Please let me know if this is sufficient, or if you believe dedicated tests should be added.

Copy link
Owner

@simonbs simonbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants