Skip to content

Commit 5ee6c3e

Browse files
committed
[Xcodeproj] Show modulemaps for C language targets
Includes both generated and user provided. - https://bugs.swift.org/browse/SR-1653 - <rdar://problem/28109196> SR-1653 Show generated modulemap in Xcode proj group structure
1 parent 7e60027 commit 5ee6c3e

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

Sources/Xcodeproj/pbxproj().swift

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -270,25 +270,6 @@ func xcodeProject(
270270
// Add framework search path to build settings.
271271
targetSettings.common.FRAMEWORK_SEARCH_PATHS = ["$(PLATFORM_DIR)/Developer/Library/Frameworks"]
272272

273-
// Generate a module map for ClangModule (if not provided by user) and
274-
// add to the build settings.
275-
if case let clangModule as ClangModule = module, clangModule.type == .library {
276-
targetSettings.common.DEFINES_MODULE = "YES"
277-
let moduleMapPath: AbsolutePath
278-
// If user provided the modulemap no need to generate.
279-
if fileSystem.isFile(clangModule.moduleMapPath) {
280-
moduleMapPath = clangModule.moduleMapPath
281-
} else {
282-
// Generate and drop the modulemap inside Xcodeproj folder.
283-
let path = xcodeprojPath.appending(components: "GeneratedModuleMap", clangModule.c99name)
284-
var moduleMapGenerator = ModuleMapGenerator(for: clangModule, fileSystem: fileSystem)
285-
try moduleMapGenerator.generateModuleMap(inDir: path)
286-
moduleMapPath = path.appending(component: moduleMapFilename)
287-
}
288-
289-
targetSettings.common.MODULEMAP_FILE = moduleMapPath.relative(to: xcodeprojPath.parentDirectory).asString
290-
}
291-
292273
// At the moment, set the Swift version to 3 (we will need to make this dynamic), but for now this is necessary.
293274
targetSettings.common.SWIFT_VERSION = "3.0"
294275

@@ -353,12 +334,29 @@ func xcodeProject(
353334
// Add the `include` group for a libary C language target.
354335
if case let clangModule as ClangModule = module, clangModule.type == .library, fileSystem.isDirectory(clangModule.includeDir) {
355336
let includeDir = clangModule.includeDir
356-
_ = makeGroup(for: includeDir)
337+
let includeGroup = makeGroup(for: includeDir)
357338
// FIXME: Support C++ headers.
358339
for header in try walk(includeDir, fileSystem: fileSystem) where header.extension == "h" {
359340
let group = makeGroup(for: header.parentDirectory)
360341
group.addFileReference(path: header.basename)
361342
}
343+
344+
// Generate a module map for ClangModule (if not provided by user) and
345+
// add to the build settings.
346+
targetSettings.common.DEFINES_MODULE = "YES"
347+
let moduleMapPath: AbsolutePath
348+
// If user provided the modulemap no need to generate.
349+
if fileSystem.isFile(clangModule.moduleMapPath) {
350+
moduleMapPath = clangModule.moduleMapPath
351+
} else {
352+
// Generate and drop the modulemap inside Xcodeproj folder.
353+
let path = xcodeprojPath.appending(components: "GeneratedModuleMap", clangModule.c99name)
354+
var moduleMapGenerator = ModuleMapGenerator(for: clangModule, fileSystem: fileSystem)
355+
try moduleMapGenerator.generateModuleMap(inDir: path)
356+
moduleMapPath = path.appending(component: moduleMapFilename)
357+
}
358+
includeGroup.addFileReference(path: moduleMapPath.asString, name: moduleMapPath.basename)
359+
targetSettings.common.MODULEMAP_FILE = moduleMapPath.relative(to: xcodeprojPath.parentDirectory).asString
362360
}
363361
}
364362

Tests/XcodeprojTests/PackageGraphTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ class PackageGraphTests: XCTestCase {
4545
"Sources/Foo/foo.swift",
4646
"Sources/Sea2/Sea2.c",
4747
"Sources/Sea2/include/Sea2.h",
48+
"Sources/Sea2/include/module.modulemap",
4849
"Sources/Bar/bar.swift",
4950
"Sources/Sea/Sea.c",
5051
"Sources/Sea/include/Sea.h",
52+
"Sources/Sea/include/module.modulemap",
5153
"Tests/BarTests/barTests.swift",
5254
"Products/Foo.framework",
5355
"Products/Sea2.framework",

0 commit comments

Comments
 (0)