Fix crash for packages with `executableTarget` (#296)

* Infer executable targets' source folder

* Don't initialize FSWatch without watchable paths

* Update Sources/CartonKit/Server/Server.swift

Co-authored-by: Max Desiatov <max@desiatov.com>

* Update Sources/CartonKit/Server/Server.swift

Co-authored-by: Max Desiatov <max@desiatov.com>
This commit is contained in:
yonihemi 2022-02-21 18:18:03 +08:00 committed by GitHub
parent 7bd54d6c0c
commit f5b8e63abe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -172,11 +172,13 @@ public actor Server {
return
}
watcher = FSWatch(paths: builder.pathsToWatch, latency: 0.1) { [weak self] changes in
guard let self = self, !changes.isEmpty else { return }
Task { try await self.onChange(changes, configuration) }
if !builder.pathsToWatch.isEmpty {
watcher = FSWatch(paths: builder.pathsToWatch, latency: 0.1) { [weak self] changes in
guard let self = self, !changes.isEmpty else { return }
Task { try await self.onChange(changes, configuration) }
}
try watcher?.start()
}
try watcher?.start()
}
private func onChange(_ changes: [AbsolutePath], _ configuration: Configuration) async throws {

View File

@ -183,9 +183,9 @@ public final class Toolchain {
guard let path = target.path else {
switch target.type {
case .regular:
case .regular, .executable:
return RelativePath("Sources").appending(component: target.name).pathString
case .test, .system, .executable, .binary, .plugin:
case .test, .system, .binary, .plugin:
return nil
}
}