mirror of
https://github.com/irmen/prog8.git
synced 2024-11-27 03:50:27 +00:00
Fixed compiler watch to work with multiple compilation modules
This commit is contained in:
parent
04d8bb8fbf
commit
8efe4c6267
@ -55,43 +55,42 @@ private fun compileMain(args: Array<String>) {
|
|||||||
exitProcess(1)
|
exitProcess(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make watching work with multiple source files
|
if(watchMode) {
|
||||||
|
|
||||||
if(watchMode && moduleFiles.size<=1) {
|
|
||||||
val watchservice = FileSystems.getDefault().newWatchService()
|
val watchservice = FileSystems.getDefault().newWatchService()
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
val filepath = pathFrom(moduleFiles.single()).normalize()
|
println("Continuous watch mode active. Modules: $moduleFiles")
|
||||||
println("Continuous watch mode active. Main module: $filepath")
|
val results = mutableListOf<CompilationResult>()
|
||||||
|
for(filepathRaw in moduleFiles) {
|
||||||
try {
|
val filepath = pathFrom(filepathRaw).normalize()
|
||||||
val compilationResult = compileProgram(filepath, !dontOptimize, !dontWriteAssembly, slowCodegenWarnings, compilationTarget, outputPath)
|
val compilationResult = compileProgram(filepath, !dontOptimize, !dontWriteAssembly, slowCodegenWarnings, compilationTarget, outputPath)
|
||||||
println("Imported files (now watching:)")
|
results.add(compilationResult)
|
||||||
for (importedFile in compilationResult.importedFiles) {
|
|
||||||
print(" ")
|
|
||||||
println(importedFile)
|
|
||||||
val watchDir = importedFile.parent ?: Path.of(".")
|
|
||||||
watchDir.register(watchservice, StandardWatchEventKinds.ENTRY_MODIFY)
|
|
||||||
}
|
|
||||||
println("[${LocalDateTime.now().withNano(0)}] Waiting for file changes.")
|
|
||||||
|
|
||||||
var recompile=false
|
|
||||||
while(!recompile) {
|
|
||||||
val event = watchservice.take()
|
|
||||||
for (changed in event.pollEvents()) {
|
|
||||||
val changedPath = changed.context() as Path
|
|
||||||
if(compilationResult.importedFiles.any { it.fileName == changedPath.fileName }) {
|
|
||||||
println(" change detected: $changedPath")
|
|
||||||
recompile = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.reset()
|
|
||||||
}
|
|
||||||
|
|
||||||
println("\u001b[H\u001b[2J") // clear the screen
|
|
||||||
} catch (x: Exception) {
|
|
||||||
throw x
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val allImportedFiles = results.flatMap { it.importedFiles }
|
||||||
|
println("Imported files (now watching:)")
|
||||||
|
for (importedFile in allImportedFiles) {
|
||||||
|
print(" ")
|
||||||
|
println(importedFile)
|
||||||
|
val watchDir = importedFile.parent ?: Path.of(".")
|
||||||
|
watchDir.register(watchservice, StandardWatchEventKinds.ENTRY_MODIFY)
|
||||||
|
}
|
||||||
|
println("[${LocalDateTime.now().withNano(0)}] Waiting for file changes.")
|
||||||
|
|
||||||
|
var recompile=false
|
||||||
|
while(!recompile) {
|
||||||
|
val event = watchservice.take()
|
||||||
|
for (changed in event.pollEvents()) {
|
||||||
|
val changedPath = changed.context() as Path
|
||||||
|
if(allImportedFiles.any { it.fileName == changedPath.fileName }) {
|
||||||
|
println(" change detected: $changedPath")
|
||||||
|
recompile = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
println("\u001b[H\u001b[2J") // clear the screen
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -93,6 +93,8 @@ Almost instant compilation times (less than a second) can be achieved when using
|
|||||||
Start the compiler with the ``-watch`` argument to enable this.
|
Start the compiler with the ``-watch`` argument to enable this.
|
||||||
It will compile your program and then instead of exiting, it waits for any changes in the module source files.
|
It will compile your program and then instead of exiting, it waits for any changes in the module source files.
|
||||||
As soon as a change happens, the program gets compiled again.
|
As soon as a change happens, the program gets compiled again.
|
||||||
|
It is possible to use the watch mode with multiple modules as well, but it will
|
||||||
|
recompile everything in that list even if only of the files got updated.
|
||||||
|
|
||||||
Other options
|
Other options
|
||||||
^^^^^^^^^^^^^
|
^^^^^^^^^^^^^
|
||||||
|
Loading…
Reference in New Issue
Block a user