Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding support for adding files that are not associated with a target #1268

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Added support for `enableGPUFrameCaptureMode` #1251 @bsudekum
- Config setting presets can now also be loaded from the main bundle when bundling XcodeGenKit #1135 @SofteqDG
- Added support for project files, files that don't belong to any target #1268 @skofgar

### Fixed

Expand Down
17 changes: 17 additions & 0 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [Scheme](#scheme)
- [Scheme Template](#scheme-template)
- [Swift Package](#swift-package)
- [Files](#files)

## General

Expand Down Expand Up @@ -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"
```
6 changes: 5 additions & 1 deletion Sources/ProjectSpec/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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? {
Expand Down Expand Up @@ -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 = jsonDictionary.json(atKeyPath: "files") ?? []
}

static func resolveProject(jsonDictionary: JSONDictionary) -> JSONDictionary {
Expand Down
5 changes: 4 additions & 1 deletion Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class PBXProjGenerator {
var carthageFrameworksByPlatform: [String: Set<PBXFileElement>] = [:]
var frameworkFiles: [PBXFileElement] = []
var bundleFiles: [PBXFileElement] = []
var projectFiles: [PBXFileElement] = []

var generated = false

Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@
6AC91042453E18DF74BA1C0F /* StaticLibrary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaticLibrary.swift; sourceTree = "<group>"; };
6B1603BA83AA0C7B94E45168 /* ResourceFolder */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ResourceFolder; path = Resources/ResourceFolder; sourceTree = SOURCE_ROOT; };
6BBE762F36D94AB6FFBFE834 /* SomeFile */ = {isa = PBXFileReference; path = SomeFile; sourceTree = "<group>"; };
6CB97D33CC3783752331E3B7 /* project.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = project.yml; sourceTree = "<group>"; };
6F165CDD5BCC13AFF50B65E2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
70A8E15C81E454DC950C59F0 /* SomeXPCService.xpc */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.xpc-service"; path = SomeXPCService.xpc; sourceTree = "<group>"; };
72A14C887EF7E9C8CBE914AC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1054,6 +1055,7 @@
80C3A0E524EC1ABCB9149EA2 /* XPC Service */,
DAA7880242A9DE61E68026CC /* Folder */,
2E1E747C7BC434ADB80CC269 /* Headers */,
6CB97D33CC3783752331E3B7 /* project.yml */,
6B1603BA83AA0C7B94E45168 /* ResourceFolder */,
6BBE762F36D94AB6FFBFE834 /* SomeFile */,
79DC4A1E4D2E0D3A215179BC /* Bundles */,
Expand Down
2 changes: 2 additions & 0 deletions Tests/Fixtures/TestProject/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,5 @@ aggregateTargets:
buildScripts:
- name: MyScript
script: echo "do the thing"
files:
- path: project.yml