diff --git a/uppsrc/umk/Console.cpp b/uppsrc/umk/Console.cpp index b25f09113..91ecc99cf 100644 --- a/uppsrc/umk/Console.cpp +++ b/uppsrc/umk/Console.cpp @@ -8,6 +8,7 @@ Console::Console() { console_lock = -1; wrap_text = true; console = false; + serial = 0; } void Console::Append(const String& s) { @@ -144,6 +145,7 @@ bool Console::Run(One process, const char *cmdline, Stream *out, bool pslot.key = key; pslot.group = current_group; pslot.last_msecs = msecs(); + pslot.serial = ++serial; groups.GetAdd(pslot.group).count += blitz_count; if(processes.GetCount() == 1) Wait(slot); @@ -218,6 +220,13 @@ bool Console::Wait() } } +void Console::OnFinish(Callback cb) +{ + Finisher& f = finisher.Add(); + f.serial = serial; + f.cb = cb; +} + void Console::Kill() { for(int i = 0; i < processes.GetCount(); i++) @@ -239,6 +248,20 @@ void Console::Kill(int islot) FlushConsole(); } CheckEndGroup(); + + int minserial = INT_MAX; + for(int i = 0; i < processes.GetCount(); i++) + minserial = min(processes[i].serial, minserial); + int i = 0; + while(i < finisher.GetCount()) { + const Finisher& f = finisher[i]; + if(f.serial > minserial) + i++; + else { + f.cb(); + finisher.Remove(i); + } + } } void Console::SetSlots(int s) diff --git a/uppsrc/umk/IdeContext.cpp b/uppsrc/umk/IdeContext.cpp index ac0d9a294..78c0b18d3 100644 --- a/uppsrc/umk/IdeContext.cpp +++ b/uppsrc/umk/IdeContext.cpp @@ -87,6 +87,11 @@ bool Ide::IdeConsoleWait(int slot) return true; } +void Ide::IdeConsoleOnFinish(Callback cb) +{ + console.OnFinish(cb); +} + bool Ide::IdeIsDebug() const { return false; diff --git a/uppsrc/umk/umake.h b/uppsrc/umk/umake.h index 45ecd14b6..1efe5f098 100644 --- a/uppsrc/umk/umake.h +++ b/uppsrc/umk/umake.h @@ -22,6 +22,7 @@ protected: bool quiet; int exitcode; int last_msecs; + int serial; }; struct Group { @@ -34,13 +35,20 @@ protected: int raw_msecs; }; + struct Finisher { + int serial; + Callback cb; + }; + Array processes; + Array finisher; ArrayMap groups; Vector error_keys; String current_group; String spooled_output; int console_lock; bool wrap_text; + int serial; void CheckEndGroup(); void FlushConsole(); @@ -70,6 +78,8 @@ public: void Wait(int slot); bool Wait(); + void OnFinish(Callback cb); + void WrapText(bool w) { wrap_text = w; } void SetSlots(int s); @@ -105,6 +115,7 @@ struct Ide : public IdeContext, public MakeBuild { virtual void IdeConsoleEndGroup(); virtual bool IdeConsoleWait(); virtual bool IdeConsoleWait(int slot); + virtual void IdeConsoleOnFinish(Callback cb); virtual bool IdeIsDebug() const ; virtual void IdeEndDebug();