Skip to content

Commit 869b66d

Browse files
committed
Suggested changes to prep for strongly typed BuildSettings
1 parent 380a493 commit 869b66d

File tree

4 files changed

+66
-80
lines changed

4 files changed

+66
-80
lines changed

Sources/XcodeGraphMapper/Mappers/Settings/BuildSettings.swift

+18-34
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,8 @@ enum BuildSettingKey: String {
55
case sdkroot = "SDKROOT"
66
case compilerFlags = "COMPILER_FLAGS"
77
case attributes = "ATTRIBUTES"
8-
case environmentVariables = "ENVIRONMENT_VARIABLES"
98
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"
179
case mergedBinaryType = "MERGED_BINARY_TYPE"
18-
case prune = "PRUNE"
19-
case mergeable = "MERGEABLE"
2010
case productBundleIdentifier = "PRODUCT_BUNDLE_IDENTIFIER"
2111
case infoPlistFile = "INFOPLIST_FILE"
2212
case codeSignEntitlements = "CODE_SIGN_ENTITLEMENTS"
@@ -27,6 +17,24 @@ enum BuildSettingKey: String {
2717
case visionOSDeploymentTarget = "VISIONOS_DEPLOYMENT_TARGET"
2818
}
2919

20+
enum TuistBuildSettingKey: String {
21+
case showEnvVarsInLog = "SHOW_ENV_VARS_IN_LOG"
22+
case shellPath = "SHELL_PATH"
23+
case launchArguments = "LAUNCH_ARGUMENTS"
24+
case tags = "TAGS"
25+
case prune = "PRUNE"
26+
case mergeable = "MERGEABLE"
27+
case environmentVariables = "ENVIRONMENT_VARIABLES"
28+
}
29+
30+
enum TuistScriptSettingKey: String {
31+
case dependencyFile = "DEPENDENCY_FILE"
32+
case inputPaths = "INPUT_PATHS"
33+
case outputPaths = "OUTPUT_PATHS"
34+
}
35+
36+
37+
3038
/// A protocol representing a type that can parse a build setting value from a generic `Any`.
3139
protocol BuildSettingValue {
3240
associatedtype Value
@@ -48,20 +56,6 @@ enum BuildSettingStringArray: BuildSettingValue {
4856
}
4957
}
5058

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-
6559
extension [String: Any] {
6660
/// Extracts a build setting value of a specified type from the dictionary.
6761
///
@@ -87,14 +81,4 @@ extension [String: Any] {
8781
func stringArray(for key: BuildSettingKey) -> [String]? {
8882
extractBuildSetting(key, as: BuildSettingStringArray.self)
8983
}
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-
}
10084
}

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
@@ -17,45 +17,45 @@ extension PBXTarget {
1717
buildPhases.compactMap { $0 as? PBXCopyFilesBuildPhase }
1818
}
1919

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

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

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

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

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

Sources/XcodeGraphMapper/Mappers/Targets/PBXTargetMapper.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ struct PBXTargetMapper: PBXTargetMapping {
176176
let buildRules = try pbxTarget.buildRules.compactMap { try buildRuleMapper.map($0) }
177177

178178
// Environment & Launch
179-
let environmentVariables = pbxTarget.extractEnvironmentVariables()
180-
let launchArguments = try pbxTarget.launchArguments()
179+
// let environmentVariables = pbxTarget.extractEnvironmentVariables()
180+
// let launchArguments = try pbxTarget.launchArguments()
181181

182182
// Files group
183183
let filesGroup = try extractFilesGroup(from: pbxTarget, xcodeProj: xcodeProj)
@@ -186,11 +186,11 @@ struct PBXTargetMapper: PBXTargetMapping {
186186
let playgrounds = try extractPlaygrounds(from: pbxTarget, xcodeProj: xcodeProj)
187187

188188
// Misc
189-
let prune = try pbxTarget.prune()
189+
// let prune = try pbxTarget.prune()
190190
let mergedBinaryType = try pbxTarget.mergedBinaryType()
191-
let mergeable = try pbxTarget.mergeable()
191+
// let mergeable = try pbxTarget.mergeable()
192192
let onDemandResourcesTags = try pbxTarget.onDemandResourcesTags()
193-
let metadata = try pbxTarget.metadata()
193+
// let metadata = try pbxTarget.metadata()
194194

195195
// Dependencies
196196
let projectNativeTargets = try pbxTarget.dependencies.compactMap {
@@ -215,19 +215,19 @@ struct PBXTargetMapper: PBXTargetMapping {
215215
headers: headers,
216216
coreDataModels: coreDataModels,
217217
scripts: scripts,
218-
environmentVariables: environmentVariables,
219-
launchArguments: launchArguments,
218+
// environmentVariables: environmentVariables,
219+
// launchArguments: launchArguments,
220220
filesGroup: filesGroup,
221221
dependencies: allDependencies,
222222
rawScriptBuildPhases: rawScriptBuildPhases,
223223
playgrounds: playgrounds,
224224
additionalFiles: additionalFiles,
225225
buildRules: buildRules,
226-
prune: prune,
226+
// prune: false,
227227
mergedBinaryType: mergedBinaryType,
228-
mergeable: mergeable,
229-
onDemandResourcesTags: onDemandResourcesTags,
230-
metadata: metadata
228+
// mergeable: mergeable,
229+
onDemandResourcesTags: onDemandResourcesTags
230+
// metadata: metadata
231231
)
232232
}
233233

0 commit comments

Comments
 (0)