From 6a6334fc78739e5fe6234475fa682dcb23ba2434 Mon Sep 17 00:00:00 2001 From: Codinget Date: Sun, 8 Nov 2020 00:53:32 +0100 Subject: [PATCH] actually honor sync requests --- moonbuild/core/DAG.moon | 6 ++++++ moonbuild/core/multiprocessexecutor.moon | 8 ++++++++ out/moonbuild | 15 +++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/moonbuild/core/DAG.moon b/moonbuild/core/DAG.moon index e57d3ed..cc6a499 100644 --- a/moonbuild/core/DAG.moon +++ b/moonbuild/core/DAG.moon @@ -12,6 +12,8 @@ nodepriority = (a, b) -> tb = type b.name da = #a.deps db = #b.deps + sa = a.sync + sb = b.sync if ta=='string' and tb!='string' return true elseif ta!='string' and tb=='string' @@ -20,6 +22,10 @@ nodepriority = (a, b) -> return true elseif a.priority < b.priority return false + elseif sa and not sb + return false + elseif sb and not sa + return true else return da < db diff --git a/moonbuild/core/multiprocessexecutor.moon b/moonbuild/core/multiprocessexecutor.moon index e54fb6c..4c8d089 100644 --- a/moonbuild/core/multiprocessexecutor.moon +++ b/moonbuild/core/multiprocessexecutor.moon @@ -37,6 +37,14 @@ class Executor error "Node #{name} wasn't built" unless node.built addprocess: (node, opts) => + if node.sync + while @nprocesses != 0 + @waitprocess + node\build opts + node.built = true + node\updatecache! + return + pid = fork! error "Failed to fork" unless pid if pid!=0 diff --git a/out/moonbuild b/out/moonbuild index a1099ce..29a50d9 100755 --- a/out/moonbuild +++ b/out/moonbuild @@ -1670,6 +1670,8 @@ nodepriority = function(a, b) local tb = type(b.name) local da = #a.deps local db = #b.deps + local sa = a.sync + local sb = b.sync if ta == 'string' and tb ~= 'string' then return true elseif ta ~= 'string' and tb == 'string' then @@ -1678,6 +1680,10 @@ nodepriority = function(a, b) return true elseif a.priority < b.priority then return false + elseif sa and not sb then + return false + elseif sb and not sa then + return true else return da < db end @@ -2248,6 +2254,15 @@ do end end, addprocess = function(self, node, opts) + if node.sync then + while self.nprocesses ~= 0 do + local _ = self.waitprocess + end + node:build(opts) + node.built = true + node:updatecache() + return + end local pid = fork() if not (pid) then error("Failed to fork")