Set the build system to nil if no compilation database can be loaded

When we couldn’t start a build server or find a SwiftPM package, we currently always create a `CompilationDatabaseBuildSystem`, even if no `compile_commands.json` or `compile_flags.txt` exits. Every request for build settings would then log an error that the compilation database can’t be opened, which was very spammy. Instead, if the compilation database can’t be loaded, just set the build system to `nil` and log a single error message.
This commit is contained in:
Alex Hoppen
2023-10-27 09:32:18 -07:00
parent 7772f0721d
commit 8286113fef
3 changed files with 17 additions and 5 deletions

View File

@@ -73,12 +73,16 @@ public actor CompilationDatabaseBuildSystem {
return nil
}
public init(projectRoot: AbsolutePath? = nil, searchPaths: [RelativePath], fileSystem: FileSystem = localFileSystem) {
public init?(projectRoot: AbsolutePath? = nil, searchPaths: [RelativePath], fileSystem: FileSystem = localFileSystem) {
self.fileSystem = fileSystem
self.projectRoot = projectRoot
self.searchPaths = searchPaths
if let path = projectRoot {
self.compdb = tryLoadCompilationDatabase(directory: path, additionalSearchPaths: searchPaths, fileSystem)
if let path = projectRoot,
let compdb = tryLoadCompilationDatabase(directory: path, additionalSearchPaths: searchPaths, fileSystem)
{
self.compdb = compdb
} else {
return nil
}
}
}