-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix swift-api-digester
search paths
#7664
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -97,6 +97,16 @@ public struct IdentifiableSet<Element: Identifiable>: Collection { | |||||
public func contains(id: Element.ID) -> Bool { | ||||||
self.storage.keys.contains(id) | ||||||
} | ||||||
|
||||||
public func filter(_ isIncluded: (Self.Element) throws -> Bool) rethrows -> Self { | ||||||
var copy = Self() | ||||||
for element in self { | ||||||
if try isIncluded(element) { | ||||||
copy.insert(element) | ||||||
} | ||||||
} | ||||||
return copy | ||||||
} | ||||||
} | ||||||
|
||||||
extension OrderedDictionary where Value: Identifiable, Key == Value.ID { | ||||||
|
@@ -118,3 +128,9 @@ extension IdentifiableSet: Hashable { | |||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
extension IdentifiableSet: ExpressibleByArrayLiteral { | ||||||
public init(arrayLiteral elements: Element...) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
self.init(elements) | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -641,6 +641,44 @@ public final class SwiftTargetBuildDescription { | |
return args | ||
} | ||
|
||
/// Determines the arguments needed to run `swift-api-digester` for emitting | ||
/// an API baseline for this module. | ||
package func apiDigesterEmitBaselineArguments() throws -> [String] { | ||
var args = [String]() | ||
args += try self.apiDigesterCommonArguments() | ||
return args | ||
} | ||
|
||
/// Determines the arguments needed to run `swift-api-digester` for | ||
/// comparing to an API baseline for this module. | ||
package func apiDigesterCompareBaselineArguments() throws -> [String] { | ||
var args = [String]() | ||
args += try self.apiDigesterCommonArguments() | ||
return args | ||
} | ||
Comment on lines
+646
to
+658
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unclear what these two methods are for if they just append the result of |
||
|
||
public func apiDigesterCommonArguments() throws -> [String] { | ||
var args = [String]() | ||
args += self.buildParameters.toolchain.extraFlags.swiftCompilerFlags | ||
|
||
// FIXME: remove additionalFlags | ||
// Add search paths determined during planning | ||
args += self.additionalFlags | ||
args += ["-I", self.modulesPath.pathString] | ||
|
||
// FIXME: Only include valid args | ||
// `swift-api-digester` args doesn't support -L args. | ||
for index in args.indices.dropLast().reversed() { | ||
if args[index] == "-L" { | ||
// Remove the flag | ||
args.remove(at: index) | ||
// Remove the argument | ||
args.remove(at: index) | ||
} | ||
} | ||
return args | ||
} | ||
|
||
// FIXME: this function should operation on a strongly typed buildSetting | ||
// Move logic from PackageBuilder here. | ||
/// Determines the arguments needed for cxx interop for this module. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -523,53 +523,6 @@ public class BuildPlan: SPMBuildCore.BuildPlan { | |
// handle that situation. | ||
} | ||
|
||
public func createAPIToolCommonArgs(includeLibrarySearchPaths: Bool) throws -> [String] { | ||
// API tool runs on products, hence using `self.productsBuildParameters`, not `self.toolsBuildParameters` | ||
let buildPath = self.destinationBuildParameters.buildPath.pathString | ||
var arguments = ["-I", buildPath] | ||
|
||
// swift-symbolgraph-extract does not support parsing `-use-ld=lld` and | ||
// will silently error failing the operation. Filter out this flag | ||
// similar to how we filter out the library search path unless | ||
// explicitly requested. | ||
var extraSwiftCFlags = self.destinationBuildParameters.toolchain.extraFlags.swiftCompilerFlags | ||
.filter { !$0.starts(with: "-use-ld=") } | ||
if !includeLibrarySearchPaths { | ||
for index in extraSwiftCFlags.indices.dropLast().reversed() { | ||
if extraSwiftCFlags[index] == "-L" { | ||
// Remove the flag | ||
extraSwiftCFlags.remove(at: index) | ||
// Remove the argument | ||
extraSwiftCFlags.remove(at: index) | ||
} | ||
} | ||
} | ||
arguments += extraSwiftCFlags | ||
|
||
// Add search paths to the directories containing module maps and Swift modules. | ||
for target in self.targets { | ||
switch target { | ||
case .swift(let targetDescription): | ||
arguments += ["-I", targetDescription.moduleOutputPath.parentDirectory.pathString] | ||
case .clang(let targetDescription): | ||
if let includeDir = targetDescription.moduleMap?.parentDirectory { | ||
arguments += ["-I", includeDir.pathString] | ||
} | ||
} | ||
} | ||
|
||
// Add search paths from the system library targets. | ||
for target in self.graph.reachableTargets { | ||
if let systemLib = target.underlying as? SystemLibraryTarget { | ||
try arguments.append(contentsOf: self.pkgConfig(for: systemLib).cFlags) | ||
// Add the path to the module map. | ||
arguments += ["-I", systemLib.moduleMapPath.parentDirectory.pathString] | ||
} | ||
} | ||
|
||
return arguments | ||
} | ||
|
||
/// Creates arguments required to launch the Swift REPL that will allow | ||
/// importing the modules in the package graph. | ||
public func createREPLArguments() throws -> [String] { | ||
|
@@ -656,6 +609,24 @@ public class BuildPlan: SPMBuildCore.BuildPlan { | |
} | ||
return try description.symbolGraphExtractArguments() | ||
} | ||
|
||
/// Determines the arguments needed to run `swift-api-digester` for emitting | ||
/// an API baseline for a particular module. | ||
public func apiDigesterEmitBaselineArguments(for module: ResolvedModule) throws -> [String] { | ||
guard let description = self.targetMap[module.id] else { | ||
throw InternalError("Expected description for module \(module)") | ||
} | ||
return try description.apiDigesterEmitBaselineArguments() | ||
} | ||
|
||
/// Determines the arguments needed to run `swift-api-digester` for | ||
/// comparing to an API baseline for a particular module. | ||
public func apiDigesterCompareBaselineArguments(for module: ResolvedModule) throws -> [String] { | ||
guard let description = self.targetMap[module.id] else { | ||
throw InternalError("Expected description for module \(module)") | ||
} | ||
return try description.apiDigesterCompareBaselineArguments() | ||
} | ||
Comment on lines
+613
to
+629
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto, it looks like these two functions are equivalent |
||
} | ||
|
||
extension Basics.Diagnostic { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.