Skip to content

Revert all of the functionality related to provided libraries #7801

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

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,6 @@ let systemSQLitePkgConfig: String? = "sqlite3"
*/
let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]

let packageModelResourcesSettings: [SwiftSetting]
let packageModelResources: [Resource]
if ProcessInfo.processInfo.environment["SWIFTPM_USE_LIBRARIES_METADATA"] == nil {
packageModelResources = []
packageModelResourcesSettings = [.define("SKIP_RESOURCE_SUPPORT")]
} else {
packageModelResources = [
.copy("InstalledLibrariesSupport/provided-libraries.json"),
]
packageModelResourcesSettings = []
}

let package = Package(
name: "SwiftPM",
platforms: [
Expand Down Expand Up @@ -245,9 +233,7 @@ let package = Package(
/** Primitive Package model objects */
name: "PackageModel",
dependencies: ["Basics"],
exclude: ["CMakeLists.txt", "README.md"],
resources: packageModelResources,
swiftSettings: packageModelResourcesSettings
exclude: ["CMakeLists.txt", "README.md"]
),

.target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
// Computed during build planning.
var dylibs: [ProductBuildDescription] = []

/// The list of provided libraries that are going to be used by this product.
var providedLibraries: [String: AbsolutePath] = [:]

/// Any additional flags to be added. These flags are expected to be computed during build planning.
var additionalFlags: [String] = []

Expand Down Expand Up @@ -161,8 +158,6 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
args += ["-F", self.buildParameters.buildPath.pathString]
}

self.providedLibraries.forEach { args += ["-L", $1.pathString, "-l", $0] }

args += ["-L", self.buildParameters.buildPath.pathString]
args += try ["-o", binaryPath.pathString]
args += ["-module-name", self.product.name.spm_mangledToC99ExtendedIdentifier()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,8 @@ extension LLBuildManifestBuilder {
if target.underlying is SystemLibraryModule { return }
// Ignore Binary Modules.
if target.underlying is BinaryModule { return }
// Ignore Plugin Targets.
// Ignore Plugin Modules.
if target.underlying is PluginModule { return }
// Ignore Provided Libraries.
if target.underlying is ProvidedLibraryModule { return }

// Depend on the binary for executable targets.
if target.type == .executable && prepareForIndexing == .off {
Expand Down
91 changes: 0 additions & 91 deletions Sources/Build/BuildOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
/// Alternative path to search for pkg-config `.pc` files.
private let pkgConfigDirectories: [AbsolutePath]

/// Map of dependency package identities by root packages that depend on them.
private let dependenciesByRootPackageIdentity: [PackageIdentity: [PackageIdentity]]

/// Map of root package identities by target names which are declared in them.
private let rootPackageIdentityByTargetName: [String: PackageIdentity]

public convenience init(
productsBuildParameters: BuildParameters,
toolsBuildParameters: BuildParameters,
Expand All @@ -210,8 +204,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
scratchDirectory: AbsolutePath,
additionalFileRules: [FileRuleDescription],
pkgConfigDirectories: [AbsolutePath],
dependenciesByRootPackageIdentity: [PackageIdentity: [PackageIdentity]],
targetsByRootPackageIdentity: [PackageIdentity: [String]],
outputStream: OutputByteStream,
logLevel: Basics.Diagnostic.Severity,
fileSystem: Basics.FileSystem,
Expand All @@ -227,8 +219,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
traitConfiguration: nil,
additionalFileRules: additionalFileRules,
pkgConfigDirectories: pkgConfigDirectories,
dependenciesByRootPackageIdentity: dependenciesByRootPackageIdentity,
targetsByRootPackageIdentity: targetsByRootPackageIdentity,
outputStream: outputStream,
logLevel: logLevel,
fileSystem: fileSystem,
Expand All @@ -246,8 +236,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
traitConfiguration: TraitConfiguration?,
additionalFileRules: [FileRuleDescription],
pkgConfigDirectories: [AbsolutePath],
dependenciesByRootPackageIdentity: [PackageIdentity: [PackageIdentity]],
targetsByRootPackageIdentity: [PackageIdentity: [String]],
outputStream: OutputByteStream,
logLevel: Basics.Diagnostic.Severity,
fileSystem: Basics.FileSystem,
Expand Down Expand Up @@ -276,8 +264,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
self.additionalFileRules = additionalFileRules
self.pluginConfiguration = pluginConfiguration
self.pkgConfigDirectories = pkgConfigDirectories
self.dependenciesByRootPackageIdentity = dependenciesByRootPackageIdentity
self.rootPackageIdentityByTargetName = (try? Dictionary<String, PackageIdentity>(throwingUniqueKeysWithValues: targetsByRootPackageIdentity.lazy.flatMap { e in e.value.map { ($0, e.key) } })) ?? [:]
}

public func getPackageGraph() throws -> ModulesGraph {
Expand Down Expand Up @@ -399,81 +385,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
}
}

private static var didEmitUnexpressedDependencies = false

private func detectUnexpressedDependencies() {
return self.detectUnexpressedDependencies(
// Note: once we switch from the toolchain global metadata, we will have to ensure we can match the right metadata used during the build.
availableLibraries: self.config.toolchain(for: .target).providedLibraries,
targetDependencyMap: self.buildDescription.targetDependencyMap
)
}

// TODO: Currently this function will only match frameworks.
func detectUnexpressedDependencies(
availableLibraries: [ProvidedLibrary],
targetDependencyMap: [String: [String]]?
) {
// Ensure we only emit these once, regardless of how many builds are being done.
guard !Self.didEmitUnexpressedDependencies else {
return
}
Self.didEmitUnexpressedDependencies = true

let availableFrameworks = Dictionary<String, PackageIdentity>(uniqueKeysWithValues: availableLibraries.compactMap {
if let identity = Set($0.metadata.identities.map(\.identity)).spm_only {
return ("\($0.metadata.productName).framework", identity)
} else {
return nil
}
})

targetDependencyMap?.keys.forEach { targetName in
let c99name = targetName.spm_mangledToC99ExtendedIdentifier()
// Since we're analysing post-facto, we don't know which parameters are the correct ones.
let possibleTempsPaths = [BuildParameters.Destination]([.target, .host]).map {
self.config.buildPath(for: $0).appending(component: "\(c99name).build")
}

let usedSDKDependencies: [String] = Set(possibleTempsPaths).flatMap { possibleTempsPath in
guard let contents = try? self.fileSystem.readFileContents(
possibleTempsPath.appending(component: "\(c99name).d")
) else {
return [String]()
}

// FIXME: We need a real makefile deps parser here...
let deps = contents.description.split(whereSeparator: { $0.isWhitespace })
return deps.filter {
!$0.hasPrefix(possibleTempsPath.parentDirectory.pathString)
}.compactMap {
try? AbsolutePath(validating: String($0))
}.compactMap {
return $0.components.first(where: { $0.hasSuffix(".framework") })
}
}

let dependencies: [PackageIdentity]
if let rootPackageIdentity = self.rootPackageIdentityByTargetName[targetName] {
dependencies = self.dependenciesByRootPackageIdentity[rootPackageIdentity] ?? []
} else {
dependencies = []
}

Set(usedSDKDependencies).forEach {
if availableFrameworks.keys.contains($0) {
if let availableFrameworkPackageIdentity = availableFrameworks[$0], !dependencies.contains(
availableFrameworkPackageIdentity
) {
observabilityScope.emit(
warning: "target '\(targetName)' has an unexpressed depedency on '\(availableFrameworkPackageIdentity)'"
)
}
}
}
}
}

/// Perform a build using the given build description and subset.
public func build(subset: BuildSubset) throws {
guard !self.config.shouldSkipBuilding(for: .target) else {
Expand Down Expand Up @@ -514,8 +425,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS

let duration = buildStartTime.distance(to: .now())

self.detectUnexpressedDependencies()

let subsetDescriptor: String?
switch subset {
case .product(let productName, _):
Expand Down
8 changes: 1 addition & 7 deletions Sources/Build/BuildPlan/BuildPlan+Product.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ extension BuildPlan {
}
buildProduct.libraryBinaryPaths = dependencies.libraryBinaryPaths

buildProduct.providedLibraries = dependencies.providedLibraries

buildProduct.availableTools = dependencies.availableTools
}

Expand All @@ -130,7 +128,6 @@ extension BuildPlan {
staticTargets: [ResolvedModule],
systemModules: [ResolvedModule],
libraryBinaryPaths: Set<AbsolutePath>,
providedLibraries: [String: AbsolutePath],
availableTools: [String: AbsolutePath]
) {
/* Prior to tools-version 5.9, we used to erroneously recursively traverse executable/plugin dependencies and statically include their
Expand Down Expand Up @@ -208,7 +205,6 @@ extension BuildPlan {
var staticTargets = [ResolvedModule]()
var systemModules = [ResolvedModule]()
var libraryBinaryPaths: Set<AbsolutePath> = []
var providedLibraries = [String: AbsolutePath]()
var availableTools = [String: AbsolutePath]()

for dependency in allTargets {
Expand Down Expand Up @@ -262,8 +258,6 @@ extension BuildPlan {
}
case .plugin:
continue
case .providedLibrary:
providedLibraries[target.name] = target.underlying.path
}

case .product(let product, _):
Expand All @@ -279,7 +273,7 @@ extension BuildPlan {
staticTargets.append(contentsOf: derivedTestTargets)
}

return (linkLibraries, staticTargets, systemModules, libraryBinaryPaths, providedLibraries, availableTools)
return (linkLibraries, staticTargets, systemModules, libraryBinaryPaths, availableTools)
}

/// Extracts the artifacts from an artifactsArchive
Expand Down
6 changes: 1 addition & 5 deletions Sources/Build/BuildPlan/BuildPlan+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
//===----------------------------------------------------------------------===//

import struct Basics.InternalError

import class PackageModel.BinaryModule
import class PackageModel.ClangModule
import class PackageModel.SystemLibraryModule
import class PackageModel.ProvidedLibraryModule

extension BuildPlan {
func plan(swiftTarget: SwiftModuleBuildDescription) throws {
Expand Down Expand Up @@ -49,10 +49,6 @@ extension BuildPlan {
swiftTarget.libraryBinaryPaths.insert(library.libraryPath)
}
}
case let target as ProvidedLibraryModule:
swiftTarget.additionalFlags += [
"-I", target.path.pathString
]
default:
break
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Build/BuildPlan/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
toolsVersion: toolsVersion,
fileSystem: fileSystem
))
case is SystemLibraryModule, is BinaryModule, is ProvidedLibraryModule:
case is SystemLibraryModule, is BinaryModule:
break
default:
throw InternalError("unhandled \(target.underlying)")
Expand Down
1 change: 0 additions & 1 deletion Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_compile_definitions(SKIP_RESOURCE_SUPPORT)
add_compile_definitions(USE_IMPL_ONLY_IMPORTS)

add_subdirectory(Basics)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Commands/PackageCommands/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extension SwiftPackageCommand {
case .removed:
report += "\n"
report += "- \(package.identity) \(currentVersion)"
case .unchanged, .usesLibrary:
case .unchanged:
continue
}
}
Expand Down
2 changes: 0 additions & 2 deletions Sources/Commands/Snippets/Cards/TopCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ fileprivate extension Module.Kind {
return "snippets"
case .macro:
return "macros"
case .providedLibrary:
return "provided libraries"
}
}
}
2 changes: 0 additions & 2 deletions Sources/CoreCommands/BuildSystemSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ private struct NativeBuildSystemFactory: BuildSystemFactory {
traitConfiguration: traitConfiguration,
additionalFileRules: FileRuleDescription.swiftpmFileTypes,
pkgConfigDirectories: self.swiftCommandState.options.locations.pkgConfigDirectories,
dependenciesByRootPackageIdentity: rootPackageInfo.dependencies,
targetsByRootPackageIdentity: rootPackageInfo.targets,
outputStream: outputStream ?? self.swiftCommandState.outputStream,
logLevel: logLevel ?? self.swiftCommandState.logLevel,
fileSystem: self.swiftCommandState.fileSystem,
Expand Down
3 changes: 2 additions & 1 deletion Sources/CoreCommands/SwiftCommandState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import var TSCBasic.stderrStream
import class TSCBasic.TerminalController
import class TSCBasic.ThreadSafeOutputByteStream

import TSCUtility // cannot be scoped because of `String.spm_mangleToC99ExtendedIdentifier()`
import var TSCUtility.verbosity

typealias Diagnostic = Basics.Diagnostic

Expand Down Expand Up @@ -503,6 +503,7 @@ public final class SwiftCommandState {
return (identities, targets)
}


private func getEditsDirectory() throws -> AbsolutePath {
// TODO: replace multiroot-data-file with explicit overrides
if let multiRootPackageDataFile = options.locations.multirootPackageDataFile {
Expand Down
5 changes: 2 additions & 3 deletions Sources/PackageGraph/BoundVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

import struct PackageModel.ProvidedLibrary
import struct TSCUtility.Version

/// A bound version for a package within an assignment.
Expand All @@ -23,7 +22,7 @@ public enum BoundVersion: Equatable, Hashable {
case excluded

/// The version of the package to include.
case version(Version, library: ProvidedLibrary? = nil)
case version(Version)

/// The package assignment is unversioned.
case unversioned
Expand All @@ -37,7 +36,7 @@ extension BoundVersion: CustomStringConvertible {
switch self {
case .excluded:
return "excluded"
case .version(let version, _):
case .version(let version):
return version.description
case .unversioned:
return "unversioned"
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageGraph/ModulesGraph+Loading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ private func createResolvedPackages(
dependencyProductName: productRef.name,
dependencyPackageName: productRef.package,
dependencyProductInDecl: !declProductsAsDependency.isEmpty,
similarProductName: bestMatchedProductName,
similarProductName: bestMatchedProductName,
packageContainingSimilarProduct: packageContainingBestMatchedProduct
)
packageObservabilityScope.emit(error)
Expand Down
Loading