-
-
Notifications
You must be signed in to change notification settings - Fork 331
refactor!: strongly typed values in BuildSettings
and BuildFileSettings
#903
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
Conversation
BuildSettings
and BuildFileSettings
a28c2ff
to
bf96639
Compare
- Updates to xcdiff for compatibility with tuist/XcodeProj#903 - Build setting values are no longer type erased and instead can now either be a `String` or `[String]` - This alleviates the need to casting values and throwing errors when dealing with build settings Test Plan: - Verify CI passes Signed-off-by: Kassem Wridan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @waltflanagan this is a much needed change! 👌
Indeed this is source breaking and would likely need a major release
e.g. updates needed for xcdiff
bloomberg/xcdiff#145
// func XCTAssertEqual(_ lhs: BuildSettings, _ rhs: BuildSettings, file: StaticString = #file, line: UInt = #line) { | ||
// XCTAssertEqual(lhs as NSDictionary, | ||
// rhs as NSDictionary, | ||
// file: file, | ||
// line: line) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then let's remove it? 😁
@kwridan thats what i was afraid of. I'll see if i can find some time to put together a 9.0 checklist so we can identify anything else that we may want to break There are some other Do you think it would be worth a transitional phase that preserves |
I wouldn't shy away from a a major release for this per se as there are already a few compatibility APIs lying around that could do with a clean up: e.g. You are right, there are other collections (e.g. Another accessor could be exposed with the strong types |
BuildSettings
and BuildFileSettings
BuildSettings
and BuildFileSettings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some minor comments, but overall, I'm very much in favor of this. Getting rid of Any
will be quite an improvement when using this library and has been long overdue. Thanks Mike!
@@ -195,3 +213,47 @@ final class PBXBuildPhaseFile: PlistSerializable, Equatable { | |||
lhs.buildFile == rhs.buildFile && lhs.buildPhase == rhs.buildPhase | |||
} | |||
} | |||
|
|||
public enum BuildFileSetting: Sendable, Equatable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: would move this to a separate file.
public var stringValue: String? { | ||
if case let .string(value) = self { | ||
value | ||
} else { | ||
nil | ||
} | ||
} | ||
|
||
public var arrayValue: [String]? { | ||
if case let .array(value) = self { | ||
value | ||
} else { | ||
nil | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where do we plan to use these? I wonder if it would be better for consumers to do the switch
themselves. Anything we put here is something that we're committed to not break (or release a major version when we do)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly convenience, the usages of these [String: Any]
collections generally are casting as? <Type>
and this felt like a reasonable convenience that would help minimize the disruption to current codebases (if case let
syntax is not fun to work with).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not totally opposed, so we can keep these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for completely new test suites, I'd start using Swift testing instead. Eventually, we'd like to get to a place where all Tuist repositories use Swift testing, although that's going to be a long way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, another thing to learn about.
case string(String) | ||
case array([String]) | ||
|
||
var valueForWriting: String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of this using the CustomStringConvertible
instead of a completely custom property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should work fine 👍
public var stringValue: String? { | ||
if case let .string(value) = self { | ||
value | ||
} else { | ||
nil | ||
} | ||
} | ||
|
||
public var arrayValue: [String]? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would probably also remove this in favor of consumers doing the switch themselves.
@@ -602,3 +605,64 @@ extension PBXProject: PlistSerializable { | |||
}) | |||
} | |||
} | |||
|
|||
public enum ProjectAttribute: Sendable, Equatable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: would also move this to its own file.
public var stringValue: String? { | ||
if case let .string(value) = self { | ||
value | ||
} else { | ||
nil | ||
} | ||
} | ||
|
||
public var arrayValue: [String]? { | ||
if case let .array(value) = self { | ||
value | ||
} else { | ||
nil | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as mentioned above, would consider not including these.
// func XCTAssertEqual(_ lhs: BuildSettings, _ rhs: BuildSettings, file: StaticString = #file, line: UInt = #line) { | ||
// XCTAssertEqual(lhs as NSDictionary, | ||
// rhs as NSDictionary, | ||
// file: file, | ||
// line: line) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then let's remove it? 😁
@kwridan i tackled the other things you mentioned and could use a re-review. also tried to include some convenience methods to make the impact smaller from a migration perspective (avoiding the need for Curious generally what else should be done to land this as a 9.0 |
The settings here are constrained to two cases, one as a string and one as a string array as defined here: https://buck.build/javadoc/com/facebook/buck/apple/xcode/xcodeproj/PBXBuildFile.html Given the narrow use case we should constraint the available types here to fit the need.
…nd not give an accurate failure count
6.0.3 is not supported and also doesnt have a fix we need.
This need a fix that is in swift 6.1 to pass on linux: swiftlang/swift-foundation#1002
875cafa
to
648909e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the looking into the other parts @waltflanagan 🙏
I didn't necessarily mean they had to happen in the build settings PR in one go rather as separate PRs we can incrementally do for the 9.0 release. Is the worry the release process for XcoeProj would automatically ship this PR as an minor release?
The attribute updates may need a closer look to see how to deal with references correctly to ensure their final values are resolved - my thinking is potentially adding another case .targetReference()
which would be accounted for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
marking as requesting changes per above (for the attributes + target reference issues)
thanks!
That would actually happen. Given the amount of changes, I think it's fine to bundle everything here. The alternative would be to create a release branch, post individual PRs there, and then merge the release branch into |
Also removed `Encodable` conformance as we have a custom `plist` method that is used for writing.
@kwridan just added the One other risk of this branch is that it would block other fixes from shipping if this was merged but not quite ready to ship. lmk next steps on releasing a 9.0.0, i was definitely going to find some time this weekend to check on the XcodeGraph and Tuist impacts of these changes to make sure they fit those needs. I can also see what kind of impact it would be on XcodeGen. |
I think that having a draft PR accommodating the change in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good to from my side. But as mentioned, would recommend validating these changes in XcodeGraph
and tuist/tuist
before merging.
@@ -0,0 +1,43 @@ | |||
public enum BuildFileSetting: Sendable, Equatable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's pretty self-explanatory but given this is public now, I'd add some basic documentation.
private let yes = "YES" | ||
private let no = "NO" | ||
|
||
public enum BuildSetting: Sendable, Equatable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would also add some basic documentation.
case no: false | ||
default: nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Xcode's behavior is actually defaulting to false
if the value is defined but it's not YES
or NO
. But conceptually, this feels better, so I'll let you decide what's better here 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the purposes of this utility it strictly checking for boolean build settings as opposed to attempting to resolve a boolean value for the build setting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @waltflanagan
@fortmarek what's the process for marking this as a major release ahead of merging?
case no: false | ||
default: nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the purposes of this utility it strictly checking for boolean build settings as opposed to attempting to resolve a boolean value for the build setting.
I believe the only thing necessary is the exclamation mark already added by @waltflanagan |
Thanks for the contribution @waltflanagan! And sorry for taking a bit longer to merge this. |
No worries! glad its moving along. I've had some other things going on as well. Thanks for merging! |
Short description 📝
Mostly work that was done on the
9.0.0
branch that shouldn't be coupled to Sendability changes.This introduces the
BuildSetting
type that will allow safer manipulation of build settings and set us with more typesafety when working with build settings that have constraints.Keys issues are that this introduces source breaking changes with the signature of the
BuildSettings
typealias.