Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import struct SPMBuildCore.BuildSystemProvider
import enum PackageModel.BuildConfiguration
import struct Basics.Environment
import struct Basics.EnvironmentKey

public var SupportedBuildSystemOnAllPlatforms: [BuildSystemProvider.Kind] = BuildSystemProvider.Kind.allCases.filter { $0 != .xcode }

Expand All @@ -28,10 +30,29 @@ public struct BuildData {
public let config: BuildConfiguration
}

package let TEST_ONLY_DEBUG_ENV_VAR = EnvironmentKey("SWIFTPM_TEST_ONLY_DEBUG_BUILD_CONFIGURATION")
public func getBuildData(for buildSystems: [BuildSystemProvider.Kind]) -> [BuildData] {
buildSystems.flatMap { buildSystem in
BuildConfiguration.allCases.compactMap { config in
let buildConfigurations: [BuildConfiguration]
if let value = Environment.current[TEST_ONLY_DEBUG_ENV_VAR], value.isTruthy {
buildConfigurations = [.debug]
} else {
buildConfigurations = BuildConfiguration.allCases
}
return buildSystems.flatMap { buildSystem in
buildConfigurations.compactMap { config in
return BuildData(buildSystem: buildSystem, config: config)
}
}
}


extension String {
package var isTruthy: Bool {
switch self.lowercased() {
case "true", "1", "yes":
return true
default:
return false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2024-2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import _InternalTestSupport
import Testing
import struct SPMBuildCore.BuildSystemProvider
import enum PackageModel.BuildConfiguration
import struct Basics.Environment

@Suite(
.tags(
.TestSize.small,
)
)
struct BuildSystemProviderSupportedTests {

@Test(
.serialized,
arguments: [
[BuildSystemProvider.Kind.native],
[BuildSystemProvider.Kind.native, .xcode],
[BuildSystemProvider.Kind.native, .xcode, .swiftbuild],
], [true, false],
)
func getBuildDataReturnsExpectedTests(
buildSystemsUT: [BuildSystemProvider.Kind],
setEnvironmantVariable: Bool,
) async throws {
let expectedCount: Int
let customEnv: Environment

if setEnvironmantVariable {
expectedCount = buildSystemsUT.count
customEnv = [TEST_ONLY_DEBUG_ENV_VAR : "true"]
} else {
expectedCount = buildSystemsUT.count * BuildConfiguration.allCases.count
customEnv = [:]
}

try Environment.makeCustom(customEnv) {
let actual = getBuildData(for: buildSystemsUT)

#expect(actual.count == expectedCount)
}

}
}
53 changes: 53 additions & 0 deletions Tests/_InternalTestSupportTests/String+ExtensionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2024-2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import _InternalTestSupport
import Testing

@Suite(
.tags(
.TestSize.small,
)
)
struct StringExtensionTests {

@Test(
arguments: [
(value: "", expected: false),
(value: " ", expected: false),
(value: "0", expected: false),
(value: "1", expected: true),
(value: "true", expected: true),
(value: "True", expected: true),
(value: "TrUe", expected: true),
(value: "ftrue", expected: false),
(value: "truef", expected: false),
(value: "ftruef", expected: false),
(value: "YES", expected: true),
(value: "YEs", expected: true),
(value: "yEs", expected: true),
(value: "yes", expected: true),
(value: "fyes", expected: false),
(value: "yesf", expected: false),
(value: "fyesf", expected: false),
(value: "11", expected: false),
],
)
func isTruthyReturnsCorrectValue(
valueUT: String,
expected: Bool,
) async throws {
let actual = valueUT.isTruthy

#expect(actual == expected, "Value \(valueUT) should be \(expected)")
}
}
8 changes: 8 additions & 0 deletions Utilities/build-using-self
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def is_on_darwin() -> bool:
return platform.system() == "Darwin"


def is_on_windows() -> bool:
return platform.system() == "Windows"


def set_environment(
*,
swiftpm_bin_dir: pathlib.Path,
Expand All @@ -147,6 +151,10 @@ def set_environment(
sdk_root = call_output(shlex.split("xcrun --show-sdk-path --sdk macosx"))
logging.debug("macos sdk root = %r", sdk_root)
os.environ["SDKROOT"] = sdk_root

if is_on_windows():
# GH #9159: Temprorarily set this environment until we figure out why the Windows internal CI is hanging
os.environ["SWIFTPM_TEST_ONLY_DEBUG_BUILD_CONFIGURATION"] = "true"
log_environment()


Expand Down