Skip to content

Commit f1be854

Browse files
committed
adjust language inference logic to fix #96
1 parent 3d5cae1 commit f1be854

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

Sources/SymbolGraphBuilder/Builds/PackageBuild.Sources.Module.swift

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,15 @@ extension PackageBuild.Sources.Module
7878
return
7979
}
8080

81-
let exclude:Set<FilePath> = exclude.reduce(into: []) { $0.insert(path / $1) }
81+
let exclude:[FilePath] = exclude.map { path / $0 }
8282
var include:Set<FilePath> = []
83-
var language:SymbolGraph.ModuleLanguage = self.module.language ?? .swift
8483

8584
defer
8685
{
8786
self.articles.sort { $0.string < $1.string }
8887
self.include = include.sorted { $0.string < $1.string }
89-
self.module.language = language
9088
}
89+
9190
try path.directory.walk
9291
{
9392
let file:(path:FilePath, extension:String)
@@ -103,27 +102,38 @@ extension PackageBuild.Sources.Module
103102
return
104103
}
105104

106-
switch (file.extension, excluded: exclude.contains(file.path))
105+
guard file.extension != "md"
106+
else
107107
{
108-
case ("md", excluded: _):
109108
// It’s common to list markdown files under exclude paths.
110109
self.articles.append(file.path)
110+
return
111+
}
111112

112-
case ("h", excluded: false):
113+
// TODO: might benefit from a better algorithm.
114+
for prefix:FilePath in exclude
115+
{
116+
if file.path.starts(with: prefix)
117+
{
118+
return
119+
}
120+
}
121+
122+
switch file.extension
123+
{
124+
case "h":
125+
// Header files don’t indicate a C or C++ module on their own.
113126
include.update(with: $0)
114-
fallthrough
115127

116-
case ("c", excluded: false):
117-
language |= .c
128+
case "c":
129+
self.module.language |= .c
118130

119-
case ("hpp", excluded: false),
120-
("hxx", excluded: false):
131+
case "hpp", "hxx":
121132
include.update(with: $0)
122133
fallthrough
123134

124-
case ("cpp", excluded: false),
125-
("cxx", excluded: false):
126-
language |= .cpp
135+
case "cpp", "cxx":
136+
self.module.language |= .cpp
127137

128138
case _:
129139
break

Sources/SymbolGraphs/Modules/SymbolGraph.ModuleLanguage.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ extension SymbolGraph.ModuleLanguage
2222
/// This is most useful when inferring the language of a module from the languages of its
2323
/// constituent source files. For example, a C++ module may contain `.c` or `.h` files.
2424
@inlinable public static
25-
func | (lhs:Self, rhs:Self) -> Self
25+
func | (lhs:Self?, rhs:Self) -> Self
2626
{
27-
max(lhs, rhs)
27+
lhs.map { max($0, rhs) } ?? rhs
2828
}
2929

3030
/// See ``|(_:_:)``.
3131
@inlinable public static
32-
func |= (lhs:inout Self, rhs:Self)
32+
func |= (lhs:inout Self?, rhs:Self)
3333
{
3434
lhs = lhs | rhs
3535
}

0 commit comments

Comments
 (0)