Skip to content

Commit

Permalink
Added includeCarthageRelated global flag, updated tests + documentati…
Browse files Browse the repository at this point in the history
…on to reflect changes
  • Loading branch information
Rogerio de Paula Assis committed Feb 23, 2019
1 parent a19871a commit 1e69d70
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 5 deletions.
1 change: 1 addition & 0 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Note that target names can also be changed by adding a `name` property to a targ
- `bottom` (default) - at the bottom, after other files
- [ ] **transitivelyLinkDependencies**: **Bool** - If this is `true` then targets will link to the dependencies of their target dependencies. If a target should embed its dependencies, such as application and test bundles, it will embed these transitive dependencies as well. Some complex setups might want to set this to `false` and explicitly specify dependencies at every level. Targets can override this with [Target](#target).transitivelyLinkDependencies. Defaults to `false`.
- [ ] **generateEmptyDirectories**: **Bool** - If this is `true` then empty directories will be added to project too else will be missed. Defaults to `false`.
- [ ] **includeCarthageRelatedDependencies**: **Bool** - When this is set to `true`, any carthage dependency with related dependencies will be included automatically. This flag can be overriden individually for each carthage dependency - for more details see See **includeRelated** in the [Dependency](#dependency) section. Defaults to `false`.

```yaml
options:
Expand Down
90 changes: 90 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@
"version": "4.3.3"
}
},
{
"package": "Carthage",
"repositoryURL": "https://github.com/Carthage/Carthage.git",
"state": {
"branch": null,
"revision": "6e1e70541ce8692945569cbcf6c9f108ee69af98",
"version": "0.32.0"
}
},
{
"package": "Commandant",
"repositoryURL": "https://github.com/Carthage/Commandant.git",
"state": {
"branch": null,
"revision": "07cad52573bad19d95844035bf0b25acddf6b0f6",
"version": "0.15.0"
}
},
{
"package": "Curry",
"repositoryURL": "https://github.com/thoughtbot/Curry.git",
"state": {
"branch": null,
"revision": "b6bf27ec9d711f607a8c7da9ca69ee9eaa201a22",
"version": "4.0.1"
}
},
{
"package": "JSONUtilities",
"repositoryURL": "https://github.com/yonaskolb/JSONUtilities.git",
Expand All @@ -19,6 +46,15 @@
"version": "4.1.0"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "9a281b1cfa1c53d1e8bd92e1798e4e473af8d263",
"version": "7.3.3"
}
},
{
"package": "PathKit",
"repositoryURL": "https://github.com/kylef/PathKit.git",
Expand All @@ -28,6 +64,24 @@
"version": "0.9.2"
}
},
{
"package": "PrettyColors",
"repositoryURL": "https://github.com/jdhealy/PrettyColors.git",
"state": {
"branch": null,
"revision": "1954a28331668a706134dc315fe264b15b74984e",
"version": "5.0.1"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "f2b5a06440ea87eba1a167cab37bf6496646c52e",
"version": "1.3.4"
}
},
{
"package": "Rainbow",
"repositoryURL": "https://github.com/onevcat/Rainbow.git",
Expand All @@ -37,6 +91,33 @@
"version": "3.1.4"
}
},
{
"package": "ReactiveSwift",
"repositoryURL": "https://github.com/ReactiveCocoa/ReactiveSwift.git",
"state": {
"branch": null,
"revision": "4f6a12ae6762e825b0e19a4f7076eafa43847e6e",
"version": "4.0.0"
}
},
{
"package": "ReactiveTask",
"repositoryURL": "https://github.com/Carthage/ReactiveTask.git",
"state": {
"branch": null,
"revision": "0f3be6022e2435e1bb91679bc2aabeff13eb794c",
"version": "0.15.0"
}
},
{
"package": "Result",
"repositoryURL": "https://github.com/antitypical/Result.git",
"state": {
"branch": null,
"revision": "2ca499ba456795616fbc471561ff1d963e6ae160",
"version": "4.1.0"
}
},
{
"package": "Spectre",
"repositoryURL": "https://github.com/kylef/Spectre.git",
Expand Down Expand Up @@ -64,6 +145,15 @@
"version": "4.1.2"
}
},
{
"package": "Tentacle",
"repositoryURL": "https://github.com/mdiep/Tentacle.git",
"state": {
"branch": null,
"revision": "ace0aedb5bd90a41de254808dbe633813f7b1882",
"version": "0.12.0"
}
},
{
"package": "xcodeproj",
"repositoryURL": "https://github.com/tuist/xcodeproj.git",
Expand Down
4 changes: 2 additions & 2 deletions Sources/ProjectSpec/Dependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public struct Dependency: Equatable {
public enum DependencyType: Equatable {
case target
case framework
case carthage(includeRelated: Bool)
case carthage(includeRelated: Bool?)
case sdk
}
}
Expand All @@ -54,7 +54,7 @@ extension Dependency: JSONObjectConvertible {
type = .framework
reference = framework
} else if let carthage: String = jsonDictionary.json(atKeyPath: "carthage") {
let includeRelated = jsonDictionary.json(atKeyPath: "includeRelated") ?? false
let includeRelated: Bool? = jsonDictionary.json(atKeyPath: "includeRelated")
type = .carthage(includeRelated: includeRelated)
reference = carthage
} else if let sdk: String = jsonDictionary.json(atKeyPath: "sdk") {
Expand Down
6 changes: 5 additions & 1 deletion Sources/ProjectSpec/SpecOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public struct SpecOptions: Equatable {
public var transitivelyLinkDependencies: Bool
public var groupSortPosition: GroupSortPosition
public var generateEmptyDirectories: Bool
public var includeCarthageRelatedDependencies: Bool

public enum ValidationType: String {
case missingConfigs
Expand Down Expand Up @@ -74,7 +75,8 @@ public struct SpecOptions: Equatable {
defaultConfig: String? = nil,
transitivelyLinkDependencies: Bool = false,
groupSortPosition: GroupSortPosition = .bottom,
generateEmptyDirectories: Bool = false
generateEmptyDirectories: Bool = false,
includeCarthageRelatedDependencies: Bool = false
) {
self.minimumXcodeGenVersion = minimumXcodeGenVersion
self.carthageBuildPath = carthageBuildPath
Expand All @@ -93,6 +95,7 @@ public struct SpecOptions: Equatable {
self.transitivelyLinkDependencies = transitivelyLinkDependencies
self.groupSortPosition = groupSortPosition
self.generateEmptyDirectories = generateEmptyDirectories
self.includeCarthageRelatedDependencies = includeCarthageRelatedDependencies
}
}

Expand All @@ -119,6 +122,7 @@ extension SpecOptions: JSONObjectConvertible {
transitivelyLinkDependencies = jsonDictionary.json(atKeyPath: "transitivelyLinkDependencies") ?? false
groupSortPosition = jsonDictionary.json(atKeyPath: "groupSortPosition") ?? .bottom
generateEmptyDirectories = jsonDictionary.json(atKeyPath: "generateEmptyDirectories") ?? false
includeCarthageRelatedDependencies = jsonDictionary.json(atKeyPath: "includeCarthageRelatedDependencies") ?? false
}
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/XcodeGenKit/CarthageDependencyResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public struct CarthageDependencyResolver {
for dependency in nonExistentDependencies {
switch dependency.type {
case .carthage(let includeRelated):
if includeRelated == true {
let includeRelated = includeRelated ?? project.options.includeCarthageRelatedDependencies
if includeRelated {
relatedDependencies(for: dependency, in: target.platform)
.filter { !frameworks.contains($0) }
.forEach { frameworks.insert($0) }
Expand Down
1 change: 1 addition & 0 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ public class PBXProjGenerator {
targetFrameworkBuildFiles.append(buildFile)

case .carthage(let includeRelated):
let includeRelated = includeRelated ?? project.options.includeCarthageRelatedDependencies
let allDependencies = includeRelated
? carthageResolver.relatedDependencies(for: dependency, in: target.platform) : [dependency]
allDependencies.forEach { dependency in
Expand Down
16 changes: 16 additions & 0 deletions Tests/XcodeGenKitTests/CarthageDependencyResolverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,23 @@ class CarthageDependencyResolverTests: XCTestCase {
}

func testDependenciesForTopLevelTarget() {

let dependencyFixtureName = "CarthageTestFixture"
let carthageBuildPath = fixturePath + "TestProject/Carthage/Build"

describe {

$0.it("overrides the includeRelated dependency global flag when specified") {
let options = SpecOptions(carthageBuildPath: carthageBuildPath.string, includeCarthageRelatedDependencies: true)
let dependency = Dependency(type: .carthage(includeRelated: false), reference: dependencyFixtureName)

let resolver = CarthageDependencyResolver(project: makeTestProject(options: options))
let target = Target(name: "1", type: .application, platform: .iOS, dependencies: [dependency])
let dependencies = resolver.dependencies(for: target)

try expect(dependencies) == [dependency]
}

$0.it("fetches all carthage dependencies for a given target, sorted alphabetically") {
let unsortedDependencyReferences = ["RxSwift", "RxCocoa", "RxBlocking", "RxTest", "RxAtomic"]
let dependencies = unsortedDependencyReferences.map {
Expand Down
4 changes: 3 additions & 1 deletion Tests/XcodeGenKitTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ class SpecLoadingTests: XCTestCase {
tvOS: "10.0",
watchOS: "3.0",
macOS: "10.12.1"
)
),
includeCarthageRelatedDependencies: true
)
let expected = Project(name: "test", options: options)
let dictionary: [String: Any] = ["options": [
Expand All @@ -627,6 +628,7 @@ class SpecLoadingTests: XCTestCase {
"createIntermediateGroups": true,
"developmentLanguage": "ja",
"deploymentTarget": ["iOS": 11.1, "tvOS": 10.0, "watchOS": "3", "macOS": "10.12.1"],
"includeCarthageRelatedDependencies": true
]]
let parsedSpec = try getProjectSpec(dictionary)
try expect(parsedSpec) == expected
Expand Down

0 comments on commit 1e69d70

Please sign in to comment.