Files
XcodeGen/Sources/ProjectSpec/FileType.swift
T
Vlad Gorlov 4455919be3 Added support for "driver-extension" and "system-extension" product types (#1094)
* Squashed commit of the following:

commit 0bcdce0d1f0f1d13fb5a284404e4eaea4e805a89
Author: Vlad Gorlov <volodymyr.gorlov@gmail.com>
Date:   Fri Jun 18 00:58:50 2021 +0200

    [#1092] Dependency version update.

commit 0040c46fd4ce9f42102faeb744104027b6c2c757
Author: Bruce Evans <bruce.evans.dev@gmail.com>
Date:   Wed Jun 16 09:12:01 2021 +0900

    Add Support for DocC in Xcode 13 (#1091)

    * Add support for DocC

    DocC "files" are actually folders `.docc` appended to the name, but Xcode 13 treats them differently. Therefore, we need to exclude them from the normal BuildPhase.

    Resolves #1089

    * Add tests for DocC

    Expanded an existing test to include .docc support.

    Also added a .docc catalog to the Test Project.

    * Update changelog.md

    * Update changelog.md to get the correct PR Link

commit 5bb7ef4e1c632f80f63c49ee280d64b8dab1603f
Author: Vlad Gorlov <volodymyr.gorlov@gmail.com>
Date:   Wed Jun 16 01:03:42 2021 +0200

    Added support for missed product types.

commit 3f8bfdf749d0d15da8490550b95a31cf961d8649
Author: Vlad Gorlov <volodymyr.gorlov@gmail.com>
Date:   Wed Jun 16 00:01:47 2021 +0200

    Added support for missed product types.

commit 235ebe4fe906716a6a37421346318fc6515836ce
Author: Vlad Gorlov <volodymyr.gorlov@gmail.com>
Date:   Tue Jun 15 23:53:52 2021 +0200

    Added support for missed product types.

* [#1094] Fixes failing tests.

* [#1094] Added test project targets.

* [#1094] Making iig-file type of source code.

* [#1094] Attempt to fix CI failure.
2021-06-20 14:08:38 +10:00

118 lines
3.9 KiB
Swift

//
// File.swift
//
//
// Created by Yonas Kolb on 1/5/20.
//
import Foundation
import JSONUtilities
import enum XcodeProj.BuildPhase
public struct FileType: Equatable {
public enum Defaults {
public static let file = true
}
public var file: Bool
public var buildPhase: BuildPhaseSpec?
public var attributes: [String]
public var resourceTags: [String]
public var compilerFlags: [String]
public init(
file: Bool = Defaults.file,
buildPhase: BuildPhaseSpec? = nil,
attributes: [String] = [],
resourceTags: [String] = [],
compilerFlags: [String] = []
) {
self.file = file
self.buildPhase = buildPhase
self.attributes = attributes
self.resourceTags = resourceTags
self.compilerFlags = compilerFlags
}
}
extension FileType: JSONObjectConvertible {
public init(jsonDictionary: JSONDictionary) throws {
if let string: String = jsonDictionary.json(atKeyPath: "buildPhase") {
buildPhase = try BuildPhaseSpec(string: string)
} else if let dict: JSONDictionary = jsonDictionary.json(atKeyPath: "buildPhase") {
buildPhase = try BuildPhaseSpec(jsonDictionary: dict)
}
file = jsonDictionary.json(atKeyPath: "file") ?? Defaults.file
attributes = jsonDictionary.json(atKeyPath: "attributes") ?? []
resourceTags = jsonDictionary.json(atKeyPath: "resourceTags") ?? []
compilerFlags = jsonDictionary.json(atKeyPath: "compilerFlags") ?? []
}
}
extension FileType: JSONEncodable {
public func toJSONValue() -> Any {
var dict: [String: Any?] = [
"buildPhase": buildPhase?.toJSONValue(),
"attributes": attributes,
"resourceTags": resourceTags,
"compilerFlags": compilerFlags,
]
if file != Defaults.file {
dict["file"] = file
}
return dict
}
}
extension FileType {
public static let defaultFileTypes: [String: FileType] = [
// resources
"bundle": FileType(buildPhase: .resources),
"xcassets": FileType(buildPhase: .resources),
"storekit": FileType(buildPhase: .resources),
// sources
"swift": FileType(buildPhase: .sources),
"m": FileType(buildPhase: .sources),
"mm": FileType(buildPhase: .sources),
"cpp": FileType(buildPhase: .sources),
"c": FileType(buildPhase: .sources),
"cc": FileType(buildPhase: .sources),
"S": FileType(buildPhase: .sources),
"xcdatamodeld": FileType(buildPhase: .sources),
"xcmappingmodel": FileType(buildPhase: .sources),
"intentdefinition": FileType(buildPhase: .sources),
"metal": FileType(buildPhase: .sources),
"mlmodel": FileType(buildPhase: .sources),
"rcproject": FileType(buildPhase: .sources),
"iig": FileType(buildPhase: .sources),
// headers
"h": FileType(buildPhase: .headers),
"hh": FileType(buildPhase: .headers),
"hpp": FileType(buildPhase: .headers),
"ipp": FileType(buildPhase: .headers),
"tpp": FileType(buildPhase: .headers),
"hxx": FileType(buildPhase: .headers),
"def": FileType(buildPhase: .headers),
// frameworks
"framework": FileType(buildPhase: .frameworks),
// copyfiles
"xpc": FileType(buildPhase: .copyFiles(.xpcServices)),
// no build phase (not resources)
"xcconfig": FileType(buildPhase: BuildPhaseSpec.none),
"entitlements": FileType(buildPhase: BuildPhaseSpec.none),
"gpx": FileType(buildPhase: BuildPhaseSpec.none),
"lproj": FileType(buildPhase: BuildPhaseSpec.none),
"xcfilelist": FileType(buildPhase: BuildPhaseSpec.none),
"apns": FileType(buildPhase: BuildPhaseSpec.none),
"pch": FileType(buildPhase: BuildPhaseSpec.none),
"docc": FileType(buildPhase: BuildPhaseSpec.none),
]
}