Skip to content

[benchmark] Refactor Package.swift manifest file #20120

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

Closed
Closed
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
2 changes: 2 additions & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore SwiftPM's default build directory.
.build
123 changes: 67 additions & 56 deletions benchmark/Package.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// swift-tools-version:4.2

import PackageDescription
import Foundation

import class Foundation.FileManager
import struct Foundation.URL

// This is a stop gap hack so we can edit benchmarks in Xcode.
let singleSourceLibraries: [String] = {
let f = FileManager.`default`
// FIXME: Side-effects in the package manifest file are not supported may lead
// to unexpected behavior. For e.g., SwiftPM might not pick up the updates
// in this directory due to manifest caching.
let dirURL = URL(fileURLWithPath: "single-source").absoluteURL
let fileURLs = try! f.contentsOfDirectory(at: dirURL,
includingPropertiesForKeys: nil)
return fileURLs.flatMap { (path: URL) -> String? in
let fileURLs = try! FileManager.default.contentsOfDirectory(at: dirURL, includingPropertiesForKeys: nil)

return fileURLs.compactMap{ path in
let c = path.lastPathComponent.split(separator: ".")
// Too many components. Must be a gyb file.
if c.count > 2 {
Expand All @@ -30,66 +33,74 @@ let singleSourceLibraries: [String] = {
}()

let multiSourceLibraries: [String] = {
let f = FileManager.`default`
// FIXME: Side-effects in the package manifest file are not supported may lead
// to unexpected behavior. For e.g., SwiftPM might not pick up the updates
// in this directory due to manifest caching.
let dirURL = URL(fileURLWithPath: "multi-source").absoluteURL
let fileURLs = try! f.contentsOfDirectory(at: dirURL,
includingPropertiesForKeys: nil)
return fileURLs.map { (path: URL) -> String in
return path.lastPathComponent
}
let fileURLs = try! FileManager.default.contentsOfDirectory(at: dirURL, includingPropertiesForKeys: nil)
return fileURLs.map{ return $0.lastPathComponent }
}()

var products: [Product] = []
products.append(.library(name: "TestsUtils", type: .static, targets: ["TestsUtils"]))
products.append(.library(name: "DriverUtils", type: .static, targets: ["DriverUtils"]))
products.append(.library(name: "ObjectiveCTests", type: .static, targets: ["ObjectiveCTests"]))
products.append(.executable(name: "SwiftBench", targets: ["SwiftBench"]))
products.append(.library(name: "PrimsSplit", type: .static, targets: ["PrimsSplit"]))
products += singleSourceLibraries.map { .library(name: $0, type: .static, targets: [$0]) }
products += multiSourceLibraries.map { .library(name: $0, type: .static, targets: [$0]) }
// Targets.
var targets: [Target] = [
.target(
name: "TestsUtils",
path: "utils",
sources: ["TestsUtils.swift"]
),

.systemLibrary(
name: "LibProc",
path: "utils/LibProc"
),

var targets: [Target] = []
targets.append(.target(name: "TestsUtils", path: "utils", sources: ["TestsUtils.swift"]))
targets.append(.systemLibrary(name: "LibProc", path: "utils/LibProc"))
targets.append(
.target(name: "DriverUtils",
dependencies: [.target(name: "TestsUtils"), "LibProc"],
.target(
name: "DriverUtils",
dependencies: ["TestsUtils", "LibProc"],
path: "utils",
sources: ["DriverUtils.swift", "ArgParse.swift"]))
targets.append(
.target(name: "SwiftBench",
sources: ["DriverUtils.swift", "ArgParse.swift"]
),

.target(
name: "ObjectiveCTests",
path: "utils/ObjectiveCTests",
publicHeadersPath: "."
)
]

targets += [
.target(
name: "SwiftBench",
dependencies: [
.target(name: "TestsUtils"),
.target(name: "ObjectiveCTests"),
.target(name: "DriverUtils"),
] + singleSourceLibraries.map { .target(name: $0) }
+ multiSourceLibraries.map { .target(name: $0) },
"TestsUtils",
"ObjectiveCTests",
"DriverUtils",
] + singleSourceLibraries.map{ .target(name: $0) } + multiSourceLibraries.map{ .target(name: $0) },
path: "utils",
sources: ["main.swift"]))
targets.append(
.target(name: "ObjectiveCTests",
path: "utils/ObjectiveCTests",
publicHeadersPath: "."))
targets += singleSourceLibraries.map { x in
return .target(name: x,
dependencies: [
.target(name: "TestsUtils"),
.target(name: "ObjectiveCTests"),
],
path: "single-source",
sources: ["\(x).swift"])
sources: ["main.swift"]
)
]

targets += singleSourceLibraries.map{
.target(name: $0,
dependencies: ["TestsUtils", "ObjectiveCTests"],
path: "single-source",
sources: ["\($0).swift"]
)
}
targets += multiSourceLibraries.map { x in
return .target(name: x,
dependencies: [
.target(name: "TestsUtils")
],
path: "multi-source/\(x)")

targets += multiSourceLibraries.map{
return .target(name: $0,
dependencies: ["TestsUtils"],
path: "multi-source/\($0)"
)
}

let p = Package(
name: "swiftbench",
products: products,
let package = Package(
name: "SwiftBench",
products: [
.executable(name: "SwiftBench", targets: ["SwiftBench"]),
],
targets: targets,
swiftLanguageVersions: [.v4]
)