Skip to content

Commit

Permalink
abstract getting apple_frame_import
Browse files Browse the repository at this point in the history
  • Loading branch information
woshimaliang committed Jun 9, 2022
1 parent 2ec613f commit 3b0e2a0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
8 changes: 2 additions & 6 deletions Sources/PodToBUILD/BuildFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,13 @@ public func makeLoadNodes(forConvertibles skylarkConvertibles: [SkylarkConvertib
let hasAppleBundleImport = skylarkConvertibles.first(where: { $0 is AppleBundleImport }) != nil
let hasAppleResourceBundle = skylarkConvertibles.first(where: { $0 is AppleResourceBundle }) != nil
let hasAppleFrameworkImport = skylarkConvertibles.first(where: { $0 is AppleFrameworkImport }) != nil
let isDynamicFramework = GetBuildOptions().isDynamicFramework
let isXCFramework = GetBuildOptions().isXCFramework
let appleFrameworkImport = appleFrameworkImport(isDynamicFramework: GetBuildOptions().isDynamicFramework, isXCFramework: GetBuildOptions().isXCFramework)

return .lines( [
hasSwift ? SkylarkNode.skylark("load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')") : nil,
hasAppleBundleImport ? SkylarkNode.skylark("load('@build_bazel_rules_apple//apple:resources.bzl', 'apple_bundle_import')") : nil,
hasAppleResourceBundle ? SkylarkNode.skylark("load('@build_bazel_rules_apple//apple:resources.bzl', 'apple_resource_bundle')") : nil,
hasAppleFrameworkImport && isDynamicFramework && !isXCFramework ? SkylarkNode.skylark("load('@build_bazel_rules_apple//apple:apple.bzl', 'apple_dynamic_framework_import')") : nil,
hasAppleFrameworkImport && !isDynamicFramework && !isXCFramework ? SkylarkNode.skylark("load('@build_bazel_rules_apple//apple:apple.bzl', 'apple_static_framework_import')") : nil,
hasAppleFrameworkImport && isDynamicFramework && isXCFramework ? SkylarkNode.skylark("load('@build_bazel_rules_apple//apple:apple.bzl', 'apple_dynamic_xcframework_import')") : nil,
hasAppleFrameworkImport && !isDynamicFramework && isXCFramework ? SkylarkNode.skylark("load('@build_bazel_rules_apple//apple:apple.bzl', 'apple_static_xcframework_import')") : nil,
hasAppleFrameworkImport ? SkylarkNode.skylark("load('@build_bazel_rules_apple//apple:apple.bzl', '\(appleFrameworkImport)')") : nil,
].compactMap { $0 }
)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/PodToBUILD/BuildOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct BasicBuildOptions: BuildOptions {
public let vendorize: Bool
public let childPaths: [String]
public let isDynamicFramework: Bool
public let isXCFramework:Bool
public let isXCFramework: Bool

public init(podName: String = "",
path: String = ".",
Expand Down
16 changes: 2 additions & 14 deletions Sources/PodToBUILD/ObjcLibrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,11 @@ public struct AppleFrameworkImport: BazelTarget {
// visibility = ["visibility:public"]
// )
public func toSkylark() -> SkylarkNode {
let isDynamicFramework = GetBuildOptions().isDynamicFramework
let isXCFramework = GetBuildOptions().isXCFramework

let frameworkType : String

if isXCFramework && isDynamicFramework {
frameworkType = "apple_dynamic_xcframework_import"
} else if isXCFramework && !isDynamicFramework {
frameworkType = "apple_static_xcframework_import"
} else if !isXCFramework && isDynamicFramework {
frameworkType = "apple_dynamic_framework_import"
} else {
frameworkType = "apple_static_framework_import"
}
let appleFrameworkImport = appleFrameworkImport(isDynamicFramework: GetBuildOptions().isDynamicFramework, isXCFramework: isXCFramework)

return SkylarkNode.functionCall(
name: frameworkType,
name: appleFrameworkImport,
arguments: [SkylarkFunctionArgument]([
.named(name: "name", value: .string(name)),
.named(name: isXCFramework ? "xcframework_imports": "framework_imports",
Expand Down
9 changes: 9 additions & 0 deletions Sources/PodToBUILD/RuleUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,12 @@ public func bazelLabel(fromString string: String) -> String {
}


/// framework import for apple framework import
/// - Parameters:
/// - isDynamicFramework: whether internal framework is dynamic or static
/// - isXCFramework: if it is XCFramework
/// - Returns: apple framework import string such as "apple_static_xcframework_import"
public func appleFrameworkImport(isDynamicFramework: Bool, isXCFramework: Bool) -> String {
return "apple_" + (isDynamicFramework ? "dynamic_" : "static_") + (isXCFramework ? "xcframework_" : "framework_") + "import"
}

2 changes: 1 addition & 1 deletion Sources/RepoToolsCore/RepoActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public enum SerializedRepoToolsAction {
static func tryParseInit(args: [String]) -> BasicBuildOptions {
// First arg is the path, we don't care about it
// The right most option will be the winner.
var options: [String: CLIArgumentType] = [
let options: [String: CLIArgumentType] = [
"--path": .string,
"--user_option": .stringList,
"--global_copt": .string,
Expand Down

0 comments on commit 3b0e2a0

Please sign in to comment.