Skip to content

Commit 1a3634d

Browse files
jflan-ddcgrindel
andauthored
fix: support implicit resource localization (#1702)
Adding a dependency on https://github.com/mapbox/mapbox-navigation-ios caused the following error: ``` ERROR: .../rules_swift_package_manager++swift_deps+swiftpkg_mapbox_navigation_ios/BUILD.bazel:55:34: Label '@@rules_swift_package_manager++swift_deps+swiftpkg_mapbox_navigation_ios//:Sources/MapboxNavigation/Resources/Base.lproj/Navigation.storyboard' is duplicated in the 'resources' attribute of rule 'MapboxNavigation.rspm_resource_bundle' ``` This is because [this file](https://github.com/mapbox/mapbox-navigation-ios/tree/v2.18.4/Sources/MapboxNavigation/Resources/Base.lproj) was being added both from `desc_map` and as a discovered resource. They aren't being deduplicated in `resources_set` because the `desc_map` instance has localization `"Base"`, but the discovered resource had `None` for its localization. This PR is intended to match the behavior of [this code](https://github.com/swiftlang/swift-package-manager/blob/2f03e7a16e2c4d08a3a16f16cca627ff53b70271/Sources/PackageLoading/TargetSourcesBuilder.swift#L312-L318) in SPM. Alternatively we could deduplicate the labels themselves closer to where the build file is constructed if there's no need to track the localizations. --------- Co-authored-by: Chuck Grindel <chuck@revealtech.ai>
1 parent 1c17998 commit 1a3634d

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed

examples/resources_example/swift/Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let package = Package(
77
dependencies: [
88
.package(path: "../third_party/another_package_with_resources"),
99
.package(path: "../third_party/app_lovin_sdk"),
10+
.package(path: "../third_party/implicit_resource_localization"),
1011
.package(path: "../third_party/package_with_resources"),
1112
.package(path: "../third_party/package_with_resources_swift_6"),
1213
.package(url: "https://github.com/Iterable/swift-sdk", from: "6.5.12"),
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// swift-tools-version: 6.1
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "implicit_resource_localization",
8+
defaultLocalization: "en",
9+
products: [
10+
.library(name: "implicit_resource_localization", targets: ["implicit_resource_localization"]),
11+
],
12+
targets: [
13+
.target(name: "implicit_resource_localization"),
14+
]
15+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This package includes resources with implicit localizations using a `.lproj` resource folder.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="17150" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17150"/>
5+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6+
</dependencies>
7+
<scenes>
8+
<!--View Controller-->
9+
<scene sceneID="PEd-7d-5j0">
10+
<objects>
11+
<viewController id="bU7-R8-ocO" sceneMemberID="viewController">
12+
<view key="view" id="tOy-S4-hL0">
13+
<rect key="frame" x="0.0" y="0.0" width="450" height="300"/>
14+
<autoresizingMask key="autoresizingMask"/>
15+
</view>
16+
</viewController>
17+
<customObject id="9uD-mB-xHs" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
18+
</objects>
19+
</scene>
20+
</scenes>
21+
</document>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Stub file to make SPM happy

swiftpkg/internal/pkginfos.bzl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,10 +1680,24 @@ def _new_resource_from_discovered_resource(path):
16801680
return _new_resource(
16811681
path = path,
16821682
rule = _new_resource_rule(
1683-
process = _new_resource_rule_process(),
1683+
process = _new_resource_rule_process(
1684+
localization = _localization_from(path),
1685+
),
16841686
),
16851687
)
16861688

1689+
def _localization_from(path):
1690+
# Extract the implict localization from the path if its parent folder ends in ".lproj"
1691+
# https://github.com/swiftlang/swift-package-manager/blob/2f03e7a16e2c4d08a3a16f16cca627ff53b70271/Sources/PackageLoading/TargetSourcesBuilder.swift#L312-L318
1692+
parent_dir = paths.basename(paths.dirname(path))
1693+
1694+
(localization, extension) = paths.split_extension(parent_dir)
1695+
1696+
if extension == ".lproj":
1697+
return localization
1698+
1699+
return None
1700+
16871701
# MARK: - Constants
16881702

16891703
target_types = struct(

0 commit comments

Comments
 (0)