From 9317f7ee9de002b93306cf6e35a940a0e615ac92 Mon Sep 17 00:00:00 2001 From: Roland Heusser Date: Thu, 29 Sep 2022 14:38:38 -0600 Subject: [PATCH 1/4] adding support for adding files that don't belong to a target --- Docs/ProjectSpec.md | 17 +++++++++++++++++ Sources/ProjectSpec/Project.swift | 6 +++++- Sources/XcodeGenKit/PBXProjGenerator.swift | 5 ++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index ad64977b8..77611b74a 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -25,6 +25,7 @@ - [Scheme](#scheme) - [Scheme Template](#scheme-template) - [Swift Package](#swift-package) +- [Files](#files) ## General @@ -1047,3 +1048,19 @@ schemes: targets: YamsProject/Yams: ["run"] ``` + +## Files + +Specify additional files to be included in the project. This can either be a single source or a list of sources. These files are not associated with a target. + +A source can be provided via a string (the path) or an object of the form of a [Target Source](#target-source) + +```yml +files: + - path: README.md + - path: project.yml + - path: Resources/Config + name: Config + includes: + - "*.json" +``` diff --git a/Sources/ProjectSpec/Project.swift b/Sources/ProjectSpec/Project.swift index bc82e9aa5..3e7f6d602 100644 --- a/Sources/ProjectSpec/Project.swift +++ b/Sources/ProjectSpec/Project.swift @@ -35,6 +35,7 @@ public struct Project: BuildSettingsContainer { projectReferencesMap = Dictionary(uniqueKeysWithValues: projectReferences.map { ($0.name, $0) }) } } + public var files: [TargetSource] private var targetsMap: [String: Target] private var aggregateTargetsMap: [String: AggregateTarget] @@ -54,7 +55,8 @@ public struct Project: BuildSettingsContainer { fileGroups: [String] = [], configFiles: [String: String] = [:], attributes: [String: Any] = [:], - projectReferences: [ProjectReference] = [] + projectReferences: [ProjectReference] = [], + files: [TargetSource] = [] ) { self.basePath = basePath self.name = name @@ -73,6 +75,7 @@ public struct Project: BuildSettingsContainer { self.attributes = attributes self.projectReferences = projectReferences projectReferencesMap = Dictionary(uniqueKeysWithValues: self.projectReferences.map { ($0.name, $0) }) + self.files = files } public func getProjectReference(_ projectName: String) -> ProjectReference? { @@ -205,6 +208,7 @@ extension Project { targetsMap = Dictionary(uniqueKeysWithValues: targets.map { ($0.name, $0) }) aggregateTargetsMap = Dictionary(uniqueKeysWithValues: aggregateTargets.map { ($0.name, $0) }) projectReferencesMap = Dictionary(uniqueKeysWithValues: projectReferences.map { ($0.name, $0) }) + files = try jsonDictionary.json(atKeyPath: "files") } static func resolveProject(jsonDictionary: JSONDictionary) -> JSONDictionary { diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index 60ebdfca3..8f4017478 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -26,6 +26,7 @@ public class PBXProjGenerator { var carthageFrameworksByPlatform: [String: Set] = [:] var frameworkFiles: [PBXFileElement] = [] var bundleFiles: [PBXFileElement] = [] + var projectFiles: [PBXFileElement] = [] var generated = false @@ -107,7 +108,9 @@ public class PBXProjGenerator { ) pbxProj.rootObject = pbxProject - + + // Files that do not belong to a target + let sourceFiles = try sourceGenerator.getAllSourceFiles(targetType: .none, sources: project.files, buildPhases: [:]).sorted { $0.path.lastComponent < $1.path.lastComponent } for target in project.targets { let targetObject: PBXTarget From 9c1421eaccd0d32b70cda0ccef40eab51643c91f Mon Sep 17 00:00:00 2001 From: Roland Heusser Date: Thu, 29 Sep 2022 15:04:02 -0600 Subject: [PATCH 2/4] make "files" optional and update TestProject --- Sources/ProjectSpec/Project.swift | 2 +- Tests/Fixtures/TestProject/project.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/ProjectSpec/Project.swift b/Sources/ProjectSpec/Project.swift index 3e7f6d602..5c13fbe2c 100644 --- a/Sources/ProjectSpec/Project.swift +++ b/Sources/ProjectSpec/Project.swift @@ -208,7 +208,7 @@ extension Project { targetsMap = Dictionary(uniqueKeysWithValues: targets.map { ($0.name, $0) }) aggregateTargetsMap = Dictionary(uniqueKeysWithValues: aggregateTargets.map { ($0.name, $0) }) projectReferencesMap = Dictionary(uniqueKeysWithValues: projectReferences.map { ($0.name, $0) }) - files = try jsonDictionary.json(atKeyPath: "files") + files = jsonDictionary.json(atKeyPath: "files") ?? [] } static func resolveProject(jsonDictionary: JSONDictionary) -> JSONDictionary { diff --git a/Tests/Fixtures/TestProject/project.yml b/Tests/Fixtures/TestProject/project.yml index fb052d3fa..89ebdffc7 100644 --- a/Tests/Fixtures/TestProject/project.yml +++ b/Tests/Fixtures/TestProject/project.yml @@ -457,3 +457,5 @@ aggregateTargets: buildScripts: - name: MyScript script: echo "do the thing" +files: + - path: project.yml From 4d6a75967999457292e1248181cd091e9ea852d0 Mon Sep 17 00:00:00 2001 From: Roland Heusser Date: Thu, 29 Sep 2022 15:11:09 -0600 Subject: [PATCH 3/4] update fixture --- Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj b/Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj index cc3fa31dc..3cc5a3012 100644 --- a/Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj +++ b/Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj @@ -725,6 +725,7 @@ 6AC91042453E18DF74BA1C0F /* StaticLibrary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaticLibrary.swift; sourceTree = ""; }; 6B1603BA83AA0C7B94E45168 /* ResourceFolder */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ResourceFolder; path = Resources/ResourceFolder; sourceTree = SOURCE_ROOT; }; 6BBE762F36D94AB6FFBFE834 /* SomeFile */ = {isa = PBXFileReference; path = SomeFile; sourceTree = ""; }; + 6CB97D33CC3783752331E3B7 /* project.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = project.yml; sourceTree = ""; }; 6F165CDD5BCC13AFF50B65E2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 70A8E15C81E454DC950C59F0 /* SomeXPCService.xpc */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.xpc-service"; path = SomeXPCService.xpc; sourceTree = ""; }; 72A14C887EF7E9C8CBE914AC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; @@ -1054,6 +1055,7 @@ 80C3A0E524EC1ABCB9149EA2 /* XPC Service */, DAA7880242A9DE61E68026CC /* Folder */, 2E1E747C7BC434ADB80CC269 /* Headers */, + 6CB97D33CC3783752331E3B7 /* project.yml */, 6B1603BA83AA0C7B94E45168 /* ResourceFolder */, 6BBE762F36D94AB6FFBFE834 /* SomeFile */, 79DC4A1E4D2E0D3A215179BC /* Bundles */, From ec9d1b617407842020f8b5c255f7a08c87ba2cf5 Mon Sep 17 00:00:00 2001 From: Roland Heusser Date: Thu, 29 Sep 2022 15:34:58 -0600 Subject: [PATCH 4/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb975bdb0..40daacb36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added - Added support for `enableGPUFrameCaptureMode` #1251 @bsudekum +- Added support for project files, files that don't belong to any target #1268 @skofgar ### Fixed