@@ -29,112 +29,7 @@ for obj in proj.allObjects.objects.values {
2929}
3030
3131// Write out a new pbxproj file
32- //try! proj.write(to: xcodeproj, format: .plist(.openStep))
33-
34-
35- public struct Xcodeproj {
36- static public let supportedExtensions : Set < String > = [ " xcodeproj " ]
37-
38- private let projectFile : XCProjectFile
39-
40- public let developmentRegion : String
41- public let knownAssetTags : [ String ] ?
42-
43- public init ( url: URL , warning: ( String ) -> Void ) throws {
44- // try Xcodeproj.throwIfUnsupportedExtension(url)
45- let projectFile : XCProjectFile
46-
47- // Parse project file
48- do {
49- do {
50- projectFile = try XCProjectFile ( xcodeprojURL: url, ignoreReferenceErrors: false )
51- }
52- catch let error as ProjectFileError {
53- warning ( error. localizedDescription)
54-
55- projectFile = try XCProjectFile ( xcodeprojURL: url, ignoreReferenceErrors: true )
56- }
57- }
58- catch {
59- fatalError ( " Project file at ' \( url) ' could not be parsed, is this a valid Xcode project file ending in *.xcodeproj? \n \( error. localizedDescription) " )
60- }
61-
62- self . projectFile = projectFile
63- self . developmentRegion = projectFile. project. developmentRegion
64- self . knownAssetTags = projectFile. project. knownAssetTags
65- }
66-
67- public var allTargets : [ PBXTarget ] {
68- projectFile. project. targets. compactMap { $0. value }
69- }
70-
71- private func findTarget( name: String ) throws -> PBXTarget {
72- // Look for target in project file
73- let allTargets = projectFile. project. targets. compactMap { $0. value }
74- guard let target = allTargets. filter ( { $0. name == name } ) . first else {
75- let availableTargets = allTargets. compactMap { $0. name } . joined ( separator: " , " )
76- fatalError ( " Target ' \( name) ' not found in project file, available targets are: \( availableTargets) " )
77- }
78-
79- return target
80- }
81-
82- public func resourcePaths( forTarget targetName: String ) throws -> [ Path ] {
83- let target = try findTarget ( name: targetName)
84-
85- let resourcesFileRefs = target. buildPhases
86- . compactMap { $0. value as? PBXResourcesBuildPhase }
87- . flatMap { $0. files }
88- . compactMap { $0. value? . fileRef }
89-
90- let fileRefPaths = resourcesFileRefs
91- . compactMap { $0. value as? PBXFileReference }
92- . compactMap { $0. fullPath }
93-
94- let variantGroupPaths = resourcesFileRefs
95- . compactMap { $0. value as? PBXVariantGroup }
96- . flatMap { $0. fileRefs }
97- . compactMap { $0. value? . fullPath }
98-
99- return fileRefPaths + variantGroupPaths
100- }
101-
102- public func buildConfigurations( forTarget targetName: String ) throws -> [ XCBuildConfiguration ] {
103- let target = try findTarget ( name: targetName)
104-
105- guard let buildConfigurationList = target. buildConfigurationList. value else { return [ ] }
106-
107- let buildConfigurations = buildConfigurationList. buildConfigurations
108- . compactMap { $0. value }
109-
110- return buildConfigurations
111- }
112- }
113-
114- extension PBXReference {
115- func fileSystemSynchronizedGroups( path: URL ) -> [ ( URL , PBXFileSystemSynchronizedRootGroup ) ] {
116- if let root = self as? PBXFileSystemSynchronizedRootGroup {
117- let newPath = root. path. map { path. appending ( path: $0) } ?? path
118- return [ ( newPath, root) ]
119- } else if let group = self as? PBXGroup {
120- let newPath = group. path. map { path. appending ( path: $0) } ?? path
121-
122- let children = group. children. compactMap ( \. value)
123-
124- return children. flatMap { $0. fileSystemSynchronizedGroups ( path: newPath) }
125-
126- } else {
127- return [ ]
128- }
129- }
130- }
131-
132-
133- let the = try Xcodeproj ( url: xcodeproj, warning: { fatalError ( $0) } )
134-
135- print ( proj. project. mainGroup. value!. fileSystemSynchronizedGroups ( path: xcodeproj. deletingLastPathComponent ( ) ) )
136-
137- print ( try the. resourcePaths ( forTarget: " RswiftUIAppClip " ) )
32+ try ! proj. write ( to: xcodeproj, format: . plist( . openStep) )
13833
13934let time = Date ( ) . timeIntervalSince ( start)
14035print ( " Timeinterval: \( time) " )
0 commit comments