[*] Strip even more out of jsonProcessor.lua

This commit is contained in:
Reece Wilson 2022-01-19 23:19:17 +00:00
parent 3e2f123f66
commit 0cd24fbede
3 changed files with 140 additions and 161 deletions

View File

@ -287,12 +287,33 @@ local function auBlockProjectKeyDepends(processor, value)
end, processor, true) end, processor, true)
end end
local function auBlockProjectKeyDllimport(processor, value)
__pushFilter(value, "value", defines, processor)
end
local function auBlockProjectKeyDllexport(processor, value)
__pushFilter(value, "value", defines, processor)
end
local function auBlockProjectKeySoftDepends(processor, value) local function auBlockProjectKeySoftDepends(processor, value)
__pushFilter(value, "value", function(obj) __pushFilter(value, "value", function(obj)
handleDepends(processor, obj, true) handleDepends(processor, obj, true)
end, processor, true) end, processor, true)
end end
local function auBlockProjectRefKeyInclSoftDepends(processor, value, taskMap, taskArray, inc, resolve)
__pushFilter(value, "value", function(obj)
resolve(processor:translateDep(obj), false)
end, processor, true)
end
local function auBlockProjectRefKeyInclDepends(processor, value, taskMap, taskArray, inc, resolve)
__pushFilter(value, "value", function(obj)
resolve(processor:translateDep(obj), false)
end, processor, true)
end
local function auBlockProjectRefKeyDepends(processor, value, taskMap, taskArray, inc, resolve) local function auBlockProjectRefKeyDepends(processor, value, taskMap, taskArray, inc, resolve)
__pushFilter(value, "value", function(obj) __pushFilter(value, "value", function(obj)
resolve(processor:translateDep(obj), false) resolve(processor:translateDep(obj), false)
@ -359,9 +380,21 @@ auProjectBlockHandlers["soft-depends"] = auBlockProjectKeySoftDepends
local auProjectRefHandlers = local auProjectRefHandlers =
{ {
linkDepends = auHeaderProjectKeyLinkDepends, linkDepends = auHeaderProjectKeyLinkDepends,
eval = auBlockProjectKeyEval eval = auBlockProjectKeyEval,
events = auBlockProjectKeyBuildEvent,
actions = auBlockProjectKeyBuildAction,
links = auBlockProjectKeyLinks,
defines = auBlockProjectKeyDefines,
include = auBlockProjectKeyIncludes,
includes = auBlockProjectKeyIncludes,
dllimport = auBlockProjectKeyDllimport,
dllexport = auBlockProjectKeyDllimport,
staticImport = auBlockProjectKeyDllimport,
staticImpDefines = auBlockProjectKeyDllimport
} }
auProjectRefHandlers["soft-depends"] = auBlockProjectRefKeySoftDepends auProjectRefHandlers["soft-depends"] = auBlockProjectRefKeySoftDepends
auProjectRefHandlers["include-soft-depends"] = auBlockProjectRefKeyInclSoftDepends
auProjectRefHandlers["include-depends"] = auBlockProjectRefKeyInclDepends
auProjectRefHandlers["depends"] = auBlockProjectRefKeyDepends auProjectRefHandlers["depends"] = auBlockProjectRefKeyDepends
kGenericTasks = {"sourcePaths", "includes","include", "sources", kGenericTasks = {"sourcePaths", "includes","include", "sources",
@ -372,8 +405,8 @@ auProjectRefHandlers["depends"] = auBlockProjectRefKeyDepends
"links", "soft-depends" "links", "soft-depends"
} }
local kReferenceTasks = {"eval", "includes", "include"} --, "features"} local kReferenceTasks = {"eval", "includes", "include", "includes"} --, "features"}
-- , "include-depends", "include-soft-depends"
__pRunTasks = function(processor, object, map, tasks, inc, resolve) __pRunTasks = function(processor, object, map, tasks, inc, resolve)
auForEachKV(tasks, function(na, key) auForEachKV(tasks, function(na, key)
@ -381,13 +414,12 @@ __pRunTasks = function(processor, object, map, tasks, inc, resolve)
if (not value) then if (not value) then
return return
end end
map[key](processor, value, map, tasks, inc, resolve) map[key](processor, value, map, tasks, inc, resolve)
end) end)
end end
local function __pRunLinkTasks(processor, object, resolve) local function __pRunLinkTasks(processor, object, resolve)
__pRunTasks(processor, object, auProjectRefHandlers, { "links", "depends", "soft-depends", "eval"}, false, resolve) __pRunTasks(processor, object, auProjectRefHandlers, { "links", "depends", "soft-depends", "eval", "linkDepends", "defines", "actions"}, false, resolve)
end end
local function __pRunIncludeTasks(processor, object, isIncludeLocalProject) local function __pRunIncludeTasks(processor, object, isIncludeLocalProject)
@ -402,10 +434,19 @@ local function __pRunIncludeTasks(processor, object, isIncludeLocalProject)
end end
end end
local function ___pRunIncludeTasks(processor, object, isIncludeLocalProject) local function ___pRunIncludeTasks(processor, object, resolve)
__pRunIncludeTasks(processor, object, isIncludeLocalProject) __pRunIncludeTasks(processor, object, false)
if (not object.noRootInclude) then if (not object.noRootInclude) then
_includeDirectoryEx(processor:getMeta().path, isIncludeLocalProject) _includeDirectoryEx(processor:getMeta().path, false)
end
end
local function ___pRunImportTask(processor, object, mask, resolve)
__pRunIncludeTasks(processor, object, false)
__pRunTasks(processor, object, auProjectRefHandlers, mask, false, resolve)
if (not object.noRootInclude) then
_includeDirectoryEx(processor:getMeta().path, false)
end end
end end
@ -420,5 +461,6 @@ end
return auCopyTables(auProjectHeaderHandlers, auProjectBlockHandlers, { return auCopyTables(auProjectHeaderHandlers, auProjectBlockHandlers, {
runProjectBlock = __pRunMainTasks, runProjectBlock = __pRunMainTasks,
runProjectLink = __pRunLinkTasks, runProjectLink = __pRunLinkTasks,
runProjectImport = ___pRunImportTask,
runProjectRef = ___pRunIncludeTasks runProjectRef = ___pRunIncludeTasks
}) })

View File

@ -14,10 +14,6 @@ function JsonProcessor(info)
end end
result.name = info.name result.name = info.name
local translateDep = function(this, dep)
return this:translateDep(dep)
end
-- ported -- ported
local includeDirEx = function(path, incFiles) local includeDirEx = function(path, incFiles)
includedirs(path) includedirs(path)
@ -35,16 +31,10 @@ function JsonProcessor(info)
includeDirEx(prefix .. "/" .. path, inc) includeDirEx(prefix .. "/" .. path, inc)
end end
local handleJSONInclude = function(result, val, incFiles) local handleJSONInclude = function(this, val, incFiles)
if (not result.include) then auRequire("Core/JSON/JSON").projectHandlers.runProjectImport(this, result, {"include", "includes", "actions"}, function(dep, soft)
if (val) then publicDepends(dep, this, soft)
return end)
end
includeDirEx (info.path, incFiles)
return
end
auForEach(result.include, handleUserJsonInclude, info.path, incFiles)
end end
local handleInclude = function(this, incFiles) local handleInclude = function(this, incFiles)
@ -57,64 +47,18 @@ function JsonProcessor(info)
includeDirEx(info.path .. "/Include") includeDirEx(info.path .. "/Include")
elseif (result.type:lower() == "lazy_free") then elseif (result.type:lower() == "lazy_free") then
includeDirEx(info.path) includeDirEx(info.path)
handleJSONInclude(result, false, incFiles) handleJSONInclude(this, false, incFiles)
elseif (result.type:lower() == "root") then elseif (result.type:lower() == "root") then
includeDirEx(info.path) includeDirEx(info.path)
handleJSONInclude(result, result.noRootInclude, incFiles) handleJSONInclude(this, result.noRootInclude, incFiles)
elseif (result.type:lower() == "generic") then elseif (result.type:lower() == "generic") then
handleJSONInclude(result, false, incFiles) handleJSONInclude(this, false, incFiles)
elseif ((result.type:lower() == "utility") or (result.type:lower() == "blank")) then
return
end end
end end
local handleBuildEvent = function(obj)
local type = ""
if ( obj.lua) then
type = "lua"
elseif (obj.bin) then
type = "bin"
else
return
end
auAddBuildAction(obj.when, type, obj[type], obj.isCwdProjRoot)
end
local handleDllImportMaybe = function(this)
if (this.info.isShared) then
auForEach(this.result.dllimport, defines)
end
end
local handleDllExportMaybe = function(this)
if (this.info.isShared) then
auForEach(this.result.dllexport, defines)
end
end
local handleDependsShort = function(dep, this, soft)
dep = translateDep(this, dep)
local processor = auGetProjectProcessor(this:translateDep(dep))
if (not processor) then
if (soft) then
print("Not including, ", dep)
return
end
fatal("Missing project", dep)
end
if (auIsProjectIntialized(dep) and not _G["_linkingcur"][dep]) then
processor:handleLink()
end
end
local processSubLinks = function(this) local processSubLinks = function(this)
auRequire("Core/JSON/JSON").projectHandlers.runProjectLink(this, result, function(dep, soft) auRequire("Core/JSON/JSON").projectHandlers.runProjectLink(this, result, function(dep, soft)
print("LINK-> ", dep, soft) auLinkProject(this:translateDep(dep), soft)
handleDependsShort(dep, this, soft)
end) end)
end end
@ -127,15 +71,6 @@ function JsonProcessor(info)
auForEach(result.linkSources, handleSourcesRel, info.path) auForEach(result.linkSources, handleSourcesRel, info.path)
local erase = false;
if (not _G["_linkingcur"]) then
erase = true
_G["_linkingcur"] = {}
end
_G["_linkingcur"][this.info.name] = true
local type = this.result.type local type = this.result.type
if ((type:lower() == "utility") or (type:lower() == "blank")) then if ((type:lower() == "utility") or (type:lower() == "blank")) then
@ -149,10 +84,7 @@ function JsonProcessor(info)
--if (not this.info.isStatic) then --if (not this.info.isStatic) then
processSubLinks(this) processSubLinks(this)
--end --end
if (erase) then
_G["_linkingcur"] = nil
end
end end
local publicDepends = function(name, this, soft) local publicDepends = function(name, this, soft)
@ -166,33 +98,30 @@ function JsonProcessor(info)
return return
end end
local cur = nil local cur = auGetCurrentProjectMeta()
if (circular) then
cur = auGetCurrentProjectMeta()
else
cur = this.info
end
local pendingOps = {}
if (cur and cur.isShared) then if (cur and cur.isShared) then
-- shared libraries are only allowed to import other shared libraries table.insert(pendingOps, "dllimport")
handleDllImportMaybe(this)
elseif (cur and cur.isStatic) then elseif (cur and cur.isStatic) then
-- static libs are allowed to reference dllexports in translation units of the parent shared module table.insert(pendingOps, "dllexport")
handleDllExportMaybe(this) table.insert(pendingOps, "staticImport")
auForEach(result.staticImport, defines)
end end
if (this.info.isStatic) then if (this.info.isStatic) then
auForEach(result.staticImpDefines, defines) table.insert(pendingOps, "staticImpDefines")
end end
table.insert(pendingOps, "include")
auForEach(result["include-depends"], publicDepends, this, false) table.insert(pendingOps, "include-depends")
auForEach(result["include-soft-depends"], publicDepends, this, true) table.insert(pendingOps, "include-soft-depends")
handleInclude(this, false) handleInclude(this, false)
defines(("_auhas_" .. this.result.name):upper():gsub("%-", "_") .. "=1") defines(("_auhas_" .. this.result.name):upper():gsub("%-", "_") .. "=1")
auRequire("Core/JSON/JSON").projectHandlers.runProjectImport(this, result, pendingOps, function(dep, soft)
publicDepends(dep, this, soft)
end)
end end
@ -200,11 +129,6 @@ function JsonProcessor(info)
auRequire("Core/JSON/JSON").projectHandlers.runProjectLink(this, result, resolve) auRequire("Core/JSON/JSON").projectHandlers.runProjectLink(this, result, resolve)
end end
local handleParse = function(this)
end
local handleProcess = function (a) local handleProcess = function (a)
local result = a.result local result = a.result
local name = a.info.name local name = a.info.name
@ -279,39 +203,7 @@ function JsonProcessor(info)
os.exit() os.exit()
end end
_G["_linkingcur"] = {}
_G["_linkingcur"][name] = true
handleInclude(a, true) handleInclude(a, true)
local handleDepends = function(dep, this, soft)
local processor = auGetProjectProcessor(this:translateDep(dep))
if (not processor) then
if (soft) then
print("Not including, ", dep)
return
end
fatal("Missing project", dep)
end
local macro = ("_auhas_" .. dep):upper():gsub("%-", "_");
if (auIsProjectIntialized(dep)) then
defines(macro .. "=1")
processor:handleReference(isWeakCircularReference(dep))
if (not this.info.isStatic) then
processor:handleLink()
end
else
--defines(macro .. "=0")
if (not soft) then
fatal("missing project: ", dep)
end
end
end
info.m4_files = {} info.m4_files = {}
@ -330,7 +222,6 @@ function JsonProcessor(info)
local processJsonBlock = function(object) local processJsonBlock = function(object)
auRequire("Core/JSON/JSON").projectHandlers.runProjectBlock(a, object) auRequire("Core/JSON/JSON").projectHandlers.runProjectBlock(a, object)
--auForEach(object["soft-depends"], handleDepends, a, true)
auForEach(object.unpack, runCopies, info.path, info.name) auForEach(object.unpack, runCopies, info.path, info.name)
addM4Defines(object.m4Defines) addM4Defines(object.m4Defines)
end end
@ -378,11 +269,6 @@ function JsonProcessor(info)
} }
valaGo(extended) valaGo(extended)
end end
auForEach(result.events, handleBuildEvent, info.path)
_G["_linkingcur"] = nil
end end
auForEach(result.subprojs, function(subproj) auForEach(result.subprojs, function(subproj)

View File

@ -166,6 +166,8 @@ local function pushProject(project, callback)
pushProjectState(project.info.name, project.info.path, callback) pushProjectState(project.info.name, project.info.path, callback)
end end
_auLinkGuard = {}
-- private -- private
local function processInit(project) local function processInit(project)
if (project.isInitialized) then if (project.isInitialized) then
@ -253,6 +255,8 @@ local function processNS(namespace)
_auFatalMsg = {} _auFatalMsg = {}
_auFatalMsg["starting projects"] = namespace _auFatalMsg["starting projects"] = namespace
auForEach(projsIdxs, function(idx) auForEach(projsIdxs, function(idx)
_auLinkGuard = {}
_auLinkGuard[projs[idx].info.name]= {}
processProject(projs[idx].info.name) processProject(projs[idx].info.name)
end) end)
end end
@ -373,32 +377,79 @@ local function getCurrentProjectName()
return _auCurrentProject return _auCurrentProject
end end
local function importAndLinkProject(dep, soft)
local processor = getProjectProcessorOrThrow(dep)
processor:handleReference(isWeakCircularReference(dep))
if (auGetCurrentProjectMeta().isStatic) then
return true
end
processor:handleLink()
return true
end
local function includeAuProject(dep, soft) local function includeAuProject(dep, soft)
local processor = getProjectProcessorOrThrow(dep) local processor = getProjectProcessor(dep)
processor:handleReference() if (not processor) then
return false
end
local processor = getProjectProcessor(dep)
if (not processor) then
return false
end
local a = _auProjects[dep]
if (not a) then
if (not soft) then
auFatal("missing project: ", dep)
else
return false
end
end
pushProject(a, function()
_auFatalMsg = {}
_auFatalMsg["processing project ref"] = a.info.name
processor:handleReference(isWeakCircularReference(dep))
end)
return true return true
end end
local function linkAuProject(dep, soft) local function linkAuProject(dep, soft)
local processor = getProjectProcessorOrThrow(dep) local processor = getProjectProcessor(dep)
if (not processor:getMeta().isStatic) then if (not processor) then
processor:handleLink() return false
end end
local a = _auProjects[dep]
if (not a) then
if (not soft) then
auFatal("missing project: ", dep)
else
return false
end
end
if (_auLinkGuard[dep] ) then
return
end
_auLinkGuard[dep] = dep
--if (not processor:getMeta().isStatic) then
pushProject(a, function()
_auFatalMsg = {}
_auFatalMsg["processing project link"] = a.info.name
processor:handleLink()
end)
--end
return true return true
end end
local function importAndLinkProject(dep, soft)
local processor = getProjectProcessorOrThrow(dep)
includeAuProject(dep, soft)
if (auGetCurrentProjectMeta().isStatic) then
return true
end
linkAuProject(dep, soft)
return true
end
local function addFeature(feature) local function addFeature(feature)
--print("adding feature ", feature) --print("adding feature ", feature)