Skip to content

Commit 168988a

Browse files
authored
Merge pull request #1997 from Jarod42/toolset_validation
Add validation for toolset.
2 parents a46cb5b + 504f6fc commit 168988a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/base/action.lua

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,45 @@
257257
return false
258258
end
259259

260+
---
261+
-- Determines if an action supports a particular toolset.
262+
--
263+
-- @param language
264+
-- The language that toolset belongs.
265+
-- @param toolset
266+
-- The toolset to check.
267+
-- @returns
268+
-- True if the toolset is supported, false otherwise.
269+
---
270+
function action.supportsToolset(language, toolset)
271+
if not language or not toolset then
272+
return true
273+
end
274+
local self = action.current()
275+
if not self then
276+
return false
277+
end
278+
local language_keys_map = {
279+
["C"] = "cc",
280+
["C++"] = "cc",
281+
["C#"] = "dotnet",
282+
["D"] = "dc",
283+
}
284+
local language_key = language_keys_map[language]
285+
if not language_key then
286+
p.warn("Unknown mapping for language %s", language)
287+
return true
288+
end
289+
if not self.valid_tools then
290+
return true
291+
end
292+
local valid_tools = self.valid_tools[language_key]
293+
if not valid_tools then
294+
return true
295+
end
296+
297+
return table.contains(valid_tools, toolset)
298+
end
260299

261300
--
262301
-- Determines if an action supports a particular configuration.

src/base/validation.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
return {
5757
m.projectHasLanguage,
5858
m.actionSupportsLanguage,
59+
m.actionSupportsToolset,
5960
m.actionSupportsKind,
6061
m.projectRulesExist,
6162
m.projectValuesInScope,
@@ -174,6 +175,13 @@
174175
end
175176

176177

178+
function m.actionSupportsToolset(prj)
179+
if not p.action.supportsToolset(prj.language, prj.toolset) then
180+
p.warn("Unsupported toolset '%s' used for language '%s' for project '%s'", prj.toolset, prj.language, prj.name)
181+
end
182+
end
183+
184+
177185
function m.configHasKind(cfg)
178186
if not cfg.kind then
179187
p.error("Project '%s' needs a kind in configuration '%s'", cfg.project.name, cfg.name)

0 commit comments

Comments
 (0)