ResolveCppIncludePath resolves a C++ include path to possible file paths.
(sourceFile, includePath string, suppliedFiles map[string]bool)
| 245 | |
| 246 | // ResolveCppIncludePath resolves a C++ include path to possible file paths. |
| 247 | func ResolveCppIncludePath(sourceFile, includePath string, suppliedFiles map[string]bool) []string { |
| 248 | sourceDir := filepath.Dir(sourceFile) |
| 249 | baseCandidates := includeBasePathCandidates(sourceDir, includePath) |
| 250 | seen := make(map[string]bool) |
| 251 | |
| 252 | var resolvedPaths []string |
| 253 | appendResolved := func(path string) { |
| 254 | if !seen[path] && suppliedFiles[path] { |
| 255 | seen[path] = true |
| 256 | resolvedPaths = append(resolvedPaths, path) |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | if filepath.Ext(includePath) != "" { |
| 261 | for _, base := range baseCandidates { |
| 262 | appendResolved(base) |
| 263 | } |
| 264 | sort.Strings(resolvedPaths) |
| 265 | return resolvedPaths |
| 266 | } |
| 267 | |
| 268 | extensions := []string{".h", ".hpp", ".hh", ".hxx"} |
| 269 | for _, base := range baseCandidates { |
| 270 | for _, ext := range extensions { |
| 271 | appendResolved(base + ext) |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | sort.Strings(resolvedPaths) |
| 276 | return resolvedPaths |
| 277 | } |
| 278 | |
| 279 | func includeBasePathCandidates(sourceDir, includePath string) []string { |
| 280 | candidates := make(map[string]bool) |