Skip to content

Commit a631f1a

Browse files
committed
Allow the feature flag to enable package extensions to be controlled by input parameters to the package graph in addition to the SWIFTPM_ENABLE_EXTENSION_TARGETS environment variable, so that unit tests can selectively enable it for synthetic-package tests.
1 parent 4249b7e commit a631f1a

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extension PackageGraph {
3030
diagnostics: DiagnosticsEngine,
3131
fileSystem: FileSystem = localFileSystem,
3232
shouldCreateMultipleTestProducts: Bool = false,
33+
allowExtensionTargets: Bool = false,
3334
createREPLProduct: Bool = false
3435
) throws -> PackageGraph {
3536

@@ -111,6 +112,7 @@ extension PackageGraph {
111112
fileSystem: fileSystem,
112113
diagnostics: diagnostics,
113114
shouldCreateMultipleTestProducts: shouldCreateMultipleTestProducts,
115+
allowExtensionTargets: allowExtensionTargets,
114116
createREPLProduct: manifest.packageKind == .root ? createREPLProduct : false
115117
)
116118
let package = try builder.construct()

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ public final class PackageBuilder {
238238
/// Temporary parameter controlling whether to warn about implicit executable targets when tools version is 5.4.
239239
private let warnAboutImplicitExecutableTargets: Bool
240240

241-
/// Temporary parameter controlling whether to allow package extension targets (durning bring-up, before proposal is accepted).
241+
/// Temporary parameter controlling whether to allow package extension targets (during bring-up, before proposal is accepted).
242+
/// This is set if SWIFTPM_ENABLE_EXTENSION_TARGETS=1 or if the feature is enabled in the initializer (for use by unit tests).
242243
private let allowExtensionTargets: Bool
243244

244245
/// Create the special REPL product for this package.
@@ -271,7 +272,7 @@ public final class PackageBuilder {
271272
diagnostics: DiagnosticsEngine,
272273
shouldCreateMultipleTestProducts: Bool = false,
273274
warnAboutImplicitExecutableTargets: Bool = true,
274-
allowExtensionTargets: Bool = (ProcessEnv.vars["SWIFTPM_ENABLE_EXTENSION_TARGETS"] == "1"),
275+
allowExtensionTargets: Bool = false,
275276
createREPLProduct: Bool = false
276277
) {
277278
self.manifest = manifest
@@ -283,7 +284,7 @@ public final class PackageBuilder {
283284
self.fileSystem = fileSystem
284285
self.diagnostics = diagnostics
285286
self.shouldCreateMultipleTestProducts = shouldCreateMultipleTestProducts
286-
self.allowExtensionTargets = allowExtensionTargets
287+
self.allowExtensionTargets = allowExtensionTargets || ProcessEnv.vars["SWIFTPM_ENABLE_EXTENSION_TARGETS"] == "1"
287288
self.createREPLProduct = createREPLProduct
288289
self.warnAboutImplicitExecutableTargets = warnAboutImplicitExecutableTargets
289290
}

Sources/SPMTestSupport/misc.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public func loadPackageGraph(
221221
manifests: [Manifest],
222222
explicitProduct: String? = nil,
223223
shouldCreateMultipleTestProducts: Bool = false,
224+
allowExtensionTargets: Bool = false,
224225
createREPLProduct: Bool = false
225226
) throws -> PackageGraph {
226227
let rootManifests = manifests.filter { $0.packageKind == .root }
@@ -236,6 +237,7 @@ public func loadPackageGraph(
236237
diagnostics: diagnostics,
237238
fileSystem: fs,
238239
shouldCreateMultipleTestProducts: shouldCreateMultipleTestProducts,
240+
allowExtensionTargets: allowExtensionTargets,
239241
createREPLProduct: createREPLProduct
240242
)
241243
}

0 commit comments

Comments
 (0)