Skip to content

Commit

Permalink
Add toolset normalization, to stabilize the 'filter'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom van Dijck committed Jun 13, 2017
1 parent 94889ef commit a2c02ef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/_premake_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,9 @@
value = value:lower()
local tool, version = p.tools.canonical(value)
if tool then
return value
return p.tools.normalize(value)
else
return nil
end
end,
}
Expand Down
44 changes: 26 additions & 18 deletions src/base/tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,33 @@
-- returns nil.
---

function p.tools.canonical(identifier)
local parts
function p.tools.normalize(identifier)
if identifier:startswith("v") then -- TODO: this should be deprecated?
parts = { "msc", identifier }
else
parts = identifier:explode("-", true, 1)

-- couple of little hacks here to fix up version names
if parts[2] ~= nil then
-- 'msc-100' is accepted, but the code expects 'v100'
if parts[1] == "msc" and tonumber(parts[2]:sub(1,3)) ~= nil then
parts[2] = "v" .. parts[2]
end

-- perform case-correction of the LLVM toolset
if parts[2]:startswith("llvm-vs") then
parts[2] = "LLVM-" .. parts[2]:sub(6)
end
end
identifier = 'msc-' .. identifier
end

local parts = identifier:explode("-", true, 1)
if parts[2] == nil then
return parts[1]
end

-- 'msc-100' is accepted, but the code expects 'v100'
if parts[1] == "msc" and tonumber(parts[2]:sub(1,3)) ~= nil then
parts[2] = "v" .. parts[2]
end

-- perform case-correction of the LLVM toolset
if parts[2]:startswith("llvm-vs") then
parts[2] = "LLVM-" .. parts[2]:sub(6)
end

return parts[1] .. '-' .. parts[2]
end


function p.tools.canonical(identifier)
identifier = p.tools.normalize(identifier)

local parts = identifier:explode("-", true, 1)
return p.tools[parts[1]], parts[2]
end
9 changes: 9 additions & 0 deletions tests/oven/test_filtering.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@
test.isequal({}, cfg.defines)
end

function suite.onFilterToolsetNormalization()
toolset "v140"
filter { "toolset:msc-v140" }
defines { "USE_MSC" }
prepare()
test.isequal({ "USE_MSC" }, cfg.defines)
end


--
-- Test filtering on system.
--
Expand Down

0 comments on commit a2c02ef

Please sign in to comment.