-
Notifications
You must be signed in to change notification settings - Fork 45
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
[swift2objc] Filtering Support #1730
base: main
Are you sure you want to change the base?
Conversation
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.
Looks like you've also got a merge conflict to resolve.
pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_variable_declaration.dart
Outdated
Show resolved
Hide resolved
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.
Tests are looking good. You can resolve the formatting and analysis issues in CI using dart format .
and dart analyze
.
final TransformationMap transformationMap; | ||
final _filter = filter ?? (declaration) => true; | ||
|
||
final _declarations = declarations.where((d) => _filter(d)); |
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 can just be declarations.where(_filter);
self.wrappedInstance = wrappedInstance | ||
} | ||
|
||
@objc init(brand: String, gearCount: Int, dimensions: DimensionsWrapper) { |
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.
Yeah, I thought this might happen. This code won't compile, because you're not generating DimensionsWrapper
. This is what makes filtering tricky, because you need to think about transitive dependencies.
There are a few ways to handle it:
- Omit any methods/properties/initializers that refer to declarations that aren't included. I think this would be confusing to users, and not expected behavior.
- Replace any omitted declarations with
NSObject
, and just cast them to the target object type instead of doing.wrappedInstance
. This is easy, but loses type safety. Also I don't think it'll work for structs. - Fully generate all transitive deps. This can and up generating quite a lot of bindings the user doesn't care about, because of the transitive bit. You have to generate the deps of the deps too.
- Generate the direct deps of the included declarations as stubs (a stub would be like a class that only has the
wrappedInstance
and one wrappinginit
method, no other properties or methods). This is the best solution, because it avoids the need to recursively generate deps of deps (the deps are stubs, so they don't have any deps). It's harder to implement though, because you have to upgrade the code generator to have a notion of stub generation.
Ffigen used to do (3), but I recently upgraded it to do (4) by default (with config options to do (3) if you want). Jnigen used to do (2), but plans to switch to (4).
(4) is a bit hard to implement though, so feel free to do (3) for now.
This Pull Request is to add filtering support to the swiftgen tool.
Config
More information can be found here: #1394