From 2be34e3866c94e75ed12b8126e4bf4ad16e02692 Mon Sep 17 00:00:00 2001 From: starkos Date: Thu, 28 May 2009 19:13:50 +0000 Subject: [PATCH] Condensed parameters to walksources to make trimpaths easier to implement --- src/actions/codelite/codelite_project.lua | 2 +- src/actions/vstudio/vs200x_vcproj.lua | 2 +- src/base/project.lua | 18 ++++++------- tests/test_project.lua | 31 ++++++++++++++--------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/actions/codelite/codelite_project.lua b/src/actions/codelite/codelite_project.lua index a58427a8..76777e4b 100644 --- a/src/actions/codelite/codelite_project.lua +++ b/src/actions/codelite/codelite_project.lua @@ -8,7 +8,7 @@ _p('') _p('', premake.esc(prj.name)) - premake.walksources(prj, prj.files, premake.codelite_files) + premake.walksources(prj, premake.codelite_files) local types = { ConsoleApp = "Executable", diff --git a/src/actions/vstudio/vs200x_vcproj.lua b/src/actions/vstudio/vs200x_vcproj.lua index c69a5e29..f9242f86 100644 --- a/src/actions/vstudio/vs200x_vcproj.lua +++ b/src/actions/vstudio/vs200x_vcproj.lua @@ -534,7 +534,7 @@ _p('\t') _p('\t') - premake.walksources(prj, prj.files, _VS.files) + premake.walksources(prj, _VS.files) _p('\t') _p('\t') diff --git a/src/base/project.lua b/src/base/project.lua index a7beaa6a..2fbca552 100644 --- a/src/base/project.lua +++ b/src/base/project.lua @@ -505,17 +505,17 @@ -- on the directory hierarchy. -- - local function walksources(prj, files, fn, group, nestlevel, finished) + local function walksources(cfg, fn, group, nestlevel, finished) local grouplen = group:len() local gname = iif(group:endswith("/"), group:sub(1, -2), group) -- open this new group if (nestlevel >= 0) then - fn(prj, gname, "GroupStart", nestlevel) + fn(cfg, gname, "GroupStart", nestlevel) end -- scan the list of files for items which belong in this group - for _,fname in ipairs(files) do + for _,fname in ipairs(cfg.files) do if (fname:startswith(group)) then -- is there a subgroup within this item? @@ -524,7 +524,7 @@ local subgroup = fname:sub(1, split) if (not finished[subgroup]) then finished[subgroup] = true - walksources(prj, files, fn, subgroup, nestlevel + 1, finished) + walksources(cfg, fn, subgroup, nestlevel + 1, finished) end end @@ -532,19 +532,19 @@ end -- process all files that belong in this group - for _,fname in ipairs(files) do + for _,fname in ipairs(cfg.files) do if (fname:startswith(group) and not fname:find("[^\.]/", grouplen + 1)) then - fn(prj, fname, "GroupItem", nestlevel + 1) + fn(cfg, fname, "GroupItem", nestlevel + 1) end end -- close the group if (nestlevel >= 0) then - fn(prj, gname, "GroupEnd", nestlevel) + fn(cfg, gname, "GroupEnd", nestlevel) end end - function premake.walksources(prj, files, fn) - walksources(prj, files, fn, "", -1, {}) + function premake.walksources(cfg, fn) + walksources(cfg, fn, "", -1, {}) end diff --git a/tests/test_project.lua b/tests/test_project.lua index 0a293fc9..8b9f4b92 100644 --- a/tests/test_project.lua +++ b/tests/test_project.lua @@ -1,15 +1,18 @@ -- -- tests/test_project.lua -- Automated test suite for the project support functions. --- Copyright (c) 2008 Jason Perkins and the Premake project +-- Copyright (c) 2008, 2009 Jason Perkins and the Premake project -- T.project = { } - local result + local cfg, result function T.project.setup() _ACTION = "gmake" + cfg = {} + cfg.files = {} + cfg.trimpaths = {} result = "\n" end @@ -31,30 +34,33 @@ result = result .. string.rep("-", nestlevel) .. item .. "\n" end + function T.project.walksources_OnNoFiles() - premake.walksources({}, {}, walktest) + premake.walksources(cfg, walktest) test.isequal("\n" .. "" ,result) end + function T.project.walksources_OnSingleFile() - local files = { + cfg.files = { "hello.cpp" } - premake.walksources({}, files, walktest) + premake.walksources(cfg, walktest) test.isequal("\n" .. "hello.cpp\n" ,result) end + function T.project.walksources_OnNestedGroups() - local files = { + cfg.files = { "rootfile.c", "level1/level1.c", "level1/level2/level2.c" } - premake.walksources({}, files, walktest) + premake.walksources(cfg, walktest) test.isequal("\n" .. "\n" .. "-\n" @@ -66,11 +72,12 @@ ,result) end + function T.project.walksources_OnDottedFolders() - local files = { + cfg.files = { "src/lua-5.1.2/lapi.c" } - premake.walksources({}, files, walktest) + premake.walksources(cfg, walktest) test.isequal("\n" .. "\n" .. "-\n" @@ -80,15 +87,15 @@ ,result) end + function T.project.walksources_OnDotDotLeaders() - local files = { + cfg.files = { "../src/hello.c", } - premake.walksources({}, files, walktest) + premake.walksources(cfg, walktest) test.isequal("\n" .. "<../src>\n" .. "-../src/hello.c\n" .. "\n" ,result) end - \ No newline at end of file