Skip to content

Commit c062a59

Browse files
mokagiokean
andauthored
Move model files from apps targets to WordPressData (#24378)
* Configure `Package.swift` with WordPressData framework deps * Add `WordPress-Swift.h` to WordPressData to work around build fail * Add prefix header * Add all required sources to WordPressData * Add required imports to Swift layer * Extract `defaultWordPressComAccountRestAPI` method to WordPressData Only the method, not the rest of the extension to avoid dependencies galore. * Add `Blog+SelfHosted` to WordPressData, including dependencies * Hack `ContextManager.swift` to compile * Replicate Keystone preprocessor macro hack for WordPressData-Swift.h * Add `Media+Blog.swift` to WordPressData to compile `PostHelper.m` * Add `RemotePost+Metadata` source to WordPressData for `PostHelper.m` * Add `PostServiceRemoteFactory` to WordPressData to fix `PostService.m` * Add `PostHelper+JetpackSocial` to WordPressData to fix `PostHelper.m` * Add `WordPressOrgRestApi+WordPress` to WordPressData Made possible by #24351 * Add `.m` file in WordPressData only to config CocoaLumberJack * Add some `import CocoaLumberJackSwift` required by WordPressData * Use `_private_wordPressComRestApi` in `Blog+WordPressComRestAPI.swift` to build WordPressData * Add CocoaLumberjack as a dependency to the extensions to fix compilation Otherwise, we'd get: ``` Undefined symbols for architecture arm64: "_OBJC_CLASS_$_DDLog", referenced from: in AppExtensionsService.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` * Remove `WordPress-Swift.h` hack from WordPressData * Add `Blog+Lookup` to WordPressData * Add `WordPress.xcdatamodeld` to WordPressData * Duplicate test infra in WordPressData in order to run `BlogTests` * Remove unnecessary `CocoaLumberJackConfiguration.h` header We don't need the header, the implementation file is enough for the CocoaLumberJack shenanigans to take place. * Remove WordPressData types from WordPress and Jetpack Not Keystone yet because I don't know if that compiles okay to verify the change. * Update imports after removing WordPressData files from WP and Jetpack * Disambiguate `Notification` usages — `/: Notification\)/` * Disambiguate `Notification` usages — `/: Notification$/` * Disambiguate `Notification` usages — `/, Notification(?!s)/` * Disambiguate `Notification` usages — `/as\? Notification/` * Disambiguate `Notification` usages — `/ Notification \{/` * Disambiguate `Notification` usages — `/ Notification\?/` * Disambiguate `Notification` usages — `/ Notification,$/` * Disambiguate `Notification` usages — `/\[Notification\]/` * Disambiguate `Notification` usages — `/ Notification\:/` * Disambiguate `Notification` usages — `/: Notification,/` * Disambiguate `Notification` usages — `/\(Notification\)/` * Disambiguate `Notification` usages — `/Notification else/` * Disambiguate `Notification` usages — `/Notification\!/` * Disambiguate `Notification` usages — `/as\? Notification/` * Add CocoaLumberjack to notification service extensions * Update imports after `Notification` disambiguation * Replace all `#import` of headers now in WordPressData with `@import WordPressData` * Work around (temporarily?!) a build failure after the WordPressData move * Remove unused `AccountService` import from `Blog.m` It matters because once `Blog` is in WordPressData, `AccountService` will no longer be available. * Move some `MenuItem` imports from `.h` to `.m` `MenuItem` was not used in the interface. Moving the import in the implementation will make it cleaner to update once WordPressData is integrated. * Remove WordPressData types from `WordPress-Bridging-Header.h` * Address module verifier warnings in WordPressData * Extract Swift-dependant logic from `Theme` * Make `Media` extension `public` * Remove unused WordPressData import from NotificationServiceExtension * Add CocoaLumberjack to extensions Jetpack uses to avoid compile failure Undefined symbol: _OBJC_CLASS_$_DDLog * Make WordPressData Swift API available to ObjC framework consumers * Add `testable import WordPressData` to unit tests * Update `WordPress.Notification` to `WordPressData.Notification` in tests * Add more required `@testable import WordPressData` Via ``` find WordPress/WordPressTest \ -name "*.swift" \ -type f \ -exec perl -i -0pe 's/(@testable import WordPress\n)(\nclass (\w+): CoreDataTestCase \{)/\1\@testable import WordPressData\n\nclass \3: CoreDataTestCase {/g' \ {} \; ``` and ``` find WordPress/WordPressTest \ -name "*.swift" \ -type f \ -exec perl -i -0pe 's/(@testable import WordPress\n)(\nfinal class (\w+): CoreDataTestCase \{)/\1\@testable import WordPressData\n\nfinal class \3: CoreDataTestCase {/g' \ {} \; ``` * Add WordPressData as a WordPressTests dependency * Add missing dependencies to WordPressTesting post WordPressData addition * Load model from the `ContextManager` bundle in the unit tests * Replace `AppEnvironment` with `WordPressComRestApi.apiBaseURL` in RestAPI Same rationale as 09990b8 * No longer access `_private_wordPressComRestApi` in `Blog` * Fix WordPressData linkage in Keystone and move sources * Update access of types required by Keystone for WordPressData link * Explicitly add WebKit as a Keystone dependency Triggered by a few errors like ``` In file included from /Users/gio/Developer/a8c/wpios/WordPress/Classes/ViewRelated/Suggestions/SuggestionsTableViewCell.m:3: /Users/gio/Developer/a8c/wpios/DerivedData/WordPress/Build/Intermediates.noindex/WordPress.build/Debug-iphonesimulator/Keystone.build/DerivedSources/Keystone-Swift.h:295:9: fatal error: module 'WebKit' not found 295 | @import WebKit; | ~~~~~~~^~~~~~ ``` which I got after linking WordPressData against Keystone and moving all the sources there. * Revert `CookieJar` `public` access level Apparently unnecessary, see #24420 (comment) * REVERT ME - Only run WordPress tests * Switch all models to use "Global Namespace" Via ``` sed -i '' -E 's/representedClassName="(WordPress)?(\.)?([^"]+)"/representedClassName=".\3"/g' \ Sources/WordPressData/Resources/WordPress.xcdatamodeld/WordPress\ 155.xcdatamodel/contents ``` which switched to "Current Product Module" but resulted in unit tests failure in WordPressData, followed by ``` ➜ sed -i '' -E 's/representedClassName="\.([^"]+)"/representedClassName="\1"/g' \ Sources/WordPressData/Resources/WordPress.xcdatamodeld/WordPress\ 155.xcdatamodel/contents ``` * Replace all string values passed to `forEntityName` with `entityName()` Done via ``` find . \ \( -path './DerivedData' -o -path './.git' -o -path './vendor' \) \ -prune -o -type f -name "*.swift" \ -exec sed -i '' -E 's/forEntityName: "([A-Za-z_][A-Za-z0-9_]*)"/forEntityName: \1.entityName()/g' {} + ``` * Replace all `NSStringFromClass` values passed to `forEntityName` Done via ``` find . \ \( -path './DerivedData' -o -path './.git' -o -path './vendor' \) \ -prune -o -type f -name "*.swift" \ -exec sed -i '' -E 's/forEntityName: NSStringFromClass\(([A-Za-z_][A-Za-z0-9_]*)\.self\)/forEntityName: \1.entityName()/g' {} + ``` The goal is to have a single way to get the entity name so we can adapt it to the new WordPressData setup in one go. * Replace all `Self.classNameWithoutNamespaces()` with `entityName()` The goal is to have a single way to get the entity name so we can adapt it to the new WordPressData setup in one go. * Replace all `classNameWithoutNamespace()` calls with `entityName()` Done via ``` find . \( -path './DerivedData' -o -path './.git' -o -path './vendor' \) \ -prune -o -type f -name "*.swift" \ -exec sed -i '' -E 's/forEntityName: ([A-Za-z_][A-Za-z0-9_]*)\.classNameWithoutNamespaces\(\)/forEntityName: \1.entityName()/g' {} + ``` The goal is to have a single way to get the entity name so we can adapt it to the new WordPressData setup in one go. * Fix WordPressData runtime issues (#24494) * Move remaining types to WordPressData * Use Current Module for Swift-only types * Fix ReaderTeamTopic compilation * Add missing class names * Remove unused SiteInfo * Add Bundle.wordPressData and update DataMigratorTests * Update CoreDataMigrationTests * Fix unit tests (AppEnvironment required) * Add `BlobEntity` to WordPressData * Address straightforward `FIXME` notes --------- Co-authored-by: Alex Grebenyuk <[email protected]>
1 parent 0112a1d commit c062a59

File tree

592 files changed

+1660
-588
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

592 files changed

+1660
-588
lines changed

Modules/Package.swift

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ enum XcodeSupport {
202202
.library(name: "XcodeTarget_App", targets: ["XcodeTarget_App"]),
203203
.library(name: "XcodeTarget_Keystone", targets: ["XcodeTarget_Keystone"]),
204204
.library(name: "XcodeTarget_WordPressTests", targets: ["XcodeTarget_WordPressTests"]),
205+
.library(name: "XcodeTarget_WordPressData", targets: ["XcodeTarget_WordPressData"]),
205206
.library(name: "XcodeTarget_WordPressAuthentificator", targets: ["XcodeTarget_WordPressAuthentificator"]),
206207
.library(name: "XcodeTarget_WordPressAuthentificatorTests", targets: ["XcodeTarget_WordPressAuthentificatorTests"]),
207208
.library(name: "XcodeTarget_ShareExtension", targets: ["XcodeTarget_ShareExtension"]),
@@ -235,6 +236,16 @@ enum XcodeSupport {
235236
"WordPressUI",
236237
"TextBundle",
237238
"TracksMini",
239+
// Even though the extensions are all in Swift, we need to include the Objective-C
240+
// version of CocoaLumberjack to avoid linking issues with other dependencies that
241+
// use it.
242+
//
243+
// Example:
244+
//
245+
// Undefined symbols for architecture arm64:
246+
// "_OBJC_CLASS_$_DDLog", referenced from:
247+
// in AppExtensionsService.o
248+
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
238249
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
239250
.product(name: "Down", package: "Down"),
240251
.product(name: "Gridicons", package: "Gridicons-iOS"),
@@ -307,6 +318,17 @@ enum XcodeSupport {
307318
.product(name: "Gravatar", package: "Gravatar-SDK-iOS"),
308319
.product(name: "Nimble", package: "Nimble"),
309320
.product(name: "BuildkiteTestCollector", package: "test-collector-swift"),
321+
// Needed by WordPressData because of how linkage works...
322+
//
323+
"BuildSettingsKit",
324+
"FormattableContentKit",
325+
"SFHFKeychainUtils",
326+
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
327+
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
328+
.product(name: "NSObject-SafeExpectations", package: "NSObject-SafeExpectations"),
329+
.product(name: "NSURL+IDN", package: "NSURL-IDN"),
330+
.product(name: "WordPressAPI", package: "wordpress-rs"),
331+
.product(name: "WordPressKit", package: "WordPressKit-iOS"),
310332
]),
311333
.xcodeTarget("XcodeTarget_WordPressAuthentificator", dependencies: wordPresAuthentificatorDependencies),
312334
.xcodeTarget("XcodeTarget_WordPressAuthentificatorTests", dependencies: wordPresAuthentificatorDependencies + testDependencies),
@@ -319,6 +341,18 @@ enum XcodeSupport {
319341
"SFHFKeychainUtils",
320342
"TracksMini",
321343
"WordPressShared",
344+
// Even though the extensions are all in Swift, we need to include the Objective-C
345+
// version of CocoaLumberjack to avoid linking issues with other dependencies that
346+
// use it.
347+
//
348+
// Example:
349+
//
350+
// EmitSwiftModule normal arm64 (in target 'WordPressNotificationServiceExtension' from project 'WordPress')
351+
// cd /path/to/repo/WordPress
352+
//
353+
// <unknown>:0: error: missing required modules: 'CocoaLumberjack', 'CocoaLumberjackSwiftSupport'
354+
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
355+
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
322356
]),
323357
.xcodeTarget("XcodeTarget_StatsWidget", dependencies: [
324358
"BuildSettingsKit",
@@ -327,18 +361,54 @@ enum XcodeSupport {
327361
"TracksMini",
328362
"WordPressShared",
329363
"WordPressUI",
364+
// Even though the extensions are all in Swift, we need to include the Objective-C
365+
// version of CocoaLumberjack to avoid linking issues with other dependencies that
366+
// use it.
367+
//
368+
// Example:
369+
//
370+
// Undefined symbols for architecture arm64:
371+
// "_OBJC_CLASS_$_DDLog", referenced from:
372+
// in AppExtensionsService.o
373+
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
330374
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
331375
.product(name: "WordPressAPI", package: "wordpress-rs"),
332376
]),
333377
.xcodeTarget("XcodeTarget_Intents", dependencies: [
334378
"BuildSettingsKit",
335379
"JetpackStatsWidgetsCore",
380+
// Even though the extensions are all in Swift, we need to include the Objective-C
381+
// version of CocoaLumberjack to avoid linking issues with other dependencies that
382+
// use it.
383+
//
384+
// Example:
385+
//
386+
// Undefined symbols for architecture arm64:
387+
// "_OBJC_CLASS_$_DDLog", referenced from:
388+
// in AppExtensionsService.o
389+
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
336390
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
337391
]),
338392
.xcodeTarget("XcodeTarget_UITests", dependencies: [
339393
"UITestsFoundation",
340394
.product(name: "BuildkiteTestCollector", package: "test-collector-swift"),
341395
]),
396+
.xcodeTarget(
397+
"XcodeTarget_WordPressData",
398+
dependencies: [
399+
"BuildSettingsKit",
400+
"FormattableContentKit",
401+
"SFHFKeychainUtils",
402+
"WordPressShared",
403+
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
404+
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
405+
.product(name: "Gravatar", package: "Gravatar-SDK-iOS"),
406+
.product(name: "NSObject-SafeExpectations", package: "NSObject-SafeExpectations"),
407+
.product(name: "NSURL+IDN", package: "NSURL-IDN"),
408+
.product(name: "WordPressAPI", package: "wordpress-rs"),
409+
.product(name: "WordPressKit", package: "WordPressKit-iOS"),
410+
]
411+
),
342412
]
343413
}
344414
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Foundation
2+
3+
public struct __Empty {}

Sources/Keystone/WordPress.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ FOUNDATION_EXPORT const unsigned char WordPressVersionString[];
1111
#import <WordPress/ActivityLogViewController.h>
1212
#import <WordPress/AccountService.h>
1313

14-
#import <WordPress/Blog.h>
1514
#import <WordPress/BlogService.h>
1615
#import <WordPress/BlogSyncFacade.h>
1716
#import <WordPress/BlogDetailsViewController.h>
@@ -20,11 +19,7 @@ FOUNDATION_EXPORT const unsigned char WordPressVersionString[];
2019
#import <WordPress/CommentsViewController.h>
2120
#import <WordPress/Constants.h>
2221

23-
#import <WordPress/LocalCoreDataService.h>
24-
25-
#import <WordPress/Media.h>
2622
#import <WordPress/MediaService.h>
27-
#import <WordPress/MenuItem.h>
2823
#import <WordPress/MenuItemsViewController.h>
2924
#import <WordPress/MenusService.h>
3025
#import <WordPress/MenusViewController.h>
@@ -33,19 +28,10 @@ FOUNDATION_EXPORT const unsigned char WordPressVersionString[];
3328
#import <WordPress/NSObject+Helpers.h>
3429

3530
#import <WordPress/PageSettingsViewController.h>
36-
#import <WordPress/PostContentProvider.h>
37-
#import <WordPress/PostCategory.h>
3831
#import <WordPress/PostCategoryService.h>
39-
#import <WordPress/PostContentProvider.h>
40-
#import <WordPress/PostHelper.h>
41-
#import <WordPress/PostService.h>
42-
#import <WordPress/PostServiceOptions.h>
4332
#import <WordPress/PostSettingsViewController.h>
44-
#import <WordPress/PostTag.h>
4533
#import <WordPress/PostTagService.h>
4634

47-
#import <WordPress/ReaderGapMarker.h>
48-
#import <WordPress/ReaderPost.h>
4935
#import <WordPress/ReaderPostService.h>
5036
#import <WordPress/ReaderSiteService.h>
5137
#import <WordPress/ReaderSiteService_Internal.h>
@@ -57,19 +43,16 @@ FOUNDATION_EXPORT const unsigned char WordPressVersionString[];
5743
#import <WordPress/SettingsTextViewController.h>
5844
#import <WordPress/SharingViewController.h>
5945
#import <WordPress/SiteSettingsViewController.h>
60-
#import <WordPress/SourcePostAttribution.h>
6146
#import <WordPress/StatsViewController.h>
6247
#import <WordPress/SuggestionsTableView.h>
6348
#import <WordPress/SuggestionsTableViewCell.h>
6449

65-
#import <WordPress/Theme.h>
6650
#import <WordPress/ThemeService.h>
6751

6852
#import <WordPress/UIAlertControllerProxy.h>
6953
#import <WordPress/UIApplication+Helpers.h>
7054
#import <WordPress/UIView+Subviews.h>
7155

72-
#import <WordPress/WPAccount.h>
7356
#import <WordPress/WPActivityDefaults.h>
7457
#import <WordPress/WPAppAnalytics.h>
7558
#import <WordPress/WPUploadStatusButton.h>

WordPress/Classes/Models/AbstractPost.m renamed to Sources/WordPressData/Objective-C/AbstractPost.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#import "AbstractPost.h"
22
#import "Media.h"
3-
#ifdef KEYSTONE
4-
#import "Keystone-Swift.h"
5-
#else
6-
#import "WordPress-Swift.h"
7-
#endif
3+
#import "WordPressData-Swift.h"
84
#import "BasePost.h"
95

106
@import WordPressKit;
File renamed without changes.

WordPress/Classes/Models/Blog/Blog.m renamed to Sources/WordPressData/Objective-C/Blog.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#import "Blog.h"
22
#import "WPAccount.h"
3-
#ifdef KEYSTONE
4-
#import "Keystone-Swift.h"
5-
#else
6-
#import "WordPress-Swift.h"
7-
#endif
3+
@import WordPressShared;
4+
#import "WordPressData-Swift.h"
85

96
@import SFHFKeychainUtils;
107
@import WordPressShared;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@import CocoaLumberjack;
2+
3+
DDLogLevel ddLogLevel = DDLogLevelInfo;
4+
5+
void SetCocoaLumberjackObjCLogLevel(NSUInteger ddLogLevelRawValue)
6+
{
7+
ddLogLevel = (DDLogLevel)ddLogLevelRawValue;
8+
}

WordPress/Classes/Models/Media.m renamed to Sources/WordPressData/Objective-C/Media.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#import "Media.h"
2-
#ifdef KEYSTONE
3-
#import "Keystone-Swift.h"
4-
#else
5-
#import "WordPress-Swift.h"
6-
#endif
2+
#import "WordPressData-Swift.h"
73

84
@implementation Media
95

File renamed without changes.

0 commit comments

Comments
 (0)