Skip to content

Support for async codegen and Sourcery 2.2.3 #359

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
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

art-divin
Copy link

@art-divin art-divin commented Mar 24, 2024

Related to krzysztofzablocki/Sourcery#1308

Context

This PR adds facilities to support concurrent codegen based on swifttemplate

Details

In order to be able to generate the code concurrently for every type, shared state needs to be removed.

This PR does the following:

  1. Removes all the shared state
  2. Update Sourcery version to 2.2.3
  3. Small improvements / refactoring

@art-divin art-divin changed the title Draft: Updated related classes Support for async codegen and Sourcery 2.1.9 Mar 24, 2024
@art-divin art-divin changed the title Support for async codegen and Sourcery 2.1.9 Support for async codegen and Sourcery 2.2 Mar 31, 2024
@markst
Copy link

markst commented Apr 2, 2024

This could probably overrule #352

<%_ var all = types.all
all += types.protocols.map { $0 }
all += types.protocolCompositions.map { $0 }
func generate(type: Type, methodRegistrar: MethodRegistrar, subscriptRegistrar: SubscriptRegistrar) async -> String {
Copy link

@markst markst Apr 2, 2024

Choose a reason for hiding this comment

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

seems to be failing for me:
image

Copy link
Author

Choose a reason for hiding this comment

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

Hey @markst , actually the screenshot looks fine. There's a print statement below, and the contents of the file on the screenshot is not the final code which would go into the generated mock

@art-divin art-divin changed the title Support for async codegen and Sourcery 2.2 Support for async codegen and Sourcery 2.2.3 Apr 19, 2024
@markst
Copy link

markst commented Aug 8, 2024

We might also need to update kSourceryVersion in Global.swift for the CLI:
https://github.com/MakeAWishFoundation/SwiftyMocky/blob/master/Sources/CLI/Core/Utils/Global.swift#L5

@markst
Copy link

markst commented Aug 8, 2024

I've built from this branch multiple times:

swift build --disable-sandbox -c release

but using the build binary:

./swiftymocky generate --disableCache --verbose

Insists on the template including characters.split which fails post Swift 5:

❌  Error: ShellOut encountered an error
Status code: 3
Message: "Building for production...
[0/5] Write sources
[2/5] Write swift-version-33747A42983211AE.txt
[4/7] Emitting module SourceryRuntime
[5/7] Compiling SourceryRuntime AccessLevel.swift
[6/9] Emitting module SwiftTemplate
[7/9] Compiling SwiftTemplate main.swift
/private/var/folders/qv/k4c8t3_95tzc96m0cpv30tn80000gq/T/SwiftTemplate/EF30FB5F-CF6A-4725-B7E7-65C3340E92C4/2.2.2/Sources/SwiftTemplate/main.swift:251:96: error: 'characters' is unavailable: Please use String directly
            split($0, byFirstOccurenceOf: " where ").0.replacingOccurrences(of: " ", with: "").characters.split(separator: ":").map(String.init).first
                                                                                               ^~~~~~~~~~
Swift.String:5:16: note: 'characters' was obsoleted in Swift 5.0

I can't work out where this template is coming from, it's determined not to use the template in your branch despite building from checked out branch.

@markst
Copy link

markst commented Aug 8, 2024

Ah! it's because we need to update the base64 encoded files at Assets.swifttemplate.mock which are used for the CLI

<%_ var all = types.all
all += types.protocols.map { $0 }
all += types.protocolCompositions.map { $0 }
func generate(type: Type, methodRegistrar: MethodRegistrar, subscriptRegistrar: SubscriptRegistrar) async -> String {
Copy link

Choose a reason for hiding this comment

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

think we're just missing an opening tag:

Suggested change
func generate(type: Type, methodRegistrar: MethodRegistrar, subscriptRegistrar: SubscriptRegistrar) async -> String {
<%_
func generate(type: Type, methodRegistrar: MethodRegistrar, subscriptRegistrar: SubscriptRegistrar) async -> String {

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.

2 participants