Skip to content

Commit

Permalink
Updates for rules_apple resource rules (#68)
Browse files Browse the repository at this point in the history
- objc_bundle is now apple_bundle_import
- Bundles and resources are passed through the `data` value of
objc_library
- Added function to optionally add load statements based on the types of
skylark nodes in the build files (swift, apple resource bundles, etc)
  • Loading branch information
rahul-malik authored Mar 19, 2019
1 parent fe2b724 commit ee8466e
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 50 deletions.
5 changes: 3 additions & 2 deletions IntegrationTests/GoldMaster/Braintree.podspec.json.goldmaster
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_apple//apple:resources.bzl', 'apple_resource_bundle')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand Down Expand Up @@ -696,7 +697,7 @@ objc_library(
] + [
"-fmodule-name=Braintree_pod_module"
],
bundles = [
data = [
":UI_Bundle_Braintree-Drop-In-Localization",
":UI_Bundle_Braintree-UI-Localization"
],
Expand Down Expand Up @@ -875,7 +876,7 @@ objc_library(
] + [
"-fmodule-name=Braintree_pod_module"
],
bundles = [
data = [
":3D-Secure_Bundle_Braintree-3D-Secure-Localization"
],
visibility = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand All @@ -15,7 +16,6 @@ native.config_setting(
"compilation_mode": "opt"
}
)
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
config_setting(
name = "iosCase",
values = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_apple//apple:resources.bzl', 'apple_bundle_import')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand Down Expand Up @@ -304,7 +305,7 @@ objc_library(
] + [
"-fmodule-name=FBSDKCoreKit_pod_module"
],
bundles = [
data = [
":FBSDKCoreKit_Bundle_FacebookSDKStrings"
],
visibility = [
Expand All @@ -318,7 +319,7 @@ acknowledged_target(
],
value = "//Vendor/FBSDKCoreKit/pod_support_buildable:acknowledgement_fragment"
)
objc_bundle(
apple_bundle_import(
name = "FBSDKCoreKit_Bundle_FacebookSDKStrings",
bundle_imports = glob(
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand All @@ -15,7 +16,6 @@ native.config_setting(
"compilation_mode": "opt"
}
)
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
swift_library(
name = "FolioReaderKit",
srcs = glob(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_apple//apple:resources.bzl', 'apple_bundle_import')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand Down Expand Up @@ -89,7 +90,7 @@ objc_library(
] + [
"-fmodule-name=GoogleAppIndexing_pod_module"
],
bundles = [
data = [
":GoogleAppIndexing_Bundle_GoogleAppIndexingResources"
],
visibility = [
Expand All @@ -103,7 +104,7 @@ acknowledged_target(
],
value = "//Vendor/GoogleAppIndexing/pod_support_buildable:acknowledgement_fragment"
)
objc_bundle(
apple_bundle_import(
name = "GoogleAppIndexing_Bundle_GoogleAppIndexingResources",
bundle_imports = glob(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ objc_library(
] + [
"-fmodule-name=GoogleAuthUtilities_pod_module"
],
resources = glob(
data = glob(
[
"Frameworks/frameworks/GoogleAuthUtilities.framework/Resources/GTMOAuth2ViewTouch.xib"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_apple//apple:resources.bzl', 'apple_bundle_import')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand Down Expand Up @@ -89,7 +90,7 @@ objc_library(
] + [
"-fmodule-name=GoogleSignIn_pod_module"
],
bundles = [
data = [
":GoogleSignIn_Bundle_GoogleSignIn"
],
visibility = [
Expand All @@ -106,7 +107,7 @@ acknowledged_target(
],
value = "//Vendor/GoogleSignIn/pod_support_buildable:acknowledgement_fragment"
)
objc_bundle(
apple_bundle_import(
name = "GoogleSignIn_Bundle_GoogleSignIn",
bundle_imports = glob(
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_apple//apple:resources.bzl', 'apple_resource_bundle')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand Down Expand Up @@ -118,7 +119,7 @@ objc_library(
] + [
"-fmodule-name=OnePasswordExtension_pod_module"
],
bundles = [
data = [
":OnePasswordExtension_Bundle_OnePasswordExtensionResources"
],
visibility = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ objc_library(
] + [
"-fmodule-name=PaymentKit_pod_module"
],
resources = glob(
data = glob(
[
"PaymentKit/Resources/*.png",
"PaymentKit/Resources/Cards/*.png"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand All @@ -15,7 +16,6 @@ native.config_setting(
"compilation_mode": "opt"
}
)
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
config_setting(
name = "iosCase",
values = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand All @@ -15,7 +16,6 @@ native.config_setting(
"compilation_mode": "opt"
}
)
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
filegroup(
name = "SFHFKeychainUtils_cxx_hdrs",
srcs = glob(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand All @@ -15,7 +16,6 @@ native.config_setting(
"compilation_mode": "opt"
}
)
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
swift_library(
name = "SevenSwitch",
srcs = glob(
Expand Down
3 changes: 2 additions & 1 deletion IntegrationTests/GoldMaster/Stripe.podspec.json.goldmaster
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_apple//apple:resources.bzl', 'apple_resource_bundle')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand Down Expand Up @@ -102,7 +103,7 @@ objc_library(
] + [
"-fmodule-name=Stripe_pod_module"
],
bundles = select(
data = select(
{
"//conditions:default": [
":Stripe_Bundle_Stripe"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand All @@ -15,7 +16,6 @@ native.config_setting(
"compilation_mode": "opt"
}
)
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
filegroup(
name = "UICollectionViewLeftAlignedLayout_cxx_hdrs",
srcs = glob(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand All @@ -15,7 +16,6 @@ native.config_setting(
"compilation_mode": "opt"
}
)
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
filegroup(
name = "iOSSnapshotTestCase_hdrs",
srcs = glob(
Expand Down
5 changes: 3 additions & 2 deletions IntegrationTests/GoldMaster/iRate.podspec.json.goldmaster
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load('@build_bazel_rules_apple//apple:resources.bzl', 'apple_bundle_import')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand Down Expand Up @@ -88,7 +89,7 @@ objc_library(
] + [
"-fmodule-name=iRate_pod_module"
],
bundles = [
data = [
":iRate_Bundle_iRate"
],
visibility = [
Expand All @@ -102,7 +103,7 @@ acknowledged_target(
],
value = "//Vendor/iRate/pod_support_buildable:acknowledgement_fragment"
)
objc_bundle(
apple_bundle_import(
name = "iRate_Bundle_iRate",
bundle_imports = glob(
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
load('@build_bazel_rules_apple//apple:resources.bzl', 'apple_bundle_import')
load(
"//Vendor/rules_pods/BazelExtensions:extensions.bzl",
"pch_with_name_hint",
Expand All @@ -15,7 +17,6 @@ native.config_setting(
"compilation_mode": "opt"
}
)
load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')
config_setting(
name = "iosCase",
values = {
Expand Down Expand Up @@ -164,7 +165,7 @@ objc_library(
] + [
"-fmodule-name=youtube-ios-player-helper_pod_module"
],
bundles = [
data = [
":youtube-ios-player-helper_Bundle_Assets"
],
visibility = [
Expand Down Expand Up @@ -344,7 +345,7 @@ objc_library(
] + [
"-fmodule-name=youtube-ios-player-helper_pod_module"
],
bundles = [
data = [
":youtube-ios-player-helper_Bundle_Assets"
],
visibility = [
Expand All @@ -358,7 +359,7 @@ acknowledged_target(
],
value = "//Vendor/youtube-ios-player-helper/pod_support_buildable:acknowledgement_fragment"
)
objc_bundle(
apple_bundle_import(
name = "youtube-ios-player-helper_Bundle_Assets",
bundle_imports = glob(
[
Expand Down
32 changes: 19 additions & 13 deletions Sources/PodToBUILD/BuildFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public func GetBuildOptions() -> BuildOptions {
return sharedBuildOptions
}


/// Config Setting Nodes
/// Write Build dependent COPTS.
/// @note We consume this as an expression in ObjCLibrary
Expand All @@ -105,9 +106,22 @@ public func makeConfigSettingNodes() -> SkylarkNode {
return .lines([.lines(comment), releaseConfig])
}


public func makeLoadNodes(forConvertibles skylarkConvertibles: [SkylarkConvertible]) -> SkylarkNode {
let hasSwift = skylarkConvertibles.first(where: { $0 is SwiftLibrary }) != nil
let hasAppleBundleImport = skylarkConvertibles.first(where: { $0 is AppleBundleImport }) != nil
let hasAppleResourceBundle = skylarkConvertibles.first(where: { $0 is AppleResourceBundle }) != nil
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
].compactMap { $0 }
)
}

// Make Nodes to be inserted at the beginning of skylark output
// public for test purposes
public func makePrefixNodes(includeSwift: Bool) -> SkylarkNode {
public func makePrefixNodes() -> SkylarkNode {
let name = "rules_pods"
let extFile = getRulePrefix(name: name) + "BazelExtensions:extensions.bzl"

Expand All @@ -119,11 +133,7 @@ public func makePrefixNodes(includeSwift: Bool) -> SkylarkNode {
.basic(.string("gen_module_map")),
.basic(.string("gen_includes"))]),
makeConfigSettingNodes(),
] + (includeSwift ? [
// Assume that the user is using the default naming convetion of
// swift_library.
SkylarkNode.skylark("load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')")
] : [])
]
return .lines(lineNodes)
}

Expand Down Expand Up @@ -184,8 +194,7 @@ public struct PodBuildFile: SkylarkConvertible {
BuildFileContext.set(BuildFileContext(convertibles: skylarkConvertibles))
let convertibleNodes: [SkylarkNode] = skylarkConvertibles.compactMap { $0.toSkylark() }
BuildFileContext.set(nil)
let hasSwift = skylarkConvertibles.first(where: { $0 is SwiftLibrary }) != nil
return .lines([makePrefixNodes(includeSwift: hasSwift)] + convertibleNodes)
return .lines([makeLoadNodes(forConvertibles: skylarkConvertibles)] + [makePrefixNodes()] + convertibleNodes)
}

public static func with(podSpec: PodSpec, buildOptions: BuildOptions = EmptyBuildOptions.shared) -> PodBuildFile {
Expand All @@ -204,18 +213,15 @@ public struct PodBuildFile: SkylarkConvertible {
})
}

// For all prebuilt bundles we found, create an ObjcBundle target. This target differs from AppleResourceBundle
// because it is stricter about keeping the structure of the bundle contents intact.
let bundleTargets = bundleResources.map { (strArr: [String]) -> [BazelTarget] in
strArr.map { (bundlePath: String) -> BazelTarget in
let bundleName = ObjcBundle.extractBundleName(fromPath: bundlePath)
let bundleName = AppleBundleImport.extractBundleName(fromPath: bundlePath)
let name = "\(spec.moduleName ?? spec.name)_Bundle_\(bundleName)"
let bundleImports = AttrSet<[String]>(basic: ["\(bundlePath)/**"])
return ObjcBundle(name: name, bundleImports: bundleImports)
return AppleBundleImport(name: name, bundleImports: bundleImports)
}
}


let resourceBundles = (AttrSet<[String: [String]]>
.sequence(attrSet: resourceBundleAttrSet)
.map { k, v -> BazelTarget in
Expand Down
Loading

0 comments on commit ee8466e

Please sign in to comment.