Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4339007

Browse files
authored
Merge pull request yonaskolb#723 from kateinoigakukun/katei/add-bundle-dependency
Add bundle dependency type
2 parents 99ce87d + fc939fd commit 4339007

File tree

16 files changed

+677
-12
lines changed

16 files changed

+677
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Added `xcodegen dump` command [#710](https://github.com/yonaskolb/XcodeGen/pull/710) @yonaskolb
1313
- Added `--no-env` option to disable environment variables expansion [#704](https://github.com/yonaskolb/XcodeGen/pull/704) @rcari
1414
- Added custom group support for target sources [#621](https://github.com/yonaskolb/XcodeGen/pull/621) @sroebert @rcari
15+
- Added new dependency type, `bundle`. This allows targets to copy bundles from other projects [#616](https://github.com/yonaskolb/XcodeGen/pull/616) @bsmith11
1516

1617
#### Fixed
1718
- Improved variable expansion runtime [#704](https://github.com/yonaskolb/XcodeGen/pull/704) @rcari

Docs/ProjectSpec.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,14 @@ targets:
374374

375375
### Dependency
376376

377-
A dependency can be one of a 3 types:
377+
A dependency can be one of a 6 types:
378378

379379
- `target: name` - links to another target
380380
- `framework: path` - links to a framework
381381
- `carthage: name` - helper for linking to a Carthage framework
382382
- `sdk: name` - links to a dependency with the SDK. This can either be a relative path within the sdk root or a single filename that references a framework (.framework) or lib (.tbd)
383383
- `package: name` - links to a Swift Package. The name must match the name of a package defined in the top level `packages`
384+
- `bundle: name` - adds the pre-built bundle for the supplied name to the copy resources build phase. This is useful when a dependency exists on a static library target that has an associated bundle target, both existing in a separate project. Only usable in target types which can copy resources.
384385

385386
**Linking options**:
386387

Sources/ProjectSpec/Dependency.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public struct Dependency: Equatable {
4646
case carthage(findFrameworks: Bool?, linkType: CarthageLinkType)
4747
case sdk(root: String?)
4848
case package(product: String?)
49+
case bundle
4950
}
5051
}
5152

@@ -77,6 +78,9 @@ extension Dependency: JSONObjectConvertible {
7778
let product: String? = jsonDictionary.json(atKeyPath: "product")
7879
type = .package(product: product)
7980
reference = package
81+
} else if let bundle: String = jsonDictionary.json(atKeyPath: "bundle") {
82+
type = .bundle
83+
reference = bundle
8084
} else {
8185
throw SpecParsingError.invalidDependency(jsonDictionary)
8286
}
@@ -130,6 +134,8 @@ extension Dependency: JSONEncodable {
130134
dict["sdk"] = reference
131135
case .package:
132136
dict["package"] = reference
137+
case .bundle:
138+
dict["bundle"] = reference
133139
}
134140

135141
return dict

Sources/XcodeGenKit/PBXProjGenerator.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class PBXProjGenerator {
2222

2323
var carthageFrameworksByPlatform: [String: Set<PBXFileElement>] = [:]
2424
var frameworkFiles: [PBXFileElement] = []
25+
var bundleFiles: [PBXFileElement] = []
2526

2627
var generated = false
2728

@@ -213,6 +214,17 @@ public class PBXProjGenerator {
213214
derivedGroups.append(group)
214215
}
215216

217+
if !bundleFiles.isEmpty {
218+
let group = addObject(
219+
PBXGroup(
220+
children: bundleFiles,
221+
sourceTree: .group,
222+
name: "Bundles"
223+
)
224+
)
225+
derivedGroups.append(group)
226+
}
227+
216228
mainGroup.children = Array(sourceGenerator.rootGroups)
217229
sortGroups(group: mainGroup)
218230
// add derived groups at the end
@@ -433,6 +445,7 @@ public class PBXProjGenerator {
433445
var copyFilesBuildPhasesFiles: [TargetSource.BuildPhase.CopyFilesSettings: [PBXBuildFile]] = [:]
434446
var copyFrameworksReferences: [PBXBuildFile] = []
435447
var copyResourcesReferences: [PBXBuildFile] = []
448+
var copyBundlesReferences: [PBXBuildFile] = []
436449
var copyWatchReferences: [PBXBuildFile] = []
437450
var packageDependencies: [XCSwiftPackageProductDependency] = []
438451
var extensions: [PBXBuildFile] = []
@@ -647,6 +660,23 @@ public class PBXProjGenerator {
647660
)
648661
dependencies.append(targetDependency)
649662
}
663+
case .bundle:
664+
// Static and dynamic libraries can't copy resources
665+
guard target.type != .staticLibrary && target.type != .dynamicLibrary else { break }
666+
667+
let fileReference = sourceGenerator.getFileReference(
668+
path: Path(dependency.reference),
669+
inPath: project.basePath,
670+
sourceTree: .buildProductsDir
671+
)
672+
673+
let pbxBuildFile = PBXBuildFile(file: fileReference, settings: nil)
674+
let buildFile = addObject(pbxBuildFile)
675+
copyBundlesReferences.append(buildFile)
676+
677+
if !bundleFiles.contains(fileReference) {
678+
bundleFiles.append(fileReference)
679+
}
650680
}
651681
}
652682

@@ -740,6 +770,15 @@ public class PBXProjGenerator {
740770
buildPhases.append(resourcesBuildPhase)
741771
}
742772

773+
if !copyBundlesReferences.isEmpty {
774+
let copyBundlesPhase = addObject(PBXCopyFilesBuildPhase(
775+
dstSubfolderSpec: .resources,
776+
name: "Copy Bundles to Resources directory",
777+
files: copyBundlesReferences
778+
))
779+
buildPhases.append(copyBundlesPhase)
780+
}
781+
743782
let swiftObjCInterfaceHeader = project.getCombinedBuildSetting("SWIFT_OBJC_INTERFACE_HEADER_NAME", target: target, config: project.configs[0]) as? String
744783

745784
if target.type == .staticLibrary
@@ -1047,6 +1086,10 @@ public class PBXProjGenerator {
10471086
dependencies[dependency.reference] = dependency
10481087
}
10491088
}
1089+
case .bundle:
1090+
if isTopLevel {
1091+
dependencies[dependency.reference] = dependency
1092+
}
10501093
}
10511094
}
10521095

Tests/FixtureTests/FixtureTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class FixtureTests: XCTestCase {
1111
func testProjectFixture() {
1212
describe {
1313
$0.it("generates Test Project") {
14+
try generateXcodeProject(specPath: fixturePath + "TestProject/AnotherProject/project.yml")
1415
try generateXcodeProject(specPath: fixturePath + "TestProject/project.yml")
1516
}
1617
$0.it("generates Carthage Project") {

0 commit comments

Comments
 (0)