Skip to content

Commit

Permalink
Allow slash in non-uti-compliant target names
Browse files Browse the repository at this point in the history
  • Loading branch information
kapitoshka438 committed May 8, 2024
1 parent 2d71fef commit e27c85f
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/TuistGenerator/Linter/TargetLinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TargetLinter: TargetLinting {
bundleIdentifier = bundleIdentifier.replacingOccurrences(of: "\\$\\(.+\\)", with: "", options: .regularExpression)

var allowed = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
allowed.formUnion(CharacterSet(charactersIn: "-."))
allowed.formUnion(CharacterSet(charactersIn: "-./"))

if !bundleIdentifier.unicodeScalars.allSatisfy({ allowed.contains($0) }) {
let reason =
Expand Down
5 changes: 4 additions & 1 deletion Sources/TuistGenerator/Mappers/ResourcesProjectMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public class ResourcesProjectMapper: ProjectMapping { // swiftlint:disable:this
var additionalTargets: [Target] = []
var sideEffects: [SideEffectDescriptor] = []

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

if !target.supportsResources {
Expand Down
1 change: 1 addition & 0 deletions Sources/TuistGraph/Models/Target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public struct Target: Equatable, Hashable, Comparable, Codable {
self.destinations = destinations
self.bundleId = bundleId
self.productName = productName ?? name.replacingOccurrences(of: "-", with: "_")
.replacingOccurrences(of: "/", with: "_")
self.deploymentTargets = deploymentTargets
self.infoPlist = infoPlist
self.entitlements = entitlements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ public final class PackageInfoMapper: PackageInfoMapping {

fileprivate class func sanitize(targetName: String) -> String {
targetName.replacingOccurrences(of: ".", with: "_")
.replacingOccurrences(of: "/", with: "_")
}

// swiftlint:disable:next function_body_length
Expand Down Expand Up @@ -594,9 +595,9 @@ public final class PackageInfoMapper: PackageInfoMapping {
product: product,
productName: PackageInfoMapper
.sanitize(targetName: target.name)
.replacingOccurrences(of: "-", with: "_"),
.replacingOccurrences(of: "-", with: "_").replacingOccurrences(of: "/", with: "_"),
bundleId: target.name
.replacingOccurrences(of: "_", with: "."),
.replacingOccurrences(of: "_", with: ".").replacingOccurrences(of: "/", with: "."),
deploymentTargets: deploymentTargets,
infoPlist: .default,
sources: sources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public final class SwiftPackageManagerModuleMapGenerator: SwiftPackageManagerMod
publicHeadersPath: AbsolutePath
) throws -> ModuleMap {
let sanitizedModuleName = moduleName.replacingOccurrences(of: "-", with: "_")
.replacingOccurrences(of: "/", with: "_")
let umbrellaHeaderPath = publicHeadersPath.appending(component: sanitizedModuleName + ".h")
let nestedUmbrellaHeaderPath = publicHeadersPath
.appending(components: sanitizedModuleName, moduleName + ".h")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,10 @@ final class ResourcesProjectMapperTests: TuistUnitTestCase {
// Given
let projectName = "sdk-with-dash"
let targetName = "target-with-dash"
let expectedBundleName = "\(projectName)_\(targetName.replacingOccurrences(of: "-", with: "_"))"
let sanitizedTargetName = targetName
.replacingOccurrences(of: "-", with: "_")
.replacingOccurrences(of: "/", with: "_")
let expectedBundleName = "\(projectName)_\(sanitizedTargetName)"
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))
Expand Down
1 change: 1 addition & 0 deletions fixtures/app_with_spm_dependencies/App/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let project = Project(
.external(name: "MarkdownUI"),
.external(name: "GoogleMobileAds"),
.external(name: "LookinServer"),
.external(name: "KSCrash"),
],
settings: .targetSettings
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ComposableArchitecture
import CrashReporter
import GoogleMobileAds
import GoogleSignIn
import KSCrash_Installations
import libzstd
import MarkdownUI
import NYTPhotoViewer
Expand Down Expand Up @@ -57,6 +58,9 @@ public enum AppKit {

// Use MarkdownUI
_ = BulletedList(of: [""])

// Use KSCrash
_ = KSCrashInstallationStandard.sharedInstance()
}
}

Expand Down
11 changes: 10 additions & 1 deletion fixtures/app_with_spm_dependencies/Tuist/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "78f7dd0ebfab47739cc0e35c49d4996c86d420124374e3f4789e90b5a00daa6a",
"originHash" : "847230e7850aba7a4d590a3b626a6151d01d3ee2db657bf0a2e120e075fa9d15",
"pins" : [
{
"identity" : "alamofire",
Expand Down Expand Up @@ -118,6 +118,15 @@
"version" : "17.7.3"
}
},
{
"identity" : "kscrash",
"kind" : "remoteSourceControl",
"location" : "https://github.com/kstenerud/KSCrash",
"state" : {
"revision" : "0ad825211ec38404e03b6f677a2312deb728528a",
"version" : "1.17.1"
}
},
{
"identity" : "lookinserver",
"kind" : "remoteSourceControl",
Expand Down
2 changes: 2 additions & 0 deletions fixtures/app_with_spm_dependencies/Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ let package = Package(
.package(url: "https://github.com/QMUI/LookinServer", from: "1.2.8"),
// Has XCTest API in a non-test target. Tuist will add Test Search path to support it
.package(url: "https://github.com/Brightify/Cuckoo.git", exact: "1.10.4"),
// Has targets with names not compliant with UTI (with "/" in their names)
.package(url: "https://github.com/kstenerud/KSCrash", exact: "1.17.1"),
]
)

0 comments on commit e27c85f

Please sign in to comment.