UUIDs in Visual Studio project files now use a deterministic, name-based generator

This commit is contained in:
Jason Perkins 2012-12-29 13:26:41 -05:00
parent 1cd3667118
commit 41198fac9a
7 changed files with 101 additions and 39 deletions

View File

@ -48,7 +48,7 @@
end
_x(2, '<Filter Include="%s">', path.translate(node.path))
_p(3, '<UniqueIdentifier>{%s}</UniqueIdentifier>', os.uuid())
_p(3, '<UniqueIdentifier>{%s}</UniqueIdentifier>', os.uuid(node.path))
_p(2, '</Filter>')
end
}, false)

View File

@ -262,3 +262,21 @@
builtin_rmdir(p)
end
--
-- Generate a UUID.
--
os._uuids = {}
local builtin_uuid = os.uuid
function os.uuid(name)
local id = builtin_uuid(name)
if name then
if os._uuids[id] and os._uuids[id] ~= name then
print(string.format("** Warning: UUID clash between %s and %s", os._uuids[id], name))
end
os._uuids[id] = name
end
return id
end

View File

@ -4,8 +4,7 @@
-- Copyright (c) 2011-2012 Jason Perkins and the Premake project
--
T.vs2010_filter_ids = { }
local suite = T.vs2010_filter_ids
local suite = test.declare("vs2010_filter_ids")
local vc2010 = premake.vstudio.vc2010
@ -14,19 +13,11 @@
--
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 = test.createsolution()
end
function suite.teardown()
os.uuid = os_uuid
end
local function prepare()
prj = premake.solution.getproject_ng(sln, 1)
@ -55,7 +46,7 @@
test.capture [[
<ItemGroup>
<Filter Include="src">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
<UniqueIdentifier>{2DAB880B-99B4-887C-2230-9F7C8E38947C}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]
@ -72,10 +63,10 @@
test.capture [[
<ItemGroup>
<Filter Include="src">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
<UniqueIdentifier>{2DAB880B-99B4-887C-2230-9F7C8E38947C}</UniqueIdentifier>
</Filter>
<Filter Include="src\departures">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
<UniqueIdentifier>{BB36ED8F-A704-E195-9098-51BC7C05BDFA}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]
@ -93,7 +84,7 @@
test.capture [[
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
<UniqueIdentifier>{E9C7FDCE-D52A-8D73-7EB0-C5296AF258F6}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]
@ -106,10 +97,10 @@
test.capture [[
<ItemGroup>
<Filter Include="Header Files">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
<UniqueIdentifier>{21EB8090-0D4E-1035-B6D3-48EBA215DCB7}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
<UniqueIdentifier>{E9C7FDCE-D52A-8D73-7EB0-C5296AF258F6}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]

View File

@ -4,9 +4,7 @@
-- Copyright (c) 2008-2011 Jason Perkins and the Premake project
--
T.os = { }
local suite = T.os
local suite = test.declare("base_os")
--
@ -105,22 +103,3 @@
function suite.pathsearch_NilPathsAllowed()
test.isequal(os.getcwd(), os.pathsearch("premake4.lua", nil, os.getcwd(), nil))
end
--
-- os.uuid() tests
--
function suite.guid_ReturnsValidUUID()
local g = os.uuid()
test.istrue(#g == 36)
for i=1,36 do
local ch = g:sub(i,i)
test.istrue(ch:find("[ABCDEF0123456789-]"))
end
test.isequal("-", g:sub(9,9))
test.isequal("-", g:sub(14,14))
test.isequal("-", g:sub(19,19))
test.isequal("-", g:sub(24,24))
end

64
tests/base/test_uuid.lua Normal file
View File

@ -0,0 +1,64 @@
--
-- tests/base/test_uuid.lua
-- Automated test suite for UUID generation.
-- Copyright (c) 2008-2012 Jason Perkins and the Premake project
--
local suite = test.declare("os_uuid")
--
-- Setup and teardown
--
local builtin_print, result
function suite.setup()
builtin_print = print
print = function(value)
result = value
end
end
function suite.teardown()
print = builtin_print
end
--
-- Make sure the return value looks like a UUID.
--
function suite.returnsValidUUID()
local g = os.uuid()
test.istrue(#g == 36)
for i=1,36 do
local ch = g:sub(i,i)
test.istrue(ch:find("[ABCDEF0123456789-]"))
end
test.isequal("-", g:sub(9,9))
test.isequal("-", g:sub(14,14))
test.isequal("-", g:sub(19,19))
test.isequal("-", g:sub(24,24))
end
--
-- Make sure the value returned is deterministic if a name is provided.
--
function suite.isDeterministic_onName()
test.isequal("885E8F4B-F43D-0EE7-FD55-99BD69B47448", os.uuid("MyValue"))
end
--
-- A warning should be shown is an ID clash is ever discovered.
--
function suite.showsWarning_onCollision()
-- use a bit of secret knowledge to make the test possible
os._uuids["885E8F4B-F43D-0EE7-FD55-99BD69B47448"] = "Some other value"
os.uuid("MyValue")
test.istrue(result:startswith("** Warning:"))
end

View File

@ -53,6 +53,7 @@
dofile("base/test_premake_command.lua")
dofile("base/test_table.lua")
dofile("base/test_tree.lua")
dofile("base/test_uuid.lua")
-- Solution object tests
dofile("solution/test_eachconfig.lua")

View File

@ -263,6 +263,15 @@
end
function test.declare(id)
if T[id] then
error("Duplicate test suite " .. id)
end
T[id] = {}
return T[id]
end
function test.runall(suitename, testname)
test.print = print