From d4cd62e913dfac82eb8c96b20c6a0a47841c58fb Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Fri, 2 Aug 2024 12:56:10 +0200 Subject: [PATCH 1/2] Compile Progress --- tools/hxcpp/BuildTool.hx | 9 ++++++--- tools/hxcpp/Compiler.hx | 7 ++++++- tools/hxcpp/Progress.hx | 27 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 tools/hxcpp/Progress.hx diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index cd562929e..368159b21 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -576,7 +576,7 @@ class BuildTool first = false; Log.lock(); Log.println(""); - Log.info("\x1b[33;1mCompiling group: " + group.mId + "\x1b[0m"); + Log.info("\x1b[33;1mCompiling group: " + group.mId + " (" + to_be_compiled.length + " files)\x1b[0m"); var message = "\x1b[1m" + (nvcc ? getNvcc() : mCompiler.mExe) + "\x1b[0m"; var flags = group.mCompilerFlags; if (!nvcc) @@ -612,10 +612,13 @@ class BuildTool } : null; Profile.push("compile"); + + var compile_progress = new Progress(0,to_be_compiled.length); + if (threadPool==null) { for(file in to_be_compiled) - mCompiler.compile(file,-1,groupHeader,pchStamp); + mCompiler.compile(file,-1,groupHeader,pchStamp,compile_progress); } else { @@ -631,7 +634,7 @@ class BuildTool break; var file = to_be_compiled[index]; - compiler.compile(file,threadId,groupHeader,pchStamp); + compiler.compile(file,threadId,groupHeader,pchStamp,compile_progress); } }); } diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index 2d0b5bb17..43e57db06 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -300,7 +300,7 @@ class Compiler catch(e:Dynamic) { } } - public function compile(inFile:File,inTid:Int,headerFunc:Void->Void,pchTimeStamp:Null) + public function compile(inFile:File,inTid:Int,headerFunc:Void->Void,pchTimeStamp:Null,inProgess:Null) { var obj_name = getObjName(inFile); var args = getArgs(inFile); @@ -394,6 +394,11 @@ class Compiler } fileName += " \x1b[3m" + tagInfo + "\x1b[0m"; + if (inProgess!=null) + { + inProgess.progress(1); + fileName = inProgess.getProgress() + fileName; + } if (inTid >= 0) { diff --git a/tools/hxcpp/Progress.hx b/tools/hxcpp/Progress.hx new file mode 100644 index 000000000..750d9ca24 --- /dev/null +++ b/tools/hxcpp/Progress.hx @@ -0,0 +1,27 @@ +package; + +class Progress { + public var current:Int; + public var total:Int; + + public function new(inCurrent:Int, inTotal:Int) { + current = inCurrent; + total = inTotal; + } + + public function progress(inCurrent:Int) { + current += inCurrent; + } + + public function getProgress() { + var percent = current / total; + var pct = Std.int(percent * 1000) / 10; + var str = Std.string(pct); + if (Std.int(pct) == pct) { + str += ".0"; + } + while (str.length < 4) + str = " " + str; + return "[" + str + "%]"; + } +} From 6f75d287687a3315242c933ca2959fe631c63278 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Thu, 29 Aug 2024 22:37:41 +0200 Subject: [PATCH 2/2] Fixed the progress being unordered + grammar fix --- tools/hxcpp/BuildTool.hx | 6 ++-- tools/hxcpp/Compiler.hx | 60 ++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index 368159b21..f71dc0691 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -576,7 +576,7 @@ class BuildTool first = false; Log.lock(); Log.println(""); - Log.info("\x1b[33;1mCompiling group: " + group.mId + " (" + to_be_compiled.length + " files)\x1b[0m"); + Log.info("\x1b[33;1mCompiling group: " + group.mId + " (" + to_be_compiled.length + " file" + (to_be_compiled.length==1 ? "" : "s") + ")\x1b[0m"); var message = "\x1b[1m" + (nvcc ? getNvcc() : mCompiler.mExe) + "\x1b[0m"; var flags = group.mCompilerFlags; if (!nvcc) @@ -613,7 +613,9 @@ class BuildTool Profile.push("compile"); - var compile_progress = new Progress(0,to_be_compiled.length); + var compile_progress = null; + if (!Log.verbose) + compile_progress = new Progress(0,to_be_compiled.length); if (threadPool==null) { diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index 43e57db06..0578e6ba7 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -1,6 +1,13 @@ import haxe.crypto.Md5; import haxe.io.Path; import sys.FileSystem; +#if haxe4 +import sys.thread.Mutex; +#elseif cpp +import cpp.vm.Mutex; +#else +import neko.vm.Mutex; +#end private class FlagInfo { @@ -300,6 +307,8 @@ class Compiler catch(e:Dynamic) { } } + static public var printMutex = new Mutex(); + public function compile(inFile:File,inTid:Int,headerFunc:Void->Void,pchTimeStamp:Null,inProgess:Null) { var obj_name = getObjName(inFile); @@ -380,34 +389,41 @@ class Compiler if (delayedFilename!=null) args.push(delayedFilename); - var tagInfo = inFile.mTags==null ? "" : " " + inFile.mTags.split(","); - - var fileName = inFile.mName; - var split = fileName.split ("/"); - if (split.length > 1) + if (!Log.verbose) { - fileName = " \x1b[2m-\x1b[0m \x1b[33m" + split.slice(0, split.length - 1).join("/") + "/\x1b[33;1m" + split[split.length - 1] + "\x1b[0m"; - } - else - { - fileName = " \x1b[2m-\x1b[0m \x1b[33;1m" + fileName + "\x1b[0m"; - } - fileName += " \x1b[3m" + tagInfo + "\x1b[0m"; + var tagInfo = inFile.mTags==null ? "" : " " + inFile.mTags.split(","); - if (inProgess!=null) - { - inProgess.progress(1); - fileName = inProgess.getProgress() + fileName; + var fileName = inFile.mName; + var split = fileName.split ("/"); + if (split.length > 1) + { + fileName = " \x1b[2m-\x1b[0m \x1b[33m" + split.slice(0, split.length - 1).join("/") + "/\x1b[33;1m" + split[split.length - 1] + "\x1b[0m"; + } + else + { + fileName = " \x1b[2m-\x1b[0m \x1b[33;1m" + fileName + "\x1b[0m"; + } + fileName += " \x1b[3m" + tagInfo + "\x1b[0m"; + + printMutex.acquire(); + + if (inProgess != null) + { + inProgess.progress(1); + fileName = inProgess.getProgress() + fileName; + } + + if((inTid >= 0 && BuildTool.threadExitCode == 0) || inTid < 0) + { + Log.info(fileName); + } + printMutex.release(); } if (inTid >= 0) { if (BuildTool.threadExitCode == 0) { - if (!Log.verbose) - { - Log.info(fileName); - } var err = ProcessManager.runProcessThreaded(exe, args, null); cleanTmp(tmpFile); if (err!=0) @@ -420,10 +436,6 @@ class Compiler } else { - if (!Log.verbose) - { - Log.info(fileName); - } var result = ProcessManager.runProcessThreaded(exe, args, null); cleanTmp(tmpFile); if (result!=0)