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 85f02d7
Show file tree
Hide file tree
Showing 20 changed files with 183 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Sources/TuistAcceptanceTesting/TuistAcceptanceFixtures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public enum TuistAcceptanceFixtures {
case iosAppWithPrivacyManifest
case iosAppWithRemoteBinarySwiftPackage
case iosAppWithRemoteSwiftPackage
case iosAppWithSpmDependencies
case iosAppWithStaticFrameworks
case iosAppWithStaticLibraries
case iosAppWithStaticLibraryAndPackage
Expand Down Expand Up @@ -142,6 +143,8 @@ public enum TuistAcceptanceFixtures {
return "ios_app_with_multi_configs"
case .iosAppWithOnDemandResources:
return "ios_app_with_on_demand_resources"
case .iosAppWithSpmDependencies:
return "ios_app_with_spm_dependencies"
case .iosAppWithPluginsAndTemplates:
return "ios_app_with_plugins_and_templates"
case .iosAppWithPrivacyManifest:
Expand Down
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 @@ -144,6 +144,15 @@ final class BuildAcceptanceTestAppWithSPMDependencies: TuistAcceptanceTestCase {
}
}

final class BuildAcceptanceTestIosAppWithSPMDependencies: TuistAcceptanceTestCase {
func test() async throws {
try setUpFixture(.iosAppWithSpmDependencies)
try await run(InstallCommand.self)
try await run(GenerateCommand.self)
try await run(BuildCommand.self, "App", "--platform", "ios")
}
}

final class BuildAcceptanceTestMultiplatformAppWithMacrosAndEmbeddedWatchOSApp: TuistAcceptanceTestCase {
func test() async throws {
try setUpFixture(.multiplatformAppWithMacrosAndEmbeddedWatchOSApp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ final class DependenciesAcceptanceTestAppWithSPMDependencies: TuistAcceptanceTes
}
}

final class DependenciesAcceptanceTestIosAppWithSPMDependencies: TuistAcceptanceTestCase {
func test_ios_app_spm_dependencies() async throws {
try setUpFixture(.iosAppWithSpmDependencies)
try await run(InstallCommand.self)
try await run(GenerateCommand.self)
try await run(BuildCommand.self, "App")
try await run(TestCommand.self, "App")
}
}

final class DependenciesAcceptanceTestAppWithSPMDependenciesWithoutInstall: TuistAcceptanceTestCase {
func test() async throws {
try setUpFixture(.appWithSpmDependencies)
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
10 changes: 10 additions & 0 deletions fixtures/ios_app_with_spm_dependencies/App/Sources/AppApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SwiftUI

@main
struct AppApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import KSCrash_Installations
import SwiftUI

struct ContentView: View {
init() {
// Use KSCrash
_ = KSCrashInstallationStandard()
}

var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
Text("Hello, world!")
}
.padding()
}
}

#Preview {
ContentView()
}
20 changes: 20 additions & 0 deletions fixtures/ios_app_with_spm_dependencies/AppTests/AppTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import XCTest
@testable import App

final class AppTests: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}
}
31 changes: 31 additions & 0 deletions fixtures/ios_app_with_spm_dependencies/Project.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import ProjectDescription

let project = Project(
name: "App",
targets: [
.target(
name: "App",
destinations: .iOS,
product: .app,
bundleId: "io.tuist.app",
deploymentTargets: .iOS("14.0"),
infoPlist: .default,
sources: "App/Sources/**",
resources: "App/Resources/**",
dependencies: [
.external(name: "KSCrash"),
.sdk(name: "c++", type: .library, status: .required),
]
),
.target(
name: "AppTests",
destinations: .iOS,
product: .unitTests,
bundleId: "io.tuist.app.tests",
deploymentTargets: .iOS("14.0"),
infoPlist: .default,
sources: "AppTests/**",
dependencies: [.target(name: "App")]
),
]
)
3 changes: 3 additions & 0 deletions fixtures/ios_app_with_spm_dependencies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# iOS app with SPM dependencies

An iOS application project with various SPM dependencies.
15 changes: 15 additions & 0 deletions fixtures/ios_app_with_spm_dependencies/Tuist/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"originHash" : "664db39a62d139ec20362d815bf22a4a4df6691783532796a140f210d57f4612",
"pins" : [
{
"identity" : "kscrash",
"kind" : "remoteSourceControl",
"location" : "https://github.com/kstenerud/KSCrash",
"state" : {
"revision" : "0ad825211ec38404e03b6f677a2312deb728528a",
"version" : "1.17.1"
}
}
],
"version" : 3
}
10 changes: 10 additions & 0 deletions fixtures/ios_app_with_spm_dependencies/Tuist/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// swift-tools-version: 5.10
import PackageDescription

let package = Package(
name: "PackageName",
dependencies: [
// 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 85f02d7

Please sign in to comment.