Implemented vpaths for VS2010

This commit is contained in:
Jason Perkins 2011-07-01 15:05:16 -04:00
parent 71cbdbdd7d
commit 144c608442
16 changed files with 664 additions and 423 deletions

View File

@ -62,6 +62,7 @@
"actions/vstudio/vs2005_csproj.lua",
"actions/vstudio/vs2005_csproj_user.lua",
"actions/vstudio/vs2010_vcxproj.lua",
"actions/vstudio/vs2010_vcxproj_filters.lua",
-- Xcode action
"actions/xcode/_xcode.lua",

View File

@ -380,7 +380,7 @@
else
premake.generate(prj, "%%.vcxproj", premake.vs2010_vcxproj)
premake.generate(prj, "%%.vcxproj.user", premake.vs2010_vcxproj_user)
premake.generate(prj, "%%.vcxproj.filters", premake.vs2010_vcxproj_filters)
premake.generate(prj, "%%.vcxproj.filters", vstudio.vc2010.generate_filters)
end
end,

View File

@ -1,5 +1,5 @@
--
-- vs200x_vcproj.lua
-- vs2010_vcxproj.lua
-- Generate a Visual Studio 2010 C/C++ project.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
@ -24,38 +24,6 @@
end
end
function vc2010.list_of_directories_in_path(path)
local list={}
path = vc2010.remove_relative_path(path)
if path then
for dir in string.gmatch(path,"[%w%-%_%.]+\\")do
if #list == 0 then
list[1] = dir:sub(1,#dir-1)
else
list[#list +1] = list[#list] .."\\" ..dir:sub(1,#dir-1)
end
end
end
return list
end
function vc2010.table_of_file_filters(files)
local filters ={}
for _, valueTable in pairs(files) do
for _, entry in ipairs(valueTable) do
local result = vc2010.list_of_directories_in_path(entry)
for __,dir in ipairs(result) do
if table.contains(filters,dir) ~= true then
filters[#filters +1] = dir
end
end
end
end
return filters
end
function vc2010.get_file_extension(file)
local ext_start,ext_end = string.find(file,"%.[%w_%-]+$")
if ext_start then
@ -540,15 +508,17 @@
end
-- TODO: remove files arg when everything is ported
function vc2010.sort_input_files(files)
local sorted =
{
ClCompile = {},
ClInclude = {},
None = {},
ResourceCompile = {}
ResourceCompile = {},
}
-- TODO: move this to path functions
local types =
{
h = "ClInclude",
@ -578,7 +548,47 @@
end
--
-- Retrieve a list of files for a particular build group, one of
-- "ClInclude", "ClCompile", "ResourceCompile", and "None".
--
function vc2010.getfilegroup(prj, group)
local sortedfiles = prj.vc2010sortedfiles
if not sortedfiles then
sortedfiles = {
ClCompile = {},
ClInclude = {},
None = {},
ResourceCompile = {},
}
for file in premake.project.eachfile(prj) do
if path.iscppfile(file.name) then
table.insert(sortedfiles.ClCompile, file)
elseif path.iscppheader(file.name) then
table.insert(sortedfiles.ClInclude, file)
elseif path.isresourcefile(file.name) then
table.insert(sortedfiles.ResourceCompile, file)
else
table.insert(sortedfiles.None, file)
end
end
-- Cache the sorted files; they are used several places
prj.vc2010sortedfiles = sortedfiles
end
return sortedfiles[group]
end
--
-- Write the files section of the project file.
--
function vc2010.files(prj)
-- TODO: I shouldn't need getconfig(), should already have root config
cfg = premake.getconfig(prj)
local sorted = vc2010.sort_input_files(cfg.files)
write_file_type_block(sorted.ClInclude, "ClInclude")
@ -589,64 +599,29 @@
--
-- Write filters
-- Output the VC2010 project file header
--
local function write_filter_includes(sorted_table)
local directories = vc2010.table_of_file_filters(sorted_table)
--I am going to take a punt here that the ItemGroup is missing if no files!!!!
--there is a test for this see
--vs10_filters.noInputFiles_bufferDoesNotContainTagItemGroup
if #directories >0 then
_p(1,'<ItemGroup>')
for _, dir in pairs(directories) do
_p(2,'<Filter Include="%s">',dir)
_p(3,'<UniqueIdentifier>{%s}</UniqueIdentifier>',os.uuid())
_p(2,'</Filter>')
end
_p(1,'</ItemGroup>')
end
end
local function write_file_filter_block(files,group_type)
if #files > 0 then
_p(1,'<ItemGroup>')
for _, current_file in ipairs(files) do
local path_to_file = vc2010.file_path(current_file)
if path_to_file then
_p(2,'<%s Include=\"%s\">', group_type,path.translate(current_file, "\\"))
_p(3,'<Filter>%s</Filter>',path_to_file)
_p(2,'</%s>',group_type)
else
_p(2,'<%s Include=\"%s\" />', group_type,path.translate(current_file, "\\"))
end
end
_p(1,'</ItemGroup>')
end
end
local tool_version_and_xmlns = 'ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"'
local xml_version_and_encoding = '<?xml version="1.0" encoding="utf-8"?>'
local function vcxproj_filter_files(prj)
cfg = premake.getconfig(prj)
local sorted = vc2010.sort_input_files(cfg.files)
function vc2010.header(targets)
io.eol = "\r\n"
_p(xml_version_and_encoding)
_p('<Project ' ..tool_version_and_xmlns ..'>')
write_filter_includes(sorted)
write_file_filter_block(sorted.ClInclude,"ClInclude")
write_file_filter_block(sorted.ClCompile,"ClCompile")
write_file_filter_block(sorted.None,"None")
write_file_filter_block(sorted.ResourceCompile,"ResourceCompile")
_p('</Project>')
_p('<?xml version="1.0" encoding="utf-8"?>')
local t = ""
if targets then
t = ' DefaultTargets="' .. targets .. '"'
end
_p('<Project%s ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">', t)
end
--
-- Output the VC2010 C/C++ project file
--
function premake.vs2010_vcxproj(prj)
io.eol = "\r\n"
_p(xml_version_and_encoding)
_p('<Project DefaultTargets="Build" ' ..tool_version_and_xmlns ..'>')
vc2010.header("Build")
vs2010_config(prj)
vs2010_globals(prj)
@ -695,8 +670,7 @@
end
function premake.vs2010_vcxproj_user(prj)
_p(xml_version_and_encoding)
_p('<Project ' ..tool_version_and_xmlns ..'>')
vc2010.header()
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))
@ -706,9 +680,5 @@
_p('</Project>')
end
function premake.vs2010_vcxproj_filters(prj)
vcxproj_filter_files(prj)
end

View File

@ -0,0 +1,120 @@
--
-- vs2010_vcxproj_filters.lua
-- Generate a Visual Studio 2010 C/C++ filters file.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
local vc2010 = premake.vstudio.vc2010
local project = premake.project
--
-- Write filters
--
local function write_file_filter_block(files,group_type)
if #files > 0 then
_p(1,'<ItemGroup>')
for _, current_file in ipairs(files) do
local path_to_file = vc2010.file_path(current_file)
if path_to_file then
_p(2,'<%s Include=\"%s\">', group_type,path.translate(current_file, "\\"))
_p(3,'<Filter>%s</Filter>',path_to_file)
_p(2,'</%s>',group_type)
else
_p(2,'<%s Include=\"%s\" />', group_type,path.translate(current_file, "\\"))
end
end
_p(1,'</ItemGroup>')
end
end
--
-- The first portion of the filters file assigns unique IDs to each
-- directory or virtual group. Would be cool if we could automatically
-- map vpaths like "**.h" to an <Extensions>h</Extensions> element.
--
function vc2010.filteridgroup(prj)
local filters = { }
local filterfound = false
for file in project.eachfile(prj) do
-- split the path into its component parts
local folders = string.explode(file.vpath, "/", true)
local path = ""
for i = 1, #folders - 1 do
-- element is only written if there *are* filters
if not filterfound then
filterfound = true
_p(1,'<ItemGroup>')
end
path = path .. folders[i]
-- have I seen this path before?
if not filters[path] then
filters[path] = true
_p(2, '<Filter Include="%s">', path)
_p(3, '<UniqueIdentifier>{%s}</UniqueIdentifier>', os.uuid())
_p(2, '</Filter>')
end
-- prepare for the next subfolder
path = path .. "\\"
end
end
if filterfound then
_p(1,'</ItemGroup>')
end
end
--
-- The second portion of the filters file assigns filters to each source
-- code file, as needed. Section is one of "ClCompile", "ClInclude",
-- "ResourceCompile", or "None".
--
function vc2010.filefiltergroup(prj, section)
local files = vc2010.getfilegroup(prj, section)
if #files > 0 then
_p(1,'<ItemGroup>')
for _, file in ipairs(files) do
local filter
if file.name ~= file.vpath then
filter = path.getdirectory(file.vpath)
else
filter = path.getdirectory(file.name)
end
if filter ~= "." then
_p(2,'<%s Include=\"%s\">', section, path.translate(file.name, "\\"))
_p(3,'<Filter>%s</Filter>', path.translate(filter, "\\"))
_p(2,'</%s>', section)
else
_p(2,'<%s Include=\"%s\" />', section, path.translate(file.name, "\\"))
end
end
_p(1,'</ItemGroup>')
end
end
--
-- Output the VC2010 filters file
--
function vc2010.generate_filters(prj)
cfg = premake.getconfig(prj)
local sorted = vc2010.sort_input_files(cfg.files)
vc2010.header()
vc2010.filteridgroup(prj)
vc2010.filefiltergroup(prj, "None")
vc2010.filefiltergroup(prj, "ClInclude")
vc2010.filefiltergroup(prj, "ClCompile")
vc2010.filefiltergroup(prj, "ResourceCompile")
_p('</Project>')
end

View File

@ -197,6 +197,13 @@
local ext = path.getextension(fname):lower()
return table.contains(extensions, ext)
end
function path.iscppheader(fname)
local extensions = { ".h", ".hh", ".hpp", ".hxx" }
local ext = path.getextension(fname):lower()
return table.contains(extensions, ext)
end
--
@ -209,8 +216,8 @@
local ext = path.getextension(fname):lower()
return table.contains(extensions, ext)
end
--
-- Join two pieces of a path together into a single path.

View File

@ -564,6 +564,19 @@
end
end
-- remove any dot ("./", "../") patterns from the start of the path
local changed
repeat
changed = true
if vpath:startswith("./") then
vpath = vpath:sub(3)
elseif vpath:startswith("../") then
vpath = vpath:sub(4)
else
changed = false
end
until not changed
return vpath
end

View File

@ -1,293 +0,0 @@
T.vs2010_filters = { }
local vs10_filters = T.vs2010_filters
local vc2010 = premake.vstudio.vc2010
local sln, prj
function vs10_filters.setup()
_ACTION = "vs2010"
sln = solution "MySolution"
configurations { "Debug" }
platforms {}
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
end
local function get_buffer()
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
premake.vs2010_vcxproj_filters(prj)
buffer = io.endcapture()
return buffer
end
function vs10_filters.path_noPath_returnsNil()
local result = vc2010.file_path("foo.h")
test.isequal(nil,result)
end
function vs10_filters.path_hasOneDirectoryPath_returnsIsFoo()
local path = "foo"
local result = vc2010.file_path(path .."\\foo.h")
test.isequal(path,result)
end
function vs10_filters.path_hasTwoDirectoryPath_returnsIsFooSlashBar()
local path = "foo\\bar"
local result = vc2010.file_path(path .."\\foo.h")
test.isequal(path,result)
end
function vs10_filters.path_hasTwoDirectoryPath_returnsIsFooSlashBar_Baz()
local path = "foo\\bar_baz"
local result = vc2010.file_path(path .."\\foo.h")
test.isequal(path,result)
end
function vs10_filters.path_extensionWithHyphen_returnsIsFoo()
local path = "foo"
local result = vc2010.file_path(path .."\\foo-bar.h")
test.isequal(path,result)
end
function vs10_filters.path_extensionWithNumber_returnsIs2Foo()
local path = "foo"
local result = vc2010.file_path(path .."\\2foo.h")
test.isequal(path,result)
end
function vs10_filters.path_hasThreeDirectoryPath_returnsIsFooSlashBarSlashBaz()
local path = "foo\\bar\\baz"
local result = vc2010.file_path(path .."\\foo.h")
test.isequal(path,result)
end
function vs10_filters.path_hasDotDotSlashDirectoryPath_returnsNil()
local path = ".."
local result = vc2010.file_path(path .."\\foo.h")
test.isequal(nil,result)
end
function vs10_filters.removeRelativePath_noRelativePath_returnsInput()
local path = "foo.h"
local result = vc2010.remove_relative_path(path)
test.isequal("foo.h",result)
end
function vs10_filters.removeRelativePath_dotDotSlashFoo_returnsFoo()
local path = "..\\foo"
local result = vc2010.remove_relative_path(path)
test.isequal("foo",result)
end
function vs10_filters.removeRelativePath_dotDotSlashDotDotSlashFoo_returnsFoo()
local path = "..\\..\\foo"
local result = vc2010.remove_relative_path(path)
test.isequal("foo",result)
end
function vs10_filters.removeRelativePath_DotSlashFoo_returnsFoo()
local path = ".\\foo"
local result = vc2010.remove_relative_path(path)
test.isequal("foo",result)
end
function vs10_filters.listOfDirectories_oneDirectory_returnsSizeIsOne()
local result = vc2010.list_of_directories_in_path("foo\\bar.h")
test.isequal(1,#result)
end
function vs10_filters.listOfDirectories_oneDirectory_returnsContainsFoo()
local result = vc2010.list_of_directories_in_path("foo\\bar.h")
test.contains(result,"foo")
end
function vs10_filters.listOfDirectories_twoDirectories_returnsSizeIsTwo()
local result = vc2010.list_of_directories_in_path("foo\\bar\\bar.h")
test.isequal(2,#result)
end
function vs10_filters.listOfDirectories_twoDirectories_secondEntryIsFooSlashBar()
local result = vc2010.list_of_directories_in_path("foo\\bar\\bar.h")
test.isequal("foo\\bar",result[2])
end
function vs10_filters.listOfDirectories_dotSlash_returnsIsEmpty()
local result = vc2010.list_of_directories_in_path(".\\bar.h")
test.isequal(0,#result)
end
function vs10_filters.tableOfFileFilters_returnSizeIsTwo()
local t =
{
foo = {'foo\\bar.h'},
bar = {'foo\\bar.h'},
baz = {'baz\\bar.h'}
}
local result = vc2010.table_of_file_filters(t)
test.isequal(2,#result)
end
function vs10_filters.tableOfFileFilters_returnContainsFoo()
local t =
{
foo = {'foo\\bar.h'},
bar = {'foo\\bar.h'},
baz = {'baz\\bar.h'}
}
local result = vc2010.table_of_file_filters(t)
--order is not defined
test.contains(result,'foo')
end
function vs10_filters.tableOfFileFilters_returnContainsBaz()
local t =
{
foo = {'foo\\bar.h'},
bar = {'foo\\bar.h'},
baz = {'baz\\bar.h'}
}
local result = vc2010.table_of_file_filters(t)
--order is not defined
test.contains(result,'baz')
end
function vs10_filters.tableOfFileFilters_returnSizeIsFour()
local t =
{
foo = {'foo\\bar.h'},
bar = {'foo\\bar\\bar.h'},
baz = {'bar\\bar.h'},
bazz = {'bar\\foo\\bar.h'}
}
local result = vc2010.table_of_file_filters(t)
--order is not defined
test.isequal(4,#result)
end
function vs10_filters.tableOfFileFilters_tableHasSubTableWithTwoEntries_returnSizeIsTwo()
local t =
{
foo = {'foo\\bar.h','foo\\bar\\bar.h'}
}
local result = vc2010.table_of_file_filters(t)
--order is not defined
test.isequal(2,#result)
end
function vs10_filters.noInputFiles_bufferDoesNotContainTagFilter()
local buffer = get_buffer()
test.string_does_not_contain(buffer,"<Filter")
end
function vs10_filters.noInputFiles_bufferDoesNotContainTagItemGroup()
local buffer = get_buffer()
test.string_does_not_contain(buffer,"<ItemGroup>")
end
function vs10_filters.oneInputFileYetNoDirectory_bufferDoesNotContainTagFilter()
files
{
"dontCare.h"
}
local buffer = get_buffer()
test.string_does_not_contain(buffer,"<Filter")
end
function vs10_filters.oneInputFileWithDirectory_bufferContainsTagFilter()
files
{
"dontCare\\dontCare.h"
}
local buffer = get_buffer()
test.string_contains(buffer,"<Filter")
end
function vs10_filters.oneInputFileWithDirectory_bufferContainsTagFilterInsideItemGroupTag()
files
{
"dontCare\\dontCare.h"
}
local buffer = get_buffer()
test.string_contains(buffer,"<ItemGroup>.*<Filter.*</Filter>.*</ItemGroup>")
end
function vs10_filters.oneInputFileWithDirectory_bufferContainsTagFilterWithIncludeSetToFoo()
files
{
"foo\\dontCare.h"
}
local buffer = get_buffer()
test.string_contains(buffer,'<Filter Include="foo">')
end
function vs10_filters.clIncludeFilter_oneInputFile_bufferContainsTagClInclude()
files
{
"dontCare.h"
}
local buffer = get_buffer()
test.string_contains(buffer,'<ClInclude')
end
function vs10_filters.clIncludeFilter_oneInputFileWithoutDirectory_bufferContainsTagClIncludeOnOneLine()
files
{
"foo.h"
}
local buffer = get_buffer()
test.string_contains(buffer,'<ClInclude Include="foo.h" />')
end
function vs10_filters.clCompileFilter_oneInputFile_bufferContainsTagClCompile()
files
{
"dontCare.cpp"
}
local buffer = get_buffer()
test.string_contains(buffer,'<ClCompile')
end
function vs10_filters.noneFilter_oneInputFile_bufferContainsTagNone()
files
{
"dontCare.ext"
}
local buffer = get_buffer()
test.string_contains(buffer,'<None')
end
function vs10_filters.tableOfFileFilters_filterContainsDots_resultsLengthIsThree()
t =
{
foo = {'src\\host\\lua-5.1.4\\foo.h'}
}
local result = vc2010.table_of_file_filters(t)
test.isequal(3,#result)
end
function vs10_filters.tableOfFileFilters_filterContainsDots_resultContainsTheEntry()
t =
{
foo = {'src\\host\\lua-5.1.4\\foo.h'}
}
local result = vc2010.table_of_file_filters(t)
test.contains(result,'src\\host\\lua-5.1.4')
end
function vs10_filters.listOfDirectories_filterContainsDots_resultContainsTheEntry()
local result = vc2010.list_of_directories_in_path('src\\host\\lua.4\\foo.h')
test.contains(result,'src\\host\\lua.4')
end
function vs10_filters.resourceCompileFilter_oneInputFile_bufferContainsTagResourceCompile()
files
{
"dontCare.rc"
}
local buffer = get_buffer()
test.string_contains(buffer,'<ResourceCompile')
end

View File

@ -55,6 +55,12 @@
return buffer
end
--
-- Tests
--
function vs10_vcxproj.xmlDeclarationPresent()
local buffer = get_buffer()
test.istrue(string.startswith(buffer, '<?xml version=\"1.0\" encoding=\"utf-8\"?>'))
@ -226,34 +232,6 @@
test.isequal('h', ext)
end
local function SortAndReturnSortedInputFiles(input)
return vc2010.sort_input_files(input)
end
function vs10_vcxproj.sortFile_headerFile_SortedClIncludeEqualToFile()
local file = {"bar.h"}
local sorted = SortAndReturnSortedInputFiles(file)
test.isequal(file, sorted.ClInclude)
end
function vs10_vcxproj.sortFile_srcFile_SortedClCompileEqualToFile()
local file = {"b.cxx"}
local sorted = SortAndReturnSortedInputFiles(file)
test.isequal(file, sorted.ClCompile)
end
function vs10_vcxproj.sortFile_notRegistered_SortedNoneEqualToFile()
local file = {"foo.bar.00h"}
local sorted = SortAndReturnSortedInputFiles(file)
test.isequal(file, sorted.None)
end
function vs10_vcxproj.sortFile_resourceScript_resourceCompileEqualToFile()
local file = {"foo.rc"}
local sorted = SortAndReturnSortedInputFiles(file)
test.isequal(file, sorted.ResourceCompile)
end
function vs10_vcxproj.itemGroupSection_hasResourceCompileSection()
--for some reason this does not work here and it needs to be in
--the project setting at the top ?
@ -420,3 +398,37 @@
local buffer = get_buffer()
test.string_does_not_contain(buffer,"WholeProgramOptimization")
end
--
-- Test file sorting into build categories
--
local function SortAndReturnSortedInputFiles(input)
return vc2010.sort_input_files(input)
end
function vs10_vcxproj.sortFile_headerFile_SortedClIncludeEqualToFile()
local file = {"bar.h"}
local sorted = SortAndReturnSortedInputFiles(file)
test.isequal(file, sorted.ClInclude)
end
function vs10_vcxproj.sortFile_srcFile_SortedClCompileEqualToFile()
local file = {"b.cxx"}
local sorted = SortAndReturnSortedInputFiles(file)
test.isequal(file, sorted.ClCompile)
end
function vs10_vcxproj.sortFile_notRegistered_SortedNoneEqualToFile()
local file = {"foo.bar.00h"}
local sorted = SortAndReturnSortedInputFiles(file)
test.isequal(file, sorted.None)
end
function vs10_vcxproj.sortFile_resourceScript_resourceCompileEqualToFile()
local file = {"foo.rc"}
local sorted = SortAndReturnSortedInputFiles(file)
test.isequal(file, sorted.ResourceCompile)
end

View File

@ -1,5 +1,5 @@
--
-- tests/actions/vstudio/vc2010/debugdir.lua
-- tests/actions/vstudio/vc2010/test_debugdir.lua
-- Validate handling of the working directory for debugging.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--

View File

@ -1,5 +1,5 @@
--
-- tests/actions/vstudio/vc2010/files.lua
-- tests/actions/vstudio/vc2010/test_files.lua
-- Validate generation of files block in Visual Studio 2010 C/C++ projects.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--

View File

@ -0,0 +1,336 @@
--
-- tests/actions/vstudio/vc2010/test_filters.lua
-- Validate generation of filter blocks in Visual Studio 2010 C/C++ projects.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vs2010_filters = { }
local suite = T.vs2010_filters
local vc2010 = premake.vstudio.vc2010
--
-- Setup/teardown
--
local sln, prj
local os_uuid
function suite.setup()
os_uuid = os.uuid
os.uuid = function() return "00112233-4455-6677-8888-99AABBCCDDEE" end
_ACTION = "vs2010"
sln, prj = test.createsolution()
end
function suite.teardown()
os.uuid = os_uuid
end
local function get_buffer()
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
vc2010.generate_filters(prj)
buffer = io.endcapture()
return buffer
end
local function prepare()
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
end
--
-- Tests
--
function suite.path_noPath_returnsNil()
local result = vc2010.file_path("foo.h")
test.isequal(nil,result)
end
function suite.path_hasOneDirectoryPath_returnsIsFoo()
local path = "foo"
local result = vc2010.file_path(path .."\\foo.h")
test.isequal(path,result)
end
function suite.path_hasTwoDirectoryPath_returnsIsFooSlashBar()
local path = "foo\\bar"
local result = vc2010.file_path(path .."\\foo.h")
test.isequal(path,result)
end
function suite.path_hasTwoDirectoryPath_returnsIsFooSlashBar_Baz()
local path = "foo\\bar_baz"
local result = vc2010.file_path(path .."\\foo.h")
test.isequal(path,result)
end
function suite.path_extensionWithHyphen_returnsIsFoo()
local path = "foo"
local result = vc2010.file_path(path .."\\foo-bar.h")
test.isequal(path,result)
end
function suite.path_extensionWithNumber_returnsIs2Foo()
local path = "foo"
local result = vc2010.file_path(path .."\\2foo.h")
test.isequal(path,result)
end
function suite.path_hasThreeDirectoryPath_returnsIsFooSlashBarSlashBaz()
local path = "foo\\bar\\baz"
local result = vc2010.file_path(path .."\\foo.h")
test.isequal(path,result)
end
function suite.path_hasDotDotSlashDirectoryPath_returnsNil()
local path = ".."
local result = vc2010.file_path(path .."\\foo.h")
test.isequal(nil,result)
end
function suite.removeRelativePath_noRelativePath_returnsInput()
local path = "foo.h"
local result = vc2010.remove_relative_path(path)
test.isequal("foo.h",result)
end
function suite.removeRelativePath_dotDotSlashFoo_returnsFoo()
local path = "..\\foo"
local result = vc2010.remove_relative_path(path)
test.isequal("foo",result)
end
function suite.removeRelativePath_dotDotSlashDotDotSlashFoo_returnsFoo()
local path = "..\\..\\foo"
local result = vc2010.remove_relative_path(path)
test.isequal("foo",result)
end
function suite.removeRelativePath_DotSlashFoo_returnsFoo()
local path = ".\\foo"
local result = vc2010.remove_relative_path(path)
test.isequal("foo",result)
end
function suite.clIncludeFilter_oneInputFile_bufferContainsTagClInclude()
files
{
"dontCare.h"
}
local buffer = get_buffer()
test.string_contains(buffer,'<ClInclude')
end
function suite.clIncludeFilter_oneInputFileWithoutDirectory_bufferContainsTagClIncludeOnOneLine()
files
{
"foo.h"
}
local buffer = get_buffer()
test.string_contains(buffer,'<ClInclude Include="foo.h" />')
end
function suite.clCompileFilter_oneInputFile_bufferContainsTagClCompile()
files
{
"dontCare.cpp"
}
local buffer = get_buffer()
test.string_contains(buffer,'<ClCompile')
end
function suite.noneFilter_oneInputFile_bufferContainsTagNone()
files
{
"dontCare.ext"
}
local buffer = get_buffer()
test.string_contains(buffer,'<None')
end
function suite.resourceCompileFilter_oneInputFile_bufferContainsTagResourceCompile()
files
{
"dontCare.rc"
}
local buffer = get_buffer()
test.string_contains(buffer,'<ResourceCompile')
end
--
-- Filter identifiers sections
--
function suite.UniqueIdentifiers_IsEmpty_OnRootFilesOnly()
files { "hello.c", "goodbye.c" }
prepare()
vc2010.filteridgroup(prj)
test.isemptycapture()
end
function suite.UniqueIdentifiers_MergeCommonSubfolders()
files { "src/hello.c", "src/goodbye.c" }
prepare()
vc2010.filteridgroup(prj)
test.capture [[
<ItemGroup>
<Filter Include="src">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]
end
function suite.UniqueIdentifiers_ListAllSubfolders()
files { "src/hello.c", "src/departures/goodbye.c" }
prepare()
vc2010.filteridgroup(prj)
test.capture [[
<ItemGroup>
<Filter Include="src">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
</Filter>
<Filter Include="src\departures">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]
end
function suite.UniqueIdentifiers_ListVpaths()
files { "hello.c", "goodbye.c" }
vpaths { ["**.c"] = "Source Files" }
prepare()
vc2010.filteridgroup(prj)
test.capture [[
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]
end
function suite.UniqueIdentifiers_ListRealAndVpaths()
files { "hello.h", "goodbye.c" }
vpaths { ["*.c"] = "Source Files", ["*.h"] = "Header Files" }
prepare()
vc2010.filteridgroup(prj)
test.capture [[
<ItemGroup>
<Filter Include="Header Files">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]
end
--
-- File/filter assignment tests
--
function suite.FileFilters_NoFilter_OnRootFile()
files { "hello.c", "goodbye.c" }
prepare()
vc2010.filefiltergroup(prj, "ClCompile")
test.capture [[
<ItemGroup>
<ClCompile Include="hello.c" />
<ClCompile Include="goodbye.c" />
</ItemGroup>
]]
end
function suite.FileFilters_NoFilter_OnRealPath()
files { "src/hello.c" }
prepare()
vc2010.filefiltergroup(prj, "ClCompile")
test.capture [[
<ItemGroup>
<ClCompile Include="src\hello.c">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
]]
end
function suite.FileFilters_HasFilter_OnVpath()
files { "src/hello.c" }
vpaths { ["**.c"] = "Source Files" }
prepare()
vc2010.filefiltergroup(prj, "ClCompile")
test.capture [[
<ItemGroup>
<ClCompile Include="src\hello.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
]]
end
function suite.FileFilters_OnIncludeSection()
files { "hello.c", "hello.h", "hello.rc", "hello.txt" }
prepare()
vc2010.filefiltergroup(prj, "ClInclude")
test.capture [[
<ItemGroup>
<ClInclude Include="hello.h" />
</ItemGroup>
]]
end
function suite.FileFilters_OnResourceSection()
files { "hello.c", "hello.h", "hello.rc", "hello.txt" }
prepare()
vc2010.filefiltergroup(prj, "ResourceCompile")
test.capture [[
<ItemGroup>
<ResourceCompile Include="hello.rc" />
</ItemGroup>
]]
end
function suite.FileFilters_OnNoneSection()
files { "hello.c", "hello.h", "hello.rc", "hello.txt" }
prepare()
vc2010.filefiltergroup(prj, "None")
test.capture [[
<ItemGroup>
<None Include="hello.txt" />
</ItemGroup>
]]
end
-- one file needs a filter, another doesn't
-- assigns to real paths
-- assigns to vpaths
-- writes none filter
-- writes include filter
-- writes resource filter
-- anything else?

View File

@ -0,0 +1,45 @@
--
-- tests/actions/vstudio/vc2010/test_header.lua
-- Validate generation of the project file header block.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs2010_header = { }
local suite = T.vstudio_vs2010_header
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln, prj
function suite.setup()
_ACTION = 'vs2010'
sln = test.createsolution()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
end
--
-- Tests
--
function suite.On2010_WithNoTarget()
vc2010.header()
test.capture [[
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
]]
end
function suite.On2010_WithTarget()
vc2010.header("Build")
test.capture [[
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
]]
end

View File

@ -76,7 +76,6 @@
dofile("actions/vstudio/test_vs2010_vcxproj.lua")
dofile("actions/vstudio/test_vs2010_flags.lua")
dofile("actions/vstudio/test_vs2010_links.lua")
dofile("actions/vstudio/test_vs2010_filters.lua")
dofile("actions/vstudio/test_vs2010_project_kinds.lua")
-- Visual Studio 2002-2003 C# projects
@ -102,8 +101,10 @@
dofile("actions/vstudio/vc200x/files.lua")
-- Visual Studio 2010 C/C++ projects
dofile("actions/vstudio/vc2010/debugdir.lua")
dofile("actions/vstudio/vc2010/files.lua")
dofile("actions/vstudio/vc2010/test_debugdir.lua")
dofile("actions/vstudio/vc2010/test_header.lua")
dofile("actions/vstudio/vc2010/test_files.lua")
dofile("actions/vstudio/vc2010/test_filters.lua")
-- Makefile tests
dofile("actions/make/test_make_escaping.lua")

View File

@ -40,8 +40,7 @@
function suite.ReturnedObjectIncludesVpath()
files { "hello.h", "hello.c" }
vpaths { ["*.h"] = "Headers" }
prepare()
local iter = project.eachfile(prj)
test.isequal("Headers/hello.h", iter().vpath)
test.isequal("hello.h", iter().vpath)
end

View File

@ -22,6 +22,7 @@
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
end
--
-- Test simple replacements
@ -59,6 +60,7 @@
test.isequal("sources/hello.c", project.getvpath(prj, "src/myproject/hello.c"))
end
--
-- Test wildcard patterns
--
@ -110,3 +112,23 @@
prepare()
test.isequal("Headers/myproject/hello.h", project.getvpath(prj, "src/myproject/hello.h"))
end
--
-- Test directory dot patterns
--
function suite.RemovesLeadingDotFolder()
prepare()
test.isequal("hello.c", project.getvpath(prj, "./hello.c"))
end
function suite.RemovesLeadingDotDotFolder()
prepare()
test.isequal("hello.c", project.getvpath(prj, "../hello.c"))
end
function suite.RemovesMultipleLeadingDotDotFolders()
prepare()
test.isequal("src/hello.c", project.getvpath(prj, "../../src/hello.c"))
end

View File

@ -86,6 +86,14 @@
end
end
function test.isemptycapture()
local actual = io.endcapture()
if actual ~= "" then
test.fail("expected empty capture, but was %s", actual);
end
end
function test.isequal(expected, actual)
if (type(expected) == "table") then