Skip to content
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
2 changes: 2 additions & 0 deletions configen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
Copy link
Author

Choose a reason for hiding this comment

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

Had to increase the deployment target from 10.10 (Yosemite, 2014) to 10.11 (El Capitan) as URL(fileURLWithPath: String, relativeTo: URL) is only available from 10.11.

PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
Expand All @@ -295,6 +296,7 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're bumping the minimum macOS version, then I think it needs to be mentioned in the CHANGELOG as well.

PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
};
Expand Down
33 changes: 22 additions & 11 deletions configen/OptionsParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,8 @@ final class OptionsParser {

lazy var plistDictionary: [String: AnyObject] = { [unowned self] in
let inputPlistFilePathURL = URL(fileURLWithPath: self.inputPlistFilePath)
guard let data = try? Data(contentsOf: inputPlistFilePathURL) else {
fatalError("No data at path: \(self.inputPlistFilePath)")
}

guard let plistDictionary = (try? PropertyListSerialization.propertyList(from: data, options: [], format: nil)) as? [String: AnyObject] else {
fatalError("Failed to create plist")
}

return plistDictionary
}()
return loadPlist(url: inputPlistFilePathURL)
}()

lazy var sortedHints: [Hint] = { [unowned self] in
guard let hintsString = try? String(contentsOfFile: self.inputHintsFilePath, encoding: String.Encoding.utf8) else {
Expand All @@ -71,5 +63,24 @@ final class OptionsParser {
hints.append(Hint(variableName: separatedHints[0], type: separatedHints[1]))
}
return hints.sorted(by: <)
}()
}()

private func loadPlist(url: URL) -> [String: AnyObject] {
guard let data = try? Data(contentsOf: url) else {
fatalError("No data at path: \(url.absoluteString)")
}

guard var plistDictionary = (try? PropertyListSerialization.propertyList(from: data, options: [], format: nil)) as? [String: AnyObject] else {
fatalError("Failed to load plist from: \(url.absoluteString)")
}
let inheritKey = ":inherit_from"
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if this deserves a special key name style - perhaps it could be simply called basePlistFile.

if let inheritPath = plistDictionary.removeValue(forKey: inheritKey) {
guard let inheritPath = inheritPath as? String, !inheritPath.isEmpty else {
fatalError("Expected \"\(inheritKey)\" in \(url.absoluteString) to be a string path")
Copy link
Contributor

Choose a reason for hiding this comment

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

The failure message should also mention that the path must be non-empty (since you're checking for it above):

Suggested change
fatalError("Expected \"\(inheritKey)\" in \(url.absoluteString) to be a string path")
fatalError("Expected \"\(inheritKey)\" in \(url.absoluteString) to be a non-empty String path")

}
let inheritedPlist = loadPlist(url: URL(fileURLWithPath: inheritPath, relativeTo: url))
plistDictionary = inheritedPlist.merging(plistDictionary, uniquingKeysWith: { (_, override) in override })
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
plistDictionary = inheritedPlist.merging(plistDictionary, uniquingKeysWith: { (_, override) in override })
plistDictionary = inheritedPlist.merging(plistDictionary, uniquingKeysWith: { (_, newValue) in newValue })

Please call this newValue for clarity.

}
return plistDictionary
}
}