From 686f3f071a6167678f33367e2605081bcec61c1e Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Sun, 29 Sep 2013 11:23:39 -0400 Subject: [PATCH] Add optimize(); deprecate Optimize, OptimizeSize, and OptimizeSpeed flags --- src/_premake_init.lua | 17 ++++++++++ src/actions/vstudio/vs200x_vcproj.lua | 17 ++-------- src/actions/vstudio/vs2010_vcxproj.lua | 13 ++----- src/base/config.lua | 12 ++----- src/base/premake.lua | 1 + src/tools/dotnet.lua | 34 +++++++++---------- src/tools/gcc.lua | 8 +++-- src/tools/msc.lua | 27 ++++++--------- .../vstudio/cs2005/test_debug_props.lua | 6 ++-- .../vstudio/vc200x/test_compiler_block.lua | 3 +- .../vstudio/vc2010/test_compile_settings.lua | 9 ++--- tests/actions/vstudio/vc2010/test_link.lua | 4 +-- .../vstudio/vc2010/test_output_props.lua | 2 +- tests/base/test_configset.lua | 14 ++++---- 14 files changed, 75 insertions(+), 92 deletions(-) diff --git a/src/_premake_init.lua b/src/_premake_init.lua index 01188cf6..488ad907 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -454,6 +454,18 @@ tokens = true, } + api.register { + name = "optimize", + scope = "config", + kind = "string", + allowed = { + "Off", + "On", + "Size", + "Speed", + } + } + api.register { name = "pchheader", scope = "config", @@ -678,6 +690,11 @@ return DOC_URL .. "nativewchar" end) + api.deprecateValue("flags", { "Optimize", "OptimizeSize", "OptimizeSpeed" }, function(value) + local map = { Optimize = "On", OptimizeSize = "Size", OptimizeSpeed = "Speed" } + optimize (map[value] or "Off") + return DOC_URL .. "optimize" + end) ----------------------------------------------------------------------------- diff --git a/src/actions/vstudio/vs200x_vcproj.lua b/src/actions/vstudio/vs200x_vcproj.lua index 3ab4bdda..e7ffe927 100644 --- a/src/actions/vstudio/vs200x_vcproj.lua +++ b/src/actions/vstudio/vs200x_vcproj.lua @@ -1275,21 +1275,8 @@ -- function vc200x.optimization(cfg) - local result = 0 - - -- step through the flags in the order they were specified, so - -- later flags can override an earlier value - for _, value in ipairs(cfg.flags) do - if (value == "Optimize") then - result = 3 - elseif (value == "OptimizeSize") then - result = 1 - elseif (value == "OptimizeSpeed") then - result = 2 - end - end - - return result + local map = { On = 3, Size = 1, Speed = 2 } + return map[cfg.optimize] or 0 end diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index 3d5e9db4..4526e43d 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -972,17 +972,8 @@ function vc2010.optimization(cfg) - local result = "Disabled" - for _, flag in ipairs(cfg.flags) do - if flag == "Optimize" then - result = "Full" - elseif flag == "OptimizeSize" then - result = "MinSpace" - elseif flag == "OptimizeSpeed" then - result = "MaxSpeed" - end - end - _p(3,'%s', result) + local map = { On = "Full", Size = "MinSpace", Speed = "MaxSpeed" } + _p(3,'%s', map[cfg.optimize] or "Disabled") end diff --git a/src/base/config.lua b/src/base/config.lua index 13d49c9f..45cb703e 100755 --- a/src/base/config.lua +++ b/src/base/config.lua @@ -466,15 +466,7 @@ -- function config.isDebugBuild(cfg) - -- If any of the optimize flags are set, it's a release build - if cfg.flags.Optimize or cfg.flags.OptimizeSize or cfg.flags.OptimizeSpeed then - return false - end - -- If symbols are not defined, it's a release build - if not cfg.flags.Symbols then - return false - end - return true + return cfg.flags.Symbols and not config.isOptimizedBuild(cfg) end @@ -485,7 +477,7 @@ -- function config.isOptimizedBuild(cfg) - return cfg.flags.Optimize or cfg.flags.OptimizeSize or cfg.flags.OptimizeSpeed + return cfg.optimize ~= nil and cfg.optimize ~= "Off" end diff --git a/src/base/premake.lua b/src/base/premake.lua index 8abdbad8..28f695c4 100644 --- a/src/base/premake.lua +++ b/src/base/premake.lua @@ -39,6 +39,7 @@ premake.MACOSX = "macosx" premake.MAKEFILE = "Makefile" premake.NONE = "None" + premake.OFF = "Off" premake.POSIX = "posix" premake.PS3 = "ps3" premake.SHAREDLIB = "SharedLib" diff --git a/src/tools/dotnet.lua b/src/tools/dotnet.lua index d1b5c05c..feaeb8af 100644 --- a/src/tools/dotnet.lua +++ b/src/tools/dotnet.lua @@ -8,25 +8,11 @@ premake.tools.dotnet = {} local dotnet = premake.tools.dotnet local project = premake.project + local config = premake.config dotnet.namestyle = "windows" --- --- Translation of Premake flags into CSC flags --- - - local flags = - { - FatalWarning = "/warnaserror", - Optimize = "/optimize", - OptimizeSize = "/optimize", - OptimizeSpeed = "/optimize", - Symbols = "/debug", - Unsafe = "/unsafe" - } - - -- -- Examine the file and project configurations to glean additional -- information about a source code in a C# project. @@ -175,8 +161,21 @@ -- Returns a list of compiler flags, based on the supplied configuration. -- + dotnet.flags = { + flags = { + FatalWarning = "/warnaserror", + Symbols = "/debug", + Unsafe = "/unsafe" + }, + optimize = { + On = "/optimize", + Size = "/optimize", + Speed = "/optimize", + }, + } + function dotnet.getflags(cfg) - local flags = {} + local flags = config.mapFlags(cfg, dotnet.flags) if cfg.project.icon then local fn = project.getrelative(cfg.project, cfg.project.icon) @@ -187,8 +186,7 @@ table.insert(flags, table.implode(cfg.defines, "/d:", "", " ")) end - flags = table.join(flags, table.translate(cfg.flags, flags), cfg.buildoptions) - return flags + return table.join(flags, cfg.buildoptions) end diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index ce1d3ff8..3dc22d91 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -100,15 +100,17 @@ FatalWarnings = "-Werror", NoWarnings = "-w", NoFramePointer = "-fomit-frame-pointer", - Optimize = "-O2", - OptimizeSize = "-Os", - OptimizeSpeed = "-O3", Symbols = "-g" }, floatingpoint = { Fast = "-ffast-math", Strict = "-ffloat-store", }, + optimize = { + On = "-O2", + Size = "-Os", + Speed = "-O3", + }, vectorextensions = { SSE = "-msse", SSE2 = "-msse2", diff --git a/src/tools/msc.lua b/src/tools/msc.lua index f98405b6..af1fbcc0 100644 --- a/src/tools/msc.lua +++ b/src/tools/msc.lua @@ -16,8 +16,7 @@ -- function msc.getcppflags(cfg) - local flags = {} - return flags + return {} end @@ -26,12 +25,18 @@ -- msc.cflags = { - SEH = "/EHa", - OptimizeSpeed = "/O2", + flags = { + SEH = "/EHa /EHsc", + Symbols = "/Z7", + }, + optimize = { + Off = "/Od", + Speed = "/O2", + } } function msc.getcflags(cfg) - local flags = table.translate(cfg.flags, msc.cflags) + local flags = config.mapFlags(cfg, msc.cflags) local runtime = iif(cfg.flags.StaticRuntime, "/MT", "/MD") if config.isDebugBuild(cfg) then @@ -39,18 +44,6 @@ end table.insert(flags, runtime) - if not config.isOptimizedBuild(cfg) then - table.insert(flags, "/Od") - end - - if cfg.flags.Symbols then - table.insert(flags, "/Z7") - end - - if not cfg.flags.SEH then - table.insert(flags, "/EHsc") - end - return flags end diff --git a/tests/actions/vstudio/cs2005/test_debug_props.lua b/tests/actions/vstudio/cs2005/test_debug_props.lua index 4334f80f..c56fbe9e 100644 --- a/tests/actions/vstudio/cs2005/test_debug_props.lua +++ b/tests/actions/vstudio/cs2005/test_debug_props.lua @@ -55,7 +55,7 @@ -- function suite.optimize_onOptimizeFlag() - flags { "Optimize" } + optimize "On" prepare() test.capture [[ pdbonly @@ -64,7 +64,7 @@ end function suite.optimize_onOptimizeSizeFlag() - flags { "OptimizeSize" } + optimize "Size" prepare() test.capture [[ pdbonly @@ -73,7 +73,7 @@ end function suite.optimize_onOptimizeSpeedFlag() - flags { "OptimizeSpeed" } + optimize "Speed" prepare() test.capture [[ pdbonly diff --git a/tests/actions/vstudio/vc200x/test_compiler_block.lua b/tests/actions/vstudio/vc200x/test_compiler_block.lua index fd2d024f..bc0c1c60 100644 --- a/tests/actions/vstudio/vc200x/test_compiler_block.lua +++ b/tests/actions/vstudio/vc200x/test_compiler_block.lua @@ -95,7 +95,8 @@ -- function suite.looksGood_onSymbolsAndOptimizeFlags() - flags { "Symbols", "Optimize" } + flags { "Symbols" } + optimize "On" prepare() test.capture [[ @@ -137,7 +137,7 @@ end function suite.optimization_onOptimizeSize() - flags "OptimizeSize" + optimize "Size" prepare() test.capture [[ @@ -152,7 +152,7 @@ end function suite.optimization_onOptimizeSpeed() - flags "OptimizeSpeed" + optimize "Speed" prepare() test.capture [[ @@ -534,7 +534,8 @@ -- function suite.debugFormat_onOptimizedBuild() - flags { "Symbols", "Optimize" } + flags { "Symbols" } + optimize "On" prepare() test.capture [[ diff --git a/tests/actions/vstudio/vc2010/test_link.lua b/tests/actions/vstudio/vc2010/test_link.lua index 85592ae0..895310a6 100644 --- a/tests/actions/vstudio/vc2010/test_link.lua +++ b/tests/actions/vstudio/vc2010/test_link.lua @@ -49,7 +49,7 @@ -- function suite.defaultSettings_onOptimize() - flags "Optimize" + optimize "On" prepare() test.capture [[ @@ -298,7 +298,7 @@ -- function suite.optimizeReferences_onOptimizeFlag() - flags { "Optimize" } + optimize "On" prepare() test.capture [[ diff --git a/tests/actions/vstudio/vc2010/test_output_props.lua b/tests/actions/vstudio/vc2010/test_output_props.lua index 9eaaf3d0..158fa446 100755 --- a/tests/actions/vstudio/vc2010/test_output_props.lua +++ b/tests/actions/vstudio/vc2010/test_output_props.lua @@ -118,7 +118,7 @@ -- function suite.noIncrementalLink_onOptimizedBuild() - flags "Optimize" + optimize "On" prepare() test.capture [[ diff --git a/tests/base/test_configset.lua b/tests/base/test_configset.lua index 29cd8573..85e639ed 100644 --- a/tests/base/test_configset.lua +++ b/tests/base/test_configset.lua @@ -15,7 +15,7 @@ -- local cset, parentset - + function suite.setup() parentset = configset.new() cset = configset.new(parentset) @@ -57,7 +57,7 @@ -- --- Make sure that I can roundtrip a value stored into a block +-- Make sure that I can roundtrip a value stored into a block -- with a simple matching term. -- @@ -80,7 +80,7 @@ -- function suite.skipsBlock_onTermMismatch() - configset.addvalue(cset, "targetextension", ".so") + configset.addvalue(cset, "targetextension", ".so") configset.addblock(cset, { "Windows" }) configset.addvalue(cset, "targetextension", ".dll") test.isequal(".so", configset.fetchvalue(cset, "targetextension", { "linux" })) @@ -168,15 +168,15 @@ -- function suite.remove_onExactValueMatch() - configset.addvalue(cset, "flags", { "Symbols", "Optimize", "NoRTTI" }) - configset.removevalues(cset, "flags", { "Optimize" }) + configset.addvalue(cset, "flags", { "Symbols", "Unsafe", "NoRTTI" }) + configset.removevalues(cset, "flags", { "Unsafe" }) test.isequal({ "Symbols", "NoRTTI" }, configset.fetchvalue(cset, "flags", {})) end function suite.remove_onMultipleValues() - configset.addvalue(cset, "flags", { "Symbols", "NoExceptions", "Optimize", "NoRTTI" }) + configset.addvalue(cset, "flags", { "Symbols", "NoExceptions", "Unsafe", "NoRTTI" }) configset.removevalues(cset, "flags", { "NoExceptions", "NoRTTI" }) - test.isequal({ "Symbols", "Optimize" }, configset.fetchvalue(cset, "flags", {})) + test.isequal({ "Symbols", "Unsafe" }, configset.fetchvalue(cset, "flags", {})) end