-
Notifications
You must be signed in to change notification settings - Fork 127
[ffigen] Add API availability propagation and block trampoline annotations #3141
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
sagar-h007
wants to merge
1
commit into
dart-lang:main
Choose a base branch
from
sagar-h007:ffigen/api-availability-union
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,14 +21,17 @@ class ApiAvailability { | |
| final PlatformAvailability? macos; | ||
|
|
||
| late final Availability availability; | ||
| final ExternalVersions? _externalVersions; | ||
|
|
||
| static final alwaysAvailable = ApiAvailability(externalVersions: null); | ||
|
|
||
| ApiAvailability({ | ||
| this.alwaysDeprecated = false, | ||
| this.alwaysUnavailable = false, | ||
| this.ios, | ||
| this.macos, | ||
| required ExternalVersions? externalVersions, | ||
| }) { | ||
| ExternalVersions? externalVersions, | ||
| }) : _externalVersions = externalVersions { | ||
| availability = _getAvailability(externalVersions); | ||
| } | ||
|
|
||
|
|
@@ -152,6 +155,57 @@ class ApiAvailability { | |
| return "$checkOsVersion('$apiName', $args);"; | ||
| } | ||
|
|
||
| ApiAvailability merge(ApiAvailability other) { | ||
| if (this == alwaysAvailable) return other; | ||
| if (other == alwaysAvailable) return this; | ||
|
|
||
| return ApiAvailability( | ||
| alwaysDeprecated: alwaysDeprecated || other.alwaysDeprecated, | ||
| alwaysUnavailable: alwaysUnavailable || other.alwaysUnavailable, | ||
| ios: PlatformAvailability.merge(ios, other.ios), | ||
| macos: PlatformAvailability.merge(macos, other.macos), | ||
| externalVersions: _externalVersions ?? other._externalVersions, | ||
| ); | ||
| } | ||
|
|
||
| String? get apiAvailableMacro { | ||
| if (alwaysUnavailable) return '__attribute__((unavailable))'; | ||
| if (alwaysDeprecated) return '__attribute__((deprecated))'; | ||
|
|
||
| final platforms = _platforms; | ||
| if (platforms.isEmpty) return null; | ||
|
|
||
| final attributes = <String>[]; | ||
| for (final platform in platforms) { | ||
| if (platform.unavailable) { | ||
| attributes.add( | ||
| 'availability(${platform.name!.toLowerCase()}, unavailable)', | ||
| ); | ||
| } else { | ||
| final platformAttrs = <String>[]; | ||
| if (platform.introduced != null) { | ||
| platformAttrs.add('introduced=${platform.introduced}'); | ||
| } | ||
| if (platform.deprecated != null) { | ||
| platformAttrs.add('deprecated=${platform.deprecated}'); | ||
| } | ||
| if (platform.obsoleted != null) { | ||
| platformAttrs.add('obsoleted=${platform.obsoleted}'); | ||
| } | ||
| if (platformAttrs.isNotEmpty) { | ||
| attributes.add( | ||
| // ignore: lines_longer_than_80_chars | ||
| 'availability(${platform.name!.toLowerCase()},${platformAttrs.join(',')})', | ||
| ); | ||
| } else { | ||
| attributes.add('availability(${platform.name!.toLowerCase()})'); | ||
| } | ||
| } | ||
| } | ||
| if (attributes.isEmpty) return null; | ||
| return attributes.map((a) => '__attribute__(($a))').join(' '); | ||
| } | ||
|
|
||
| @override | ||
| String toString() => | ||
| '''Availability { | ||
|
|
@@ -185,6 +239,53 @@ class PlatformAvailability { | |
| return deprecated! < obsoleted! ? deprecated : obsoleted; | ||
| } | ||
|
|
||
| static PlatformAvailability? merge( | ||
| PlatformAvailability? a, | ||
| PlatformAvailability? b, | ||
| ) { | ||
| if (a == null) return b; | ||
| if (b == null) return a; | ||
|
|
||
| Version? newIntroduced; | ||
| if (a.introduced == null) { | ||
| newIntroduced = b.introduced; | ||
| } else if (b.introduced == null) { | ||
| newIntroduced = a.introduced; | ||
| } else { | ||
| newIntroduced = a.introduced! > b.introduced! | ||
| ? a.introduced | ||
| : b.introduced; | ||
| } | ||
|
|
||
| Version? newDeprecated; | ||
| if (a.deprecated == null) { | ||
| newDeprecated = b.deprecated; | ||
| } else if (b.deprecated == null) { | ||
| newDeprecated = a.deprecated; | ||
| } else { | ||
| newDeprecated = a.deprecated! < b.deprecated! | ||
| ? a.deprecated | ||
| : b.deprecated; | ||
| } | ||
|
|
||
| Version? newObsoleted; | ||
| if (a.obsoleted == null) { | ||
| newObsoleted = b.obsoleted; | ||
| } else if (b.obsoleted == null) { | ||
| newObsoleted = a.obsoleted; | ||
| } else { | ||
| newObsoleted = a.obsoleted! < b.obsoleted! ? a.obsoleted : b.obsoleted; | ||
| } | ||
|
|
||
| return PlatformAvailability( | ||
| name: a.name ?? b.name, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| introduced: newIntroduced, | ||
| deprecated: newDeprecated, | ||
| obsoleted: newObsoleted, | ||
| unavailable: a.unavailable || b.unavailable, | ||
| ); | ||
| } | ||
|
|
||
| @visibleForTesting | ||
| Availability getAvailability(Versions version) { | ||
| if (unavailable) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
externalVersionscomes from the config, which is stored in the context. Rather than storing it here, you should passContextto themergemethod and get it from there. It will mean a bit more plumbing, but it's a cleaner solution.