replaced:

os.get() -> os.target()
os.is() -> os.istarget()
_OS -> _TARGET_OS

added:
os.current()
os.iscurrent()
This commit is contained in:
Tom van Dijck 2017-04-11 13:39:25 -07:00
parent 97856fe923
commit 5f589ad5a6
28 changed files with 122 additions and 62 deletions

View File

@ -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

View File

@ -35,7 +35,7 @@
-- Xcode always uses Mac OS X path and naming conventions
os = "macosx",
targetos = "macosx",
-- The capabilities of this action

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -95,7 +95,7 @@
-- Visual Studio always uses Windows path and naming conventions
os = "windows",
targetos = "windows",
-- The capabilities of this action

View File

@ -22,7 +22,7 @@
-- Visual Studio always uses Windows path and naming conventions
os = "windows",
targetos = "windows",
-- The capabilities of this action

View File

@ -118,7 +118,7 @@
-- Visual Studio always uses Windows path and naming conventions
os = "windows",
targetos = "windows",
-- The capabilities of this action

View File

@ -24,7 +24,7 @@
-- Visual Studio always uses Windows path and naming conventions
os = "windows",
targetos = "windows",
-- The capabilities of this action

View File

@ -26,7 +26,7 @@
-- Visual Studio always uses Windows path and naming conventions
os = "windows",
targetos = "windows",
-- The capabilities of this action

View File

@ -26,7 +26,7 @@
-- Visual Studio always uses Windows path and naming conventions
os = "windows",
targetos = "windows",
-- The capabilities of this action

View File

@ -26,7 +26,7 @@
-- Visual Studio always uses Windows path and naming conventions
os = "windows",
targetos = "windows",
-- The capabilities of this action

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

13
src/host/os_current.c Normal file
View File

@ -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;
}

View File

@ -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");

View File

@ -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);

View File

@ -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"

View File

@ -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" }

View File

@ -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

View File

@ -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,41 +232,41 @@
-- 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

View File

@ -16,7 +16,7 @@
function suite.setup()
premake.action.set("test")
_OS = "windows"
_TARGET_OS = "windows"
wks, prj = test.createWorkspace()
end

View File

@ -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()

View File

@ -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"

View File

@ -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