Ported CodeLite to trees

This commit is contained in:
Jason Perkins 2011-05-12 16:00:07 -04:00
parent eedf10ef6a
commit f7609a9fa5
7 changed files with 124 additions and 35 deletions

View File

@ -4,6 +4,8 @@
-- Copyright (c) 2008-2009 Jason Perkins and the Premake project
--
premake.codelite = { }
newaction {
trigger = "codelite",
shortname = "CodeLite",
@ -18,11 +20,11 @@
},
onsolution = function(sln)
premake.generate(sln, "%%.workspace", premake.codelite_workspace)
premake.generate(sln, "%%.workspace", premake.codelite.workspace)
end,
onproject = function(prj)
premake.generate(prj, "%%.project", premake.codelite_project)
premake.generate(prj, "%%.project", premake.codelite.project)
end,
oncleansolution = function(sln)

View File

@ -1,14 +1,50 @@
--
-- codelite_project.lua
-- Generate a CodeLite C/C++ project file.
-- Copyright (c) 2009 Jason Perkins and the Premake project
-- Copyright (c) 2009, 2011 Jason Perkins and the Premake project
--
function premake.codelite_project(prj)
local codelite = premake.codelite
local tree = premake.tree
--
-- Write out a list of the source code files in the project.
--
function codelite.files(prj)
local tr = premake.project.buildsourcetree(prj)
tree.traverse(tr, {
-- folders are handled at the internal nodes
onbranchenter = function(node, depth)
_p(depth, '<VirtualDirectory Name="%s">', node.name)
end,
onbranchexit = function(node, depth)
_p(depth, '</VirtualDirectory>')
end,
-- source files are handled at the leaves
onleaf = function(node, depth)
_p(depth, '<File Name="%s"/>', node.path)
end,
}, false, 1)
end
--
-- The main function: write out the project file.
--
function premake.codelite.project(prj)
io.indent = " "
_p('<?xml version="1.0" encoding="utf-8"?>')
_p('<CodeLite_Project Name="%s">', premake.esc(prj.name))
premake.walksources(prj, premake.codelite_files)
-- Write out the list of source code files in the project
codelite.files(prj)
local types = {
ConsoleApp = "Executable",
@ -124,24 +160,3 @@
_p('</CodeLite_Project>')
end
--
-- Write out entries for the files element; called from premake.walksources().
--
function premake.codelite_files(prj, fname, state, nestlevel)
local indent = string.rep(" ", nestlevel + 1)
if (state == "GroupStart") then
io.write(indent .. '<VirtualDirectory Name="' .. path.getname(fname) .. '">\n')
elseif (state == "GroupEnd") then
io.write(indent .. '</VirtualDirectory>\n')
else
io.write(indent .. '<File Name="' .. fname .. '"/>\n')
end
end

View File

@ -1,10 +1,10 @@
--
-- codelite_workspace.lua
-- Generate a CodeLite workspace file.
-- Copyright (c) 2009 Jason Perkins and the Premake project
-- Copyright (c) 2009, 2011 Jason Perkins and the Premake project
--
function premake.codelite_workspace(sln)
function premake.codelite.workspace(sln)
_p('<?xml version="1.0" encoding="utf-8"?>')
_p('<CodeLite_Workspace Name="%s" Database="./%s.tags">', premake.esc(sln.name), premake.esc(sln.name))

View File

@ -53,13 +53,16 @@
--
function io.printf(msg, ...)
if (not io.eol) then
if not io.eol then
io.eol = "\n"
end
local s
if not io.indent then
io.indent = "\t"
end
if type(msg) == "number" then
s = string.rep("\t", msg) .. string.format(unpack(arg))
s = string.rep(io.indent, msg) .. string.format(unpack(arg))
else
s = string.format(msg, unpack(arg))
end

View File

@ -0,0 +1,64 @@
--
-- tests/actions/codelite/codelite_files.lua
-- Validate generation of files block in CodeLite C/C++ projects.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.codelite_files = { }
local suite = T.codelite_files
local codelite = premake.codelite
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
io.indent = " "
premake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
codelite.files(prj)
end
--
-- Test grouping and nesting
--
function suite.SimpleSourceFile()
files { "hello.c" }
prepare()
test.capture [[
<File Name="hello.c"/>
]]
end
function suite.SingleFolderLevel()
files { "src/hello.c" }
prepare()
test.capture [[
<VirtualDirectory Name="src">
<File Name="src/hello.c"/>
</VirtualDirectory>
]]
end
function suite.MultipleFolderLevels()
files { "src/greetings/hello.c" }
prepare()
test.capture [[
<VirtualDirectory Name="src">
<VirtualDirectory Name="greetings">
<File Name="src/greetings/hello.c"/>
</VirtualDirectory>
</VirtualDirectory>
]]
end

View File

@ -103,12 +103,16 @@
dofile("actions/make/test_make_pch.lua")
dofile("actions/make/test_make_linking.lua")
-- Xcode tests
-- Xcode3 tests
dofile("actions/xcode/test_xcode_common.lua")
dofile("actions/xcode/test_xcode_project.lua")
dofile("actions/xcode/test_xcode_dependencies.lua")
-- Xcode4 tests
dofile("actions/xcode/test_xcode4_workspace.lua")
-- CodeLite tests
dofile("actions/codelite/codelite_files.lua")
--
-- Register a test action

View File

@ -190,11 +190,12 @@
_ARGS = { }
_OPTIONS = { }
premake.solution.list = { }
io.indent = nil
-- reset captured I/O values
test.value_openedfilename = nil
test.value_openedfilemode = nil
test.value_closedfile = false
test.value_closedfile = false
if suite.setup then
return pcall(suite.setup)