Skip to content

Commit

Permalink
Add support for the new package access modifier (#5983)
Browse files Browse the repository at this point in the history
* Pass the -package-name flag

* Include the -package-name Swift compiler flag

* Fix tests
  • Loading branch information
pepicrft committed Feb 24, 2024
1 parent 0440b6b commit e7ea1b1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
28 changes: 15 additions & 13 deletions Sources/TuistCoreTesting/Graph/DependenciesGraph+TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extension TuistCore.DependenciesGraph {
),
.sdk(name: "WatchKit", type: .framework, status: .required, condition: .when([.watchos])),
],
settings: Self.spmSettings(with: [
settings: Self.spmSettings(packageName: "Tuist", with: [
"HEADER_SEARCH_PATHS": [
"$(SRCROOT)/customPath/cSearchPath",
"$(SRCROOT)/customPath/cxxSearchPath",
Expand Down Expand Up @@ -122,7 +122,7 @@ extension TuistCore.DependenciesGraph {
path: Self.packageFolder(spmFolder: spmFolder, packageName: "another-dependency")
),
],
settings: Self.spmSettings()
settings: Self.spmSettings(packageName: "TuistKit")
),
]

Expand Down Expand Up @@ -190,7 +190,7 @@ extension TuistCore.DependenciesGraph {
name: "ALibraryUtils"
),
],
settings: Self.spmSettings()
settings: Self.spmSettings(packageName: "ALibrary")
),
.target(
name: "ALibraryUtils",
Expand All @@ -203,7 +203,7 @@ extension TuistCore.DependenciesGraph {
sources: [
"\(packageFolder.pathString)/Sources/ALibraryUtils/**",
],
settings: Self.spmSettings()
settings: Self.spmSettings(packageName: "ALibraryUtils")
),
]

Expand Down Expand Up @@ -258,7 +258,7 @@ extension TuistCore.DependenciesGraph {
sources: [
"\(packageFolder.pathString)/Sources/AnotherLibrary/**",
],
settings: Self.spmSettings()
settings: Self.spmSettings(packageName: "AnotherLibrary")
),
]

Expand Down Expand Up @@ -321,7 +321,7 @@ extension TuistCore.DependenciesGraph {
condition: .when([.ios, .macos, .tvos, .watchos])
),
],
settings: Self.spmSettings()
settings: Self.spmSettings(packageName: "Alamofire")
),
]

Expand Down Expand Up @@ -406,7 +406,7 @@ extension TuistCore.DependenciesGraph {
.sdk(name: "z", type: .library, status: .required),
.sdk(name: "StoreKit", type: .framework, status: .required),
],
settings: Self.spmSettings()
settings: Self.spmSettings(packageName: "GoogleAppMeasurementTarget")
),
.target(
name: "GoogleAppMeasurementWithoutAdIdSupportTarget",
Expand Down Expand Up @@ -448,7 +448,7 @@ extension TuistCore.DependenciesGraph {
.sdk(name: "z", type: .library, status: .required),
.sdk(name: "StoreKit", type: .framework, status: .required),
],
settings: Self.spmSettings()
settings: Self.spmSettings(packageName: "GoogleAppMeasurementWithoutAdIdSupportTarget")
),
]

Expand Down Expand Up @@ -527,7 +527,7 @@ extension TuistCore.DependenciesGraph {
sources: [
"\(packageFolder.pathString)/Sources/GULAppDelegateSwizzler/**",
],
settings: Self.spmSettings()
settings: Self.spmSettings(packageName: "GULAppDelegateSwizzler")
),
.target(
name: "GULMethodSwizzler",
Expand All @@ -540,7 +540,7 @@ extension TuistCore.DependenciesGraph {
sources: [
"\(packageFolder.pathString)/Sources/GULMethodSwizzler/**",
],
settings: Self.spmSettings()
settings: Self.spmSettings(packageName: "GULMethodSwizzler")
),

.target(
Expand All @@ -554,7 +554,7 @@ extension TuistCore.DependenciesGraph {
sources: [
"\(packageFolder.pathString)/Sources/GULNSData/**",
],
settings: Self.spmSettings()
settings: Self.spmSettings(packageName: "GULNSData")
),
.target(
name: "GULNetwork",
Expand All @@ -567,7 +567,7 @@ extension TuistCore.DependenciesGraph {
sources: [
"\(packageFolder.pathString)/Sources/GULNetwork/**",
],
settings: Self.spmSettings()
settings: Self.spmSettings(packageName: "GULNetwork")
),
]

Expand Down Expand Up @@ -622,7 +622,7 @@ extension TuistCore.DependenciesGraph {
sources: [
"\(packageFolder.pathString)/Sources/nanopb/**",
],
settings: Self.spmSettings()
settings: Self.spmSettings(packageName: "nanopb")
),
]

Expand Down Expand Up @@ -661,6 +661,7 @@ extension DependenciesGraph {
}

static func spmSettings(
packageName: String,
baseSettings: Settings = .settings(),
with customSettings: SettingsDictionary = [:],
moduleMap: String? = nil
Expand All @@ -675,6 +676,7 @@ extension DependenciesGraph {
"FRAMEWORK_SEARCH_PATHS": ["$(inherited)", "$(PLATFORM_DIR)/Developer/Library/Frameworks"],
"GCC_NO_COMMON_BLOCKS": "NO",
"USE_HEADERMAP": "NO",
"OTHER_SWIFT_FLAGS": ["-package-name", packageName],
]
var settingsDictionary = customSettings.merging(defaultSpmSettings, uniquingKeysWith: { custom, _ in custom })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public final class PackageInfoMapper: PackageInfoMapping {
uniquingKeysWith: { userDefined, _ in userDefined }
)

let targetSettings = targetSettings.merging(
var targetSettings = targetSettings.merging(
// Force enable testing search paths
Dictionary(
uniqueKeysWithValues: [
Expand All @@ -441,6 +441,10 @@ public final class PackageInfoMapper: PackageInfoMapping {
userDefined.merging(defaultDictionary, uniquingKeysWith: { userDefined, _ in userDefined })
}
)
// Setting the -package-name Swift compiler flag
let baseSettings = baseSettings.with(base: [
"OTHER_SWIFT_FLAGS": ["$(inherited)", "-package-name", name],
])

let targets: [ProjectDescription.Target] = try packageInfo.targets
.compactMap { target -> ProjectDescription.Target? in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3278,6 +3278,7 @@ extension ProjectDescription.Target {

fileprivate static func test(
_ name: String,
packageName: String = "Package",
basePath: AbsolutePath = "/",
destinations: ProjectDescription.Destinations = [.iPhone, .iPad, .appleVisionWithiPadDesign, .macWithiPadDesign],
product: ProjectDescription.Product = .staticFramework,
Expand Down Expand Up @@ -3318,7 +3319,12 @@ extension ProjectDescription.Target {
resources: resources.isEmpty ? nil : .resources(resources),
headers: headers,
dependencies: dependencies,
settings: DependenciesGraph.spmSettings(baseSettings: baseSettings, with: customSettings, moduleMap: moduleMap)
settings: DependenciesGraph.spmSettings(
packageName: packageName,
baseSettings: baseSettings,
with: customSettings,
moduleMap: moduleMap
)
)
}
}
Expand Down

0 comments on commit e7ea1b1

Please sign in to comment.