From 32183f039f5e7185aee3913c641644574e6ecb6a Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Tue, 28 Apr 2015 18:50:56 -0400 Subject: [PATCH] Modify toolset() to accept an option version number. toolset("gcc") -- specifies GCC with no specific version toolset("gcc-4.8") -- GCC version 4.8 toolset("msc-100") -- MSC with platform toolset v100 toolset("v100") -- same as above --- src/_manifest.lua | 1 + src/_premake_init.lua | 10 ++- src/actions/vstudio/vs2010_vcxproj.lua | 15 ++-- src/base/_foundation.lua | 1 - src/base/config.lua | 9 +- src/base/tools.lua | 40 +++++++++ tests/_tests.lua | 1 + .../vstudio/vc2010/test_config_props.lua | 49 ----------- .../vstudio/vc2010/test_platform_toolset.lua | 88 +++++++++++++++++++ 9 files changed, 152 insertions(+), 62 deletions(-) create mode 100644 src/base/tools.lua create mode 100644 tests/actions/vstudio/vc2010/test_platform_toolset.lua diff --git a/src/_manifest.lua b/src/_manifest.lua index 39bf1129..9e4d5e68 100644 --- a/src/_manifest.lua +++ b/src/_manifest.lua @@ -16,6 +16,7 @@ "base/path.lua", "base/os.lua", "base/io.lua", + "base/tools.lua", "base/tree.lua", "base/globals.lua", diff --git a/src/_premake_init.lua b/src/_premake_init.lua index f7770ec5..2680db42 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -6,7 +6,8 @@ -- Copyright (c) 2012-2015 Jason Perkins and the Premake project -- - local api = premake.api + local p = premake + local api = p.api local DOC_URL = "See https://github.com/premake/premake-core/wiki/" @@ -898,9 +899,10 @@ scope = "config", kind = "string", allowed = function(value) - local key = value:lower() - if premake.tools[key] ~= nil then - return key + value = value:lower() + local tool, version = p.tools.canonical(value) + if tool then + return value end end, } diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index 591de064..919da7b6 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -1396,14 +1396,19 @@ function m.platformToolset(cfg) - local action = premake.action.current() - local value = action.vstudio.platformToolset - if value then + local tool, version = p.config.toolset(cfg) + if version then + version = "v" .. version + else + local action = premake.action.current() + version = action.vstudio.platformToolset + end + if version then -- should only be written if there is a C/C++ file in the config for i = 1, #cfg.files do if path.iscppfile(cfg.files[i]) then - _p(2,'%s', value) - return + p.w('%s', version) + break end end end diff --git a/src/base/_foundation.lua b/src/base/_foundation.lua index cd5e8128..fc19847f 100644 --- a/src/base/_foundation.lua +++ b/src/base/_foundation.lua @@ -5,7 +5,6 @@ premake = premake or {} premake.modules = {} - premake.tools = {} premake.extensions = premake.modules diff --git a/src/base/config.lua b/src/base/config.lua index 37e87720..1133b260 100755 --- a/src/base/config.lua +++ b/src/base/config.lua @@ -1,7 +1,7 @@ -- -- config.lua -- Premake configuration object API --- Copyright (c) 2011-2013 Jason Perkins and the Premake project +-- Copyright (c) 2011-2015 Jason Perkins and the Premake project -- local p = premake @@ -539,9 +539,12 @@ --- -- Return the appropriate toolset adapter for the provided configuration, --- or nil if no toolset is specified. +-- or nil if no toolset is specified. If a specific version was provided, +-- returns that as a second argument. --- function config.toolset(cfg) - return premake.tools[cfg.toolset] + if cfg.toolset then + return p.tools.canonical(cfg.toolset) + end end diff --git a/src/base/tools.lua b/src/base/tools.lua new file mode 100644 index 00000000..1197f748 --- /dev/null +++ b/src/base/tools.lua @@ -0,0 +1,40 @@ +--- +-- tools.lua +-- Work with Premake's collection of tool adapters. +-- Author Jason Perkins +-- Copyright (c) 2015 Jason Perkins and the Premake project +--- + + local p = premake + p.tools = {} + + +--- +-- Given a toolset identifier (e.g. "gcc" or "gcc-4.8") returns the +-- corresponding tool adapter and the version, if one was provided. +-- +-- @param identifier +-- A toolset identifier composed of two parts: the toolset name, +-- which should match of the name of the adapter object ("gcc", +-- "clang", etc.) in the premake.tools namespace, and and optional +-- version number, separated by a dash. +-- +-- To make things more intuitive for Visual Studio users, supports +-- identifiers like "v100" to represent the v100 Microsoft platform +-- toolset. +-- @return +-- If successful, returns the toolset adapter object. If a version +-- was specified as part of the identifier, that is returned as a +-- second return value. If no corresponding tool adapter exists, +-- returns nil. +--- + + function p.tools.canonical(identifier) + local parts + if identifier:startswith("v") then + parts = { "msc", identifier:sub(2) } + else + parts = identifier:explode("-") + end + return p.tools[parts[1]], parts[2] + end diff --git a/tests/_tests.lua b/tests/_tests.lua index e8a8f9d4..2079f5fb 100644 --- a/tests/_tests.lua +++ b/tests/_tests.lua @@ -117,6 +117,7 @@ return { "actions/vstudio/vc2010/test_manifest.lua", "actions/vstudio/vc2010/test_nmake_props.lua", "actions/vstudio/vc2010/test_output_props.lua", + "actions/vstudio/vc2010/test_platform_toolset.lua", "actions/vstudio/vc2010/test_project_configs.lua", "actions/vstudio/vc2010/test_project_refs.lua", "actions/vstudio/vc2010/test_prop_sheet.lua", diff --git a/tests/actions/vstudio/vc2010/test_config_props.lua b/tests/actions/vstudio/vc2010/test_config_props.lua index e74d9b00..f8420a68 100755 --- a/tests/actions/vstudio/vc2010/test_config_props.lua +++ b/tests/actions/vstudio/vc2010/test_config_props.lua @@ -302,52 +302,3 @@ true ]] end - - - ---- --- Visual Studio 2012 adds a new element. ---- - - function suite.addsPlatformToolset_onVS2012() - _ACTION = "vs2012" - files "hello.cpp" - prepare() - test.capture [[ - - Application - false - MultiByte - v110 - - ]] - end - - - function suite.addsPlatformToolset_onVS2013() - _ACTION = "vs2013" - files "hello.cpp" - prepare() - test.capture [[ - - Application - false - MultiByte - v120 - - ]] - end - - - function suite.excludesPlatformToolset_onNoRelevantSources() - _ACTION = "vs2012" - files "hello.x" - prepare() - test.capture [[ - - Application - false - MultiByte - - ]] - end diff --git a/tests/actions/vstudio/vc2010/test_platform_toolset.lua b/tests/actions/vstudio/vc2010/test_platform_toolset.lua new file mode 100644 index 00000000..6e618956 --- /dev/null +++ b/tests/actions/vstudio/vc2010/test_platform_toolset.lua @@ -0,0 +1,88 @@ +-- +-- tests/actions/vstudio/vc2010/test_platform_toolset.lua +-- Validate VC platform toolset generation. +-- Copyright (c) 2013-2015 Jason Perkins and the Premake project +-- + + local suite = test.declare("vstudio_vs2010_platform_toolset") + local vc2010 = premake.vstudio.vc2010 + + +-- +-- Setup +-- + + local sln, prj + + function suite.setup() + _ACTION = "vs2012" + sln, prj = test.createsolution() + files "hello.cpp" + end + + local function prepare() + cfg = test.getconfig(prj, "Debug") + vc2010.platformToolset(cfg) + end + + + +-- +-- Check default values for each version. +-- + + function suite.correctDefault_onVS2010() + _ACTION = "vs2010" + prepare() + test.isemptycapture() + end + + + function suite.correctDefault_onVS2012() + _ACTION = "vs2012" + prepare() + test.capture [[ +v110 + ]] + end + + + function suite.correctDefault_onVS2013() + _ACTION = "vs2013" + prepare() + test.capture [[ +v120 + ]] + end + + +-- +-- Element should only be written if C++ files are present. +-- + + function suite.empty_onNoRelevantSources() + removefiles "hello.cpp" + prepare() + test.isemptycapture() + end + + +-- +-- Check for overrides from project scripts. +-- + + function suite.canOverrideFromScript_withV() + toolset "v90" + prepare() + test.capture [[ +v90 + ]] + end + + function suite.canOverrideFromScript_withMsc() + toolset "msc-100" + prepare() + test.capture [[ +v100 + ]] + end