-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow library tool resource handling to be disabled (#928)
This allows the wrap resource in filegroups and resource bundle generators to be disabled completely. It allows users to just pass in `data` and have the rule just forward that to the underlying libraries. This cleans up the code a bit too since we use `data` directly instead of `module_data` which had to be converted into a list in a few places. I added a test showcasing where this ability would be required. It fails without this change and passes when disabling the library tools
- Loading branch information
1 parent
57d46ed
commit c148e6a
Showing
5 changed files
with
76 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
load("//rules:framework.bzl", "apple_framework") | ||
load("//rules:precompiled_apple_resource_bundle.bzl", "precompiled_apple_resource_bundle") | ||
load("//rules:test.bzl", "ios_unit_test") | ||
|
||
precompiled_apple_resource_bundle( | ||
name = "BundleInDataResources", | ||
bundle_id = "com.example.BundleInDataResources", | ||
bundle_name = "BundleInDataResources", | ||
platforms = {"ios": "12.0"}, | ||
resources = ["fake-data.txt"], | ||
) | ||
|
||
apple_framework( | ||
name = "BundleInDataResourcesFramework", | ||
srcs = ["BundleInData.swift"], | ||
data = [":BundleInDataResources"], | ||
# Because the `library.bzl` wraps `data` in a filegroup by default, the `rules_apple` aspects | ||
# seem to fail to find the resource bundle. It seems in order to directly use a resource bundle rule | ||
# within `data`, it must be directly referenced vs. wrapped in a filegroup. | ||
library_tools = {"wrap_resources_in_filegroup": None}, | ||
platforms = {"ios": "12.0"}, | ||
) | ||
|
||
ios_unit_test( | ||
name = "BundleInDataTests", | ||
srcs = ["BundleInDataTests.swift"], | ||
minimum_os_version = "12.0", | ||
deps = [":BundleInDataResourcesFramework"], | ||
) |
13 changes: 13 additions & 0 deletions
13
tests/ios/frameworks/bundle-in-data-resources/BundleInData.swift
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Foundation | ||
|
||
private class BundleInDataBundleFinder {} | ||
|
||
// Helper for finding the bundle named "BundleInDataResources" | ||
public extension Bundle { | ||
static let bundleInDataResources: Bundle = { | ||
let container = Bundle(for: BundleInDataBundleFinder.self) | ||
let bundlePath = container.path(forResource: "BundleInDataResources", ofType: "bundle")! | ||
return Bundle(path: bundlePath)! | ||
}() | ||
} | ||
|
17 changes: 17 additions & 0 deletions
17
tests/ios/frameworks/bundle-in-data-resources/BundleInDataTests.swift
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Foundation | ||
import XCTest | ||
|
||
@testable import BundleInDataResourcesFramework | ||
|
||
class BundleInDataTests: XCTestCase { | ||
|
||
func testBundleInData() throws { | ||
let fakeDataPath = try XCTUnwrap(Bundle.bundleInDataResources.path(forResource: "fake-data", ofType: "txt")) | ||
let fakeDataContents = try XCTUnwrap(String(contentsOfFile: fakeDataPath)) | ||
|
||
XCTAssertEqual( | ||
fakeDataContents, | ||
"fake-data\n" | ||
) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fake-data |