Skip to content

Commit ca2fa6e

Browse files
committed
Added Xcodeproj module from spm 5.7 as a local module.
1 parent 0be3a68 commit ca2fa6e

File tree

9 files changed

+2985
-0
lines changed

9 files changed

+2985
-0
lines changed

Sources/Xcodeproj/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This source file is part of the Swift open source project
2+
#
3+
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_library(Xcodeproj STATIC
10+
generate.swift
11+
pbxproj.swift
12+
PropertyList.swift
13+
SchemesGenerator.swift
14+
Target+PBXProj.swift
15+
XcodeProjectModel.swift
16+
XcodeProjectModelSerialization.swift)
17+
target_link_libraries(Xcodeproj PUBLIC
18+
TSCBasic
19+
Basics
20+
PackageGraph)
21+
# NOTE(compnerd) workaround for CMake not setting up include flags yet
22+
set_target_properties(Xcodeproj PROPERTIES
23+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
24+
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2014-2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
/// A enum representing data types for legacy PropertyList type.
14+
/// Note that the `identifier` enum is not strictly necessary,
15+
/// but useful to semantically distinguish the strings that
16+
/// represents object identifiers from those that are just data.
17+
/// see: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/PropertyLists/OldStylePlists/OldStylePLists.html
18+
public enum PropertyList {
19+
case identifier(String)
20+
case string(String)
21+
case array([PropertyList])
22+
case dictionary([String: PropertyList])
23+
24+
var string: String? {
25+
if case .string(let string) = self {
26+
return string
27+
}
28+
return nil
29+
}
30+
31+
var array: [PropertyList]? {
32+
if case .array(let array) = self {
33+
return array
34+
}
35+
return nil
36+
}
37+
}
38+
39+
extension PropertyList: ExpressibleByStringLiteral {
40+
public typealias UnicodeScalarLiteralType = StringLiteralType
41+
public typealias ExtendedGraphemeClusterLiteralType = StringLiteralType
42+
43+
public init(unicodeScalarLiteral value: UnicodeScalarLiteralType) {
44+
self = .string(value)
45+
}
46+
public init(extendedGraphemeClusterLiteral value: ExtendedGraphemeClusterLiteralType) {
47+
self = .string(value)
48+
}
49+
public init(stringLiteral value: StringLiteralType) {
50+
self = .string(value)
51+
}
52+
}
53+
54+
extension PropertyList: CustomStringConvertible {
55+
public var description: String {
56+
return serialize()
57+
}
58+
}
59+
60+
extension PropertyList {
61+
/// Serializes the Plist enum to string.
62+
public func serialize() -> String {
63+
return generatePlistRepresentation(plist: self, indentation: Indentation())
64+
}
65+
66+
/// Escapes the string for plist.
67+
/// Finds the instances of quote (") and backward slash (\) and prepends
68+
/// the escape character backward slash (\).
69+
static func escape(string: String) -> String {
70+
func needsEscape(_ char: UInt8) -> Bool {
71+
return char == UInt8(ascii: "\\") || char == UInt8(ascii: "\"")
72+
}
73+
74+
guard let pos = string.utf8.firstIndex(where: needsEscape) else {
75+
return string
76+
}
77+
var newString = String(string[..<pos])
78+
for char in string.utf8[pos...] {
79+
if needsEscape(char) {
80+
newString += "\\"
81+
}
82+
newString += String(UnicodeScalar(char))
83+
}
84+
return newString
85+
}
86+
}
87+
88+
extension PropertyList {
89+
/// Private struct to generate indentation strings.
90+
fileprivate struct Indentation: CustomStringConvertible {
91+
var level: Int = 0
92+
mutating func increase() {
93+
level += 1
94+
precondition(level > 0, "indentation level overflow")
95+
}
96+
mutating func decrease() {
97+
precondition(level > 0, "indentation level underflow")
98+
level -= 1
99+
}
100+
var description: String {
101+
return String(repeating: " ", count: level)
102+
}
103+
}
104+
105+
/// Private function to generate OPENSTEP-style plist representation.
106+
fileprivate func generatePlistRepresentation(plist: PropertyList, indentation: Indentation) -> String {
107+
// Do the appropriate thing for each type of plist node.
108+
switch plist {
109+
110+
case .identifier(let ident):
111+
// FIXME: we should assert that the identifier doesn't need quoting
112+
return ident
113+
114+
case .string(let string):
115+
return "\"" + PropertyList.escape(string: string) + "\""
116+
117+
case .array(let array):
118+
var indent = indentation
119+
var str = "(\n"
120+
indent.increase()
121+
for (i, item) in array.enumerated() {
122+
str += "\(indent)\(generatePlistRepresentation(plist: item, indentation: indent))"
123+
str += (i != array.count - 1) ? ",\n" : "\n"
124+
}
125+
indent.decrease()
126+
str += "\(indent))"
127+
return str
128+
129+
case .dictionary(let dict):
130+
var indent = indentation
131+
let dict = dict.sorted(by: {
132+
// Make `isa` sort first (just for readability purposes).
133+
switch ($0.key, $1.key) {
134+
case ("isa", "isa"): return false
135+
case ("isa", _): return true
136+
case (_, "isa"): return false
137+
default: return $0.key < $1.key
138+
}
139+
})
140+
var str = "{\n"
141+
indent.increase()
142+
for item in dict {
143+
str += "\(indent)\(item.key) = \(generatePlistRepresentation(plist: item.value, indentation: indent));\n"
144+
}
145+
indent.decrease()
146+
str += "\(indent)}"
147+
return str
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)