mirror of
https://github.com/irmen/prog8.git
synced 2024-09-10 09:54:32 +00:00
Fixed compiler watch flag crashing when not used on a subdirectory. Fixes #20
This commit is contained in:
parent
08aa13c90c
commit
04d8bb8fbf
@ -55,6 +55,8 @@ private fun compileMain(args: Array<String>) {
|
|||||||
exitProcess(1)
|
exitProcess(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: make watching work with multiple source files
|
||||||
|
|
||||||
if(watchMode && moduleFiles.size<=1) {
|
if(watchMode && moduleFiles.size<=1) {
|
||||||
val watchservice = FileSystems.getDefault().newWatchService()
|
val watchservice = FileSystems.getDefault().newWatchService()
|
||||||
|
|
||||||
@ -68,15 +70,24 @@ private fun compileMain(args: Array<String>) {
|
|||||||
for (importedFile in compilationResult.importedFiles) {
|
for (importedFile in compilationResult.importedFiles) {
|
||||||
print(" ")
|
print(" ")
|
||||||
println(importedFile)
|
println(importedFile)
|
||||||
importedFile.parent.register(watchservice, StandardWatchEventKinds.ENTRY_MODIFY)
|
val watchDir = importedFile.parent ?: Path.of(".")
|
||||||
|
watchDir.register(watchservice, StandardWatchEventKinds.ENTRY_MODIFY)
|
||||||
}
|
}
|
||||||
println("[${LocalDateTime.now().withNano(0)}] Waiting for file changes.")
|
println("[${LocalDateTime.now().withNano(0)}] Waiting for file changes.")
|
||||||
|
|
||||||
|
var recompile=false
|
||||||
|
while(!recompile) {
|
||||||
val event = watchservice.take()
|
val event = watchservice.take()
|
||||||
for (changed in event.pollEvents()) {
|
for (changed in event.pollEvents()) {
|
||||||
val changedPath = changed.context() as Path
|
val changedPath = changed.context() as Path
|
||||||
|
if(compilationResult.importedFiles.any { it.fileName == changedPath.fileName }) {
|
||||||
println(" change detected: $changedPath")
|
println(" change detected: $changedPath")
|
||||||
|
recompile = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
event.reset()
|
event.reset()
|
||||||
|
}
|
||||||
|
|
||||||
println("\u001b[H\u001b[2J") // clear the screen
|
println("\u001b[H\u001b[2J") // clear the screen
|
||||||
} catch (x: Exception) {
|
} catch (x: Exception) {
|
||||||
throw x
|
throw x
|
||||||
|
Loading…
Reference in New Issue
Block a user