Skip to content

Commit ae3b097

Browse files
committed
Implement buildXcodeprojPath
1 parent ce5936b commit ae3b097

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

Sources/Commands/SwiftPackageTool.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,13 @@ public class SwiftPackageTool: SwiftTool<PackageToolOptions> {
162162
dstdir = try getPackageRoot()
163163
projectName = graph.rootPackages[0].name
164164
}
165-
let (_, xcodeProjPath) = try Xcodeproj.generate(
166-
outputDir: dstdir,
165+
let xcodeprojPath = Xcodeproj.buildXcodeprojPath(outputDir: dstdir, projectName: projectName)
166+
try Xcodeproj.generate(
167167
projectName: projectName,
168+
xcodeprojPath: xcodeprojPath,
168169
graph: graph,
169170
options: options.xcodeprojOptions)
170-
print("generated:", xcodeProjPath.prettyPath(cwd: originalWorkingDirectory))
171+
print("generated:", xcodeprojPath.prettyPath(cwd: originalWorkingDirectory))
171172

172173
case .describe:
173174
let graph = try loadPackageGraph()

Sources/Xcodeproj/generate().swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,21 @@ public struct XcodeprojOptions {
3838
}
3939
}
4040

41+
public func buildXcodeprojPath(outputDir: AbsolutePath, projectName: String) -> AbsolutePath {
42+
// Determine the path of the .xcodeproj wrapper directory.
43+
let xcodeprojName = "\(projectName).xcodeproj"
44+
return outputDir.appending(RelativePath(xcodeprojName))
45+
}
46+
4147
/// Generates an Xcode project and all needed support files. The .xcodeproj
4248
/// wrapper directory is created in the path specified by `outputDir`, basing
4349
/// the file name on the project name `projectName`. Returns the path of the
4450
/// generated project. All ancillary files will be generated inside of the
4551
/// .xcodeproj wrapper directory.
52+
@discardableResult
4653
public func generate(
47-
outputDir: AbsolutePath,
4854
projectName: String,
55+
xcodeprojPath: AbsolutePath,
4956
graph: PackageGraph,
5057
options: XcodeprojOptions
5158
) throws -> (Xcode.Project, AbsolutePath) {
@@ -54,10 +61,6 @@ public func generate(
5461

5562
let srcroot = graph.rootPackages[0].path
5663

57-
// Determine the path of the .xcodeproj wrapper directory.
58-
let xcodeprojName = "\(projectName).xcodeproj"
59-
let xcodeprojPath = outputDir.appending(RelativePath(xcodeprojName))
60-
6164
// Determine the path of the scheme directory (it's inside the .xcodeproj).
6265
let schemesDir = xcodeprojPath.appending(components: "xcshareddata", "xcschemes")
6366

Tests/XcodeprojTests/GenerateXcodeprojTests.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ import Utility
1818
import XCTest
1919

2020
class GenerateXcodeprojTests: XCTestCase {
21+
func testBuildXcodeprojPath() {
22+
let outdir = AbsolutePath("/path/to/project")
23+
let projectName = "Bar"
24+
let xcodeprojPath = Xcodeproj.buildXcodeprojPath(outputDir: outdir, projectName: projectName)
25+
let expectedPath = AbsolutePath("/path/to/project/Bar.xcodeproj")
26+
XCTAssertEqual(xcodeprojPath, expectedPath)
27+
}
28+
2129
func testXcodebuildCanParseIt() {
2230
#if os(macOS)
2331
mktmpdir { dstdir in
@@ -28,7 +36,8 @@ class GenerateXcodeprojTests: XCTestCase {
2836
XCTAssertFalse(diagnostics.hasErrors)
2937

3038
let projectName = "DummyProjectName"
31-
let (_, outpath) = try Xcodeproj.generate(outputDir: dstdir, projectName: projectName, graph: graph, options: XcodeprojOptions())
39+
let outpath = Xcodeproj.buildXcodeprojPath(outputDir: dstdir, projectName: projectName)
40+
try Xcodeproj.generate(projectName: projectName, xcodeprojPath: outpath, graph: graph, options: XcodeprojOptions())
3241

3342
XCTAssertDirectoryExists(outpath)
3443
XCTAssertEqual(outpath, dstdir.appending(component: projectName + ".xcodeproj"))

0 commit comments

Comments
 (0)