Skip to content

Conditional dependencies not available to build plugin #9848

@madsodgaard

Description

@madsodgaard

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

When specifying a condition for a dependency of a target, it will not appear in the target.dependencies, evne if the condition is fulfilled.

Take for example the following example, where we want to use OkHttp only on Android:

.product(
  name: "OkHttp",
  package: "swift-openapi-okhttp",
  condition: .when(platforms: [.android])
),

Inside the swift-java JExtract build plugin we are traversing the dependencies of the target, to find any related config files. OkHttp does not appear in target.dependencies when using condition:. This is even though we are building for Android with the Swift Android SDK.

This therefore means the JExtract build plugin is not able to find any config files related to OkHttp, and we are forced to include that dependency on all platforms, or do some ugly #if !canImport(Darwin) hack.

Removing

  condition: .when(platforms: [.android])

makes OkHttp appear in the dependency list.

Expected behavior

I would expect the conditional dependency to appear in the list, especially when the condition is fulfilled.

Actual behavior

No response

Steps to reproduce

No response

Swift Package Manager version/commit hash

6.3

Swift & OS version (output of swift --version ; uname -a)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions