Skip to content

Commit 586e6f2

Browse files
authored
Merge pull request #1633 from ahoppen/ahoppen/5.9/automatic-libraries
[5.9] Change all library types to automatic
2 parents e2e430a + e041db7 commit 586e6f2

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

Package.swift

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ let package = Package(
4545
.macCatalyst(.v13),
4646
],
4747
products: [
48-
.library(name: "SwiftCompilerPlugin", type: .static, targets: ["SwiftCompilerPlugin"]),
49-
.library(name: "SwiftCompilerPluginMessageHandling", type: .static, targets: ["SwiftCompilerPluginMessageHandling"]),
50-
.library(name: "SwiftDiagnostics", type: .static, targets: ["SwiftDiagnostics"]),
51-
.library(name: "SwiftIDEUtils", type: .static, targets: ["SwiftIDEUtils"]),
52-
.library(name: "SwiftOperators", type: .static, targets: ["SwiftOperators"]),
53-
.library(name: "SwiftParser", type: .static, targets: ["SwiftParser"]),
54-
.library(name: "SwiftParserDiagnostics", type: .static, targets: ["SwiftParserDiagnostics"]),
55-
.library(name: "SwiftRefactor", type: .static, targets: ["SwiftRefactor"]),
56-
.library(name: "SwiftSyntax", type: .static, targets: ["SwiftSyntax"]),
57-
.library(name: "SwiftSyntaxBuilder", type: .static, targets: ["SwiftSyntaxBuilder"]),
58-
.library(name: "SwiftSyntaxMacros", type: .static, targets: ["SwiftSyntaxMacros"]),
59-
.library(name: "SwiftSyntaxMacrosTestSupport", type: .static, targets: ["SwiftSyntaxMacrosTestSupport"]),
48+
.library(name: "SwiftCompilerPlugin", targets: ["SwiftCompilerPlugin"]),
49+
.library(name: "SwiftCompilerPluginMessageHandling", targets: ["SwiftCompilerPluginMessageHandling"]),
50+
.library(name: "SwiftDiagnostics", targets: ["SwiftDiagnostics"]),
51+
.library(name: "SwiftIDEUtils", targets: ["SwiftIDEUtils"]),
52+
.library(name: "SwiftOperators", targets: ["SwiftOperators"]),
53+
.library(name: "SwiftParser", targets: ["SwiftParser"]),
54+
.library(name: "SwiftParserDiagnostics", targets: ["SwiftParserDiagnostics"]),
55+
.library(name: "SwiftRefactor", targets: ["SwiftRefactor"]),
56+
.library(name: "SwiftSyntax", targets: ["SwiftSyntax"]),
57+
.library(name: "SwiftSyntaxBuilder", targets: ["SwiftSyntaxBuilder"]),
58+
.library(name: "SwiftSyntaxMacros", targets: ["SwiftSyntaxMacros"]),
59+
.library(name: "SwiftSyntaxMacrosTestSupport", targets: ["SwiftSyntaxMacrosTestSupport"]),
6060
],
6161
targets: [
6262
// MARK: - Internal helper targets
@@ -277,6 +277,22 @@ let package = Package(
277277
]
278278
)
279279

280+
// This is a fake target that depends on all targets in the package.
281+
// We need to define it manually because the `SwiftSyntax-Package` target doesn't exist for `swift build`.
282+
283+
package.targets.append(
284+
.target(
285+
name: "SwiftSyntax-all",
286+
dependencies: package.targets.compactMap {
287+
if $0.type == .test {
288+
return nil
289+
} else {
290+
return .byName(name: $0.name)
291+
}
292+
}
293+
)
294+
)
295+
280296
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
281297
// Building standalone.
282298
package.dependencies += [

Sources/SwiftSyntax-all/empty.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This is a fake target that depends on all targets in the package.
2+
// We need to define it manually because the `SwiftSyntax-Package` target doesn't exist for `swift build`.

build-script.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,19 @@ def __get_swiftpm_invocation(self, package_dir: str) -> List[str]:
215215

216216
def buildProduct(self, product_name: str) -> None:
217217
print("** Building product " + product_name + " **")
218-
self.__build(PACKAGE_DIR, product_name)
218+
self.__build(PACKAGE_DIR, product_name, is_product=True)
219+
220+
def buildTarget(self, target_name: str) -> None:
221+
print("** Building target " + target_name + " **")
222+
self.__build(PACKAGE_DIR, target_name, is_product=False)
219223

220224
def buildExample(self, example_name: str) -> None:
221225
print("** Building example " + example_name + " **")
222-
self.__build(EXAMPLES_DIR, example_name)
226+
self.__build(EXAMPLES_DIR, example_name, is_product=True)
223227

224-
def __build(self, package_dir: str, product_name: str) -> None:
228+
def __build(self, package_dir: str, name: str, is_product: bool) -> None:
225229
command = list(self.__get_swiftpm_invocation(package_dir))
226-
command.extend(["--product", product_name])
230+
command.extend(["--product" if is_product else "--target", name])
227231

228232
env = dict(os.environ)
229233
env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1"
@@ -499,10 +503,7 @@ def build_command(args: argparse.Namespace) -> None:
499503
verbose=args.verbose,
500504
disable_sandbox=args.disable_sandbox,
501505
)
502-
# Until rdar://53881101 is implemented, we cannot request a build of multiple
503-
# targets simultaneously. For now, just build one product after the other.
504-
builder.buildProduct("SwiftSyntax")
505-
builder.buildProduct("SwiftSyntaxBuilder")
506+
builder.buildTarget("SwiftSyntax-all")
506507

507508
# Build examples
508509
builder.buildExample("AddOneToIntegerLiterals")

0 commit comments

Comments
 (0)