Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/vstudio/tests/_tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ return {
"vc2010/test_rule_xml.lua",
"vc2010/test_tokens.lua",
"vc2010/test_target_machine.lua",
"vc2010/test_target_name.lua",
"vc2010/test_user_file.lua",
"vc2010/test_vectorextensions.lua",
"vc2010/test_ensure_nuget_imports.lua",
Expand Down
128 changes: 128 additions & 0 deletions modules/vstudio/tests/vc2010/test_target_name.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
--
-- test_target_name.lua
-- Test target names.
-- Author: Nick Clark
-- Copyright (c) 2026 Jess Perkins and the Premake project
--

local p = premake
local suite = test.declare("vstudio_vs2010_target_name")
local vc2010 = p.vstudio.vc2010

--
-- Setup
--

local wks, prj

function suite.setup()
p.action.set("vs2010")
wks, prj = test.createWorkspace()
end

local function prepare(platform)
local cfg = test.getconfig(prj, "Debug", platform)
vc2010.targetName(cfg)
end


--
-- Default target name is the project name
--

function suite.defaultTargetName()
prepare()
test.capture [[
<TargetName>MyProject</TargetName>
]]
end


function suite.targetWithSuffix()
targetsuffix "_suffix"

prepare()
test.capture [[
<TargetName>MyProject_suffix</TargetName>
]]
end


--
-- Target name with targetsuffix with AARCH architecture
--

function suite.targetWithAarch64FilterSuffix()
architecture "AARCH64"

filter { "architecture:AARCH64" } -- Fails if it is set to ARM64
targetsuffix "_ARM64"

prepare()
test.capture [[
<TargetName>MyProject_ARM64</TargetName>
]]
end


--
-- Target name with targetsuffix with ARM64 architecture
--

function suite.targetWithArm64FilterSuffix()
architecture "ARM64"

filter { "architecture:ARM64" } -- Should match when architecture is AARCH64

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth adding a lowercase test?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or better yet, a mixed case test, e.g. aRm64.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should, but that sort of test would be better fit elsewhere in the filter logic, not the VS logic.

targetsuffix "_ARM64"

prepare()
test.capture [[
<TargetName>MyProject_ARM64</TargetName>
]]
end


--
-- Target name with targetsuffix and x64 architecture
--

function suite.targetWithX64FilterSuffix()
architecture "x64"

filter { "architecture:x64" }
targetsuffix "_x64"

prepare()
test.capture [[
<TargetName>MyProject_x64</TargetName>
]]
end


--
-- Target name with targetprefix
--

function suite.targetWithPrefix()
targetprefix "lib"

prepare()
test.capture [[
<TargetName>libMyProject</TargetName>
]]
end


--
-- Target name with targetprefix and targetsuffix
--

function suite.targetWithPrefixAndSuffix()
targetprefix "lib"
targetsuffix "_suffix"

prepare()
test.capture [[
<TargetName>libMyProject_suffix</TargetName>
]]
end
4 changes: 4 additions & 0 deletions modules/vstudio/vstudio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
vstudio.vs2010_architectures =
{
win32 = "x86",
x86 = "x86",
x86_64 = "x64",
ARM = "ARM",
AARCH64 = "ARM64",
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is now identical to vs200x_architectures.
It seems they can be regrouped, and so below function might be simplified.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping is separate in case any plugins are relying on this.


local function architecture(system, arch)
Expand Down
4 changes: 2 additions & 2 deletions src/base/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@
function context.addFilter(ctx, key, value)
if type(value) == "table" then
for i = 1, #value do
value[i] = tostring(value[i]):lower()
value[i] = p.field.resolvealias(key, tostring(value[i]))
end
elseif value ~= nil then
value = tostring(value):lower()
value = p.field.resolvealias(key, value)
end
ctx.terms[key:lower()] = value
end
Expand Down
5 changes: 1 addition & 4 deletions src/base/criteria.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@

-- check for field value aliases
if prefix then
local fld = p.field.get(prefix)
if fld and fld.aliases then
word[1] = fld.aliases[word[1]] or word[1]
end
word[1] = p.field.resolvealias(prefix, word[1])
end

-- Check if the prefix is an action
Expand Down
13 changes: 13 additions & 0 deletions src/base/field.lua
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,16 @@
return (field.accessor(f, "translate") ~= nil)
end


function field.resolvealias(key, value)
value = value:lower()
local f = field.get(key)
if f and f.aliases then
local alias = f.aliases[value]
if alias then
return tostring(alias):lower()
end
end
return value
end

Loading