Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify that only targets that are manifest dependencies can be import…
…ed. (#3562) * Verify that only targets that are manifest dependencies can be imported. This change introduces a build verification step that attempts to detect scenarios where a target contains an `import` of another target in the package without declaring the imported target as a dependency in the manifest. This is done via SwiftDriver's import-prescan capability which relies on libSwiftScan to quickly parse a target's sources and identify all `import`ed modules. Related to rdar://79423257 * Skip target-import dependency verification procedure and test, if the host compiler does not support it. * Skip targets that contain or depend-on generated code, because generated source-code may not be available at the time of scan. * Add an opt-out from explicit target dependency import checking. `--disable-explicit-target-dependency-import-checking` prevents the verification code from being run as a just-in-case option to opt-out from this warning * Flip the `--disable-explicit-target-dependency-import-checking` option to an opt-in `enable` option. While we work on optimizing incremental build performance of this check, it would be nice to have it as an opt-in option. * Allow configuring the explicit import checking with either 'error', 'warning', or 'none' modes, with 'none' being the default.
- Loading branch information
Showing
11 changed files
with
229 additions
and
11 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Fixtures/Miscellaneous/ImportOfMissingDependency/Package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// swift-tools-version:5.1 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "VerificationTestPackage", | ||
products: [ | ||
.executable(name: "BExec", targets: ["B"]), | ||
], | ||
dependencies: [ | ||
|
||
], | ||
targets: [ | ||
.target( | ||
name: "A", | ||
dependencies: []), | ||
.target( | ||
name: "B", | ||
dependencies: []), | ||
] | ||
) |
4 changes: 4 additions & 0 deletions
4
Fixtures/Miscellaneous/ImportOfMissingDependency/Sources/A/A.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import B | ||
public func bar(x: Int) -> Int { | ||
return 11 + foo(x: x) | ||
} |
3 changes: 3 additions & 0 deletions
3
Fixtures/Miscellaneous/ImportOfMissingDependency/Sources/B/B.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public func foo(x: Int) -> Int { | ||
return 11 + x | ||
} |
1 change: 1 addition & 0 deletions
1
Fixtures/Miscellaneous/ImportOfMissingDependency/Sources/B/main.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print(baz(x: 11)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters