Moved remaining functions from global and added them to the table premake.vstudio.vs10_helpers

This commit is contained in:
LiamDevine 2010-07-14 23:31:31 +01:00
parent 60422741da
commit 5c49aa8638
3 changed files with 97 additions and 92 deletions

View File

@ -3,14 +3,14 @@ premake.vstudio.vs10_helpers = { }
local vs10_helpers = premake.vstudio.vs10_helpers
function remove_relative_path(file)
function vs10_helpers.remove_relative_path(file)
file = file:gsub("%.%.\\",'')
file = file:gsub("%.\\",'')
return file
end
function file_path(file)
file = remove_relative_path(file)
function vs10_helpers.file_path(file)
file = vs10_helpers.remove_relative_path(file)
local path = string.find(file,'\\[%w%.%_%-]+$')
if path then
return string.sub(file,1,path-1)
@ -19,7 +19,7 @@ local vs10_helpers = premake.vstudio.vs10_helpers
end
end
function list_of_directories_in_path(path)
function vs10_helpers.list_of_directories_in_path(path)
local list={}
if path then
for dir in string.gmatch(path,"[%w%-%_%.]+\\")do
@ -33,11 +33,11 @@ local vs10_helpers = premake.vstudio.vs10_helpers
return list
end
function table_of_filters(t)
function vs10_helpers.table_of_filters(t)
local filters ={}
for key, value in pairs(t) do
local result = list_of_directories_in_path(value)
local result = vs10_helpers.list_of_directories_in_path(value)
for __,dir in ipairs(result) do
if table.contains(filters,dir) ~= true then
filters[#filters +1] = dir
@ -48,12 +48,12 @@ local vs10_helpers = premake.vstudio.vs10_helpers
return filters
end
function table_of_file_filters(files)
function vs10_helpers.table_of_file_filters(files)
local filters ={}
for key, valueTable in pairs(files) do
for _, entry in ipairs(valueTable) do
local result = list_of_directories_in_path(entry)
local result = vs10_helpers.list_of_directories_in_path(entry)
for __,dir in ipairs(result) do
if table.contains(filters,dir) ~= true then
filters[#filters +1] = dir
@ -64,7 +64,45 @@ local vs10_helpers = premake.vstudio.vs10_helpers
return filters
end
function vs10_helpers.get_file_extension(file)
local ext_start,ext_end = string.find(file,"%.[%w_%-]+$")
if ext_start then
return string.sub(file,ext_start+1,ext_end)
end
end
--also translates file paths from '/' to '\\'
function vs10_helpers.sort_input_files(files,sorted_container)
local types =
{
h = "ClInclude",
hpp = "ClInclude",
hxx = "ClInclude",
c = "ClCompile",
cpp = "ClCompile",
cxx = "ClCompile",
cc = "ClCompile"
}
for _, current_file in ipairs(files) do
local translated_path = path.translate(current_file, '\\')
local ext = vs10_helpers.get_file_extension(translated_path)
if ext then
local type = types[ext]
if type then
table.insert(sorted_container[type],translated_path)
else
table.insert(sorted_container.None,translated_path)
end
end
end
end
local function vs2010_config(prj)
_p(1,'<ItemGroup Label="ProjectConfigurations">')
for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
@ -490,41 +528,7 @@ local vs10_helpers = premake.vstudio.vs10_helpers
end
--[[local--]] function get_file_extension(file)
local ext_start,ext_end = string.find(file,"%.[%w_%-]+$")
if ext_start then
return string.sub(file,ext_start+1,ext_end)
end
end
--also translates file paths from '/' to '\\'
--[[local--]] function sort_input_files(files,sorted_container)
local types =
{
h = "ClInclude",
hpp = "ClInclude",
hxx = "ClInclude",
c = "ClCompile",
cpp = "ClCompile",
cxx = "ClCompile",
cc = "ClCompile"
}
for _, current_file in ipairs(files) do
local translated_path = path.translate(current_file, '\\')
local ext = get_file_extension(translated_path)
if ext then
local type = types[ext]
if type then
table.insert(sorted_container[type],translated_path)
else
table.insert(sorted_container.None,translated_path)
end
end
end
end
--
-- <ItemGroup>
-- <ProjectReference Include="zlibvc.vcxproj">
@ -552,7 +556,7 @@ local vs10_helpers = premake.vstudio.vs10_helpers
}
cfg = premake.getconfig(prj)
sort_input_files(cfg.files,sorted)
vs10_helpers.sort_input_files(cfg.files,sorted)
write_file_type_block(sorted.ClInclude,"ClInclude")
write_file_type_block(sorted.ClCompile,'ClCompile')
write_file_type_block(sorted.None,'None')
@ -560,7 +564,7 @@ local vs10_helpers = premake.vstudio.vs10_helpers
end
local function write_filter_includes(sorted_table)
local directories = table_of_file_filters(sorted_table)
local directories = vs10_helpers.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
@ -579,7 +583,7 @@ local vs10_helpers = premake.vstudio.vs10_helpers
if #files > 0 then
_p(1,'<ItemGroup>')
for _, current_file in ipairs(files) do
local path_to_file = file_path(current_file)
local path_to_file = vs10_helpers.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)
@ -601,7 +605,7 @@ local vs10_helpers = premake.vstudio.vs10_helpers
}
cfg = premake.getconfig(prj)
sort_input_files(cfg.files,sorted)
vs10_helpers.sort_input_files(cfg.files,sorted)
io.eol = "\r\n"
_p('<?xml version="1.0" encoding="utf-8"?>')

View File

@ -1,6 +1,6 @@
T.vs2010_filters = { }
local vs10_filters = T.vs2010_filters
local vs10_helpers = premake.vstudio.vs10_helpers
local sln, prj
@ -25,104 +25,104 @@
end
function vs10_filters.path_noPath_returnsNil()
local result = file_path("foo.h")
local result = vs10_helpers.file_path("foo.h")
test.isequal(nil,result)
end
function vs10_filters.path_hasOneDirectoryPath_returnsIsFoo()
local path = "foo"
local result = file_path(path .."\\foo.h")
local result = vs10_helpers.file_path(path .."\\foo.h")
test.isequal(path,result)
end
function vs10_filters.path_hasTwoDirectoryPath_returnsIsFooSlashBar()
local path = "foo\\bar"
local result = file_path(path .."\\foo.h")
local result = vs10_helpers.file_path(path .."\\foo.h")
test.isequal(path,result)
end
function vs10_filters.path_hasTwoDirectoryPath_returnsIsFooSlashBar_Baz()
local path = "foo\\bar_baz"
local result = file_path(path .."\\foo.h")
local result = vs10_helpers.file_path(path .."\\foo.h")
test.isequal(path,result)
end
function vs10_filters.path_extensionWithHyphen_returnsIsFoo()
local path = "foo"
local result = file_path(path .."\\foo-bar.h")
local result = vs10_helpers.file_path(path .."\\foo-bar.h")
test.isequal(path,result)
end
function vs10_filters.path_extensionWithNumber_returnsIs2Foo()
local path = "foo"
local result = file_path(path .."\\2foo.h")
local result = vs10_helpers.file_path(path .."\\2foo.h")
test.isequal(path,result)
end
function vs10_filters.path_hasThreeDirectoryPath_returnsIsFooSlashBarSlashBaz()
local path = "foo\\bar\\baz"
local result = file_path(path .."\\foo.h")
local result = vs10_helpers.file_path(path .."\\foo.h")
test.isequal(path,result)
end
function vs10_filters.path_hasDotDotSlashDirectoryPath_returnsNil()
local path = ".."
local result = file_path(path .."\\foo.h")
local result = vs10_helpers.file_path(path .."\\foo.h")
test.isequal(nil,result)
end
function vs10_filters.removeRelativePath_noRelativePath_returnsInput()
local path = "foo.h"
local result = remove_relative_path(path)
local result = vs10_helpers.remove_relative_path(path)
test.isequal("foo.h",result)
end
function vs10_filters.removeRelativePath_dotDotSlashFoo_returnsFoo()
local path = "..\\foo"
local result = remove_relative_path(path)
local result = vs10_helpers.remove_relative_path(path)
test.isequal("foo",result)
end
function vs10_filters.removeRelativePath_dotDotSlashDotDotSlashFoo_returnsFoo()
local path = "..\\..\\foo"
local result = remove_relative_path(path)
local result = vs10_helpers.remove_relative_path(path)
test.isequal("foo",result)
end
function vs10_filters.removeRelativePath_DotSlashFoo_returnsFoo()
local path = ".\\foo"
local result = remove_relative_path(path)
local result = vs10_helpers.remove_relative_path(path)
test.isequal("foo",result)
end
function vs10_filters.listOfDirectories_passedNil_returnsIsEmpty()
local result = list_of_directories_in_path(nil)
local result = vs10_helpers.list_of_directories_in_path(nil)
test.isequal(0,#result)
end
function vs10_filters.listOfDirectories_oneDirectory_returnsSizeIsOne()
local result = list_of_directories_in_path("foo\\bar.h")
local result = vs10_helpers.list_of_directories_in_path("foo\\bar.h")
test.isequal(1,#result)
end
function vs10_filters.listOfDirectories_oneDirectory_returnsContainsFoo()
local result = list_of_directories_in_path("foo\\bar.h")
local result = vs10_helpers.list_of_directories_in_path("foo\\bar.h")
test.contains(result,"foo")
end
function vs10_filters.listOfDirectories_twoDirectories_returnsSizeIsTwo()
local result = list_of_directories_in_path("foo\\bar\\bar.h")
local result = vs10_helpers.list_of_directories_in_path("foo\\bar\\bar.h")
test.isequal(2,#result)
end
function vs10_filters.listOfDirectories_twoDirectories_secondEntryIsFooSlashBar()
local result = list_of_directories_in_path("foo\\bar\\bar.h")
local result = vs10_helpers.list_of_directories_in_path("foo\\bar\\bar.h")
test.isequal("foo\\bar",result[2])
end
function vs10_filters.tableOfFilters_emptyTable_returnsEmptyTable()
t = {}
local result = table_of_filters(t)
local result = vs10_helpers.table_of_filters(t)
test.isequal(0,#result)
end
@ -131,7 +131,7 @@
{
'foo.h'
}
local result = table_of_filters(t)
local result = vs10_helpers.table_of_filters(t)
test.isequal(0,#result)
end
@ -140,7 +140,7 @@
{
'bar\\foo.h'
}
local result = table_of_filters(t)
local result = vs10_helpers.table_of_filters(t)
test.isequal(1,#result)
end
function vs10_filters.tableOfFilters_tableHasTwoDirectories_returnSizeIsOne()
@ -149,7 +149,7 @@
'bar\\foo.h',
'baz\\foo.h'
}
local result = table_of_filters(t)
local result = vs10_helpers.table_of_filters(t)
test.isequal(2,#result)
end
function vs10_filters.tableOfFilters_tableHasTwoDirectories_firstEntryIsBar()
@ -158,7 +158,7 @@
'bar\\foo.h',
'baz\\foo.h'
}
local result = table_of_filters(t)
local result = vs10_helpers.table_of_filters(t)
test.isequal("bar",result[1])
end
function vs10_filters.tableOfFilters_tableHasTwoDirectories_secondEntryIsBaz()
@ -167,7 +167,7 @@
'bar\\foo.h',
'baz\\foo.h'
}
local result = table_of_filters(t)
local result = vs10_helpers.table_of_filters(t)
test.isequal("baz",result[2])
end
@ -177,7 +177,7 @@
'bar\\foo.h',
'bar\\baz.h'
}
local result = table_of_filters(t)
local result = vs10_helpers.table_of_filters(t)
test.isequal(1,#result)
end
@ -186,7 +186,7 @@
{
'bar\\baz\\foo.h'
}
local result = table_of_filters(t)
local result = vs10_helpers.table_of_filters(t)
test.isequal(2,#result)
end
@ -195,7 +195,7 @@
{
'bar\\baz\\foo.h'
}
local result = table_of_filters(t)
local result = vs10_helpers.table_of_filters(t)
test.isequal('bar',result[1])
end
@ -204,7 +204,7 @@
{
'bar\\baz\\foo.h'
}
local result = table_of_filters(t)
local result = vs10_helpers.table_of_filters(t)
test.isequal('bar\\baz',result[2])
end
@ -215,7 +215,7 @@
'bar\\baz\\foo.h',
'baz\\foo.h'
}
local result = table_of_filters(t)
local result = vs10_helpers.table_of_filters(t)
test.isequal(3,#result)
end
@ -226,7 +226,7 @@
bar = {'foo\\bar.h'},
baz = {'baz\\bar.h'}
}
local result = table_of_file_filters(t)
local result = vs10_helpers.table_of_file_filters(t)
test.isequal(2,#result)
end
@ -237,7 +237,7 @@
bar = {'foo\\bar.h'},
baz = {'baz\\bar.h'}
}
local result = table_of_file_filters(t)
local result = vs10_helpers.table_of_file_filters(t)
--order is not defined
test.contains(result,'foo')
end
@ -249,7 +249,7 @@
bar = {'foo\\bar.h'},
baz = {'baz\\bar.h'}
}
local result = table_of_file_filters(t)
local result = vs10_helpers.table_of_file_filters(t)
--order is not defined
test.contains(result,'baz')
end
@ -262,7 +262,7 @@
baz = {'bar\\bar.h'},
bazz = {'bar\\foo\\bar.h'}
}
local result = table_of_file_filters(t)
local result = vs10_helpers.table_of_file_filters(t)
--order is not defined
test.isequal(4,#result)
end
@ -272,7 +272,7 @@
{
foo = {'foo\\bar.h','foo\\bar\\bar.h'}
}
local result = table_of_file_filters(t)
local result = vs10_helpers.table_of_file_filters(t)
--order is not defined
test.isequal(2,#result)
end
@ -366,7 +366,7 @@
{
'bar\\baz\\foo.bar.h'
}
local result = table_of_filters(t)
local result = vs10_helpers.table_of_filters(t)
test.isequal(2,#result)
end
function vs10_filters.tableOfFileFilters_filterContainsDots_resultsLengthIsThree()
@ -374,7 +374,7 @@
{
foo = {'src\\host\\lua-5.1.4\\foo.h'}
}
local result = table_of_file_filters(t)
local result = vs10_helpers.table_of_file_filters(t)
test.isequal(3,#result)
end
@ -383,11 +383,11 @@
{
foo = {'src\\host\\lua-5.1.4\\foo.h'}
}
local result = table_of_file_filters(t)
local result = vs10_helpers.table_of_file_filters(t)
test.contains(result,'src\\host\\lua-5.1.4')
end
function vs10_filters.listOfDirectories_filterContainsDots_resultContainsTheEntry()
local result = list_of_directories_in_path('src\\host\\lua.4\\foo.h')
local result = vs10_helpers.list_of_directories_in_path('src\\host\\lua.4\\foo.h')
test.contains(result,'src\\host\\lua.4')
end

View File

@ -3,6 +3,7 @@
local include_directory = "bar/foo"
local include_directory2 = "baz/foo"
local debug_define = "I_AM_ALIVE_NUMBER_FIVE"
local vs10_helpers = premake.vstudio.vs10_helpers
local sln, prj
function vs10_vcxproj.setup()
@ -192,32 +193,32 @@
end
function vs10_vcxproj.fileExtension_extEqualH()
local ext = get_file_extension('foo.h')
local ext = vs10_helpers.get_file_extension('foo.h')
test.isequal('h', ext)
end
function vs10_vcxproj.fileExtension_containsTwoDots_extEqualH()
local ext = get_file_extension('foo.bar.h')
local ext = vs10_helpers.get_file_extension('foo.bar.h')
test.isequal('h', ext)
end
function vs10_vcxproj.fileExtension_alphaNumeric_extEqualOneH()
local ext = get_file_extension('foo.1h')
local ext = vs10_helpers.get_file_extension('foo.1h')
test.isequal('1h', ext)
end
function vs10_vcxproj.fileExtension_alphaNumericWithUnderscore_extEqualOne_H()
local ext = get_file_extension('foo.1_h')
local ext = vs10_helpers.get_file_extension('foo.1_h')
test.isequal('1_h', ext)
end
function vs10_vcxproj.fileExtension_containsHyphen_extEqualHHyphenH()
local ext = get_file_extension('foo.h-h')
local ext = vs10_helpers.get_file_extension('foo.h-h')
test.isequal('h-h', ext)
end
function vs10_vcxproj.fileExtension_containsMoreThanOneDot_extEqualOneH()
local ext = get_file_extension('foo.bar.h')
local ext = vs10_helpers.get_file_extension('foo.bar.h')
test.isequal('h', ext)
end
@ -228,7 +229,7 @@
ClCompile ={},
None ={}
}
sort_input_files(input,sorted)
vs10_helpers.sort_input_files(input,sorted)
return sorted
end
function vs10_vcxproj.sortFile_headerFile_SortedClIncludeEqualToFile()