Skip to content

Fix data races in SettingsBuilder. #1233

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
37 changes: 37 additions & 0 deletions Sources/XcodeGenKit/NSCacheExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import XcodeProj
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, maybe the proper place for this file is XcodeGenCore target
Because, XcodeGenKit target mostly contains public business logic, closely related to project generation

import Foundation

enum Cached<T> {
case cached(T)
case nothing

var value: T? {
switch self {
case let .cached(value): return value
case .nothing: return nil
}
}
}

final class CacheContainer {
let value: Cached<BuildSettings>

init(value: Cached<BuildSettings>) {
self.value = value
}
}

extension NSCache where KeyType == NSString, ObjectType == CacheContainer {
subscript(aKey: String) -> Cached<BuildSettings>? {
get {
object(forKey: aKey as NSString)?.value
}
set {
if let value = newValue {
setObject(CacheContainer(value: value), forKey: aKey as NSString)
} else {
removeObject(forKey: aKey as NSString)
}
}
}
}
16 changes: 2 additions & 14 deletions Sources/XcodeGenKit/SettingsBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,11 @@ extension Project {
}
}

private enum Cached<T> {
case cached(T)
case nothing

var value: T? {
switch self {
case let .cached(value): return value
case .nothing: return nil
}
}
}

// cached flattened xcconfig file settings
private var configFileSettings: [String: Cached<BuildSettings>] = [:]
private var configFileSettings = NSCache<NSString, CacheContainer>()

// cached setting preset settings
private var settingPresetSettings: [String: Cached<BuildSettings>] = [:]
private var settingPresetSettings = NSCache<NSString, CacheContainer>()

extension SettingsPresetFile {

Expand Down