Skip to content

Commit

Permalink
Fix: should use product name instead of module name when patching XCF…
Browse files Browse the repository at this point in the history
…rameworks

When patching support files, we should use just product.name to replace XCFrameworks paths. This is because module name is used for importing modules in swift, which doesn't allow special characters like '-'; however for header search path and library search path, special characters are allowed. Therefore when we have targets whose name has characters not supported in Swift, such as "foo-bar", using product.moduleName makes the regex pattern "${PODS_XCFRAMEWORKS_BUILD_DIR}/foo_bar", which causes search path "${PODS_XCFRAMEWORKS_BUILD_DIR}/foo-bar" cannot be substituted because regex pattern doesn't match.
  • Loading branch information
Kaining Zhong authored and swiftyfinch committed Nov 12, 2023
1 parent 8537a8f commit a8c83d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions Sources/RugbyFoundation/Core/Use/SupportFilesPatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ final class SupportFilesPatcher {
replacement: binaryFolderPath))

guard let moduleName = product.moduleName else { return }
let name = product.name
let moduleMap = "\(moduleName).modulemap"
result.append(("\(PODS_CONFIGURATION_BUILD_DIR)\(parentFolderName)/\(moduleMap)",
replacement: "\(binaryFolderPath)/\(moduleMap)"))

if product.type == .staticLibrary {
result.append((
"\(PODS_XCFRAMEWORKS_BUILD_DIR)\(moduleName)/\(HEADERS)",
replacement: "\(binaryFolderPath)/\(moduleName)/\(HEADERS)"
"\(PODS_XCFRAMEWORKS_BUILD_DIR)\(name)/\(HEADERS)",
replacement: "\(binaryFolderPath)/\(name)/\(HEADERS)"
))
result.append((
"\(PODS_XCFRAMEWORKS_BUILD_DIR)\(moduleName)",
replacement: "\(binaryFolderPath)/\(moduleName)"
"\(PODS_XCFRAMEWORKS_BUILD_DIR)\(name)",
replacement: "\(binaryFolderPath)/\(name)"
))
}
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/FoundationTests/Core/Use/SupportFilesPatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ extension SupportFilesPatcherTests {
func test_prepareReplacements_umbrella() throws {
let target = Target.podsExample
// swiftlint:disable line_length
let xcconfigReplacements = ["\"${PODS_CONFIGURATION_BUILD_DIR}/Realm-library\"": "\"${HOME}/.rugby/bin/Realm-library/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/d2d48c5\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Realm-library/Realm.modulemap\"": "\"${HOME}/.rugby/bin/Realm-library/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/d2d48c5/Realm.modulemap\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Alamofire\"": "\"${HOME}/.rugby/bin/Alamofire/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/36ff0bc\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Moya/Moya.modulemap\"": "\"${HOME}/.rugby/bin/Moya/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/badaa58/Moya.modulemap\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Moya\"": "\"${HOME}/.rugby/bin/Moya/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/badaa58\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Realm-library/libRealm-library.a/Headers\"": "\"${HOME}/.rugby/bin/Realm-library/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/d2d48c5/libRealm-library.a/Headers\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Alamofire/Alamofire.modulemap\"": "\"${HOME}/.rugby/bin/Alamofire/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/36ff0bc/Alamofire.modulemap\"", "\"${PODS_XCFRAMEWORKS_BUILD_DIR}/Realm\"": "\"${HOME}/.rugby/bin/Realm-library/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/d2d48c5/Realm\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Moya/Moya.framework/Headers\"": "\"${HOME}/.rugby/bin/Moya/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/badaa58/Moya.framework/Headers\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Alamofire/Alamofire.framework/Headers\"": "\"${HOME}/.rugby/bin/Alamofire/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/36ff0bc/Alamofire.framework/Headers\"", "\"${PODS_XCFRAMEWORKS_BUILD_DIR}/Realm/Headers\"": "\"${HOME}/.rugby/bin/Realm-library/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/d2d48c5/Realm/Headers\""]
let xcconfigRegexPattern = #""(\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Moya\/Moya\.framework\/Headers|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Moya|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Moya\/Moya\.modulemap|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Alamofire\/Alamofire\.framework\/Headers|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Alamofire|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Alamofire\/Alamofire\.modulemap|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Realm-library\/libRealm-library\.a\/Headers|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Realm-library|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Realm-library\/Realm\.modulemap|\$\{PODS_XCFRAMEWORKS_BUILD_DIR\}\/Realm\/Headers|\$\{PODS_XCFRAMEWORKS_BUILD_DIR\}\/Realm)""#
let xcconfigReplacements = ["\"${PODS_CONFIGURATION_BUILD_DIR}/Realm-library\"": "\"${HOME}/.rugby/bin/Realm-library/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/d2d48c5\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Realm-library/Realm_library.modulemap\"": "\"${HOME}/.rugby/bin/Realm-library/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/d2d48c5/Realm_library.modulemap\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Alamofire\"": "\"${HOME}/.rugby/bin/Alamofire/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/36ff0bc\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Moya/Moya.modulemap\"": "\"${HOME}/.rugby/bin/Moya/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/badaa58/Moya.modulemap\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Moya\"": "\"${HOME}/.rugby/bin/Moya/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/badaa58\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Realm-library/libRealm-library.a/Headers\"": "\"${HOME}/.rugby/bin/Realm-library/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/d2d48c5/libRealm-library.a/Headers\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Alamofire/Alamofire.modulemap\"": "\"${HOME}/.rugby/bin/Alamofire/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/36ff0bc/Alamofire.modulemap\"", "\"${PODS_XCFRAMEWORKS_BUILD_DIR}/Realm-library\"": "\"${HOME}/.rugby/bin/Realm-library/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/d2d48c5/Realm-library\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Moya/Moya.framework/Headers\"": "\"${HOME}/.rugby/bin/Moya/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/badaa58/Moya.framework/Headers\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Alamofire/Alamofire.framework/Headers\"": "\"${HOME}/.rugby/bin/Alamofire/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/36ff0bc/Alamofire.framework/Headers\"", "\"${PODS_XCFRAMEWORKS_BUILD_DIR}/Realm-library/Headers\"": "\"${HOME}/.rugby/bin/Realm-library/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/d2d48c5/Realm-library/Headers\""]
let xcconfigRegexPattern = #""(\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Moya\/Moya\.framework\/Headers|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Moya|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Moya\/Moya\.modulemap|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Alamofire\/Alamofire\.framework\/Headers|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Alamofire|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Alamofire\/Alamofire\.modulemap|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Realm-library\/libRealm-library\.a\/Headers|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Realm-library|\$\{PODS_CONFIGURATION_BUILD_DIR\}\/Realm-library\/Realm_library\.modulemap|\$\{PODS_XCFRAMEWORKS_BUILD_DIR\}\/Realm-library\/Headers|\$\{PODS_XCFRAMEWORKS_BUILD_DIR\}\/Realm-library)""#
let frameworkReplacements = ["\"${BUILT_PRODUCTS_DIR}/Moya/Moya.framework\"": "\"${HOME}/.rugby/bin/Moya/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/badaa58/Moya.framework\"", "\"${BUILT_PRODUCTS_DIR}/Realm-library/libRealm-library.a\"": "\"${HOME}/.rugby/bin/Realm-library/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/d2d48c5/libRealm-library.a\"", "\"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework\"": "\"${HOME}/.rugby/bin/Alamofire/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/36ff0bc/Alamofire.framework\""]
let frameworksRegexPattern = #""\$\{BUILT_PRODUCTS_DIR\}\/(Moya\/Moya\.framework|Alamofire\/Alamofire\.framework|Realm-library\/libRealm-library\.a)""#
let resourcesReplacements = ["${BUILT_PRODUCTS_DIR}/Realm-library/libRealm-library.a/": "${HOME}/.rugby/bin/Realm-library/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/d2d48c5/libRealm-library.a/", "${BUILT_PRODUCTS_DIR}/Moya/Moya.framework/": "${HOME}/.rugby/bin/Moya/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/badaa58/Moya.framework/", "\"${PODS_CONFIGURATION_BUILD_DIR}/LocalPod/LocalPodResources.bundle\"": "\"${HOME}/.rugby/bin/LocalPodResources/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/17da84b/LocalPodResources.bundle\"", "${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework/": "${HOME}/.rugby/bin/Alamofire/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}-${ARCHS}/36ff0bc/Alamofire.framework/"]
Expand Down Expand Up @@ -258,7 +258,7 @@ private extension Target {
realm.name = "Realm-library"
let product = Product(
name: "Realm-library",
moduleName: "Realm",
moduleName: "Realm_library",
type: .staticLibrary,
parentFolderName: "Realm-library"
)
Expand Down

0 comments on commit a8c83d9

Please sign in to comment.