From 309ef32ff87b515c0583501f3fe68a3903a32a60 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Mon, 18 Jan 2016 14:11:50 -0500 Subject: [PATCH] Move character set command line flags from switch lists to defines --- src/actions/make/make_cpp.lua | 2 +- src/tools/msc.lua | 28 +++++++++++++++++++++------- tests/tools/test_msc.lua | 8 ++++---- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/actions/make/make_cpp.lua b/src/actions/make/make_cpp.lua index f5912861..5c178d1d 100644 --- a/src/actions/make/make_cpp.lua +++ b/src/actions/make/make_cpp.lua @@ -390,7 +390,7 @@ function make.defines(cfg, toolset) - _p(' DEFINES +=%s', make.list(table.join(toolset.getdefines(cfg.defines), toolset.getundefines(cfg.undefines)))) + _p(' DEFINES +=%s', make.list(table.join(toolset.getdefines(cfg.defines, cfg), toolset.getundefines(cfg.undefines)))) end diff --git a/src/tools/msc.lua b/src/tools/msc.lua index 1f79c7e2..6592724e 100644 --- a/src/tools/msc.lua +++ b/src/tools/msc.lua @@ -29,11 +29,6 @@ -- msc.cflags = { - characterset = { - Default = { '/D"_UNICODE"', '/D"UNICODE"' }, - MBCS = '/D"_MBCS"', - Unicode = { '/D"_UNICODE"', '/D"UNICODE"' }, - }, clr = { On = "/clr", Unsafe = "/clr", @@ -133,8 +128,27 @@ -- Decorate defines for the MSVC command line. -- - function msc.getdefines(defines) - local result = {} + msc.defines = { + characterset = { + Default = { '/D"_UNICODE"', '/D"UNICODE"' }, + MBCS = '/D"_MBCS"', + Unicode = { '/D"_UNICODE"', '/D"UNICODE"' }, + } + } + + function msc.getdefines(defines, cfg) + local result + + -- HACK: I need the cfg to tell what the character set defines should be. But + -- there's lots of legacy code using the old getdefines(defines) signature. + -- For now, detect one or two arguments and apply the right behavior; will fix + -- it properly when the I roll out the adapter overhaul + if cfg and defines then + result = config.mapFlags(cfg, msc.defines) + else + result = {} + end + for _, define in ipairs(defines) do table.insert(result, '/D"' .. define .. '"') end diff --git a/tests/tools/test_msc.lua b/tests/tools/test_msc.lua index 9d9e925b..87d495ae 100644 --- a/tests/tools/test_msc.lua +++ b/tests/tools/test_msc.lua @@ -196,7 +196,7 @@ function suite.defines() defines "DEF" prepare() - test.contains({ '/D"DEF"' }, msc.getdefines(cfg.defines)) + test.contains({ '/D"DEF"' }, msc.getdefines(cfg.defines, cfg)) end function suite.undefines() @@ -317,19 +317,19 @@ function suite.cflags_onCharSetDefault() prepare() - test.contains('/D"_UNICODE"', msc.getcflags(cfg)) + test.contains('/D"_UNICODE"', msc.getdefines(cfg.defines, cfg)) end function suite.cflags_onCharSetUnicode() characterset "Unicode" prepare() - test.contains('/D"_UNICODE"', msc.getcflags(cfg)) + test.contains('/D"_UNICODE"', msc.getdefines(cfg.defines, cfg)) end function suite.cflags_onCharSetMBCS() characterset "MBCS" prepare() - test.contains('/D"_MBCS"', msc.getcflags(cfg)) + test.contains('/D"_MBCS"', msc.getdefines(cfg.defines, cfg)) end