Skip to content

Commit

Permalink
Merge pull request #234 from cashapp/bradfol/fix-erbs
Browse files Browse the repository at this point in the history
Fix gencode script for erb files
  • Loading branch information
bradfol authored Jan 28, 2025
2 parents 60e11b4 + 06ff8c3 commit 204451a
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 159 deletions.
4 changes: 2 additions & 2 deletions Scripts/gencode
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh

# This script is similar to Swinject's gencode script.
# This script is based on Swinject's gencode script.
# It generates high-arity overloads of generic functions using the file templates listed below.
# The generated files are checked in since they are not dynamic and don't change often.

files="Sources/Knit/ServiceCollection/Container+ServiceCollection"
files="Sources/Knit/ServiceCollection/Container+ServiceCollection Sources/Swinject/Container.Arguments Sources/Swinject/Resolver Sources/Swinject/ServiceEntry.TypeForwarding"

for file in $files; do
echo "Generating code to $file.swift"
Expand Down
11 changes: 5 additions & 6 deletions Sources/Swinject/Container.Arguments.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//
// Container.Arguments.swift
// Swinject
//
// Created by Yoichi Tagaya on 8/18/15.
// Copyright © 2015 Swinject Contributors. All rights reserved.
//
Expand All @@ -11,14 +8,15 @@
//
// Container.Arguments.swift is generated from Container.Arguments.erb by ERB.
// Do NOT modify Container.Arguments.swift directly.
// Instead, modify Container.Arguments.erb and run `script/gencode` at the project root directory to generate the code.
// Instead, modify Container.Arguments.erb and run `Scripts/gencode` at the project root directory to generate the code.
//

<% arg_count = 9 %>

import Foundation

// MARK: - Registration with Arguments

extension Container {
<% (1..arg_count).each do |i| %>
<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %>
Expand All @@ -39,15 +37,16 @@ extension Container {
public func register<Service, <%= arg_types %>>(
_ serviceType: Service.Type,
name: String? = nil,
factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry<Service>
{
factory: @escaping (Resolver, <%= arg_types %>) -> Service
) -> ServiceEntry<Service> {
return _register(serviceType, factory: factory, name: name)
}

<% end %>
}

// MARK: - Resolver with Arguments

extension Container {
<% (1..arg_count).each do |i| %>
<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %>
Expand Down
188 changes: 96 additions & 92 deletions Sources/Swinject/Container.Arguments.swift

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions Sources/Swinject/Resolver.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
//
// Resolver.swift
// Swinject
//
// Created by Yoichi Tagaya on 8/18/15.
// Copyright (c) 2015 Swinject Contributors. All rights reserved.
// Copyright © 2019 Swinject Contributors. All rights reserved.
//

//
// NOTICE:
//
// Resolver.swift is generated from Resolver.erb by ERB.
// Do NOT modify Container.Arguments.swift directly.
// Instead, modify Resolver.erb and run `script/gencode` at the project root directory to generate the code.
// Instead, modify Resolver.erb and run `Scripts/gencode` at the project root directory to generate the code.
//

<% arg_count = 9 %>
Expand Down
62 changes: 24 additions & 38 deletions Sources/Swinject/Resolver.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
//
// Created by Yoichi Tagaya on 8/18/15.
// Copyright © 2019 Swinject Contributors. All rights reserved.
//

//
// NOTICE:
//
// Resolver.swift is generated from Resolver.erb by ERB.
// Do NOT modify Resolver.swift directly.
// Instead, modify Resolver.erb and run `script/gencode` at the project root directory to generate the code.
// Do NOT modify Container.Arguments.swift directly.
// Instead, modify Resolver.erb and run `Scripts/gencode` at the project root directory to generate the code.
//


public protocol Resolver {
/// Retrieves the instance with the specified service type.
///
Expand Down Expand Up @@ -37,8 +39,7 @@ public protocol Resolver {
/// and 1 argument is found.
func resolve<Service, Arg1>(
_ serviceType: Service.Type,
argument: Arg1
) -> Service?
argument: Arg1) -> Service?

/// Retrieves the instance with the specified service type, 1 argument to the factory closure and registration name.
///
Expand All @@ -52,8 +53,7 @@ public protocol Resolver {
func resolve<Service, Arg1>(
_ serviceType: Service.Type,
name: String?,
argument: Arg1
) -> Service?
argument: Arg1) -> Service?

/// Retrieves the instance with the specified service type and list of 2 arguments to the factory closure.
///
Expand All @@ -65,8 +65,7 @@ public protocol Resolver {
/// and list of 2 arguments is found.
func resolve<Service, Arg1, Arg2>(
_ serviceType: Service.Type,
arguments arg1: Arg1, _ arg2: Arg2
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2) -> Service?

/// Retrieves the instance with the specified service type, list of 2 arguments to the factory closure and registration name.
///
Expand All @@ -80,8 +79,7 @@ public protocol Resolver {
func resolve<Service, Arg1, Arg2>(
_ serviceType: Service.Type,
name: String?,
arguments arg1: Arg1, _ arg2: Arg2
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2) -> Service?

/// Retrieves the instance with the specified service type and list of 3 arguments to the factory closure.
///
Expand All @@ -93,8 +91,7 @@ public protocol Resolver {
/// and list of 3 arguments is found.
func resolve<Service, Arg1, Arg2, Arg3>(
_ serviceType: Service.Type,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service?

/// Retrieves the instance with the specified service type, list of 3 arguments to the factory closure and registration name.
///
Expand All @@ -108,8 +105,7 @@ public protocol Resolver {
func resolve<Service, Arg1, Arg2, Arg3>(
_ serviceType: Service.Type,
name: String?,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service?

/// Retrieves the instance with the specified service type and list of 4 arguments to the factory closure.
///
Expand All @@ -121,8 +117,7 @@ public protocol Resolver {
/// and list of 4 arguments is found.
func resolve<Service, Arg1, Arg2, Arg3, Arg4>(
_ serviceType: Service.Type,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service?

/// Retrieves the instance with the specified service type, list of 4 arguments to the factory closure and registration name.
///
Expand All @@ -136,8 +131,7 @@ public protocol Resolver {
func resolve<Service, Arg1, Arg2, Arg3, Arg4>(
_ serviceType: Service.Type,
name: String?,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service?

/// Retrieves the instance with the specified service type and list of 5 arguments to the factory closure.
///
Expand All @@ -149,8 +143,7 @@ public protocol Resolver {
/// and list of 5 arguments is found.
func resolve<Service, Arg1, Arg2, Arg3, Arg4, Arg5>(
_ serviceType: Service.Type,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service?

/// Retrieves the instance with the specified service type, list of 5 arguments to the factory closure and registration name.
///
Expand All @@ -164,8 +157,7 @@ public protocol Resolver {
func resolve<Service, Arg1, Arg2, Arg3, Arg4, Arg5>(
_ serviceType: Service.Type,
name: String?,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service?

/// Retrieves the instance with the specified service type and list of 6 arguments to the factory closure.
///
Expand All @@ -177,8 +169,7 @@ public protocol Resolver {
/// and list of 6 arguments is found.
func resolve<Service, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>(
_ serviceType: Service.Type,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service?

/// Retrieves the instance with the specified service type, list of 6 arguments to the factory closure and registration name.
///
Expand All @@ -192,8 +183,7 @@ public protocol Resolver {
func resolve<Service, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>(
_ serviceType: Service.Type,
name: String?,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service?

/// Retrieves the instance with the specified service type and list of 7 arguments to the factory closure.
///
Expand All @@ -205,8 +195,7 @@ public protocol Resolver {
/// and list of 7 arguments is found.
func resolve<Service, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>(
_ serviceType: Service.Type,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service?

/// Retrieves the instance with the specified service type, list of 7 arguments to the factory closure and registration name.
///
Expand All @@ -220,8 +209,7 @@ public protocol Resolver {
func resolve<Service, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>(
_ serviceType: Service.Type,
name: String?,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service?

/// Retrieves the instance with the specified service type and list of 8 arguments to the factory closure.
///
Expand All @@ -233,8 +221,7 @@ public protocol Resolver {
/// and list of 8 arguments is found.
func resolve<Service, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8>(
_ serviceType: Service.Type,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service?

/// Retrieves the instance with the specified service type, list of 8 arguments to the factory closure and registration name.
///
Expand All @@ -248,8 +235,7 @@ public protocol Resolver {
func resolve<Service, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8>(
_ serviceType: Service.Type,
name: String?,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service?

/// Retrieves the instance with the specified service type and list of 9 arguments to the factory closure.
///
Expand All @@ -261,8 +247,7 @@ public protocol Resolver {
/// and list of 9 arguments is found.
func resolve<Service, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9>(
_ serviceType: Service.Type,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service?

/// Retrieves the instance with the specified service type, list of 9 arguments to the factory closure and registration name.
///
Expand All @@ -276,6 +261,7 @@ public protocol Resolver {
func resolve<Service, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9>(
_ serviceType: Service.Type,
name: String?,
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9
) -> Service?
arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service?


}
11 changes: 4 additions & 7 deletions Sources/Swinject/ServiceEntry.TypeForwarding.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
//
// ServiceEntry.TypeForwarding.swift
// Swinject-iOS
//
// Created by Jakub Vaňo on 16/02/2018.
// Copyright © 2018 Swinject Contributors. All rights reserved.
// Copyright © 2019 Swinject Contributors. All rights reserved.
//

//
// NOTICE:
//
// ServiceEntry.TypeForwarding.swift is generated from ServiceEntry.TypeForwarding.erb by ERB.
// Do NOT modify ServiceEntry.TypeForwarding.swift directly.
// Instead, modify ServiceEntry.TypeForwarding.erb and run `script/gencode` at the project root directory to generate the code.
// Instead, modify ServiceEntry.TypeForwarding.erb and run `Scripts/gencode` at the project root directory to generate the code.
//

<% type_count = 9 %>
Expand Down Expand Up @@ -40,8 +37,8 @@ extension ServiceEntry {
@discardableResult
public func implements<<%= types %>>(<%= params %>) -> ServiceEntry<Service> {
return self<% (1..i).each do |k| %>.implements(type<%= k %>)<% end %>

}

<% end %>
}
21 changes: 12 additions & 9 deletions Sources/Swinject/ServiceEntry.TypeForwarding.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//
// Created by Jakub Vaňo on 16/02/2018.
// Copyright © 2019 Swinject Contributors. All rights reserved.
//

Expand All @@ -7,9 +8,10 @@
//
// ServiceEntry.TypeForwarding.swift is generated from ServiceEntry.TypeForwarding.erb by ERB.
// Do NOT modify ServiceEntry.TypeForwarding.swift directly.
// Instead, modify ServiceEntry.TypeForwarding.erb and run `script/gencode` at the project root directory to generate the code.
// Instead, modify ServiceEntry.TypeForwarding.erb and run `Scripts/gencode` at the project root directory to generate the code.
//


extension ServiceEntry {
/// Adds another type which should be resolved using this ServiceEntry - i.e. using the same object scope,
/// arguments and `initCompleted` closures
Expand All @@ -30,7 +32,7 @@ extension ServiceEntry {
/// - types: List of 2 types resolution of which should be forwarded
@discardableResult
public func implements<T1, T2>(_ type1: T1.Type, _ type2: T2.Type) -> ServiceEntry<Service> {
return implements(type1).implements(type2)
return self.implements(type1).implements(type2)
}

/// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope,
Expand All @@ -40,7 +42,7 @@ extension ServiceEntry {
/// - types: List of 3 types resolution of which should be forwarded
@discardableResult
public func implements<T1, T2, T3>(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type) -> ServiceEntry<Service> {
return implements(type1).implements(type2).implements(type3)
return self.implements(type1).implements(type2).implements(type3)
}

/// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope,
Expand All @@ -50,7 +52,7 @@ extension ServiceEntry {
/// - types: List of 4 types resolution of which should be forwarded
@discardableResult
public func implements<T1, T2, T3, T4>(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type) -> ServiceEntry<Service> {
return implements(type1).implements(type2).implements(type3).implements(type4)
return self.implements(type1).implements(type2).implements(type3).implements(type4)
}

/// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope,
Expand All @@ -60,7 +62,7 @@ extension ServiceEntry {
/// - types: List of 5 types resolution of which should be forwarded
@discardableResult
public func implements<T1, T2, T3, T4, T5>(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type) -> ServiceEntry<Service> {
return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5)
return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5)
}

/// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope,
Expand All @@ -70,7 +72,7 @@ extension ServiceEntry {
/// - types: List of 6 types resolution of which should be forwarded
@discardableResult
public func implements<T1, T2, T3, T4, T5, T6>(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type) -> ServiceEntry<Service> {
return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6)
return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6)
}

/// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope,
Expand All @@ -80,7 +82,7 @@ extension ServiceEntry {
/// - types: List of 7 types resolution of which should be forwarded
@discardableResult
public func implements<T1, T2, T3, T4, T5, T6, T7>(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type, _ type7: T7.Type) -> ServiceEntry<Service> {
return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7)
return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7)
}

/// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope,
Expand All @@ -90,7 +92,7 @@ extension ServiceEntry {
/// - types: List of 8 types resolution of which should be forwarded
@discardableResult
public func implements<T1, T2, T3, T4, T5, T6, T7, T8>(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type, _ type7: T7.Type, _ type8: T8.Type) -> ServiceEntry<Service> {
return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8)
return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8)
}

/// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope,
Expand All @@ -100,6 +102,7 @@ extension ServiceEntry {
/// - types: List of 9 types resolution of which should be forwarded
@discardableResult
public func implements<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type, _ type7: T7.Type, _ type8: T8.Type, _ type9: T9.Type) -> ServiceEntry<Service> {
return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8).implements(type9)
return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8).implements(type9)
}

}

0 comments on commit 204451a

Please sign in to comment.