diff options
-rw-r--r-- | src/_premake_main.lua | 6 | ||||
-rw-r--r-- | src/host/path_isabsolute.c | 2 | ||||
-rwxr-xr-x | src/host/premake.c | 20 | ||||
-rw-r--r-- | tests/base/test_premake_command.lua | 14 | ||||
-rw-r--r-- | tests/premake4.lua | 1 |
5 files changed, 41 insertions, 2 deletions
diff --git a/src/_premake_main.lua b/src/_premake_main.lua index 12ec033..d0cef0a 100644 --- a/src/_premake_main.lua +++ b/src/_premake_main.lua @@ -64,6 +64,12 @@ end + -- Now that the scripts are loaded, I can use path.getabsolute() to properly + -- canonicalize the executable path. + + _PREMAKE_COMMAND = path.getabsolute(_PREMAKE_COMMAND) + + -- Set up the environment for the chosen action early, so side-effects -- can be picked up by the scripts. diff --git a/src/host/path_isabsolute.c b/src/host/path_isabsolute.c index 14942d1..961ed77 100644 --- a/src/host/path_isabsolute.c +++ b/src/host/path_isabsolute.c @@ -9,7 +9,7 @@ int path_isabsolute(lua_State* L) { - const char* path = luaL_checkstring(L, 1); + const char* path = luaL_checkstring(L, -1); if (path[0] == '/' || path[0] == '\\' || path[0] == '$' || (path[0] != '\0' && path[1] == ':')) { lua_pushboolean(L, 1); diff --git a/src/host/premake.c b/src/host/premake.c index 1db66fd..41d42f9 100755 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -160,7 +160,7 @@ int premake_locate(lua_State* L, const char* argv0) lua_pushcfunction(L, os_pathsearch); lua_pushstring(L, argv0); lua_pushstring(L, getenv("PATH")); - if (lua_pcall(L, 2, 1, 0) == OKAY) + if (lua_pcall(L, 2, 1, 0) == OKAY && !lua_isnil(L, -1)) { lua_pushstring(L, "/"); lua_pushstring(L, argv0); @@ -169,6 +169,24 @@ int premake_locate(lua_State* L, const char* argv0) } } + /* If all else fails, use argv[0] as-is and hope for the best */ + if (!path) + { + /* make it absolute, if needed */ + os_getcwd(L); + lua_pushstring(L, "/"); + lua_pushstring(L, argv0); + + if (!path_isabsolute(L)) { + lua_concat(L, 3); + } + else { + lua_pop(L, 1); + } + + path = lua_tostring(L, -1); + } + lua_pushstring(L, path); return 1; } diff --git a/tests/base/test_premake_command.lua b/tests/base/test_premake_command.lua new file mode 100644 index 0000000..0c29c5f --- /dev/null +++ b/tests/base/test_premake_command.lua @@ -0,0 +1,14 @@ +-- +-- tests/base/test_premake_command.lua +-- Test the initialization of the _PREMAKE_COMMAND global. +-- Copyright (c) 2012 Jason Perkins and the Premake project +-- + + T.premake_command = { } + local suite = T.premake_command + + + function suite.valueIsSet() + local filename = iif(os.is("windows"), "premake4.exe", "premake4") + test.isequal(path.getabsolute("../bin/debug/" .. filename), _PREMAKE_COMMAND) + end diff --git a/tests/premake4.lua b/tests/premake4.lua index ea3a122..a2d0d5f 100644 --- a/tests/premake4.lua +++ b/tests/premake4.lua @@ -51,6 +51,7 @@ dofile("base/test_location.lua") dofile("base/test_os.lua") dofile("base/test_path.lua") + dofile("base/test_premake_command.lua") dofile("base/test_table.lua") dofile("base/test_tree.lua") dofile("tools/test_gcc.lua") |