diff --git a/modules/self-test/test_runner.lua b/modules/self-test/test_runner.lua index 84b0a2b7..df349593 100644 --- a/modules/self-test/test_runner.lua +++ b/modules/self-test/test_runner.lua @@ -108,7 +108,7 @@ hooks.action = _ACTION hooks.options = _OPTIONS - hooks.os = _OS + hooks.targetOs = _TARGET_OS hooks.io_open = io.open hooks.io_output = io.output @@ -151,7 +151,7 @@ function _.removeTestingHooks(hooks) _ACTION = hooks.action _OPTIONS = hooks.options - _OS = hooks.os + _TARGET_OS = hooks.targetOs io.open = hooks.io_open io.output = hooks.io_output diff --git a/modules/xcode/_preload.lua b/modules/xcode/_preload.lua index 4c1cc1b2..412974af 100644 --- a/modules/xcode/_preload.lua +++ b/modules/xcode/_preload.lua @@ -35,7 +35,7 @@ -- Xcode always uses Mac OS X path and naming conventions - os = "macosx", + targetos = "macosx", -- The capabilities of this action diff --git a/modules/xcode/tests/test_xcode4_project.lua b/modules/xcode/tests/test_xcode4_project.lua index 9729cb37..bf4b3961 100644 --- a/modules/xcode/tests/test_xcode4_project.lua +++ b/modules/xcode/tests/test_xcode4_project.lua @@ -48,7 +48,7 @@ end function suite.setup() - _OS = "macosx" + _TARGET_OS = "macosx" _ACTION = "xcode4" io.eol = "\n" xcode.used_ids = { } -- reset the list of generated IDs diff --git a/modules/xcode/tests/test_xcode_project.lua b/modules/xcode/tests/test_xcode_project.lua index 1f13f90b..de9d02e1 100644 --- a/modules/xcode/tests/test_xcode_project.lua +++ b/modules/xcode/tests/test_xcode_project.lua @@ -19,7 +19,7 @@ end function suite.setup() - _OS = "macosx" + _TARGET_OS = "macosx" _ACTION = "xcode4" premake.eol("\n") xcode.used_ids = { } -- reset the list of generated IDs diff --git a/scripts/package.lua b/scripts/package.lua index 8cd1b71d..4c4c1643 100644 --- a/scripts/package.lua +++ b/scripts/package.lua @@ -60,7 +60,7 @@ local pkgName = "premake-" .. version local pkgExt = ".zip" - if not os.is("windows") and kind == "binary" then + if not os.istarget("windows") and kind == "binary" then pkgExt = ".tar.gz" end @@ -180,8 +180,8 @@ if kind == "binary" then os.chdir("bin/release") - local name = string.format("%s-%s%s", pkgName, os.get(), pkgExt) - if os.is("windows") then + local name = string.format("%s-%s%s", pkgName, os.current(), pkgExt) + if os.iscurrent("windows") then execQuiet("zip -9 %s premake5.exe", name) else execQuiet("tar czvf %s premake5", name) diff --git a/src/actions/make/make_csharp.lua b/src/actions/make/make_csharp.lua index 7a7e3fbd..01d622a0 100644 --- a/src/actions/make/make_csharp.lua +++ b/src/actions/make/make_csharp.lua @@ -200,7 +200,7 @@ _x('\t$(SILENT) if exist $(RESPONSE) del %s', path.translate(response, '\\')) _p('endif') - local sep = os.is("windows") and "\\" or "/" + local sep = os.istarget("windows") and "\\" or "/" local tr = project.getsourcetree(prj) premake.tree.traverse(tr, { onleaf = function(node, depth) diff --git a/src/actions/vstudio/vs2005.lua b/src/actions/vstudio/vs2005.lua index 2a7ebc88..71a9a69b 100644 --- a/src/actions/vstudio/vs2005.lua +++ b/src/actions/vstudio/vs2005.lua @@ -95,7 +95,7 @@ -- Visual Studio always uses Windows path and naming conventions - os = "windows", + targetos = "windows", -- The capabilities of this action diff --git a/src/actions/vstudio/vs2008.lua b/src/actions/vstudio/vs2008.lua index afe3e49a..81116e00 100644 --- a/src/actions/vstudio/vs2008.lua +++ b/src/actions/vstudio/vs2008.lua @@ -22,7 +22,7 @@ -- Visual Studio always uses Windows path and naming conventions - os = "windows", + targetos = "windows", -- The capabilities of this action diff --git a/src/actions/vstudio/vs2010.lua b/src/actions/vstudio/vs2010.lua index 4cd57f91..7445c1e3 100644 --- a/src/actions/vstudio/vs2010.lua +++ b/src/actions/vstudio/vs2010.lua @@ -118,7 +118,7 @@ -- Visual Studio always uses Windows path and naming conventions - os = "windows", + targetos = "windows", -- The capabilities of this action diff --git a/src/actions/vstudio/vs2012.lua b/src/actions/vstudio/vs2012.lua index 4f46dc56..64653f68 100644 --- a/src/actions/vstudio/vs2012.lua +++ b/src/actions/vstudio/vs2012.lua @@ -24,7 +24,7 @@ -- Visual Studio always uses Windows path and naming conventions - os = "windows", + targetos = "windows", -- The capabilities of this action diff --git a/src/actions/vstudio/vs2013.lua b/src/actions/vstudio/vs2013.lua index 558f02bc..c0edb028 100644 --- a/src/actions/vstudio/vs2013.lua +++ b/src/actions/vstudio/vs2013.lua @@ -26,7 +26,7 @@ -- Visual Studio always uses Windows path and naming conventions - os = "windows", + targetos = "windows", -- The capabilities of this action diff --git a/src/actions/vstudio/vs2015.lua b/src/actions/vstudio/vs2015.lua index 88ab8e5e..f5754238 100644 --- a/src/actions/vstudio/vs2015.lua +++ b/src/actions/vstudio/vs2015.lua @@ -26,7 +26,7 @@ -- Visual Studio always uses Windows path and naming conventions - os = "windows", + targetos = "windows", -- The capabilities of this action diff --git a/src/actions/vstudio/vs2017.lua b/src/actions/vstudio/vs2017.lua index 0d5617c3..4afc9a1a 100644 --- a/src/actions/vstudio/vs2017.lua +++ b/src/actions/vstudio/vs2017.lua @@ -26,7 +26,7 @@ -- Visual Studio always uses Windows path and naming conventions - os = "windows", + targetos = "windows", -- The capabilities of this action diff --git a/src/base/action.lua b/src/base/action.lua index c403742c..b9ff31f8 100644 --- a/src/base/action.lua +++ b/src/base/action.lua @@ -61,6 +61,12 @@ error(string.format('action "%s" needs a %s', name, missing), 3) end + if act.os ~= nil then + premake.warnOnce(act.trigger, "action '" .. act.trigger .. "' sets 'os' field, which is deprecated, use 'targetos' instead.") + act.targetos = act.os + act.os = nil + end + action._list[act.trigger] = act end @@ -212,7 +218,7 @@ -- Some actions imply a particular operating system local act = action.get(name) if act then - _OS = act.os or _OS + _TARGET_OS = act.targetos or _TARGET_OS end -- Some are implemented in standalone modules diff --git a/src/base/moduledownloader.lua b/src/base/moduledownloader.lua index 30c8c7d7..55b76950 100644 --- a/src/base/moduledownloader.lua +++ b/src/base/moduledownloader.lua @@ -23,7 +23,7 @@ -- get current user. local user = 'UNKNOWN' - if os.get() == 'windows' then + if os.iscurrent('windows') then user = os.getenv('USERNAME') or user else user = os.getenv('LOGNAME') or user diff --git a/src/base/os.lua b/src/base/os.lua index bd1aa547..82912481 100644 --- a/src/base/os.lua +++ b/src/base/os.lua @@ -69,14 +69,14 @@ local path, formats -- assemble a search path, depending on the platform - if os.is("windows") then + if os.istarget("windows") then formats = { "%s.dll", "%s" } path = os.getenv("PATH") or "" - elseif os.is("haiku") then + elseif os.istarget("haiku") then formats = { "lib%s.so", "%s.so" } path = os.getenv("LIBRARY_PATH") or "" else - if os.is("macosx") then + if os.istarget("macosx") then formats = { "lib%s.dylib", "%s.dylib" } path = os.getenv("DYLD_LIBRARY_PATH") or "" else @@ -100,7 +100,7 @@ table.insert(formats, "%s") path = path or "" local archpath = "/lib:/usr/lib:/usr/local/lib" - if os.is64bit() and not os.is("macosx") then + if os.is64bit() and not os.istarget("macosx") then archpath = "/lib64:/usr/lib64/:usr/local/lib64" .. ":" .. archpath end if (#path > 0) then @@ -134,26 +134,65 @@ end +-- +-- Retrieve the current target operating system ID string. +-- --- --- Retrieve the current operating system ID string. --- + function os.target() + return _OPTIONS.os or _TARGET_OS + end function os.get() - return _OPTIONS.os or _OS + premake.warnOnce("os.get", "os.get() is deprecated, use 'os.target()' or 'os.current()'.") + return os.target() end + -- deprecate _OS + _G_metatable = { + __index = function(t, k) + if (k == '_OS') then + premake.warnOnce("_OS+get", "_OS is deprecated, use '_TARGET_OS'.") + return rawget(t, "_TARGET_OS") + else + return rawget(t, k) + end + end, + + __newindex = function(t, k, v) + if (k == '_OS') then + premake.warnOnce("_OS+set", "_OS is deprecated, use '_TARGET_OS'.") + rawset(t, "_TARGET_OS", v) + else + rawset(t, k, v) + end + end + } + setmetatable(_G, _G_metatable) + -- --- Check the current operating system; may be set with the /os command line flag. +-- Check the current target operating system; may be set with the /os command line flag. -- + function os.istarget(id) + return (os.target():lower() == id:lower()) + end + function os.is(id) - return (os.get():lower() == id:lower()) + premake.warnOnce("os.is", "os.is() is deprecated, use 'os.istarget()' or 'os.iscurrent()'.") + return os.istarget(id) end +-- +-- Check the current executing operating system. +-- + + function os.iscurrent(id) + return (os.current():lower() == id:lower()) + end + --- -- Determine if a directory exists on the file system, and that it is a @@ -219,9 +258,9 @@ else -- Identify the system local arch - if _OS == "windows" then + if os.iscurrent("windows") then arch = os.getenv("PROCESSOR_ARCHITECTURE") - elseif _OS == "macosx" then + elseif os.iscurrent("macosx") then arch = os.outputof("echo $HOSTTYPE") else arch = os.outputof("uname -m") @@ -529,7 +568,7 @@ } function os.translateCommands(cmd, map) - map = map or os.get() + map = map or os.target() if type(map) == "string" then map = os.commandTokens[map] or os.commandTokens["_"] end diff --git a/src/base/oven.lua b/src/base/oven.lua index a781ac91..d0a8197d 100644 --- a/src/base/oven.lua +++ b/src/base/oven.lua @@ -63,7 +63,7 @@ context.addFilter(self, "_ACTION", _ACTION) context.addFilter(self, "action", _ACTION) - self.system = self.system or p.action.current().os or os.get() + self.system = self.system or p.action.current().targetos or os.target() context.addFilter(self, "system", self.system) -- Add command line options to the filtering options @@ -204,7 +204,7 @@ -- Now filter on the current system and architecture, allowing the -- values that might already in the context to override my defaults. - self.system = self.system or p.action.current().os or os.get() + self.system = self.system or p.action.current().targetos or os.target() context.addFilter(self, "system", self.system) context.addFilter(self, "architecture", self.architecture) @@ -528,7 +528,7 @@ -- More than a convenience; this is required to work properly with -- external Visual Studio project files. - local system = p.action.current().os or os.get() + local system = p.action.current().targetos or os.target() local architecture = nil local toolset = nil diff --git a/src/host/os_current.c b/src/host/os_current.c new file mode 100644 index 00000000..9869e986 --- /dev/null +++ b/src/host/os_current.c @@ -0,0 +1,13 @@ +/** + * \file os_current.c + * \brief Get the current OS we're executing on. + * \author Copyright (c) 2014-2017 Tom van Dijck, Jason Perkins and the Premake project + */ + +#include "premake.h" + +int os_current(lua_State* L) +{ + lua_pushstring(L, PLATFORM_STRING); + return 1; +} diff --git a/src/host/premake.c b/src/host/premake.c index 8b03b2f0..60cc2b0b 100644 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -58,6 +58,7 @@ static const luaL_Reg os_functions[] = { { "chdir", os_chdir }, { "chmod", os_chmod }, { "copyfile", os_copyfile }, + { "current", os_current }, { "_is64bit", os_is64bit }, { "isdir", os_isdir }, { "getcwd", os_getcwd }, @@ -153,7 +154,7 @@ int premake_init(lua_State* L) /* set the OS platform variable */ lua_pushstring(L, PLATFORM_STRING); - lua_setglobal(L, "_OS"); + lua_setglobal(L, "_TARGET_OS"); /* find the user's home directory */ value = getenv("HOME"); diff --git a/src/host/premake.h b/src/host/premake.h index c8bb3f23..64f951ec 100644 --- a/src/host/premake.h +++ b/src/host/premake.h @@ -102,6 +102,7 @@ int path_wildcards(lua_State* L); int os_chdir(lua_State* L); int os_chmod(lua_State* L); int os_copyfile(lua_State* L); +int os_current(lua_State* L); int os_getcwd(lua_State* L); int os_getpass(lua_State* L); int os_getWindowsRegistry(lua_State* L); diff --git a/src/tools/dotnet.lua b/src/tools/dotnet.lua index 63748727..ffa02809 100644 --- a/src/tools/dotnet.lua +++ b/src/tools/dotnet.lua @@ -222,7 +222,7 @@ } if tool == "csc" then - local toolset = _OPTIONS.dotnet or iif(os.is(premake.WINDOWS), "msnet", "mono") + local toolset = _OPTIONS.dotnet or iif(os.istarget("windows"), "msnet", "mono") return compilers[toolset] else return "resgen" diff --git a/tests/actions/make/cpp/test_make_linking.lua b/tests/actions/make/cpp/test_make_linking.lua index 1118c251..0b952638 100644 --- a/tests/actions/make/cpp/test_make_linking.lua +++ b/tests/actions/make/cpp/test_make_linking.lua @@ -16,7 +16,7 @@ local wks, prj function suite.setup() - _OS = "linux" + _TARGET_OS = "linux" wks, prj = test.createWorkspace() end @@ -41,7 +41,7 @@ end function suite.links_onMacOSXCppSharedLib() - _OS = "macosx" + _TARGET_OS = "macosx" kind "SharedLib" prepare { "ldFlags", "linkCmd" } test.capture [[ @@ -169,7 +169,7 @@ end function suite.links_onMacOSXSiblingSharedLib() - _OS = "macosx" + _TARGET_OS = "macosx" links "MyProject2" flags { "RelativeLinks" } diff --git a/tests/actions/make/cs/test_response.lua b/tests/actions/make/cs/test_response.lua index 64ee427c..d766d45a 100644 --- a/tests/actions/make/cs/test_response.lua +++ b/tests/actions/make/cs/test_response.lua @@ -55,7 +55,7 @@ $(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS) $(RESPONSE) end function suite.listResponseRulesPosix() - _OS = "linux" + _TARGET_OS = "linux" suite.listResponseRules() test.capture [[ $(RESPONSE): MyProject.make @@ -72,7 +72,7 @@ endif end function suite.listResponseRulesWindows() - _OS = "windows" + _TARGET_OS = "windows" suite.listResponseRules() test.capture [[ $(RESPONSE): MyProject.make diff --git a/tests/base/test_os.lua b/tests/base/test_os.lua index 98e5ddad..99931e29 100644 --- a/tests/base/test_os.lua +++ b/tests/base/test_os.lua @@ -23,9 +23,9 @@ -- function suite.findlib_FindSystemLib() - if os.is("windows") then + if os.istarget("windows") then test.istrue(os.findlib("user32")) - elseif os.is("haiku") then + elseif os.istarget("haiku") then test.istrue(os.findlib("root")) else test.istrue(os.findlib("m")) @@ -143,10 +143,10 @@ -- Check if outputof returns the command exit code -- in addition of the command output function suite.outputof_commandExitCode() - if os.is("macosx") - or os.is("linux") - or os.is("solaris") - or os.is("bsd") + if os.istarget("macosx") + or os.istarget("linux") + or os.istarget("solaris") + or os.istarget("bsd") then -- Assumes 'true' and 'false' commands exist -- which should be the case on all *nix platforms @@ -232,48 +232,48 @@ -- os.getWindowsRegistry windows tests -- function suite.getreg_nonExistentValue() - if os.is("windows") then + if os.iscurrent("windows") then local x = os.getWindowsRegistry("HKCU:Should\\Not\\Exist\\At\\All") test.isequal(nil, x) end end function suite.getreg_nonExistentDefaultValue() - if os.is("windows") then + if os.iscurrent("windows") then local x = os.getWindowsRegistry("HKCU:Should\\Not\\Exist\\At\\All\\") test.isequal(nil, x) end end function suite.getreg_noSeparators() - if os.is("windows") then + if os.iscurrent("windows") then os.getWindowsRegistry("HKCU:ShouldNotExistAtAll") end end function suite.getreg_namedValue() - if os.is("windows") then + if os.iscurrent("windows") then local x = os.getWindowsRegistry("HKCU:Environment\\TEMP") test.istrue(x ~= nil) end end function suite.getreg_namedValueOptSeparator() - if os.is("windows") then + if os.iscurrent("windows") then local x = os.getWindowsRegistry("HKCU:\\Environment\\TEMP") test.istrue(x ~= nil) end end function suite.getreg_defaultValue() - if os.is("windows") then + if os.iscurrent("windows") then local x = os.getWindowsRegistry("HKLM:SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Minimal\\AppInfo\\") test.isequal("Service", x) end end --- +-- -- os.getversion tests. -- diff --git a/tests/config/test_links.lua b/tests/config/test_links.lua index c4034092..67f68a33 100755 --- a/tests/config/test_links.lua +++ b/tests/config/test_links.lua @@ -16,7 +16,7 @@ function suite.setup() premake.action.set("test") - _OS = "windows" + _TARGET_OS = "windows" wks, prj = test.createWorkspace() end diff --git a/tests/config/test_targetinfo.lua b/tests/config/test_targetinfo.lua index 2c7617b8..bad4b393 100755 --- a/tests/config/test_targetinfo.lua +++ b/tests/config/test_targetinfo.lua @@ -252,7 +252,7 @@ -- function suite.appUsesExe_onDotNet() - _OS = "macosx" + _TARGET_OS = "macosx" language "C#" i = prepare() test.isequal("MyProject.exe", i.name) @@ -265,7 +265,7 @@ -- function suite.appUsesExe_onDotNet() - _OS = "macosx" + _TARGET_OS = "macosx" language "C#" kind "SharedLib" i = prepare() diff --git a/tests/project/test_getconfig.lua b/tests/project/test_getconfig.lua index 34c55cb5..78b4f447 100755 --- a/tests/project/test_getconfig.lua +++ b/tests/project/test_getconfig.lua @@ -29,7 +29,7 @@ -- function suite.usesCurrentOS_onNoSystemSpecified() - _OS = "linux" + _TARGET_OS = "linux" project ("MyProject") filter { "system:linux" } defines { "correct" } @@ -45,7 +45,7 @@ -- function suite.actionOverridesOS() - _OS = "linux" + _TARGET_OS = "linux" _ACTION = "vs2005" project ("MyProject") filter { "system:windows" } @@ -61,7 +61,7 @@ -- function suite.usesCfgSystem() - _OS = "linux" + _TARGET_OS = "linux" _ACTION = "vs2005" project ("MyProject") system "macosx" diff --git a/tests/tools/test_dotnet.lua b/tests/tools/test_dotnet.lua index 005d1a50..cd86946b 100644 --- a/tests/tools/test_dotnet.lua +++ b/tests/tools/test_dotnet.lua @@ -28,7 +28,7 @@ -- function suite.defaultCompiler_onWindows() - _OS = "windows" + _TARGET_OS = "windows" prepare() test.isequal("csc", dotnet.gettoolname(cfg, "csc")) end @@ -39,7 +39,7 @@ -- function suite.defaultCompiler_onMacOSX() - _OS = "macosx" + _TARGET_OS = "macosx" prepare() test.isequal("mcs", dotnet.gettoolname(cfg, "csc")) end