Fix watcher missing root directories (#48)

This commit is contained in:
Max Desiatov 2020-07-14 20:44:08 +01:00 committed by GitHub
parent dc56e8387b
commit 01fc71b320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 13 deletions

View File

@ -25,7 +25,7 @@ struct Package: Codable {
let targets: [Target]
init(with swiftPath: AbsolutePath, _ terminal: TerminalController) throws {
terminal.write("Parsing package manifest: ", inColor: .yellow)
terminal.write("\nParsing package manifest: ", inColor: .yellow)
terminal.write("\(swiftPath) package dump-package\n")
let output = try Data(processDataOutput([swiftPath.pathString, "package", "dump-package"]))

View File

@ -107,7 +107,7 @@ public final class Toolchain {
}
}
public func inferSourcesPaths() throws -> [String] {
public func inferSourcesPaths() throws -> [AbsolutePath] {
let package = try Package(with: swiftPath, terminal)
let targetPaths = package.targets.compactMap { target -> String? in
@ -122,7 +122,9 @@ public final class Toolchain {
return path
}
return targetPaths
return try targetPaths.compactMap {
try fileSystem.currentWorkingDirectory?.appending(RelativePath(validating: $0))
}
}
private func inferDestinationPath() throws -> AbsolutePath {

View File

@ -58,17 +58,13 @@ struct Dev: ParsableCommand {
release: release
)
let sources = try toolchain.inferSourcesPaths().map { source -> [AbsolutePath] in
let relativePath = try RelativePath(validating: source)
guard let sources = localFileSystem.currentWorkingDirectory?.appending(relativePath)
else { fatalError("failed to infer the sources directory") }
let paths = try toolchain.inferSourcesPaths()
terminal.write("\nWatching this directory for changes: ", inColor: .green)
terminal.logLookup("", sources)
terminal.write("\n")
terminal.write("\nWatching these directories for changes:\n", inColor: .green)
paths.forEach { terminal.logLookup("", $0) }
terminal.write("\n")
return try localFileSystem.traverseRecursively(sources)
}.flatMap { $0 }
let sources = try paths.flatMap { try localFileSystem.traverseRecursively($0) }
try Server(
builderArguments: arguments,

View File

@ -18,7 +18,7 @@ import TSCBasic
extension FileSystem {
func traverseRecursively(_ root: AbsolutePath) throws -> [AbsolutePath] {
precondition(isDirectory(root))
var result = [AbsolutePath]()
var result = [root]
var pathsToTraverse = [root]
while let currentDirectory = pathsToTraverse.popLast() {