Skip to content

Commit

Permalink
Align bundle name sanization with SPM (#6234)
Browse files Browse the repository at this point in the history
* Comply to SPM  bundle accessors

* unit tests fix

* templates updates

* small fixes

* Updates

* removed duplicated bundle module symbol

* lint

* PR fixes

* MR fixes

* Fix bundle name parsing

* Adding naming tests

* lint

---------

Co-authored-by: Daniel Bachar <danielbac@zillowgroup.com>
  • Loading branch information
danibachar and Daniel Bachar committed Apr 25, 2024
1 parent c8c5f8a commit 492b350
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sources/TuistGenerator/Mappers/ResourcesProjectMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ResourcesProjectMapper: ProjectMapping { // swiftlint:disable:this
var additionalTargets: [Target] = []
var sideEffects: [SideEffectDescriptor] = []

let bundleName = "\(project.name)_\(target.name)"
let bundleName = "\(project.name)_\(target.name.replacingOccurrences(of: "-", with: "_"))"
var modifiedTarget = target

if !target.supportsResources {
Expand Down Expand Up @@ -126,7 +126,7 @@ public class ResourcesProjectMapper: ProjectMapping { // swiftlint:disable:this

let content: String = ResourcesProjectMapper.fileContent(
targetName: target.name,
bundleName: bundleName.replacingOccurrences(of: "-", with: "_"),
bundleName: bundleName,
target: target,
in: project
)
Expand All @@ -149,7 +149,7 @@ public class ResourcesProjectMapper: ProjectMapping { // swiftlint:disable:this

let content: String = ResourcesProjectMapper.objcImplementationFileContent(
targetName: target.name,
bundleName: bundleName.replacingOccurrences(of: "-", with: "_")
bundleName: bundleName
)
return (filePath, content.data(using: .utf8))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,25 @@ final class ResourcesProjectMapperTests: TuistUnitTestCase {
)
}

func test_map_when_project_name_has_dashes_in_it_bundle_name_include_dash_for_project_name_and_underscore_for_target_name(
) throws {
// Given
let projectName = "sdk-with-dash"
let targetName = "target-with-dash"
let expectedBundleName = "\(projectName)_\(targetName.replacingOccurrences(of: "-", with: "_"))"
let sources: [SourceFile] = ["/ViewController.m", "/ViewController2.swift"]
let resources: [ResourceFileElement] = [.file(path: "/AbsolutePath/Project/Resources/image.png")]
let target = Target.test(name: targetName, product: .staticLibrary, sources: sources, resources: .init(resources))
project = Project.test(path: try AbsolutePath(validating: "/AbsolutePath/Project"), name: projectName, targets: [target])

// Got
let (gotProject, _) = try subject.map(project: project)
let bundleTarget = try XCTUnwrap(gotProject.targets.first(where: { $0.product == .bundle }))

// Then
XCTAssertEqual(expectedBundleName, bundleTarget.name)
}

// MARK: - Verifiers

private func verify(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AppKit
import BrazeUI
import Styles
import UIKit

Expand Down Expand Up @@ -36,6 +37,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
fatalError("singleFile is missing")
}

let brazeUILocalizedString = BrazeUIResources.bundle?.localizedString(
forKey: "braze.in-app-message.close-button.title",
value: nil,
table: nil
)
precondition(brazeUILocalizedString == "Close", "Failed to fetch localized resource from BrazeUI")

AppKit.start()

return true
Expand Down

0 comments on commit 492b350

Please sign in to comment.