Skip to content

Commit

Permalink
Support Scheme shared flag (#341)
Browse files Browse the repository at this point in the history
* Support Scheme `shared` flag

* Fix Project generator tests

* Correct scheme write path

* Update tests and change log
  • Loading branch information
dangthaison91 committed May 16, 2019
1 parent a236717 commit a8eb839
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/

- Adding generate command timer https://github.com/tuist/tuist/pull/335 by @kwridan
- Support Scheme manifest with pre/post action https://github.com/tuist/tuist/pull/336 by @dangthaison91
- Support local Scheme (not shared) flag https://github.com/tuist/tuist/pull/341 by @dangthaison91

### Removed

Expand Down
13 changes: 10 additions & 3 deletions Sources/TuistGenerator/Generator/SchemesGenerator.swift
Expand Up @@ -75,7 +75,7 @@ final class SchemesGenerator: SchemesGenerating {
func generateScheme(scheme: Scheme,
project: Project,
generatedProject: GeneratedProject) throws {
let schemesDirectory = try createSchemesDirectory(projectPath: generatedProject.path)
let schemesDirectory = try createSchemesDirectory(projectPath: generatedProject.path, shared: scheme.shared)
let schemePath = schemesDirectory.appending(component: "\(scheme.name).xcscheme")

let generatedBuildAction = schemeBuildAction(scheme: scheme, project: project, generatedProject: generatedProject)
Expand Down Expand Up @@ -428,10 +428,17 @@ final class SchemesGenerator: SchemesGenerating {
///
/// - Parameters:
/// - projectPath: Path to the Xcode project.
/// - shared: Scheme should be shared or not
/// - Returns: Path to the schemes directory.
/// - Throws: A FatalError if the creation of the directory fails.
private func createSchemesDirectory(projectPath: AbsolutePath) throws -> AbsolutePath {
let path = projectPath.appending(RelativePath("xcshareddata/xcschemes"))
private func createSchemesDirectory(projectPath: AbsolutePath, shared: Bool = true) throws -> AbsolutePath {
var path: AbsolutePath!
if shared {
path = projectPath.appending(RelativePath("xcshareddata/xcschemes"))
} else {
let username = NSUserName()
path = projectPath.appending(RelativePath("xcuserdata/\(username).xcuserdatad/xcschemes"))
}
if !fileHandler.exists(path) {
try fileHandler.createFolder(path)
}
Expand Down
33 changes: 31 additions & 2 deletions Tests/TuistGeneratorTests/Generator/ProjectGeneratorTests.swift
Expand Up @@ -51,10 +51,10 @@ final class ProjectGeneratorTests: XCTestCase {
func test_generate_scheme() throws {
// Given
let target = Target.test(name: "Target", platform: .iOS, product: .framework)
let scheme = Scheme.test(name: "Target-Scheme", shared: true, buildAction: BuildAction(targets: ["Target"]))
let sharedScheme = Scheme.test(name: "Target-Scheme", shared: true, buildAction: BuildAction(targets: ["Target"]))

let targets = [target]
let project = Project.test(path: fileHandler.currentPath, name: "Project", targets: targets, schemes: [scheme])
let project = Project.test(path: fileHandler.currentPath, name: "Project", targets: targets, schemes: [sharedScheme])
try fileHandler.touch(fileHandler.currentPath.appending(component: "Project.swift"))

let cache = GraphLoaderCache()
Expand All @@ -76,6 +76,35 @@ final class ProjectGeneratorTests: XCTestCase {
XCTAssertTrue(fileHandler.exists(targetScheme))
}

func test_generate_local_scheme() throws {
// Given
let target = Target.test(name: "Target", platform: .iOS, product: .framework)
let localScheme = Scheme.test(name: "Target-Local", shared: false, buildAction: BuildAction(targets: ["Target"]))

let targets = [target]
let project = Project.test(path: fileHandler.currentPath, name: "Project", targets: targets, schemes: [localScheme])
try fileHandler.touch(fileHandler.currentPath.appending(component: "Project.swift"))

let cache = GraphLoaderCache()
cache.add(project: project)
let graph = Graph.test(entryPath: fileHandler.currentPath,
cache: cache,
entryNodes: [TargetNode(project: project,
target: target,
dependencies: [])])

// When
let got = try subject.generate(project: project,
options: GenerationOptions(),
graph: graph)

// Then
let username = NSUserName()
let userSchemesPath = got.path.appending(RelativePath("xcuserdata/\(username).xcuserdatad/xcschemes"))
let userScheme = userSchemesPath.appending(component: "Target-Local.xcscheme")
XCTAssertTrue(fileHandler.exists(userScheme))
}

func test_generate_testTargetIdentity() throws {
// Given
let app = Target.test(name: "App",
Expand Down
1 change: 1 addition & 0 deletions features/generate.feature
Expand Up @@ -106,6 +106,7 @@ Scenario: The project is an iOS application that has resources (ios_app_with_cus
Then tuist generates the project
Then I should be able to build the scheme App-Debug
Then I should be able to build the scheme App-Release
Then I should be able to build the scheme App-Local
Then I should be able to test the scheme AppTests
Then I should be able to build the scheme Framework1
Then I should be able to test the scheme Framework1Tests
Expand Down
8 changes: 7 additions & 1 deletion fixtures/ios_app_with_custom_scheme/App/Project.swift
Expand Up @@ -14,6 +14,12 @@ let releaseScheme = Scheme(name: "App-Release",
testAction: TestAction(targets: ["AppTests"]),
runAction: RunAction(executable: "App"))

let userScheme = Scheme(name: "App-Local",
shared: false,
buildAction: BuildAction(targets: ["App"], preActions: [debugAction]),
testAction: TestAction(targets: ["AppTests"]),
runAction: RunAction(executable: "App"))

let project = Project(name: "MainApp",
targets: [
Target(name: "App",
Expand All @@ -35,6 +41,6 @@ let project = Project(name: "MainApp",
dependencies: [
.target(name: "App"),
])],
schemes: [debugScheme, releaseScheme])
schemes: [debugScheme, releaseScheme, userScheme])


0 comments on commit a8eb839

Please sign in to comment.