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-6375] SwiftPM parses the Package.swift of all possible dependencies in the dependency tree, even when unnecessary. #4917

Open
Lukasa opened this issue Nov 13, 2017 · 1 comment
Labels

Comments

@Lukasa
Copy link
Contributor

Lukasa commented Nov 13, 2017

Previous ID SR-6375
Radar rdar://problem/40205155
Original Reporter @Lukasa
Type Bug

Attachment: Download

Environment

Swift 4

Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: 21bb328f0003af1c21ffa211feb59e6f

Issue Description:

When building a package with SwiftPM, the package manager builds the Package.swift for each package in the complete hypothetical dependency tree of the root package: that is, it builds all the dependencies for all products defined in any Package.swift.

This can be demonstrated by considering the following three Package.swift files. The first one, for the root package:

import PackageDescription

let package = Package(
{{ name: "head",}}
{{ products: [}}
{{ .executable(name: "head", targets: ["head"]),}}
{{ ],}}
{{ dependencies: [}}
{{ .package(url: "../middle", from: "1.0.0"),}}
{{ ],}}
{{ targets: [}}
{{ .target(name: "head", dependencies: ["MiddleSecond"]),}}
{{ ]}}
)

The second one, containing the declaration for the middle package:

import PackageDescription

let package = Package(
{{ name: "middle",}}
{{ products: [}}
{{ .library(name: "MiddleFirst", targets: ["MiddleFirst"]),}}
{{ .library(name: "MiddleSecond", targets: ["MiddleSecond"]),}}
{{ ],}}
{{ dependencies: [}}
{{ .package(url: "../leaf", from: "1.0.0"),}}
{{ ],}}
{{ targets: [}}
{{ .target(name: "MiddleFirst", dependencies: ["leaf"]),}}
{{ .target(name: "MiddleSecond"),}}
{{ ]}}
)

The third one, containing the leaf dependency:

import PackageDescription

let package = Package(
{{ name: "leaf",}}
{{ products: [}}
{{ .library(name: "leaf", targets: ["leaf"]),}}
{{ ],}}
{{ targets: [}}
{{ .target(name: "leaf")}}
{{ ]}}
)

invalidSyntax()

If, from the directory containing the first Package.swift, you run swift build, the build will fail due to the error in leaf's Package.swift. This is despite the fact that leaf is not necessary to build head: head's only dependency is on products that do not depend on leaf.

Put another way, SwiftPM eagerly compiles the Package.swift for all possible dependencies of each package, rather than restricting itself only to the actual dependencies of each package. SwiftPM doesn't go so far as to actually compile each of the packages, so there is no issue with errors in the package themselves, but if for some reason the Package.swift generates warnings or errors then this will cause builds that appear to fail, while actually being quite capable of succeeding. This can happen for Package.swift's that require system dependencies that are not present, but which are not required for the actual build in question.

Please find attached a tarball that expands to a trio of repositories that demonstrate the issue.

@ankitspd
Copy link
Member

@swift-ci create

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants