Build/Core/JSON/jsonProjectBase.lua

247 lines
7.1 KiB
Lua

local auProject = auRequire("Core/project").startProject
local projectHandlers = auRequire("Core/JSON/jsonProjectHandlers")
local otherLangs = auRequire("Core/OtherLang")
function JsonProcessor(info)
local interface = {}
local result, err = json.decode(io.readfile(info.jpath))
if (not result) then
auFatal("parse error", info.path, err)
return
end
if (not info.name) then
info.name = result.name
end
if (not info.projectType) then
info.projectType = result.projectType
end
result.name = info.name
local otherLang = otherLangs[info.projectType]
if (otherLang) then
info.projectType = "utility"
interface.lang = {
name = info.projectType
}
otherLang.processJson(info, interface.lang, result)
end
-- ported
local includeDirEx = function(path, incFiles)
includedirs(path)
if (not incFiles) then
return
end
files(path .. "/**.h")
files(path .. "/**.hpp")
files(path .. "/**.inl")
end
local handleJSONInclude = function(this, val, incFiles)
projectHandlers.runProjectImport(this, result, {"include", "includes", "actions"}, function(dep, soft)
auIncludeProject(this:translateDep(dep), soft)
end)
end
local handleInclude = function(this, incFiles)
local result = this.result
auForEach(result.defines, defines)
if (result.type:lower() == "aurora") then
includeDirEx(info.path .. "/Include")
elseif (result.type:lower() == "lazy_free") then
includeDirEx(info.path)
handleJSONInclude(this, false, incFiles)
elseif (result.type:lower() == "root") then
includeDirEx(info.path)
handleJSONInclude(this, result.noRootInclude, incFiles)
elseif (result.type:lower() == "generic") then
handleJSONInclude(this, false, incFiles)
end
end
local handleLink = function(this)
dependson(this.info.name)
auForEach(result.linkSources, function(source)
files(path.join(this:getMeta().path, source))
end)
local type = this.result.type
if ((type:lower() == "utility") or (type:lower() == "blank")) then
return
end
if ((not this.result.noLink)) then
links(this.info.name)
end
projectHandlers.runProjectLink(this, result, function(dep, soft)
auLinkProject(this:translateDep(dep), soft)
end)
end
local handleReference = function(this, circular)
local type = this.result.type
if ((type:lower() == "utility") or (type:lower() == "blank")) then
return
end
local cur = auGetCurrentProjectMeta()
local staticImport = circular
local jsonKeys = {}
if (cur and cur.isShared and not circular) then
table.insert(jsonKeys, "dllimport")
elseif (cur and cur.isStatic and not circular) then
table.insert(jsonKeys, "dllexport")
table.insert(jsonKeys, "staticImport")
table.insert(jsonKeys, "staticImpDefines")
elseif (circular) then
table.insert(jsonKeys, "staticImport")
table.insert(jsonKeys, "staticImpDefines")
end
table.insert(jsonKeys, "include")
table.insert(jsonKeys, "include-depends")
table.insert(jsonKeys, "include-soft-depends")
handleInclude(this, false)
defines(("_auhas_" .. this.result.name):upper():gsub("%-", "_") .. "=1")
projectHandlers.runProjectImport(this, result, jsonKeys, function(dep, soft)
auIncludeProject(this:translateDep(dep), soft)
end)
end
local resolveDependencies = function(this, resolve)
projectHandlers.runProjectLink(this, result, resolve)
end
local handleProcess = function (this)
local result = this.result
local name = this:getMeta().name
local path = this:getMeta().path
local isUtility = false
local project = {
name = info.name,
projectType = info.projectType or result.projectType,
dest = info.out,
noLink = result.noLink
}
if (result.noLink) then
project.projectType = "none"
info.projectType = "none"
end
if (project.projectType == "none") then
if (os.host() == "linux") then
project.projectType = "utility"
end
end
if (interface.lang) then
project.projectType = "utility"
result.type = "utility"
end
if (result.type:lower() == "aurora") then
local srcPath = path .. "/Source"
local incPath = path .. "/Include" -- /Source is emitted by design. Use it as a prefix in <> includes; eg, #include <Source/MyLib.hpp>
project.src = srcPath
project.inc = {incPath, path}
auProject(project)
elseif (result.type:lower() == "lazy_free") then
project.src = path .. "/*.*"
project.inc = path
auProject(project)
elseif (result.type:lower() == "root") then
project.src = path
project.inc = path
auProject(project)
elseif (result.type:lower() == "generic") then
auProject(project)
elseif (result.type:lower() == "utility") then
auProject(project)
kind "utility"
isUtility = true
elseif (result.type:lower() == "blank") then
return
else
auFatal("invalid project type", result.type)
end
handleInclude(this, true)
if (not isUtility) then
projectHandlers.runProjectBlock(this, result)
if (this:getMeta().projectType:lower() == "sharedlib") then
auForEach(result.dllexport, defines)
end
end
if (interface.lang) then
projectHandlers.runOtherLang(this, result)
otherLang.processProject(info, interface.lang)
end
if (info.options and info.options.alsoEval) then
auForEach(info.options.alsoEval, function(eval)
eval.type = "nvrgunagivuup"
projectHandlers.runProjectBlock(this, eval)
end)
end
end
auForEach(result.subprojs, function(subproj)
local subinfo = {
namespace = info.namespace,
path = path.join(info.path, subproj.path),
projectType = subproj.projectType,
out = info.out,
name = subproj.name,
translations = auCopyTables(info.translations, subproj.translations)
}
auAddVist(subinfo)
end)
interface.result = result
interface.info = info
interface.resolveDependencies = resolveDependencies
interface.process = handleProcess
interface.handleLink = handleLink
interface.handleReference = handleReference
return interface
end
return JsonProcessor