Last active
September 26, 2022 04:44
-
-
Save minsOne/1d1ff76d2a02993a824c884f251a0b59 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env ruby | |
| def find_interface_type(key, path) | |
| cmd = <<SHELL | |
| cat #{path} | grep "property descriptor for #{key}.type :" | sed -E "s/.* : (.*)\\?/\\1/g" | |
| SHELL | |
| #puts cmd | |
| value = `#{cmd}` | |
| #puts value | |
| return value.strip | |
| end | |
| def find_concreate_type(interface, path) | |
| cmd = <<SHELL | |
| cat #{path} | grep "#{interface}" | grep "protocol conformance descriptor for " | grep -v "KKBContainer.InjectionKey" | sed -E "s/protocol conformance descriptor for (.*) : .* in .*/\\1/g" | |
| SHELL | |
| #puts cmd | |
| value = `#{cmd}` | |
| #puts value | |
| return value.strip | |
| end | |
| def generate_symbol(path) | |
| cmd = <<SHELL | |
| echo $(pwd) | |
| BUILD_APP_DIR=${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME} | |
| echo $BUILD_APP_DIR | |
| if test -z "$BUILT_PRODUCTS_DIR" | |
| then | |
| echo "\$BUILD_APP_DIR is empty" | |
| exit 1 | |
| else | |
| find ${BUILD_APP_DIR} -type f -exec file {} \\; | grep "framework" | grep -e "Mach-O 64-bit dynamically linked shared library arm64" | awk '{print $1}' | tr -d ":" | xargs nm | awk '{print $3}' | xcrun swift-demangle > #{path} | |
| fi | |
| SHELL | |
| #puts cmd | |
| value = `#{cmd}` | |
| end | |
| def find_keylist(path) | |
| cmd = <<SHELL | |
| cat #{path} | grep "protocol conformance descriptor for " | grep "KKBContainer.InjectionKey" | sed -E "s/protocol conformance descriptor for (.*) : (.*) in .*/\\1/g" | |
| SHELL | |
| #puts cmd | |
| value = `#{cmd}` | |
| # puts value | |
| return value | |
| end | |
| def makeContainer(hash) | |
| output = "// MARK: - Generated File From Scripts\n\n" | |
| import_list = ["import DIContainer\n"] | |
| for key in hash.keys do | |
| import_list.append("import #{key.split(".")[0]}\n") | |
| if !hash[key].empty? | |
| import_list.append("import #{hash[key].split(".")[0]}\n") | |
| end | |
| end | |
| for import in import_list.uniq.sort do | |
| output += import | |
| end | |
| output += "\n" | |
| output += <<SHELL | |
| struct ContainerRegisterService { | |
| func register() { | |
| Container { | |
| SHELL | |
| hash.each do |key, value| | |
| if value.empty? | |
| output += " Module(#{key}.self){ <#구현타입없음확인필요#> }\n" | |
| else | |
| output += " Module(#{key}.self){ #{value}() }\n" | |
| end | |
| # output += " Component(#{key.split(".")[1..-1].join('.')}.self){ <#구현타입없음확인필요#> }\n" | |
| end | |
| output += " }.build()\n" | |
| output += " }\n" | |
| output += "}\n" | |
| puts output | |
| end | |
| symbolfilePath="/tmp/symbolfile" | |
| generate_symbol(symbolfilePath) | |
| key_list = find_keylist(symbolfilePath).split("\n") | |
| container = Hash.new | |
| for key in key_list do | |
| #puts key | |
| container[key] = "" | |
| interface_type = find_interface_type(key, symbolfilePath) | |
| #puts interface_type | |
| concreate_type = find_concreate_type(interface_type, symbolfilePath) | |
| #puts concreate_type | |
| container[key] = concreate_type | |
| end | |
| # puts container | |
| makeContainer(container) |
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
| cd $SRCROOT && cd $(git rev-parse --show-toplevel) | |
| make generate_di_register > $SRCROOT/Example/Sources/ContainerRegisterService.swift |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment