Skip to content

Commit 4d52caf

Browse files
committed
[Xcodeproj] Break pbxproj() method to make it easier for unit testing
Will need Xcode.Project to unit test this area instead of a serialized string
1 parent 57c5be1 commit 4d52caf

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

Sources/Xcodeproj/pbxproj().swift

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,26 @@ import Utility
2323
/// sources is not necessarily related to this path; the source root directory
2424
/// is the path of the root package in the package graph, independent of the
2525
/// directory to which the .xcodeproj is being generated.
26-
public func pbxproj(xcodeprojPath: AbsolutePath, graph: PackageGraph, extraDirs: [AbsolutePath], options: XcodeprojOptions) throws -> String {
26+
public func pbxproj(
27+
xcodeprojPath: AbsolutePath,
28+
graph: PackageGraph,
29+
extraDirs: [AbsolutePath],
30+
options: XcodeprojOptions,
31+
fileSystem: FileSystem = localFileSystem
32+
) throws -> String {
33+
let project = try xcodeProject(xcodeprojPath: xcodeprojPath, graph: graph, extraDirs: extraDirs, options: options, fileSystem: fileSystem)
34+
// Serialize the project model we created to a plist, and return
35+
// its string description.
36+
return "// !$*UTF8*$!\n" + project.generatePlist().description
37+
}
38+
39+
func xcodeProject(
40+
xcodeprojPath: AbsolutePath,
41+
graph: PackageGraph,
42+
extraDirs: [AbsolutePath],
43+
options: XcodeprojOptions,
44+
fileSystem: FileSystem
45+
) throws -> Xcode.Project {
2746

2847
// Create the project.
2948
let project = Xcode.Project()
@@ -257,12 +276,12 @@ public func pbxproj(xcodeprojPath: AbsolutePath, graph: PackageGraph, extraDirs:
257276
targetSettings.common.DEFINES_MODULE = "YES"
258277
let moduleMapPath: AbsolutePath
259278
// If user provided the modulemap no need to generate.
260-
if isFile(clangModule.moduleMapPath) {
279+
if fileSystem.isFile(clangModule.moduleMapPath) {
261280
moduleMapPath = clangModule.moduleMapPath
262281
} else {
263282
// Generate and drop the modulemap inside Xcodeproj folder.
264283
let path = xcodeprojPath.appending(components: "GeneratedModuleMap", clangModule.c99name)
265-
var moduleMapGenerator = ModuleMapGenerator(for: clangModule)
284+
var moduleMapGenerator = ModuleMapGenerator(for: clangModule, fileSystem: fileSystem)
266285
try moduleMapGenerator.generateModuleMap(inDir: path)
267286
moduleMapPath = path.appending(component: moduleMapFilename)
268287
}
@@ -362,10 +381,8 @@ public func pbxproj(xcodeprojPath: AbsolutePath, graph: PackageGraph, extraDirs:
362381
let _ = linkPhase.addBuildFile(fileRef: otherTarget.productReference!)
363382
}
364383
}
365-
366-
// Finally, serialize the project model we created to a plist, and return
367-
// its string description.
368-
return "// !$*UTF8*$!\n" + project.generatePlist().description
384+
385+
return project
369386
}
370387

371388
extension Module {

0 commit comments

Comments
 (0)