@@ -50,14 +50,14 @@ extension ClangModule {
50
50
51
51
public func generateModuleMap( inDir wd: String ) throws {
52
52
53
- //Return if module map is already present
53
+ /// Return if module map is already present
54
54
guard !moduleMapPath. isFile else {
55
55
return
56
56
}
57
57
58
58
let includeDir = path
59
59
60
- //Warn and return if no include directory
60
+ /// Warn and return if no include directory
61
61
guard includeDir. isDirectory else {
62
62
print ( " warning: No include directory found, a library can not be imported without any public headers. " )
63
63
return
@@ -68,17 +68,31 @@ extension ClangModule {
68
68
let files = walked. filter { $0. isFile && $0. hasSuffix ( " .h " ) }
69
69
let dirs = walked. filter { $0. isDirectory}
70
70
71
+ ///There are three possible cases for which we will generate modulemaps:
72
+ ///Flat includes dir with only header files, in that case we generate
73
+ /// `umbrella "path/to/includes/"`
74
+ ///Module name dir is the only dir in includes, in that case we generate
75
+ /// `umbrella header "path/to/includes/modulename/modulename.h"` if there is a `modulename.h`
76
+ ///inside that directory, otherwise we generate
77
+ /// `umbrella "path/to/includes/modulename"`
78
+
71
79
if dirs. isEmpty {
72
80
guard !files. isEmpty else { throw ModuleMapError . UnsupportedIncludeLayoutForModule ( name) }
73
81
try createModuleMap ( inDir: wd, type: . FlatHeaderLayout)
74
82
return
75
83
}
76
84
77
- guard let moduleHeaderDir = dirs. first where moduleHeaderDir. basename == name && files. isEmpty else {
85
+ guard let moduleHeaderDir = dirs. first where moduleHeaderDir. basename == c99name && files. isEmpty else {
78
86
throw ModuleMapError . UnsupportedIncludeLayoutForModule ( name)
79
87
}
80
88
81
- let umbrellaHeader = Path . join ( moduleHeaderDir, " \( name) .h " )
89
+ let umbrellaHeader = Path . join ( moduleHeaderDir, " \( c99name) .h " )
90
+
91
+ let invalidUmbrellaHeader = Path . join ( moduleHeaderDir, " \( name) .h " )
92
+ if c99name != name && invalidUmbrellaHeader. isFile {
93
+ print ( " warning: \( invalidUmbrellaHeader) should be renamed to \( umbrellaHeader) to be used as Umbrella header " )
94
+ }
95
+
82
96
if umbrellaHeader. isFile {
83
97
try createModuleMap ( inDir: wd, type: . HeaderFile)
84
98
} else {
@@ -98,24 +112,22 @@ extension ClangModule {
98
112
let moduleMap = try fopen ( moduleMapFile, mode: . Write)
99
113
defer { fclose ( moduleMap) }
100
114
101
- try fputs ( " module \( name) { \n " , moduleMap)
102
- try fputs ( " umbrella " , moduleMap)
103
-
115
+ var output = " module \( c99name) { \n "
104
116
switch type {
105
117
case . FlatHeaderLayout:
106
- try fputs ( " \" \( path) \" \n " , moduleMap )
118
+ output += " umbrella \" \( path) \" \n "
107
119
case . ModuleNameDir:
108
- let path = Path . join ( self . path, name )
109
- try fputs ( " \" \( path) \" \n " , moduleMap )
120
+ let path = Path . join ( self . path, c99name )
121
+ output += " umbrella \" \( path) \" \n "
110
122
case . HeaderFile:
111
- let path = Path . join ( self . path, name, " \( name) .h " )
112
- try fputs ( " header \" \( path) \" \n " , moduleMap)
113
-
123
+ let path = Path . join ( self . path, c99name, " \( c99name) .h " )
124
+ output += " umbrella header \" \( path) \" \n "
114
125
}
115
-
116
- try fputs ( " link \" \( name) \" \n " , moduleMap)
117
- try fputs ( " export * \n " , moduleMap)
118
- try fputs ( " } \n " , moduleMap)
126
+ output += " link \" \( c99name) \" \n "
127
+ output += " export * \n "
128
+ output += " } \n "
129
+
130
+ try fputs ( output, moduleMap)
119
131
}
120
132
}
121
133
0 commit comments