[#1657833] Set working directory an IDE starts/debugs the program in

This commit is contained in:
Jason Perkins 2011-04-25 15:55:17 -04:00
parent 0357046d36
commit 229e31a465
15 changed files with 314 additions and 23 deletions

View File

@ -2,6 +2,8 @@ syntax: glob
.DS_Store
*.orig
build
bin
obj

View File

@ -3,6 +3,7 @@
-------
* Feature 3100379: C# support for Visual Studio 2010
* Feature 1657833: Set working directory for debugging
* Added support for Haiku OS (Yuriy O'Donnell)
* Patch 2963313: Enable setting .NET framework version (Justen Hyde)
* Switched PS3 builds from GCC to SNC

0
samples/project/premake4 Normal file → Executable file
View File

View File

@ -1,7 +1,7 @@
--
-- _manifest.lua
-- Manage the list of built-in Premake scripts.
-- Copyright (c) 2002-2010 Jason Perkins and the Premake project
-- Copyright (c) 2002-2011 Jason Perkins and the Premake project
--
-- The master list of built-in scripts. Order is important! If you want to
@ -55,6 +55,7 @@
"actions/vstudio/vs2002_csproj.lua",
"actions/vstudio/vs2002_csproj_user.lua",
"actions/vstudio/vs200x_vcproj.lua",
"actions/vstudio/vs200x_vcproj_user.lua",
"actions/vstudio/vs2003_solution.lua",
"actions/vstudio/vs2005_solution.lua",
"actions/vstudio/vs2005_csproj.lua",

View File

@ -33,6 +33,11 @@
_p(3,'<Target title="%s">', premake.esc(cfg.longname))
_p(4,'<Option output="%s" prefix_auto="0" extension_auto="0" />', premake.esc(cfg.buildtarget.fullpath))
if cfg.debugdir then
_p(4,'<Option working_dir="%s" />', premake.esc(cfg.debugdir))
end
_p(4,'<Option object_output="%s" />', premake.esc(cfg.objectsdir))
-- identify the type of binary

View File

@ -35,9 +35,10 @@
local fname = premake.esc(cfg.buildtarget.fullpath)
local objdir = premake.esc(cfg.objectsdir)
local runcmd = cfg.buildtarget.name
local rundir = cfg.buildtarget.directory
local rundir = cfg.debugdir or cfg.buildtarget.directory
local runargs = table.concat(cfg.debugargs, " ")
local pause = iif(cfg.kind == "WindowedApp", "no", "yes")
_p(' <General OutputFile="%s" IntermediateDirectory="%s" Command="./%s" CommandArguments="" WorkingDirectory="%s" PauseExecWhenProcTerminates="%s"/>', fname, objdir, runcmd, rundir, pause)
_p(' <General OutputFile="%s" IntermediateDirectory="%s" Command="./%s" CommandArguments="%s" WorkingDirectory="%s" PauseExecWhenProcTerminates="%s"/>', fname, objdir, runcmd, runargs, rundir, pause)
-- begin compiler block --
local flags = premake.esc(table.join(premake.gcc.getcflags(cfg), premake.gcc.getcxxflags(cfg), cfg.buildoptions))

View File

@ -222,6 +222,7 @@
premake.generate(prj, "%%.csproj.user", vstudio.cs2002.generate_user)
else
premake.generate(prj, "%%.vcproj", vstudio.vc200x.generate)
premake.generate(prj, "%%.vcproj.user", vstudio.vc200x.generate_user)
end
end,
@ -232,7 +233,7 @@
--
-- Register Visual Studio 2002
-- Register Visual Studio 2003
--
newaction {
@ -260,6 +261,7 @@
premake.generate(prj, "%%.csproj.user", vstudio.cs2002.generate_user)
else
premake.generate(prj, "%%.vcproj", vstudio.vc200x.generate)
premake.generate(prj, "%%.vcproj.user", vstudio.vc200x.generate_user)
end
end,
@ -270,7 +272,7 @@
--
-- Register Visual Studio 2002
-- Register Visual Studio 2005
--
newaction {
@ -298,6 +300,7 @@
premake.generate(prj, "%%.csproj.user", vstudio.cs2005.generate_user)
else
premake.generate(prj, "%%.vcproj", vstudio.vc200x.generate)
premake.generate(prj, "%%.vcproj.user", vstudio.vc200x.generate_user)
end
end,
@ -308,7 +311,7 @@
--
-- Register Visual Studio 2002
-- Register Visual Studio 2008
--
newaction {
@ -336,6 +339,7 @@
premake.generate(prj, "%%.csproj.user", vstudio.cs2005.generate_user)
else
premake.generate(prj, "%%.vcproj", vstudio.vc200x.generate)
premake.generate(prj, "%%.vcproj.user", vstudio.vc200x.generate_user)
end
end,
@ -346,7 +350,7 @@
--
-- Register Visual Studio 2002
-- Register Visual Studio 2010
--
newaction

View File

@ -48,6 +48,28 @@
--
-- Write the project file header
--
function vc200x.header(element)
io.eol = "\r\n"
_p('<?xml version="1.0" encoding="Windows-1252"?>')
_p('<%s', element)
_p(1,'ProjectType="Visual C++"')
if _ACTION == "vs2002" then
_p(1,'Version="7.00"')
elseif _ACTION == "vs2003" then
_p(1,'Version="7.10"')
elseif _ACTION == "vs2005" then
_p(1,'Version="8.00"')
elseif _ACTION == "vs2008" then
_p(1,'Version="9.00"')
end
end
--
-- Write out the <Configuration> element.
--
@ -664,21 +686,8 @@
--
function vc200x.generate(prj)
io.eol = "\r\n"
_p('<?xml version="1.0" encoding="Windows-1252"?>')
vc200x.header('VisualStudioProject')
-- Write opening project block
_p('<VisualStudioProject')
_p(1,'ProjectType="Visual C++"')
if _ACTION == "vs2002" then
_p(1,'Version="7.00"')
elseif _ACTION == "vs2003" then
_p(1,'Version="7.10"')
elseif _ACTION == "vs2005" then
_p(1,'Version="8.00"')
elseif _ACTION == "vs2008" then
_p(1,'Version="9.00"')
end
_p(1,'Name="%s"', premake.esc(prj.name))
_p(1,'ProjectGUID="{%s}"', prj.uuid)
if _ACTION > "vs2003" then

View File

@ -0,0 +1,61 @@
--
-- vs200x_vcproj_user.lua
-- Generate a Visual Studio 2002-2008 C/C++ project .user file
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
--
-- Set up namespaces
--
local vc200x = premake.vstudio.vc200x
--
-- Generate the .vcproj.user file
--
function vc200x.generate_user(prj)
vc200x.header('VisualStudioUserFile')
_p(1,'ShowAllFiles="false"')
_p(1,'>')
_p(1,'<Configurations>')
for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
if cfginfo.isreal then
local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
_p(2,'<Configuration')
_p(3,'Name="%s"', premake.esc(cfginfo.name))
_p(3,'>')
vc200x.debugdir(cfg)
_p(2,'</Configuration>')
end
end
_p(1,'</Configurations>')
_p('</VisualStudioUserFile>')
end
--
-- Output the debug settings element
--
function vc200x.debugdir(cfg)
_p(3,'<DebugSettings')
if cfg.debugdir then
_p(4,'WorkingDirectory="%s"', path.translate(cfg.debugdir, '\\'))
end
if #cfg.debugargs > 0 then
_p(4,'CommandArguments="%s"', table.concat(cfg.debugargs, " "))
end
_p(3,'/>')
end

View File

@ -676,9 +676,29 @@
end
--
-- Generate the .vcxproj.user file
--
function vc2010.debugdir(cfg)
if cfg.debugdir then
_p(' <LocalDebuggerWorkingDirectory>%s</LocalDebuggerWorkingDirectory>', path.translate(cfg.debugdir, '\\'))
_p(' <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>')
end
if cfg.debugargs then
_p(' <LocalDebuggerCommandArguments>%s</LocalDebuggerCommandArguments>', table.concat(cfg.debugargs, " "))
end
end
function premake.vs2010_vcxproj_user(prj)
_p(xml_version_and_encoding)
_p('<Project ' ..tool_version_and_xmlns ..'>')
for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
_p(' <PropertyGroup '.. if_config_and_platform() ..'>', premake.esc(cfginfo.name))
vc2010.debugdir(cfg)
_p(' </PropertyGroup>')
end
_p('</Project>')
end

View File

@ -1,7 +1,7 @@
--
-- api.lua
-- Implementation of the solution, project, and configuration APIs.
-- Copyright (c) 2002-2008 Jason Perkins and the Premake project
-- Copyright (c) 2002-2011 Jason Perkins and the Premake project
--
@ -42,6 +42,18 @@
scope = "solution",
},
debugargs =
{
kind = "list",
scope = "config",
},
debugdir =
{
kind = "path",
scope = "config",
},
defines =
{
kind = "list",

View File

@ -0,0 +1,60 @@
--
-- tests/actions/vstudio/vc200x/debugdir.lua
-- Validate handling of the working directory for debugging.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs200x_debugdir = { }
local suite = T.vstudio_vs200x_debugdir
local vc200x = premake.vstudio.vc200x
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
vc200x.debugdir(prj)
end
--
-- Tests
--
function suite.EmptyBlock_OnNoDebugSettings()
prepare()
test.capture [[
<DebugSettings
/>
]]
end
function suite.WorkingDirectory_OnRelativePath()
debugdir "bin/debug"
prepare()
test.capture [[
<DebugSettings
WorkingDirectory="bin\debug"
/>
]]
end
function suite.Arguments()
debugargs { "arg1", "arg2" }
prepare()
test.capture [[
<DebugSettings
CommandArguments="arg1 arg2"
/>
]]
end

View File

@ -0,0 +1,55 @@
--
-- tests/actions/vstudio/vc200x/header.lua
-- Validate generation of the project file header block.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs200x_header = { }
local suite = T.vstudio_vs200x_header
local vc200x = premake.vstudio.vc200x
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
vc200x.header('VisualStudioProject')
end
--
-- Tests
--
function suite.On2002()
_ACTION = 'vs2002'
prepare()
test.capture [[
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.00"
]]
end
function suite.On2008()
_ACTION = 'vs2008'
prepare()
test.capture [[
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
]]
end

View File

@ -0,0 +1,55 @@
--
-- tests/actions/vstudio/vc2010/debugdir.lua
-- Validate handling of the working directory for debugging.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs2010_debugdir = { }
local suite = T.vstudio_vs2010_debugdir
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
vc2010.debugdir(prj)
end
--
-- Tests
--
function suite.PrintsNothing_OnDebugDirSet()
prepare()
test.capture [[
]]
end
function suite.IsFormattedCorrectly_OnRelativePath()
debugdir "bin/debug"
prepare()
test.capture [[
<LocalDebuggerWorkingDirectory>bin\debug</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
]]
end
function suite.Arguments()
debugargs { "arg1", "arg2" }
prepare()
test.capture [[
<LocalDebuggerCommandArguments>arg1 arg2</LocalDebuggerCommandArguments>
]]
end

View File

@ -88,9 +88,14 @@
dofile("actions/vstudio/sln2005/projectplatforms.lua")
dofile("actions/vstudio/sln2005/projects.lua")
-- Visual Studio 2002-2008 C/++ projects
-- Visual Studio 2002-2008 C/C++ projects
dofile("actions/vstudio/vc200x/debugdir.lua")
dofile("actions/vstudio/vc200x/header.lua")
dofile("actions/vstudio/vc200x/files.lua")
-- Visual Studio 2010 C/C++ projects
dofile("actions/vstudio/vc2010/debugdir.lua")
-- Makefile tests
dofile("actions/make/test_make_escaping.lua")
dofile("actions/make/test_make_pch.lua")