-- Represent a specific Gear4 Library (GearCore or one of the satellite) -- Each Library is composed of 3 Projects: -- * the standard library -- * the blob library (_compile) -- * the test executable require "utils" require "operators" require "functools" require "itertools" require "project" Library = { -- The name of the library name = "Unknown", -- The Library Project LibProject = LibProject, -- The Test Project TestProject = TestProject, excludedirs = { "tests", "projects", "doc", "extern" } } function Library:New(sat) sat = sat or {} setmetatable(sat, self) self.__index = self return sat end -- Log a message preceded by the library name. function Library:Log(log, ...) printf("%s: " .. log, self.name, unpack(arg)) end -- Log a message only on debug. function Library:Debug(...) if _debug then self:Log(unpack(arg)) end end -- Configure the library, setting various parameters. function Library:Configure() self:Debug("Configuration") self.basename = self.name .. "_" .. self.platform .. self.suffix self.dir = self.dir or self.name self.proj = joindir(self.dir, "projects", self.subdir) self.tests = joinpath(self.dir, "tests") self.pch = nil -- not using pch, otherwise this is the name of the file without extension local relsources = partial(path.getrelative, self.dir) -- only remove the final '/' local modpath = joinpath(self.dir, "*") function modulesonly(mod) return not table.contains(self.excludedirs, mod) end self.modules = self.modules or collect(filter(modulesonly,map(relsources, matchdirs(modpath)))) end function Library:GetConfig(name) return { name = name, platform = self.platform, suffix = self.suffix, noblob = self.noblob or false, modules = self.modules, library = self, location = self.proj, dir = self.dir, externals = self.externals, libext = self.libext, includedirs = { '.', eal_api_path, }, } end -- Create the main project. function Library:CreateMainProject() local config = self:GetConfig(self.basename) updatetable(config, { targetdir = joinpath(self.top, "lib", self.subdir), blob = self.blob, -- replace "blob = self.blob" with "noblob = true" to test without blobs modules = self.modules, extramodules = self.extramodules, pch = self.pch }) return self.LibProject:New(config) end function Library:CreateExternalLib(name, config) local baseconfig = self:GetConfig(name .. "_" .. self.platform .. self.suffix) baseconfig.pch = nil -- remove the pch. updatetable(baseconfig, { targetdir = joinpath(self.top, "lib", self.subdir), noblob = true, externals = {}, }, config) local lib = self.LibProject:New(baseconfig) lib:Populate() self.projects[name] = lib return lib end -- Create the test project. function Library:CreateTestProject() local config = self:GetConfig(self.basename .. "_tests") table.insert(config.includedirs, joindir("gear_testing", "extern")) updatetable(config, { targetdir = joinpath(self.proj, "exe"), dependencies = collect( unique({ "gear_testing", "gear_core", iif(eal_impl, eal_impl.name), self.name, })), modules = { "tests" } }) return self.TestProject:New(config) end function Library:Initialize() self:Configure() self.projects = { library = self:CreateMainProject(), tests = self:CreateTestProject() } for project in iter(self.projects) do project:Populate() end end -- Generate all projects in the Library. function Library:Generate() -- Call Generate() on all projects, starting with the first "test" project first_test_project = nil other_projects = {} i = 0 for project in iter(self.projects) do if first_test_project == nil and project.name:find("tests", 1, true) ~= nil then first_test_project = project self:Debug("Generation project " .. first_test_project.name) first_test_project:Generate() else other_projects[i] = project i = i + 1 end end for j = 0, table.getn(other_projects), 1 do self:Debug("Generation project " .. other_projects[j].name) other_projects[j]:Generate() end end