Skip to content

Commit e660b0a

Browse files
committed
Suggested changes to prep for strongly typed BuildSettings
1 parent 9689550 commit e660b0a

File tree

4 files changed

+74
-84
lines changed

4 files changed

+74
-84
lines changed

Sources/XcodeGraphMapper/Mappers/Settings/BuildSettings.swift

+25-37
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,8 @@ import Foundation
33
/// Keys representing various build settings that may appear in an Xcode project or workspace configuration.
44
enum BuildSettingKey: String {
55
case sdkroot = "SDKROOT"
6-
case compilerFlags = "COMPILER_FLAGS"
7-
case attributes = "ATTRIBUTES"
8-
case environmentVariables = "ENVIRONMENT_VARIABLES"
96
case codeSignOnCopy = "CODE_SIGN_ON_COPY"
10-
case dependencyFile = "DEPENDENCY_FILE"
11-
case inputPaths = "INPUT_PATHS"
12-
case outputPaths = "OUTPUT_PATHS"
13-
case showEnvVarsInLog = "SHOW_ENV_VARS_IN_LOG"
14-
case shellPath = "SHELL_PATH"
15-
case launchArguments = "LAUNCH_ARGUMENTS"
16-
case tags = "TAGS"
17-
case mergedBinaryType = "MERGED_BINARY_TYPE"
18-
case prune = "PRUNE"
19-
case mergeable = "MERGEABLE"
7+
208
case productBundleIdentifier = "PRODUCT_BUNDLE_IDENTIFIER"
219
case infoPlistFile = "INFOPLIST_FILE"
2210
case codeSignEntitlements = "CODE_SIGN_ENTITLEMENTS"
@@ -27,6 +15,30 @@ enum BuildSettingKey: String {
2715
case visionOSDeploymentTarget = "VISIONOS_DEPLOYMENT_TARGET"
2816
}
2917

18+
enum TuistBuildSettingKey: String {
19+
case launchArguments = "LAUNCH_ARGUMENTS" // Used for scheme generation
20+
case environmentVariables = "ENVIRONMENT_VARIABLES" // Used for scheme generation
21+
case tags = "TAGS" // metadata
22+
case prune = "PRUNE"
23+
case mergeable = "MERGEABLE" // Mergable library build settings generation
24+
case mergedBinaryType = "MERGED_BINARY_TYPE" // Default settings configuration for mergable libraries
25+
}
26+
27+
enum TuistScriptSettingKey: String {
28+
case showEnvVarsInLog = "SHOW_ENV_VARS_IN_LOG"
29+
case shellPath = "SHELL_PATH"
30+
case dependencyFile = "DEPENDENCY_FILE"
31+
case inputPaths = "INPUT_PATHS"
32+
case outputPaths = "OUTPUT_PATHS"
33+
}
34+
35+
enum BuildFileSettings: String {
36+
case compilerFlags = "COMPILER_FLAGS"
37+
case attributes = "ATTRIBUTES"
38+
}
39+
40+
41+
3042
/// A protocol representing a type that can parse a build setting value from a generic `Any`.
3143
protocol BuildSettingValue {
3244
associatedtype Value
@@ -48,20 +60,6 @@ enum BuildSettingStringArray: BuildSettingValue {
4860
}
4961
}
5062

51-
/// A type that parses build settings as booleans.
52-
enum BuildSettingBool: BuildSettingValue {
53-
static func parse(_ any: Any) -> Bool? {
54-
any as? Bool
55-
}
56-
}
57-
58-
/// A type that parses build settings as dictionaries of strings to strings.
59-
enum BuildSettingStringDict: BuildSettingValue {
60-
static func parse(_ any: Any) -> [String: String]? {
61-
any as? [String: String]
62-
}
63-
}
64-
6563
extension [String: Any] {
6664
/// Extracts a build setting value of a specified type from the dictionary.
6765
///
@@ -87,14 +85,4 @@ extension [String: Any] {
8785
func stringArray(for key: BuildSettingKey) -> [String]? {
8886
extractBuildSetting(key, as: BuildSettingStringArray.self)
8987
}
90-
91-
/// Retrieves a boolean value for the given build setting key.
92-
func bool(for key: BuildSettingKey) -> Bool? {
93-
extractBuildSetting(key, as: BuildSettingBool.self)
94-
}
95-
96-
/// Retrieves a dictionary of strings for the given build setting key.
97-
func stringDict(for key: BuildSettingKey) -> [String: String]? {
98-
extractBuildSetting(key, as: BuildSettingStringDict.self)
99-
}
10088
}

Sources/XcodeGraphMapper/Mappers/Targets/PBXTarget+BuildSettings.swift

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import XcodeProj
66
extension PBXTarget {
77
enum EnvironmentExtractor {
88
static func extract(from buildSettings: BuildSettings) -> [String: EnvironmentVariable] {
9-
guard let envVars = buildSettings.stringDict(for: .environmentVariables) else {
10-
return [:]
11-
}
12-
return envVars.reduce(into: [:]) { result, pair in
13-
result[pair.key] = EnvironmentVariable(value: pair.value, isEnabled: true)
14-
}
9+
// guard let envVars = buildSettings.stringDict(for: .environmentVariables) else {
10+
// return [:]
11+
// }
12+
// return envVars.reduce(into: [:]) { result, pair in
13+
// result[pair.key] = EnvironmentVariable(value: pair.value, isEnabled: true)
14+
// }
15+
//
16+
[:]
1517
}
1618
}
1719

Sources/XcodeGraphMapper/Mappers/Targets/PBXTarget+GraphMapping.swift

+29-29
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,45 @@ extension PBXTarget {
1818
buildPhases.compactMap { $0 as? PBXCopyFilesBuildPhase }
1919
}
2020

21-
func launchArguments() throws -> [LaunchArgument] {
22-
guard let buildConfigList = buildConfigurationList else { return [] }
23-
var launchArguments: [LaunchArgument] = []
24-
for buildConfig in buildConfigList.buildConfigurations {
25-
if let args = buildConfig.buildSettings.stringArray(for: .launchArguments) {
26-
launchArguments.append(contentsOf: args.map { LaunchArgument(name: $0, isEnabled: true) })
27-
}
28-
}
29-
return launchArguments.uniqued()
30-
}
31-
32-
func prune() throws -> Bool {
33-
debugBuildSettings.bool(for: .prune) ?? false
34-
}
21+
// func launchArguments() throws -> [LaunchArgument] {
22+
// guard let buildConfigList = buildConfigurationList else { return [] }
23+
// var launchArguments: [LaunchArgument] = []
24+
// for buildConfig in buildConfigList.buildConfigurations {
25+
// if let args = buildConfig.buildSettings.stringArray(for: .launchArguments) {
26+
// launchArguments.append(contentsOf: args.map { LaunchArgument(name: $0, isEnabled: true) })
27+
// }
28+
// }
29+
// return launchArguments.uniqued()
30+
// }
31+
32+
// func prune() throws -> Bool {
33+
// debugBuildSettings.bool(for: .prune) ?? false
34+
// }
3535

3636
func mergedBinaryType() throws -> MergedBinaryType {
3737
let mergedBinaryTypeString = debugBuildSettings.string(for: .mergedBinaryType)
3838
return mergedBinaryTypeString == "automatic" ? .automatic : .disabled
3939
}
4040

41-
func mergeable() throws -> Bool {
42-
debugBuildSettings.bool(for: .mergeable) ?? false
43-
}
41+
// func mergeable() throws -> Bool {
42+
// debugBuildSettings.bool(for: .mergeable) ?? false
43+
// }
4444

4545
func onDemandResourcesTags() throws -> OnDemandResourcesTags? {
4646
// Currently returns nil, could be extended if needed
4747
return nil
4848
}
4949

50-
func metadata() throws -> TargetMetadata {
51-
var tags: Set<String> = []
52-
for buildConfig in buildConfigurationList?.buildConfigurations ?? [] {
53-
if let tagsString = buildConfig.buildSettings.string(for: .tags) {
54-
let extractedTags = tagsString
55-
.split(separator: ",")
56-
.map { $0.trimmingCharacters(in: .whitespaces) }
57-
tags.formUnion(extractedTags)
58-
}
59-
}
60-
return .metadata(tags: tags)
61-
}
50+
// func metadata() throws -> TargetMetadata {
51+
// var tags: Set<String> = []
52+
// for buildConfig in buildConfigurationList?.buildConfigurations ?? [] {
53+
// if let tagsString = buildConfig.buildSettings.string(for: .tags) {
54+
// let extractedTags = tagsString
55+
// .split(separator: ",")
56+
// .map { $0.trimmingCharacters(in: .whitespaces) }
57+
// tags.formUnion(extractedTags)
58+
// }
59+
// }
60+
// return .metadata(tags: tags)
61+
// }
6262
}

Sources/XcodeGraphMapper/Mappers/Targets/PBXTargetMapper.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ struct PBXTargetMapper: PBXTargetMapping {
186186
let buildRules = try pbxTarget.buildRules.compactMap { try buildRuleMapper.map($0) }
187187

188188
// Environment & Launch
189-
let environmentVariables = pbxTarget.extractEnvironmentVariables()
190-
let launchArguments = try pbxTarget.launchArguments()
189+
// let environmentVariables = pbxTarget.extractEnvironmentVariables()
190+
// let launchArguments = try pbxTarget.launchArguments()
191191

192192
// Files group
193193
let filesGroup = try extractFilesGroup(from: pbxTarget, xcodeProj: xcodeProj)
@@ -196,11 +196,11 @@ struct PBXTargetMapper: PBXTargetMapping {
196196
let playgrounds = try extractPlaygrounds(from: pbxTarget, xcodeProj: xcodeProj)
197197

198198
// Misc
199-
let prune = try pbxTarget.prune()
200-
let mergedBinaryType = try pbxTarget.mergedBinaryType()
201-
let mergeable = try pbxTarget.mergeable()
199+
// let prune = try pbxTarget.prune()
200+
// let mergedBinaryType = try pbxTarget.mergedBinaryType()
201+
// let mergeable = try pbxTarget.mergeable()
202202
let onDemandResourcesTags = try pbxTarget.onDemandResourcesTags()
203-
let metadata = try pbxTarget.metadata()
203+
// let metadata = try pbxTarget.metadata()
204204

205205
// Dependencies
206206
let projectNativeTargets = try pbxTarget.dependencies.compactMap {
@@ -225,19 +225,19 @@ struct PBXTargetMapper: PBXTargetMapping {
225225
headers: headers,
226226
coreDataModels: coreDataModels,
227227
scripts: scripts,
228-
environmentVariables: environmentVariables,
229-
launchArguments: launchArguments,
228+
// environmentVariables: environmentVariables,
229+
// launchArguments: launchArguments,
230230
filesGroup: filesGroup,
231231
dependencies: allDependencies,
232232
rawScriptBuildPhases: rawScriptBuildPhases,
233233
playgrounds: playgrounds,
234234
additionalFiles: additionalFiles,
235235
buildRules: buildRules,
236-
prune: prune,
237-
mergedBinaryType: mergedBinaryType,
238-
mergeable: mergeable,
236+
// prune: false,
237+
// mergedBinaryType: mergedBinaryType,
238+
// mergeable: mergeable,
239239
onDemandResourcesTags: onDemandResourcesTags,
240-
metadata: metadata,
240+
// metadata: metadata
241241
packages: packages
242242
)
243243
}

0 commit comments

Comments
 (0)