This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Reland "ios: remove shared_application and support app extension build #44732" #45351
Merged
auto-submit
merged 1 commit into
flutter:main
from
cyanglaz:reland_remove_shared_application
Sep 1, 2023
Merged
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,9 @@ | |
|
|
||
| FLUTTER_ASSERT_ARC | ||
|
|
||
| NSBundle* FLTFrameworkBundleInternal(NSString* bundleID, NSURL* searchURL) { | ||
| const NSString* kDefaultAssetPath = @"Frameworks/App.framework/flutter_assets"; | ||
|
|
||
| NSBundle* FLTFrameworkBundleInternal(NSString* flutterFrameworkBundleID, NSURL* searchURL) { | ||
| NSDirectoryEnumerator<NSURL*>* frameworkEnumerator = [NSFileManager.defaultManager | ||
| enumeratorAtURL:searchURL | ||
| includingPropertiesForKeys:nil | ||
|
|
@@ -18,19 +20,49 @@ | |
| errorHandler:nil]; | ||
|
|
||
| for (NSURL* candidate in frameworkEnumerator) { | ||
| NSBundle* bundle = [NSBundle bundleWithURL:candidate]; | ||
| if ([bundle.bundleIdentifier isEqualToString:bundleID]) { | ||
| return bundle; | ||
| NSBundle* flutterFrameworkBundle = [NSBundle bundleWithURL:candidate]; | ||
| if ([flutterFrameworkBundle.bundleIdentifier isEqualToString:flutterFrameworkBundleID]) { | ||
| return flutterFrameworkBundle; | ||
| } | ||
| } | ||
| return nil; | ||
| } | ||
|
|
||
| NSBundle* FLTFrameworkBundleWithIdentifier(NSString* bundleID) { | ||
| NSBundle* bundle = FLTFrameworkBundleInternal(bundleID, NSBundle.mainBundle.privateFrameworksURL); | ||
| if (bundle != nil) { | ||
| return bundle; | ||
| NSBundle* FLTGetApplicationBundle() { | ||
| NSBundle* mainBundle = [NSBundle mainBundle]; | ||
| // App extension bundle is in <AppName>.app/PlugIns/Extension.appex. | ||
| if ([mainBundle.bundleURL.pathExtension isEqualToString:@"appex"]) { | ||
| // Up two levels. | ||
| return [NSBundle bundleWithURL:mainBundle.bundleURL.URLByDeletingLastPathComponent | ||
| .URLByDeletingLastPathComponent]; | ||
| } | ||
| return mainBundle; | ||
| } | ||
|
|
||
| NSBundle* FLTFrameworkBundleWithIdentifier(NSString* flutterFrameworkBundleID) { | ||
| NSBundle* appBundle = FLTGetApplicationBundle(); | ||
| NSBundle* flutterFrameworkBundle = | ||
| FLTFrameworkBundleInternal(flutterFrameworkBundleID, appBundle.privateFrameworksURL); | ||
| if (flutterFrameworkBundle == nil) { | ||
| // Fallback to slow implementation. | ||
| flutterFrameworkBundle = [NSBundle bundleWithIdentifier:flutterFrameworkBundleID]; | ||
| } | ||
| if (flutterFrameworkBundle == nil) { | ||
| flutterFrameworkBundle = [NSBundle mainBundle]; | ||
| } | ||
| return flutterFrameworkBundle; | ||
| } | ||
|
|
||
| NSString* FLTAssetPath(NSBundle* bundle) { | ||
| return [bundle objectForInfoDictionaryKey:@"FLTAssetsPath"] ?: kDefaultAssetPath; | ||
| } | ||
|
|
||
| NSURL* FLTAssetsURLFromBundle(NSBundle* bundle) { | ||
| NSString* flutterAssetsPath = FLTAssetPath(bundle); | ||
| NSURL* assets = [bundle URLForResource:flutterAssetsPath withExtension:nil]; | ||
|
|
||
| if (!assets) { | ||
| assets = [[NSBundle mainBundle] URLForResource:flutterAssetsPath withExtension:nil]; | ||
| } | ||
| // Fallback to slow implementation. | ||
| return [NSBundle bundleWithIdentifier:bundleID]; | ||
| return assets; | ||
|
Contributor
Author
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. This is the fix, original PR had a url reachability test and returns nil here |
||
| } | ||
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 |
|---|---|---|
|
|
@@ -73,6 +73,50 @@ - (void)testFLTFrameworkBundleInternalWhenBundleIsPresent { | |
| XCTAssertNotNil(found); | ||
| } | ||
|
|
||
| - (void)testFLTGetApplicationBundleWhenCurrentTargetIsNotExtension { | ||
| NSBundle* bundle = FLTGetApplicationBundle(); | ||
| XCTAssertEqual(bundle, [NSBundle mainBundle]); | ||
| } | ||
|
|
||
| - (void)testFLTGetApplicationBundleWhenCurrentTargetIsExtension { | ||
| id mockMainBundle = OCMPartialMock([NSBundle mainBundle]); | ||
| NSURL* url = [[NSBundle mainBundle].bundleURL URLByAppendingPathComponent:@"foo/ext.appex"]; | ||
| OCMStub([mockMainBundle bundleURL]).andReturn(url); | ||
| NSBundle* bundle = FLTGetApplicationBundle(); | ||
| [mockMainBundle stopMocking]; | ||
| XCTAssertEqualObjects(bundle.bundleURL, [NSBundle mainBundle].bundleURL); | ||
| } | ||
|
|
||
| - (void)testFLTAssetsURLFromBundle { | ||
|
Contributor
Author
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. This is the test for the fix |
||
| { | ||
| // Found asset path in info.plist (even not reachable) | ||
| id mockBundle = OCMClassMock([NSBundle class]); | ||
| OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(@"foo/assets"); | ||
| NSURL* mockAssetsURL = OCMClassMock([NSURL class]); | ||
| OCMStub([mockBundle URLForResource:@"foo/assets" withExtension:nil]).andReturn(mockAssetsURL); | ||
| OCMStub([mockAssetsURL checkResourceIsReachableAndReturnError:NULL]).andReturn(NO); | ||
| OCMStub([mockAssetsURL path]).andReturn(@"foo/assets"); | ||
| NSURL* url = FLTAssetsURLFromBundle(mockBundle); | ||
| XCTAssertEqualObjects(url.path, @"foo/assets"); | ||
| } | ||
| { | ||
| // No asset path in info.plist, defaults to main bundle | ||
| id mockBundle = OCMClassMock([NSBundle class]); | ||
| id mockMainBundle = OCMPartialMock([NSBundle mainBundle]); | ||
| NSURL* mockAssetsURL = OCMClassMock([NSURL class]); | ||
| OCMStub([mockBundle URLForResource:@"Frameworks/App.framework/flutter_assets" | ||
| withExtension:nil]) | ||
| .andReturn(nil); | ||
| OCMStub([mockAssetsURL checkResourceIsReachableAndReturnError:NULL]).andReturn(NO); | ||
| OCMStub([mockAssetsURL path]).andReturn(@"path/to/foo/assets"); | ||
| OCMStub([mockMainBundle URLForResource:@"Frameworks/App.framework/flutter_assets" | ||
| withExtension:nil]) | ||
| .andReturn(mockAssetsURL); | ||
| NSURL* url = FLTAssetsURLFromBundle(mockBundle); | ||
| XCTAssertEqualObjects(url.path, @"path/to/foo/assets"); | ||
| } | ||
| } | ||
|
|
||
| - (void)testDisableImpellerSettingIsCorrectlyParsed { | ||
| id mockMainBundle = OCMPartialMock([NSBundle mainBundle]); | ||
| OCMStub([mockMainBundle objectForInfoDictionaryKey:@"FLTEnableImpeller"]).andReturn(@"NO"); | ||
|
|
||
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
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.
Compares to the original PR, also refactored this method in this PR