Skip to content

[feedback wanted] refactor: Limit BuildSettings usage to only String and [String] values #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
62 changes: 25 additions & 37 deletions Sources/XcodeGraphMapper/Mappers/Settings/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,8 @@ import Foundation
/// Keys representing various build settings that may appear in an Xcode project or workspace configuration.
enum BuildSettingKey: String {
case sdkroot = "SDKROOT"
case compilerFlags = "COMPILER_FLAGS"
case attributes = "ATTRIBUTES"
case environmentVariables = "ENVIRONMENT_VARIABLES"
case codeSignOnCopy = "CODE_SIGN_ON_COPY"
case dependencyFile = "DEPENDENCY_FILE"
case inputPaths = "INPUT_PATHS"
case outputPaths = "OUTPUT_PATHS"
case showEnvVarsInLog = "SHOW_ENV_VARS_IN_LOG"
case shellPath = "SHELL_PATH"
case launchArguments = "LAUNCH_ARGUMENTS"
case tags = "TAGS"
case mergedBinaryType = "MERGED_BINARY_TYPE"
case prune = "PRUNE"
case mergeable = "MERGEABLE"

case productBundleIdentifier = "PRODUCT_BUNDLE_IDENTIFIER"
case infoPlistFile = "INFOPLIST_FILE"
case codeSignEntitlements = "CODE_SIGN_ENTITLEMENTS"
Expand All @@ -27,6 +15,30 @@ enum BuildSettingKey: String {
case visionOSDeploymentTarget = "VISIONOS_DEPLOYMENT_TARGET"
}

enum TuistBuildSettingKey: String {
case launchArguments = "LAUNCH_ARGUMENTS" // Used for scheme generation
case environmentVariables = "ENVIRONMENT_VARIABLES" // Used for scheme generation
case tags = "TAGS" // metadata
case prune = "PRUNE"
case mergeable = "MERGEABLE" // Mergable library build settings generation
case mergedBinaryType = "MERGED_BINARY_TYPE" // Default settings configuration for mergable libraries
}

enum TuistScriptSettingKey: String {
case showEnvVarsInLog = "SHOW_ENV_VARS_IN_LOG"
case shellPath = "SHELL_PATH"
case dependencyFile = "DEPENDENCY_FILE"
case inputPaths = "INPUT_PATHS"
case outputPaths = "OUTPUT_PATHS"
}

enum BuildFileSettings: String {
case compilerFlags = "COMPILER_FLAGS"
case attributes = "ATTRIBUTES"
}



/// A protocol representing a type that can parse a build setting value from a generic `Any`.
protocol BuildSettingValue {
associatedtype Value
Expand All @@ -48,20 +60,6 @@ enum BuildSettingStringArray: BuildSettingValue {
}
}

/// A type that parses build settings as booleans.
enum BuildSettingBool: BuildSettingValue {
static func parse(_ any: Any) -> Bool? {
any as? Bool
}
}

/// A type that parses build settings as dictionaries of strings to strings.
enum BuildSettingStringDict: BuildSettingValue {
static func parse(_ any: Any) -> [String: String]? {
any as? [String: String]
}
}

extension [String: Any] {
/// Extracts a build setting value of a specified type from the dictionary.
///
Expand All @@ -87,14 +85,4 @@ extension [String: Any] {
func stringArray(for key: BuildSettingKey) -> [String]? {
extractBuildSetting(key, as: BuildSettingStringArray.self)
}

/// Retrieves a boolean value for the given build setting key.
func bool(for key: BuildSettingKey) -> Bool? {
extractBuildSetting(key, as: BuildSettingBool.self)
}

/// Retrieves a dictionary of strings for the given build setting key.
func stringDict(for key: BuildSettingKey) -> [String: String]? {
extractBuildSetting(key, as: BuildSettingStringDict.self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import XcodeProj
extension PBXTarget {
enum EnvironmentExtractor {
static func extract(from buildSettings: BuildSettings) -> [String: EnvironmentVariable] {
guard let envVars = buildSettings.stringDict(for: .environmentVariables) else {
return [:]
}
return envVars.reduce(into: [:]) { result, pair in
result[pair.key] = EnvironmentVariable(value: pair.value, isEnabled: true)
}
// guard let envVars = buildSettings.stringDict(for: .environmentVariables) else {
// return [:]
// }
// return envVars.reduce(into: [:]) { result, pair in
// result[pair.key] = EnvironmentVariable(value: pair.value, isEnabled: true)
// }
//
[:]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,45 @@ extension PBXTarget {
buildPhases.compactMap { $0 as? PBXCopyFilesBuildPhase }
}

func launchArguments() throws -> [LaunchArgument] {
guard let buildConfigList = buildConfigurationList else { return [] }
var launchArguments: [LaunchArgument] = []
for buildConfig in buildConfigList.buildConfigurations {
if let args = buildConfig.buildSettings.stringArray(for: .launchArguments) {
launchArguments.append(contentsOf: args.map { LaunchArgument(name: $0, isEnabled: true) })
}
}
return launchArguments.uniqued()
}

func prune() throws -> Bool {
debugBuildSettings.bool(for: .prune) ?? false
}
// func launchArguments() throws -> [LaunchArgument] {
// guard let buildConfigList = buildConfigurationList else { return [] }
// var launchArguments: [LaunchArgument] = []
// for buildConfig in buildConfigList.buildConfigurations {
// if let args = buildConfig.buildSettings.stringArray(for: .launchArguments) {
// launchArguments.append(contentsOf: args.map { LaunchArgument(name: $0, isEnabled: true) })
// }
// }
// return launchArguments.uniqued()
// }

// func prune() throws -> Bool {
// debugBuildSettings.bool(for: .prune) ?? false
// }

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

func mergeable() throws -> Bool {
debugBuildSettings.bool(for: .mergeable) ?? false
}
// func mergeable() throws -> Bool {
// debugBuildSettings.bool(for: .mergeable) ?? false
// }

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

func metadata() throws -> TargetMetadata {
var tags: Set<String> = []
for buildConfig in buildConfigurationList?.buildConfigurations ?? [] {
if let tagsString = buildConfig.buildSettings.string(for: .tags) {
let extractedTags = tagsString
.split(separator: ",")
.map { $0.trimmingCharacters(in: .whitespaces) }
tags.formUnion(extractedTags)
}
}
return .metadata(tags: tags)
}
// func metadata() throws -> TargetMetadata {
// var tags: Set<String> = []
// for buildConfig in buildConfigurationList?.buildConfigurations ?? [] {
// if let tagsString = buildConfig.buildSettings.string(for: .tags) {
// let extractedTags = tagsString
// .split(separator: ",")
// .map { $0.trimmingCharacters(in: .whitespaces) }
// tags.formUnion(extractedTags)
// }
// }
// return .metadata(tags: tags)
// }
}
24 changes: 12 additions & 12 deletions Sources/XcodeGraphMapper/Mappers/Targets/PBXTargetMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ struct PBXTargetMapper: PBXTargetMapping {
let buildRules = try pbxTarget.buildRules.compactMap { try buildRuleMapper.map($0) }

// Environment & Launch
let environmentVariables = pbxTarget.extractEnvironmentVariables()
let launchArguments = try pbxTarget.launchArguments()
// let environmentVariables = pbxTarget.extractEnvironmentVariables()
// let launchArguments = try pbxTarget.launchArguments()

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

// Misc
let prune = try pbxTarget.prune()
let mergedBinaryType = try pbxTarget.mergedBinaryType()
let mergeable = try pbxTarget.mergeable()
// let prune = try pbxTarget.prune()
// let mergedBinaryType = try pbxTarget.mergedBinaryType()
// let mergeable = try pbxTarget.mergeable()
let onDemandResourcesTags = try pbxTarget.onDemandResourcesTags()
let metadata = try pbxTarget.metadata()
// let metadata = try pbxTarget.metadata()

// Dependencies
let projectNativeTargets = try pbxTarget.dependencies.compactMap {
Expand All @@ -225,19 +225,19 @@ struct PBXTargetMapper: PBXTargetMapping {
headers: headers,
coreDataModels: coreDataModels,
scripts: scripts,
environmentVariables: environmentVariables,
launchArguments: launchArguments,
// environmentVariables: environmentVariables,
// launchArguments: launchArguments,
filesGroup: filesGroup,
dependencies: allDependencies,
rawScriptBuildPhases: rawScriptBuildPhases,
playgrounds: playgrounds,
additionalFiles: additionalFiles,
buildRules: buildRules,
prune: prune,
mergedBinaryType: mergedBinaryType,
mergeable: mergeable,
// prune: false,
// mergedBinaryType: mergedBinaryType,
// mergeable: mergeable,
onDemandResourcesTags: onDemandResourcesTags,
metadata: metadata,
// metadata: metadata
packages: packages
)
}
Expand Down
Loading