Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for toolset. #1997

Merged
merged 1 commit into from
Apr 16, 2023
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
39 changes: 39 additions & 0 deletions src/base/action.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,45 @@
return false
end

---
-- Determines if an action supports a particular toolset.
--
-- @param language
-- The language that toolset belongs.
-- @param toolset
-- The toolset to check.
-- @returns
-- True if the toolset is supported, false otherwise.
---
function action.supportsToolset(language, toolset)
if not language or not toolset then
return true
end
samsinsane marked this conversation as resolved.
Show resolved Hide resolved
local self = action.current()
if not self then
return false
end
local language_keys_map = {
["C"] = "cc",
["C++"] = "cc",
["C#"] = "dotnet",
["D"] = "dc",
}
local language_key = language_keys_map[language]
if not language_key then
p.warn("Unknown mapping for language %s", language)
return true
end
if not self.valid_tools then
return true
end
local valid_tools = self.valid_tools[language_key]
if not valid_tools then
return true
end

return table.contains(valid_tools, toolset)
end

--
-- Determines if an action supports a particular configuration.
Expand Down
8 changes: 8 additions & 0 deletions src/base/validation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
return {
m.projectHasLanguage,
m.actionSupportsLanguage,
m.actionSupportsToolset,
m.actionSupportsKind,
m.projectRulesExist,
m.projectValuesInScope,
Expand Down Expand Up @@ -174,6 +175,13 @@
end


function m.actionSupportsToolset(prj)
if not p.action.supportsToolset(prj.language, prj.toolset) then
p.warn("Unsupported toolset '%s' used for language '%s' for project '%s'", prj.toolset, prj.language, prj.name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most other validations use warn and not error...
So I stay coherent with above checks. (but I think all should be error).

end
end


function m.configHasKind(cfg)
if not cfg.kind then
p.error("Project '%s' needs a kind in configuration '%s'", cfg.project.name, cfg.name)
Expand Down