Skip to content

[PackageLoading] Make sure JSON-encoded rule keys are stable #1802

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

Merged
merged 1 commit into from
Oct 6, 2018
Merged
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
10 changes: 9 additions & 1 deletion Sources/SPMLLBuild/llbuild.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ private func fromBytes<T: Decodable>(_ bytes: [UInt8]) throws -> T {
}

private func toBytes<T: Encodable>(_ value: T) throws -> [UInt8] {
let encoded = try JSONEncoder().encode(value)
let encoder = JSONEncoder()
#if os(macOS)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this #if os(macOS) is necessary?

The way #available works is that the '*' indicates that the code path inside the if body will be taken on any platforms not listed. So this by itself:

if #available(OSX 10.13, *) {
    encoder.outputFormatting = [.sortedKeys]
}

should be entirely equivalent to:

#if os(macOS)
if #available(OSX 10.13, *) {
    encoder.outputFormatting = [.sortedKeys]
}
#else
encoder.outputFormatting = [.sortedKeys]
#endif

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right. IDK why I thought that was required 🤷‍♂️. Fixed here #1803

if #available(OSX 10.13, *) {
encoder.outputFormatting = [.sortedKeys]
}
#else
encoder.outputFormatting = [.sortedKeys]
#endif
let encoded = try encoder.encode(value)
return [UInt8](encoded)
}