Skip to content

Commit 15cd755

Browse files
authored
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. (#3285)
1 parent 42f4bcf commit 15cd755

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
@@ -224,6 +224,7 @@ public func loadPackageGraph(
224224
manifests: [Manifest],
225225
explicitProduct: String? = nil,
226226
shouldCreateMultipleTestProducts: Bool = false,
227+
allowExtensionTargets: Bool = false,
227228
createREPLProduct: Bool = false
228229
) throws -> PackageGraph {
229230
let rootManifests = manifests.filter { $0.packageKind == .root }
@@ -239,6 +240,7 @@ public func loadPackageGraph(
239240
diagnostics: diagnostics,
240241
fileSystem: fs,
241242
shouldCreateMultipleTestProducts: shouldCreateMultipleTestProducts,
243+
allowExtensionTargets: allowExtensionTargets,
242244
createREPLProduct: createREPLProduct
243245
)
244246
}

0 commit comments

Comments
 (0)