* Added debug environment variable support for Codeblocks using gdb

Changes the name from environmentargs to debugenvs
Effects VS flags EnvironmentArgsInherit and EnvironmentArgsDontMerge which become DebugEnvsInherit and DebugEnvsDontMerge respectively.
This commit is contained in:
Liam Devine 2011-08-23 21:48:16 +01:00
parent fcc2563a23
commit 7185aaf0a0
7 changed files with 147 additions and 57 deletions

View File

@ -26,8 +26,9 @@
* Bug 3297634: Special characters in directory name Xcode3 (jdale)
* Feature 3100194: English alais' for Optimize flags
* Bug 3308203: Incorrect relative paths for gmake sibling static libraries (Adam)
* Added environment argument support for Visual Studio
* Added debug environment variable support for Visual Studio
* Bug 3277343: SM_SERVERR2 is not always defined by default (Martin Ridgers)
* Added debug environment variable support for Codeblocks using gdb
-------
4.3

View File

@ -37,7 +37,27 @@
end
end
function premake.codeblocks.debugenvs(cfg)
--Assumption: if gcc is being used then so is gdb although this section will be ignored by
--other debuggers. If using gcc and not gdb it will silently not pass the
--environment arguments to the debugger
if premake.gettool(cfg) == premake.gcc then
_p(3,'<debugger>')
_p(4,'<remote_debugging target="%s">', premake.esc(cfg.longname))
local args = ''
local sz = #cfg.debugenvs
for idx, v in ipairs(cfg.debugenvs) do
args = args .. 'set env ' .. v
if sz ~= idx then args = args .. '&#x0A;' end
end
_p(5,'<options additional_cmds_before="%s" />',args)
_p(4,'</remote_debugging>')
_p(3,'</debugger>')
else
error('Sorry at this moment there is no support for debug environment variables with this debugger and codeblocks')
end
end
--
-- The main function: write out the project file.
--
@ -152,7 +172,16 @@
codeblocks.files(prj)
_p(2,'<Extensions />')
_p(2,'<Extensions>')
for _, platform in ipairs(platforms) do
for cfg in premake.eachconfig(prj, platform) do
if cfg.debugenvs and #cfg.debugenvs > 0 then
premake.codeblocks.debugenvs(cfg)
end
end
end
_p(2,'</Extensions>')
_p(1,'</Project>')
_p('</CodeBlocks_project_file>')
_p('')

View File

@ -601,12 +601,12 @@
end
end
function vc2010.environmentargs(cfg)
if cfg.environmentargs and #cfg.environmentargs > 0 then
_p(2,'<LocalDebuggerEnvironment>%s%s</LocalDebuggerEnvironment>',table.concat(cfg.environmentargs, "\n")
,iif(cfg.flags.EnvironmentArgsInherit,'\n$(LocalDebuggerEnvironment)','')
function vc2010.debugenvs(cfg)
if cfg.debugenvs and #cfg.debugenvs > 0 then
_p(2,'<LocalDebuggerEnvironment>%s%s</LocalDebuggerEnvironment>',table.concat(cfg.debugenvs, "\n")
,iif(cfg.flags.DebugEnvsInherit,'\n$(LocalDebuggerEnvironment)','')
)
if cfg.flags.EnvironmentArgsDontMerge then
if cfg.flags.DebugEnvsDontMerge then
_p(2,'<LocalDebuggerMergeEnvironment>false</LocalDebuggerMergeEnvironment>')
end
end

View File

@ -54,6 +54,12 @@
scope = "config",
},
debugenvs =
{
kind = "list",
scope = "config",
},
defines =
{
kind = "list",
@ -66,13 +72,7 @@
scope = "config",
usagecopy = true,
},
environmentargs =
{
kind = "list",
scope = "config",
},
excludes =
{
kind = "filelist",
@ -94,11 +94,11 @@
allowed = function(value)
local allowed_flags = {
DebugEnvsDontMerge = 1,
DebugEnvsInherit = 1,
EnableSSE = 1,
EnableSSE2 = 1,
ExtraWarnings = 1,
EnvironmentArgsInherit = 1,
EnvironmentArgsDontMerge =1,
FatalWarnings = 1,
FloatFast = 1,
FloatStrict = 1,

View File

@ -0,0 +1,59 @@
--
-- tests/actions/codeblocks/environment_variables.lua
-- Validate generation of files block in CodeLite C/C++ projects.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.codeblocks_environment = { }
local suite = T.codeblocks_environment
local codeblocks = premake.codeblocks
local old_eol = io.eol
function suite.setup()
_OPTIONS.cc = 'gcc'
old_eol = io.eol
io.eol = '\n'
end
function suite.teardown()
io.eol = old_eol
end
function suite.withVar_bufferContainsDebugger()
local MockName = 'MockName'
codeblocks.debugenvs( {debugenvs = {'foo=bar'},language='C',longname=MockName} )
test.string_contains(io.endcapture(),
'\t\t\t<debugger>\n' ..
'\t\t\t\t<remote_debugging target="'..MockName..'">\n' ..
'\t\t\t\t\t<options additional_cmds_before=.- />\n' ..
'\t\t\t\t</remote_debugging>\n' ..
'\t\t\t</debugger>'
)
end
function suite.format_SetEnvKeyValuePair()
local env_arg = 'foo=bar'
codeblocks.debugenvs( {debugenvs = {env_arg},language='C',longname='DontCare'} )
test.string_contains(io.endcapture(),'<options additional_cmds_before="set env '..env_arg..'" />')
end
function suite.format_mutipleValues_setEnvKeyValuePairEscapeSetEnvKeyValuePair()
local env_arg = { 'foo=bar','baz=qux'}
codeblocks.debugenvs( {debugenvs = env_arg,language='C',longname='DontCare'} )
test.string_contains(io.endcapture(),'<options additional_cmds_before="set env '.. env_arg[1]
..'&#x0A;set env ' .. env_arg[2] .. '" />')
end
--Why is this an error and not silent? Because I feel if you are setting environment variables
--and they are not getting set in your IDE, than that is a problem which premake should not be
--quite about.
--See codeblocks project generator source for the assumption that gcc has anything to do with this setting.
function suite.withVar_noneGccCompiler_willCallError()
_OPTIONS.cc = 'msc'
local called = 0
local real_error = error
error = function() called = 1 end
codeblocks.debugenvs( {debugenvs = {'foo=bar'},language='C',longname='foo'} )
error = real_error
test.isequal(1,called)
end

View File

@ -54,43 +54,43 @@
]]
end
T.vs2010_env_args = { }
local vs10_env_args = T.vs2010_env_args
local env_args = premake.vstudio.vc2010.environmentargs
function vs10_env_args.environmentArgs_notSet_bufferDoesNotContainLocalDebuggerEnvironment()
env_args( {flags={}} )
test.string_does_not_contain(io.endcapture(),'<LocalDebuggerEnvironment>')
end
function vs10_env_args.environmentArgs_set_bufferContainsLocalDebuggerEnvironment()
env_args({flags={},environmentargs ={'key=value'}} )
test.string_contains(io.endcapture(),'<LocalDebuggerEnvironment>')
end
function vs10_env_args.environmentArgs_oneArgformat_openTagKeyValuePairCloseTag()
env_args({flags={},environmentargs ={'key=value'}} )
test.string_contains(io.endcapture(),'<LocalDebuggerEnvironment>key=value</LocalDebuggerEnvironment>')
end
function vs10_env_args.environmentArgs_twoArgformat_openTagKeyValueNewLineSecondPairCloseTag()
env_args({flags={},environmentargs ={'key=value','foo=bar'}} )
test.string_contains(io.endcapture(),'<LocalDebuggerEnvironment>key=value\nfoo=bar</LocalDebuggerEnvironment>')
end
function vs10_env_args.environmentArgs_withOutFlagEnvironmentArgsInherit_doesNotContainLocalDebuggerEnvironmentArg()
env_args({flags={},environmentargs ={'key=value'}} )
test.string_does_not_contain(io.endcapture(),'%$%(LocalDebuggerEnvironment%)')
end
function vs10_env_args.environmentArgs_withFlagEnvironmentArgsInherit_endsWithNewLineLocalDebuggerEnvironmentFollowedByClosedTag()
env_args({flags={EnvironmentArgsInherit=1},environmentargs ={'key=value'}} )
test.string_contains(io.endcapture(),'\n%$%(LocalDebuggerEnvironment%)</LocalDebuggerEnvironment>')
end
function vs10_env_args.environmentArgs_withEnvironmentArgsDontMerge_localDebuggerMergeEnvironmentSetToFalse()
env_args({flags={EnvironmentArgsDontMerge=1},environmentargs ={'key=value'}} )
test.string_contains(io.endcapture(),'<LocalDebuggerMergeEnvironment>false</LocalDebuggerMergeEnvironment>')
end
T.vs2010_debug_environment = { }
local vs10_debug_environment = T.vs2010_debug_environment
local vs2010 = premake.vstudio.vc2010
function vs10_debug_environment.config_noDebugEnvsTable_bufferDoesNotContainLocalDebuggerEnvironment()
vs2010.debugenvs( {flags={}} )
test.string_does_not_contain(io.endcapture(),'<LocalDebuggerEnvironment>')
end
function vs10_debug_environment.config_NoneEmtpyDebugEnvTable_bufferContainsLocalDebuggerEnvironment()
vs2010.debugenvs({flags={},debugenvs ={'key=value'}} )
test.string_contains(io.endcapture(),'<LocalDebuggerEnvironment>')
end
function vs10_debug_environment.format_listContainsOneEntry_openTagKeyValuePairCloseTag()
vs2010.debugenvs({flags={},debugenvs ={'key=value'}} )
test.string_contains(io.endcapture(),'<LocalDebuggerEnvironment>key=value</LocalDebuggerEnvironment>')
end
function vs10_debug_environment.format_listContainsTwoEntries_openTagFirstPairNewLineSecondPairCloseTag()
vs2010.debugenvs({flags={},debugenvs ={'key=value','foo=bar'}} )
test.string_contains(io.endcapture(),'<LocalDebuggerEnvironment>key=value\nfoo=bar</LocalDebuggerEnvironment>')
end
function vs10_debug_environment.flags_withOutEnvironmentArgsInherit_doesNotContainLocalDebuggerEnvironmentArg()
vs2010.debugenvs({flags={},environmentargs ={'key=value'}} )
test.string_does_not_contain(io.endcapture(),'%$%(LocalDebuggerEnvironment%)')
end
function vs10_debug_environment.flags_withDebugEnvsInherit_endsWithNewLineLocalDebuggerEnvironmentFollowedByClosedTag()
vs2010.debugenvs({flags={DebugEnvsInherit=1},debugenvs ={'key=value'}} )
test.string_contains(io.endcapture(),'\n%$%(LocalDebuggerEnvironment%)</LocalDebuggerEnvironment>')
end
function vs10_debug_environment.flags_withDebugEnvsDontMerge_localDebuggerMergeEnvironmentSetToFalse()
vs2010.debugenvs({flags={DebugEnvsDontMerge=1},debugenvs ={'key=value'}} )
test.string_contains(io.endcapture(),'<LocalDebuggerMergeEnvironment>false</LocalDebuggerMergeEnvironment>')
end

View File

@ -127,6 +127,7 @@
-- CodeBlocks tests
dofile("actions/codeblocks/codeblocks_files.lua")
dofile("actions/codeblocks/test_filters.lua")
dofile("actions/codeblocks/environment_variables.lua")
--
-- Register a test action