Skip to content

Commit d01097b

Browse files
Fixes filters using an aliased value (#2615)
1 parent 411496c commit d01097b

File tree

6 files changed

+149
-6
lines changed

6 files changed

+149
-6
lines changed

modules/vstudio/tests/_tests.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ return {
9696
"vc2010/test_rule_xml.lua",
9797
"vc2010/test_tokens.lua",
9898
"vc2010/test_target_machine.lua",
99+
"vc2010/test_target_name.lua",
99100
"vc2010/test_user_file.lua",
100101
"vc2010/test_vectorextensions.lua",
101102
"vc2010/test_ensure_nuget_imports.lua",
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
--
2+
-- test_target_name.lua
3+
-- Test target names.
4+
-- Author: Nick Clark
5+
-- Copyright (c) 2026 Jess Perkins and the Premake project
6+
--
7+
8+
local p = premake
9+
local suite = test.declare("vstudio_vs2010_target_name")
10+
local vc2010 = p.vstudio.vc2010
11+
12+
--
13+
-- Setup
14+
--
15+
16+
local wks, prj
17+
18+
function suite.setup()
19+
p.action.set("vs2010")
20+
wks, prj = test.createWorkspace()
21+
end
22+
23+
local function prepare(platform)
24+
local cfg = test.getconfig(prj, "Debug", platform)
25+
vc2010.targetName(cfg)
26+
end
27+
28+
29+
--
30+
-- Default target name is the project name
31+
--
32+
33+
function suite.defaultTargetName()
34+
prepare()
35+
test.capture [[
36+
<TargetName>MyProject</TargetName>
37+
]]
38+
end
39+
40+
41+
function suite.targetWithSuffix()
42+
targetsuffix "_suffix"
43+
44+
prepare()
45+
test.capture [[
46+
<TargetName>MyProject_suffix</TargetName>
47+
]]
48+
end
49+
50+
51+
--
52+
-- Target name with targetsuffix with AARCH architecture
53+
--
54+
55+
function suite.targetWithAarch64FilterSuffix()
56+
architecture "AARCH64"
57+
58+
filter { "architecture:AARCH64" } -- Fails if it is set to ARM64
59+
targetsuffix "_ARM64"
60+
61+
prepare()
62+
test.capture [[
63+
<TargetName>MyProject_ARM64</TargetName>
64+
]]
65+
end
66+
67+
68+
--
69+
-- Target name with targetsuffix with ARM64 architecture
70+
--
71+
72+
function suite.targetWithArm64FilterSuffix()
73+
architecture "ARM64"
74+
75+
filter { "architecture:ARM64" } -- Should match when architecture is AARCH64
76+
targetsuffix "_ARM64"
77+
78+
prepare()
79+
test.capture [[
80+
<TargetName>MyProject_ARM64</TargetName>
81+
]]
82+
end
83+
84+
85+
--
86+
-- Target name with targetsuffix and x64 architecture
87+
--
88+
89+
function suite.targetWithX64FilterSuffix()
90+
architecture "x64"
91+
92+
filter { "architecture:x64" }
93+
targetsuffix "_x64"
94+
95+
prepare()
96+
test.capture [[
97+
<TargetName>MyProject_x64</TargetName>
98+
]]
99+
end
100+
101+
102+
--
103+
-- Target name with targetprefix
104+
--
105+
106+
function suite.targetWithPrefix()
107+
targetprefix "lib"
108+
109+
prepare()
110+
test.capture [[
111+
<TargetName>libMyProject</TargetName>
112+
]]
113+
end
114+
115+
116+
--
117+
-- Target name with targetprefix and targetsuffix
118+
--
119+
120+
function suite.targetWithPrefixAndSuffix()
121+
targetprefix "lib"
122+
targetsuffix "_suffix"
123+
124+
prepare()
125+
test.capture [[
126+
<TargetName>libMyProject_suffix</TargetName>
127+
]]
128+
end

modules/vstudio/vstudio.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
vstudio.vs2010_architectures =
3535
{
3636
win32 = "x86",
37+
x86 = "x86",
38+
x86_64 = "x64",
39+
ARM = "ARM",
40+
AARCH64 = "ARM64",
3741
}
3842

3943
local function architecture(system, arch)

src/base/context.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@
9999
function context.addFilter(ctx, key, value)
100100
if type(value) == "table" then
101101
for i = 1, #value do
102-
value[i] = tostring(value[i]):lower()
102+
value[i] = p.field.resolvealias(key, tostring(value[i]))
103103
end
104104
elseif value ~= nil then
105-
value = tostring(value):lower()
105+
value = p.field.resolvealias(key, value)
106106
end
107107
ctx.terms[key:lower()] = value
108108
end

src/base/criteria.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@
111111

112112
-- check for field value aliases
113113
if prefix then
114-
local fld = p.field.get(prefix)
115-
if fld and fld.aliases then
116-
word[1] = fld.aliases[word[1]] or word[1]
117-
end
114+
word[1] = p.field.resolvealias(prefix, word[1])
118115
end
119116

120117
-- Check if the prefix is an action

src/base/field.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,16 @@
389389
return (field.accessor(f, "translate") ~= nil)
390390
end
391391

392+
393+
function field.resolvealias(key, value)
394+
value = value:lower()
395+
local f = field.get(key)
396+
if f and f.aliases then
397+
local alias = f.aliases[value]
398+
if alias then
399+
return tostring(alias):lower()
400+
end
401+
end
402+
return value
403+
end
404+

0 commit comments

Comments
 (0)