From 6d471ecc2a4e573e5859e4564612500dc3fd13d2 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Mon, 24 Apr 2017 13:37:28 -0700 Subject: [PATCH] Add 'supports_language' callback to action to validate languages now that we have multiple dialects --- modules/codelite/_preload.lua | 5 ++++- modules/d/actions/gmake.lua | 4 +++- modules/d/actions/vstudio.lua | 4 +++- modules/raw/_preload.lua | 4 ---- modules/xcode/_preload.lua | 5 ++++- src/actions/make/_make.lua | 8 ++++++-- src/actions/vstudio/vs2005.lua | 6 +++++- src/actions/vstudio/vs2008.lua | 6 +++++- src/actions/vstudio/vs2010.lua | 6 +++++- src/actions/vstudio/vs2012.lua | 6 +++++- src/actions/vstudio/vs2013.lua | 6 +++++- src/actions/vstudio/vs2015.lua | 6 +++++- src/actions/vstudio/vs2017.lua | 6 +++++- src/base/action.lua | 23 ++++++++++++++--------- 14 files changed, 69 insertions(+), 26 deletions(-) diff --git a/modules/codelite/_preload.lua b/modules/codelite/_preload.lua index d7accaaece..be544968b3 100644 --- a/modules/codelite/_preload.lua +++ b/modules/codelite/_preload.lua @@ -22,10 +22,13 @@ -- The capabilities of this action valid_kinds = { "ConsoleApp", "WindowedApp", "Makefile", "SharedLib", "StaticLib", "Utility" }, - valid_languages = { "C", "C++" }, valid_tools = { cc = { "gcc", "clang", "msc" } }, + supports_language = function(lang) + return p.languages.isc(lang) or + p.languages.iscpp(lang) + end, -- Workspace and project generation logic diff --git a/modules/d/actions/gmake.lua b/modules/d/actions/gmake.lua index 8559e8c4ab..6aa148e716 100644 --- a/modules/d/actions/gmake.lua +++ b/modules/d/actions/gmake.lua @@ -28,9 +28,11 @@ -- -- Patch the gmake action with the allowed tools... -- - gmake.valid_languages = table.join(gmake.valid_languages, { p.D } ) gmake.valid_tools.dc = { "dmd", "gdc", "ldc" } + p.override(gmake, "supports_language", function(oldfn, lang) + return oldfn(lang) or lang == p.D; + end) function m.make.separateCompilation(prj) local some = false diff --git a/modules/d/actions/vstudio.lua b/modules/d/actions/vstudio.lua index 31bef12122..2106f29fd3 100644 --- a/modules/d/actions/vstudio.lua +++ b/modules/d/actions/vstudio.lua @@ -22,7 +22,9 @@ for k,v in pairs({ "vs2005", "vs2008", "vs2010", "vs2012", "vs2013", "vs2015" }) do local vs = p.action.get(v) if vs ~= nil then - table.insert( vs.valid_languages, p.D ) + p.override(vs, "supports_language", function(oldfn, lang) + return oldfn(lang) or lang == p.D; + end) vs.valid_tools.dc = { "dmd", "gdc", "ldc" } p.override(vs, "onProject", function(oldfn, prj) diff --git a/modules/raw/_preload.lua b/modules/raw/_preload.lua index b8bef93ddd..3c056a2eb2 100644 --- a/modules/raw/_preload.lua +++ b/modules/raw/_preload.lua @@ -4,10 +4,6 @@ newaction shortname = "Raw output", description = "Generate raw representation of Premake structures", - valid_kinds = { "ConsoleApp", "WindowedApp", "SharedLib", "StaticLib", "Makefile", "None", "Utility" }, - valid_languages = { "C", "C++" }, - valid_tools = { cc = { "clang" } }, - onsolution = function(sln) require('raw') diff --git a/modules/xcode/_preload.lua b/modules/xcode/_preload.lua index 4c1cc1b29d..63b62bc819 100644 --- a/modules/xcode/_preload.lua +++ b/modules/xcode/_preload.lua @@ -40,10 +40,13 @@ -- The capabilities of this action valid_kinds = { "ConsoleApp", "WindowedApp", "SharedLib", "StaticLib", "Makefile", "None" }, - valid_languages = { "C", "C++" }, valid_tools = { cc = { "gcc", "clang" }, }, + supports_language = function(lang) + return p.languages.isc(lang) or + p.languages.iscpp(lang) + end, -- Workspace and project generation logic diff --git a/src/actions/make/_make.lua b/src/actions/make/_make.lua index 7da88ec99f..dbd09b023c 100644 --- a/src/actions/make/_make.lua +++ b/src/actions/make/_make.lua @@ -22,13 +22,17 @@ valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Utility", "Makefile" }, - valid_languages = { "C", "C++", "C#" }, - valid_tools = { cc = { "clang", "gcc" }, dotnet = { "mono", "msnet", "pnet" } }, + supports_language = function(lang) + return p.languages.isc(lang) or + p.languages.iscpp(lang) or + p.languages.isdotnet(lang) + end, + onWorkspace = function(wks) premake.escaper(make.esc) premake.generate(wks, make.getmakefilename(wks, false), make.generate_workspace) diff --git a/src/actions/vstudio/vs2005.lua b/src/actions/vstudio/vs2005.lua index 2a7ebc88a6..9cbfe81d88 100644 --- a/src/actions/vstudio/vs2005.lua +++ b/src/actions/vstudio/vs2005.lua @@ -100,11 +100,15 @@ -- The capabilities of this action valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None" }, - valid_languages = { "C", "C++", "C#" }, valid_tools = { cc = { "msc" }, dotnet = { "msnet" }, }, + supports_language = function(lang) + return p.languages.isc(lang) or + p.languages.iscpp(lang) or + p.languages.isdotnet(lang) + end, -- Workspace and project generation logic diff --git a/src/actions/vstudio/vs2008.lua b/src/actions/vstudio/vs2008.lua index afe3e49a2c..6ee1a6cf97 100644 --- a/src/actions/vstudio/vs2008.lua +++ b/src/actions/vstudio/vs2008.lua @@ -27,11 +27,15 @@ -- The capabilities of this action valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None" }, - valid_languages = { "C", "C++", "C#" }, valid_tools = { cc = { "msc" }, dotnet = { "msnet" }, }, + supports_language = function(lang) + return p.languages.isc(lang) or + p.languages.iscpp(lang) or + p.languages.isdotnet(lang) + end, -- Workspace and project generation logic diff --git a/src/actions/vstudio/vs2010.lua b/src/actions/vstudio/vs2010.lua index 4cd57f91b2..fd7109bb8f 100644 --- a/src/actions/vstudio/vs2010.lua +++ b/src/actions/vstudio/vs2010.lua @@ -123,11 +123,15 @@ -- The capabilities of this action valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None", "Utility" }, - valid_languages = { "C", "C++", "C#" }, valid_tools = { cc = { "msc" }, dotnet = { "msnet" }, }, + supports_language = function(lang) + return p.languages.isc(lang) or + p.languages.iscpp(lang) or + p.languages.isdotnet(lang) + end, -- Workspace and project generation logic diff --git a/src/actions/vstudio/vs2012.lua b/src/actions/vstudio/vs2012.lua index 4f46dc56c3..cc6910b64e 100644 --- a/src/actions/vstudio/vs2012.lua +++ b/src/actions/vstudio/vs2012.lua @@ -29,11 +29,15 @@ -- The capabilities of this action valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None", "Utility" }, - valid_languages = { "C", "C++", "C#" }, valid_tools = { cc = { "msc" }, dotnet = { "msnet" }, }, + supports_language = function(lang) + return p.languages.isc(lang) or + p.languages.iscpp(lang) or + p.languages.isdotnet(lang) + end, -- Workspace and project generation logic diff --git a/src/actions/vstudio/vs2013.lua b/src/actions/vstudio/vs2013.lua index 558f02bc83..7ade06dbb4 100644 --- a/src/actions/vstudio/vs2013.lua +++ b/src/actions/vstudio/vs2013.lua @@ -31,11 +31,15 @@ -- The capabilities of this action valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None", "Utility" }, - valid_languages = { "C", "C++", "C#" }, valid_tools = { cc = { "msc" }, dotnet = { "msnet" }, }, + supports_language = function(lang) + return p.languages.isc(lang) or + p.languages.iscpp(lang) or + p.languages.isdotnet(lang) + end, -- Workspace and project generation logic diff --git a/src/actions/vstudio/vs2015.lua b/src/actions/vstudio/vs2015.lua index 88ab8e5eb1..ab2676a35c 100644 --- a/src/actions/vstudio/vs2015.lua +++ b/src/actions/vstudio/vs2015.lua @@ -31,11 +31,15 @@ -- The capabilities of this action valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None", "Utility" }, - valid_languages = { "C", "C++", "C#" }, valid_tools = { cc = { "msc" }, dotnet = { "msnet" }, }, + supports_language = function(lang) + return p.languages.isc(lang) or + p.languages.iscpp(lang) or + p.languages.isdotnet(lang) + end, -- Workspace and project generation logic diff --git a/src/actions/vstudio/vs2017.lua b/src/actions/vstudio/vs2017.lua index 0d5617c3b2..0ecb53f998 100644 --- a/src/actions/vstudio/vs2017.lua +++ b/src/actions/vstudio/vs2017.lua @@ -31,11 +31,15 @@ -- The capabilities of this action valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None", "Utility", "Installer" }, - valid_languages = { "C", "C++", "C#" }, valid_tools = { cc = { "msc" }, dotnet = { "msnet" }, }, + supports_language = function(lang) + return p.languages.isc(lang) or + p.languages.iscpp(lang) or + p.languages.isdotnet(lang) + end, -- Workspace and project generation logic diff --git a/src/base/action.lua b/src/base/action.lua index c403742ccb..5edabf2378 100644 --- a/src/base/action.lua +++ b/src/base/action.lua @@ -239,19 +239,24 @@ if not self then return false end - if not self.valid_languages and not self.valid_kinds then + + if not self.valid_languages and not self.valid_kinds and not self.supports_language then return true end - if self.valid_languages then - if table.contains(self.valid_languages, feature) then - return true - end + + if self.valid_languages and table.contains(self.valid_languages, feature) then + return true end - if self.valid_kinds then - if table.contains(self.valid_kinds, feature) then - return true - end + + if self.valid_kinds and table.contains(self.valid_kinds, feature) then + return true + end + + if self.supports_language and self.supports_language(feature) then + return true end + + return false end