swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.76k stars 1.35k forks source link

[SR-12688] Incorrect builds in the presence of non-trivial dependency trees #4554

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-12688
Radar rdar://problem/62895060
Original Reporter saeta (JIRA User)
Type Bug

Attachment: Download

Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: fdd57c62922cb379b72d41c2a4322140

Issue Description:

When building complicated SwiftPM-based projects, it's easy to forget to mark dependencies. This results in nondeterministic builds, especially if using incremental building. Attached to this issue is a tar file containing a simple SwiftPM-based project (I've reproduced the salient parts inline below, but to reproduce, just download and extract the attached tar file.)

// swift-tools-version:5.1

import PackageDescription

let package = Package(
  name: "Buggy",
  products: [
    .library(name: "A", targets: ["A"]),
    .library(name: "B", targets: ["B"]),
    .library(name: "C", targets: ["C"]),
  ],
  targets: [
    .target(name: "A"),
    .target(name: "B"),
    .target(name: "C", dependencies: ["A", "B"]),
  ]
)

In the code, A vends a type MyType. Sources/B/MyUser.swift imports A and uses MyType inside MyOtherType. (Note: no dependency is made in Package.swift above. Finally, C depends on both and properly declares the dependencies.

When I build this project clean the first time, I correctly get a compile error. But if I re-build (making zero changes!) once or twice more, I inevitably get a successful build. This reproduces both on Linux and mac, including with toolchains newer than 5.3.

swift-ci commented 4 years ago

Comment by Brennan Saeta (JIRA)

I believe the correct way to resolve this issue is via compiler sandboxing: https://forums.swift.org/t/my-swiftpm-wishlist-aka-proposal-proposals/35292/36?u=saeta

beccadax commented 4 years ago

@swift-ci create