From 946d2cea7a585142e7c42d8deb496ed006597b1b Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 3 Mar 2016 14:10:52 +0100 Subject: [PATCH] SDK: Add global headers (improved global headers script) Former-commit-id: f04a3526b185c6c5b8025168cd56829898082bc6 --- SDK/include/NDK/Components.hpp | 17 +++++ SDK/include/NDK/Systems.hpp | 13 ++++ build/scripts/actions/generateheaders.lua | 77 +++++++++++++++++------ 3 files changed, 87 insertions(+), 20 deletions(-) create mode 100644 SDK/include/NDK/Components.hpp create mode 100644 SDK/include/NDK/Systems.hpp diff --git a/SDK/include/NDK/Components.hpp b/SDK/include/NDK/Components.hpp new file mode 100644 index 000000000..a6d41e543 --- /dev/null +++ b/SDK/include/NDK/Components.hpp @@ -0,0 +1,17 @@ +// This file was automatically generated on 03 Mar 2016 at 14:09:12 + +#pragma once + +#ifndef NDK_COMPONENTS_GLOBAL_HPP +#define NDK_COMPONENTS_GLOBAL_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // NDK_COMPONENTS_GLOBAL_HPP diff --git a/SDK/include/NDK/Systems.hpp b/SDK/include/NDK/Systems.hpp new file mode 100644 index 000000000..d9bd12c75 --- /dev/null +++ b/SDK/include/NDK/Systems.hpp @@ -0,0 +1,13 @@ +// This file was automatically generated on 03 Mar 2016 at 14:09:12 + +#pragma once + +#ifndef NDK_SYSTEMS_GLOBAL_HPP +#define NDK_SYSTEMS_GLOBAL_HPP + +#include +#include +#include +#include + +#endif // NDK_SYSTEMS_GLOBAL_HPP diff --git a/build/scripts/actions/generateheaders.lua b/build/scripts/actions/generateheaders.lua index 01cea67e8..943919a90 100644 --- a/build/scripts/actions/generateheaders.lua +++ b/build/scripts/actions/generateheaders.lua @@ -1,11 +1,20 @@ ACTION.Name = "GenerateHeaders" ACTION.Description = "Generate a global header for each module" +ACTION.ModuleExcludes = {} +ACTION.ModuleExcludes["ConfigCheck.hpp"] = true +ACTION.ModuleExcludes["Debug.hpp"] = true +ACTION.ModuleExcludes["DebugOff.hpp"] = true +ACTION.ModuleExcludes["ThreadSafety.hpp"] = true +ACTION.ModuleExcludes["ThreadSafetyOff.hpp"] = true + +local action = ACTION ACTION.Function = function () + local paths = {} + local modules = os.matchdirs("../include/Nazara/*") for k, modulePath in pairs(modules) do local moduleName = modulePath:match(".*/(.*)") - print(moduleName) local config, err = io.open(modulePath .. "/Config.hpp", "r") local head = "" @@ -14,44 +23,72 @@ ACTION.Function = function () end for line in config:lines() do - head = head .. line .. "\n" - if (line == "#pragma once") then -- On s'arrête au #pragma once, qu'on inclut quand même + if (line == "#pragma once") then -- Stop before including the #pragma once as it's already written automatically break end + head = head .. line .. "\n" end config:close() - local header, err = io.open(modulePath .. ".hpp", "w+") + table.insert(paths, { + Excludes = action.ModuleExcludes, + Header = head, + HeaderGuard = "NAZARA_GLOBAL_" .. moduleName:upper() .. "_HPP", + Name = "Nazara" .. moduleName, + SearchDir = modulePath, + Target = modulePath .. ".hpp", + TopDir = "Nazara" + }) + end + + table.insert(paths, { + Excludes = {}, + HeaderGuard = "NDK_COMPONENTS_GLOBAL_HPP", + Name = "NDK Components", + SearchDir = "../SDK/include/NDK/Components", + TopDir = "NDK", + Target = "../SDK/include/NDK/Components.hpp" + }) + + table.insert(paths, { + Excludes = {}, + HeaderGuard = "NDK_SYSTEMS_GLOBAL_HPP", + Name = "NDK Systems", + SearchDir = "../SDK/include/NDK/Systems", + TopDir = "NDK", + Target = "../SDK/include/NDK/Systems.hpp" + }) + + for k,v in ipairs(paths) do + print(v.Name) + local header, err = io.open(v.Target, "w+") if (not header) then - error("Failed to create header file: " .. err) + error("Failed to create header file (" .. v.Target .. "): " .. err) end header:write("// This file was automatically generated on " .. os.date("%d %b %Y at %X") .. "\n\n") - header:write(head .. "\n") + if (v.Header) then + header:write(v.Header) + end - -- Protection du multi-including - local preprocessorName = "NAZARA_GLOBAL_" .. string.upper(moduleName) .. "_HPP" - header:write("#ifndef " .. preprocessorName .. "\n") - header:write("#define " .. preprocessorName .. "\n\n") + header:write("#pragma once\n\n") + header:write("#ifndef " .. v.HeaderGuard .. "\n") + header:write("#define " .. v.HeaderGuard .. "\n\n") - local files = os.matchfiles(modulePath .. "/*.hpp") + local files = os.matchfiles(v.SearchDir .. "/*.hpp") local count = 0 for k, filePath in pairs(files) do - local include, fileName = filePath:match(".*(Nazara/.*/(.*))") - if (fileName ~= "ConfigCheck.hpp" and - fileName ~= "Debug.hpp" and - fileName ~= "DebugOff.hpp" and - fileName ~= "ThreadSafety.hpp" and - fileName ~= "ThreadSafetyOff.hpp") then + local include, fileName = filePath:match(".*(" .. v.TopDir .. "/.*/(.*))") + if (not v.Excludes[fileName]) then header:write("#include <" .. include .. ">\n") count = count + 1 end end - - header:write("\n#endif // " .. preprocessorName .. "\n") + + header:write("\n#endif // " .. v.HeaderGuard .. "\n") header:close() - + print(string.format("-#include count: %d", count)) end end