Skip to content
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

Improve SPM Integration, break into sub-modules 📦 #205

Merged
merged 5 commits into from
Apr 7, 2021

Conversation

portellaa
Copy link
Contributor

@portellaa portellaa commented Oct 24, 2019

Checklist

Motivation and Context

Since Swift Package Manager is becoming quite popular and Alicerce via CocoaPods supports subspecs, this is quite achievable with Swift Package Manager. It isn't very fancy, but at least is supported.

Description

So each module as it's own target which will be referenced by each library.

The name of the target it's only visible in the xcode project and the library is what is exposed to the products of libraries that includes Alicerce.
That's why i have named each library with the prefix Alicerce and gave the name of the module to the target.

Regarding the Extensions, since SPM doesn't supports the same as CocoaPods supports - sub-subspecs - the only way to achieve that is using a library with the name AlicerceExtensionsFoundation, ...

It would become something like:

// swift-tools-version:5.1

import PackageDescription

let package = Package(
    name: "Alicerce",
    platforms: [
        .iOS(.v10)
    ],
    products: [
        .library(
            name: "Alicerce",
            targets: [
                "Analytics",
                "Core",
                "DeepLinking",
                "ExtensionsFoundation",
                "ExtensionsQuartzCore",
                "ExtensionsUIKit",
                "Logging",
                "Network",
                "Observers",
                "PerformanceMetrics",
                "Persistence",
                "Resource",
                "Stores",
                "View"
            ]
        ),
        .library(name: "AlicerceAnalytics", targets: ["Analytics"]),
        .library(name: "AlicerceCore", targets: ["Core"]),
        .library(name: "AlicerceDeepLinking", targets: ["DeepLinking"]),
        .library(name: "AlicerceExtensionsFoundation", targets: ["ExtensionsFoundation"]),
        .library(name: "AlicerceExtensionsQuartzCore", targets: ["ExtensionsQuartzCore"]),
        .library(name: "AlicerceExtensionsUIKit", targets: ["ExtensionsUIKit"]),
        .library(name: "AlicerceLogging", targets: ["Logging"]),
        .library(name: "AlicerceNetwork", targets: ["Network"]),
        .library(name: "AlicerceObservers", targets: ["Observers"]),
        .library(name: "AlicercePerformanceMetrics", targets: ["PerformanceMetrics"]),
        .library(name: "AlicercePersistence", targets: ["Persistence"]),
        .library(name: "AlicerceResource", targets: ["Resource"]),
        .library(name: "AlicerceStores", targets: ["Stores"]),
        .library(name: "AlicerceView", targets: ["View"]),
    ],
    targets: [
        .target(name: "Analytics", dependencies: ["Core"]),
        .target(
            name: "Core",
            dependencies: ["ExtensionsFoundation", "ExtensionsQuartzCore", "ExtensionsUIKit"],
            path: "Sources",
            sources: ["Shared", "Utils"]
        ),
        .target(name: "DeepLinking", dependencies: ["Core"]),
        .target(name: "ExtensionsFoundation", path: "Sources/Extensions/Foundation"),
        .target(name: "ExtensionsQuartzCore", path: "Sources/Extensions/QuartzCore"),
        .target(name: "ExtensionsUIKit", path: "Sources/Extensions/UIKit"),
        .target(name: "Logging", dependencies: ["Core"]),
        .target(name: "Network", dependencies: ["Resource"]),
        .target(name: "Observers", dependencies: ["Core"]),
        .target(name: "PerformanceMetrics", dependencies: ["Core"]),
        .target(name: "Persistence", dependencies: ["Core", "Logging", "PerformanceMetrics"]),
        .target(name: "Resource", dependencies: ["Core"]),
        .target(
            name: "Stores",
            dependencies: ["Core", "Logging", "Network", "PerformanceMetrics", "Persistence", "Resource"]
        ),
        .target(name: "View", dependencies: ["Core"])
    ],
    swiftLanguageVersions: [ .version("5") ]
)

⚠️ important ⚠️ :
Regarding the tests Target has Objective-C code, this is not supported by Swift Package Manager, as far as i know, i'm still investigating.
One thing i can do is exclude the CoreData path, since this is the one that includes Objective-C code.

EDIT: We are not adding support for Unit Tests via SPM for now, and will leave that as future work. CocoaPods is under the same situation.

All the suggestions are welcome, let's support modules on SPM 🚀

Additions

  • Remove QuartzCore extensions sub-sub-spec and merge them into UIKit extensions
  • Add reference to Alicerce SPM package in workspace for easier iteration
  • Add schemas for each library product (main + sub-libraries) that are now available via SPM
  • Add stage in Travis CI to build the products via SPM

@portellaa portellaa changed the title Improve Package.swift with modules 🦵 WIP: Improve Package.swift with modules 🦵 Oct 24, 2019
@codecov
Copy link

codecov bot commented Oct 24, 2019

Codecov Report

Merging #205 (b79d10a) into master (85f7848) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #205   +/-   ##
=======================================
  Coverage   94.96%   94.96%           
=======================================
  Files          97       97           
  Lines        3254     3254           
=======================================
  Hits         3090     3090           
  Misses        164      164           
Impacted Files Coverage Δ
...es/Analytics/Trackers/Analytics+MultiTracker.swift 100.00% <ø> (ø)
Sources/DeepLinking/Route+TrieRouter.swift 91.78% <ø> (ø)
Sources/Extensions/UIKit/CAGradientLayer.swift 100.00% <ø> (ø)
Sources/Extensions/UIKit/CALayer.swift 100.00% <ø> (ø)
Sources/Logging/Loggers/Log+MultiLogger.swift 97.36% <ø> (ø)
Sources/Logging/Loggers/Logger.swift 100.00% <ø> (ø)
Sources/Logging/Loggers/ModuleLogger.swift 100.00% <ø> (ø)
Sources/Network/Network+BaseRequestMaking.swift 100.00% <ø> (ø)
Sources/Network/Network+URLSessionError.swift 100.00% <ø> (ø)
...urces/Network/Network+URLSessionNetworkStack.swift 96.15% <ø> (ø)
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 85f7848...b79d10a. Read the comment docs.

@p4checo p4checo requested a review from a team October 24, 2019 19:26
Copy link
Member

@p4checo p4checo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 🚀 Minor 💄 comment

Package.swift Outdated Show resolved Hide resolved
Package.swift Show resolved Hide resolved
@p4checo
Copy link
Member

p4checo commented Dec 30, 2019

Regarding your questions, @portellaa:

  1. Extensions sub-sub-specs equivalent in SPM
    Do you think it's worth it? IMO perhaps we can drop them for SPM 🤔

  2. Test targets in SPM
    We currently don't publish our tests via CocoaPods either (although I have that almost done in a stash 😅), so we don't have to in SPM either, I guess 😇. I agree that would be nice, but perhaps we can leave that as a future improvement?
    The Obj-C limitation you mention only affects test targets?

Additionally, do you think we should add a stage on our pipeline to validate the SPM package description?

@p4checo p4checo force-pushed the swift-package-manager branch from a6432ea to 98c77ca Compare April 5, 2021 17:53
@p4checo p4checo changed the title WIP: Improve Package.swift with modules 🦵 Improve SPM Integration, break into sub-modules 📦 Apr 5, 2021
@p4checo p4checo requested a review from a team April 6, 2021 12:55
Copy link
Contributor

@diogoeiras diogoeiras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

.travis.yml Show resolved Hide resolved
Package.swift Show resolved Hide resolved
portellaa and others added 5 commits April 7, 2021 15:06
## Changes

- Fix `Package.swift` by prefixing target names with `Alicerce` since
that's the name of the generated frameworks (to use in imports).

- Add Alicerce package to the workspace, as well as targets for each SPM
product (libraries).

- Add necessary imports so that sub-modules are correctly imported if
building sub-libraries.
@p4checo p4checo force-pushed the swift-package-manager branch from 98c77ca to b79d10a Compare April 7, 2021 14:06
@p4checo p4checo merged commit 45bdc59 into master Apr 7, 2021
@p4checo p4checo deleted the swift-package-manager branch April 7, 2021 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants