diff options
| author | TitanSnow <[email protected]> | 2017-05-23 19:51:30 +0800 |
|---|---|---|
| committer | TitanSnow <[email protected]> | 2017-05-23 19:51:41 +0800 |
| commit | 550e0a96ce87a164d6a74b915d4ffa49ac9455fd (patch) | |
| tree | fb34a2c28b1cc2c427903a3d63f8139ef9db67c2 /core/src | |
| parent | f2e0d829b43011cce87568118a5b8b0b469ade1e (diff) | |
add xmake._EXECUTABLE_PATH to fix $(xmake)
$(xmake) is set to join(_PROGRAM_DIR, 'xmake')
that is wrong when XMAKE_PROGRAM_DIR is set to
another program dir (like developing dir) with no executable
so use system-special ways to get absolution path
of executable file always
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/machine.c | 94 |
1 files changed, 62 insertions, 32 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index ccfd91254..f6818d3be 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -244,29 +244,39 @@ static tb_bool_t xm_machine_main_get_program_directory(xm_machine_impl_t* impl, { // ok ok = tb_true; - break; + // not break // even XMAKE_PROGRAM_DIR is set, exact path is needed } #if defined(TB_CONFIG_OS_WINDOWS) // get the executale file path as program directory - tb_size_t size = (tb_size_t)GetModuleFileName(tb_null, path, (DWORD)maxn); + tb_size_t size = (tb_size_t)GetModuleFileName(tb_null, data, (DWORD)maxn); tb_assert_and_check_break(size < maxn); // end - path[size] = '\0'; + data[size] = '\0'; - // get the directory - while (size-- > 0) + // set _EXECUTABLE_PATH + lua_pushstring(impl -> lua, data); + lua_setglobal(impl -> lua, "_EXECUTABLE_PATH"); + + if (!ok) { - if (path[size] == '\\') + // get the directory + while (size-- > 0) { - path[size] = '\0'; - break; + if (data[size] == '\\') + { + data[size] = '\0'; + break; + } } - } - // ok - ok = tb_true; + // copy to path + tb_strcpy(path, data); + + // ok + ok = tb_true; + } #elif defined(TB_CONFIG_OS_MACOSX) /* * _NSGetExecutablePath() copies the path of the main executable into the buffer. The bufsize parameter @@ -279,44 +289,64 @@ static tb_bool_t xm_machine_main_get_program_directory(xm_machine_impl_t* impl, * needed could be more than MAXPATHLEN. */ tb_uint32_t size = (tb_uint32_t)maxn; - if (!_NSGetExecutablePath(path, &size)) + if (!_NSGetExecutablePath(data, &size)) { - // get path size - size = tb_strlen(path); + // set _EXECUTABLE_PATH + lua_pushstring(impl -> lua, data); + lua_setglobal(impl -> lua, "_EXECUTABLE_PATH"); - // get the directory - while (size-- > 0) + if (!ok) { - if (path[size] == '/') + // get path size + size = tb_strlen(data); + + // get the directory + while (size-- > 0) { - path[size] = '\0'; - break; + if (data[size] == '/') + { + data[size] = '\0'; + break; + } } - } - // ok - ok = tb_true; + // copy to path + tb_strcpy(path, data); + + // ok + ok = tb_true; + } } #elif defined(TB_CONFIG_OS_LINUX) // get the executale file path as program directory - ssize_t size = readlink("/proc/self/exe", path, (size_t)maxn); + ssize_t size = readlink("/proc/self/exe", data, (size_t)maxn); if (size > 0 && size < maxn) { // end - path[size] = '\0'; + data[size] = '\0'; - // get the directory - while (size-- > 0) + // set _EXECUTABLE_PATH + lua_pushstring(impl -> lua, data); + lua_setglobal(impl -> lua, "_EXECUTABLE_PATH"); + + if (!ok) { - if (path[size] == '/') + // get the directory + while (size-- > 0) { - path[size] = '\0'; - break; + if (data[size] == '/') + { + data[size] = '\0'; + break; + } } - } - // ok - ok = tb_true; + // copy to path + tb_strcpy(path, data); + + // ok + ok = tb_true; + } } #endif |
