From 7e908a52265f414304f1262f346aade9f2937e3c Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 28 Sep 2016 13:06:48 +0200 Subject: [PATCH] Build/Package: Improve package builder, add unit tests Former-commit-id: 4dd27dd88564a8527dce268c3941f92804a55ade [formerly fdf45e4846285005a6dfccb940756b9d1b092b3a] [formerly 8f0ba428a30ab1716bc93545b7a5eb491176e600 [formerly d4a711f0813706bbd9ef094c4340e7dca2de92fe]] Former-commit-id: 2fbcb21bda1b9660c2dbacd17571adb517342926 [formerly 75446e538072a1fae14aee28b528899be3c217ea] Former-commit-id: e53d8b6e050f5887e86ff7d7825c514b725f936b --- build/scripts/actions/package.lua | 84 +++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 22 deletions(-) diff --git a/build/scripts/actions/package.lua b/build/scripts/actions/package.lua index 254bbec26..b62ca3643 100644 --- a/build/scripts/actions/package.lua +++ b/build/scripts/actions/package.lua @@ -48,6 +48,18 @@ ACTION.Function = function () Masks = {"**.*"}, Source = "../examples/bin/resources/", Target = "examples/bin/resources/" + }, + -- Unit test sources + { + Masks = {"**.hpp", "**.inl", "**.cpp"}, + Source = "../tests/", + Target = "tests/src/" + }, + -- Unit test resources + { + Masks = {"**.*"}, + Source = "../tests/resources/", + Target = "tests/resources/" } } @@ -76,9 +88,17 @@ ACTION.Function = function () -- Demo executable (Windows) table.insert(copyTargets, { Masks = {"Demo*.exe"}, - Source = "../examples/bin", - Target = "examples/bin" + Source = "../examples/bin/", + Target = "examples/bin/" }) + + -- Unit test (Windows) + table.insert(copyTargets, { + Masks = {"*.exe"}, + Source = "../tests/", + Target = "tests/" + }) + elseif (os.is("macosx")) then -- Engine/SDK binaries table.insert(copyTargets, { @@ -101,13 +121,22 @@ ACTION.Function = function () Target = "bin/" }) - -- Demo executable (Windows) + -- Demo executable (OS X) table.insert(copyTargets, { Masks = {"Demo*"}, Filter = function (path) return path.getextension(path) == "" end, - Source = "../examples/bin", - Target = "examples/bin" + Source = "../examples/bin/", + Target = "examples/bin/" }) + + -- Unit test (OS X) + table.insert(copyTargets, { + Masks = {"*.*"}, + Filter = function (path) return path.getextension(path) == "" end, + Source = "../tests/", + Target = "tests/" + }) + else -- Engine/SDK binaries table.insert(copyTargets, { @@ -130,12 +159,20 @@ ACTION.Function = function () Target = "bin/" }) - -- Demo executable (Windows) + -- Demo executable (Linux) table.insert(copyTargets, { Masks = {"Demo*"}, Filter = function (path) return path.getextension(path) == "" end, - Source = "../examples/bin", - Target = "examples/bin" + Source = "../examples/bin/", + Target = "examples/bin/" + }) + + -- Unit test (Linux) + table.insert(copyTargets, { + Masks = {"*.*"}, + Filter = function (path) return path.getextension(path) == "" end, + Source = "../tests/", + Target = "tests/" }) end @@ -143,24 +180,14 @@ ACTION.Function = function () -- Processing os.mkdir(packageDir) + local size = 0 for k,v in pairs(copyTargets) do local target = packageDir .. v.Target local includePrefix = v.Source - for k,v in pairs(os.matchdirs(includePrefix .. "**")) do - local relPath = v:sub(#includePrefix + 1) - - local targetPath = target .. relPath - - if (not os.isdir(targetPath)) then - local ok, err = os.mkdir(targetPath) - if (not ok) then - print("Failed to create directory \"" .. targetPath .. "\": " .. err) - end - end - end local targetFiles = {} for k, mask in pairs(v.Masks) do + print(includePrefix .. mask .. " => " .. target) local files = os.matchfiles(includePrefix .. mask) if (v.Filter) then for k,path in pairs(files) do @@ -169,7 +196,7 @@ ACTION.Function = function () end end end - + targetFiles = table.join(targetFiles, files) end @@ -177,13 +204,26 @@ ACTION.Function = function () local relPath = v:sub(#includePrefix + 1) local targetPath = target .. relPath + local targetDir = path.getdirectory(targetPath) + if (not os.isdir(targetDir)) then + local ok, err = os.mkdir(targetDir) + if (not ok) then + print("Failed to create directory \"" .. targetDir .. "\": " .. err) + end + end + local ok, err = os.copyfile(v, targetPath) if (not ok) then print("Failed to copy \"" .. v .. "\" to \"" .. targetPath .. "\": " .. err) end + + local stat = os.stat(targetPath) + if (stat) then + size = size + stat.size + end end end - print(string.format("Package successfully created at \"%s\"", packageDir)) + print(string.format("Package successfully created at \"%s\" (%u MB, %s)", packageDir, size / (1024 * 1024), libDir)) end