diff options
| author | ruki <[email protected]> | 2018-08-15 00:47:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-08-14 22:47:29 +0800 |
| commit | 7824ce2bf02fe0438a04f074152847a773130d17 (patch) | |
| tree | a5bf281a1ccdf7870d1c421986a41c62d65dae93 | |
| parent | 6b471f65f4536d07150b89504bf52753461064a5 (diff) | |
add winos
| -rw-r--r-- | core/src/xmake/machine.c | 28 | ||||
| -rw-r--r-- | core/src/xmake/makefile | 1 | ||||
| -rw-r--r-- | core/src/xmake/winos/logical_drives.c | 89 | ||||
| -rw-r--r-- | core/src/xmake/winos/prefix.h (renamed from core/src/xmake/winreg/prefix.h) | 8 | ||||
| -rw-r--r-- | core/src/xmake/winos/registry_query.c (renamed from core/src/xmake/winreg/query.c) | 13 | ||||
| -rw-r--r-- | core/src/xmake/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/core/base/filter.lua | 3 | ||||
| -rw-r--r-- | xmake/core/base/winos.lua | 29 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/winos.lua | 37 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_qt.lua | 16 |
10 files changed, 198 insertions, 31 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 9fe975803..b9eceb6ae 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -101,9 +101,10 @@ tb_int_t xm_path_is_absolute(lua_State* lua); tb_int_t xm_hash_uuid(lua_State* lua); tb_int_t xm_hash_sha256(lua_State* lua); -// the winreg functions +// the windows functions #ifdef TB_CONFIG_OS_WINDOWS -tb_int_t xm_winreg_query(lua_State* lua); +tb_int_t xm_winos_logical_drives(lua_State* lua); +tb_int_t xm_winos_registry_query(lua_State* lua); #endif // the string functions @@ -177,6 +178,16 @@ static luaL_Reg const g_os_functions[] = , { tb_null, tb_null } }; +// the windows functions +#ifdef TB_CONFIG_OS_WINDOWS +static luaL_Reg const g_winos_functions[] = +{ + { "logical_drives", xm_winos_logical_drives } +, { "registry_query", xm_winos_registry_query } +, { tb_null, tb_null } +}; +#endif + // the io functions static luaL_Reg const g_io_functions[] = { @@ -210,15 +221,6 @@ static luaL_Reg const g_string_functions[] = , { tb_null, tb_null } }; -#ifdef TB_CONFIG_OS_WINDOWS -// the winreg functions -static luaL_Reg const g_winreg_functions[] = -{ - { "query", xm_winreg_query } -, { tb_null, tb_null } -}; -#endif - // the process functions static luaL_Reg const g_process_functions[] = { @@ -545,9 +547,9 @@ xm_machine_ref_t xm_machine_init() // bind sandbox functions luaL_register(machine->lua, "sandbox", g_sandbox_functions); - // bind winreg functions + // bind windows functions #ifdef TB_CONFIG_OS_WINDOWS - luaL_register(machine->lua, "winreg", g_winreg_functions); + luaL_register(machine->lua, "winos", g_winos_functions); #endif #ifdef XM_CONFIG_API_HAVE_READLINE diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index 5c11d0a62..833c80241 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -48,7 +48,6 @@ xmake_C_FILES += \ path/is_absolute \ hash/uuid \ hash/sha256 \ - winreg/query \ string/endswith \ string/startswith \ process/open \ diff --git a/core/src/xmake/winos/logical_drives.c b/core/src/xmake/winos/logical_drives.c new file mode 100644 index 000000000..cd4368c47 --- /dev/null +++ b/core/src/xmake/winos/logical_drives.c @@ -0,0 +1,89 @@ +/*!The Make-like Build Utility based on Lua + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (C) 2015 - 2018, TBOOX Open Source Group. + * + * @author ruki + * @file logical_drives.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "logical_drives" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ + +// get the logical drives +tb_int_t xm_winos_logical_drives(lua_State* lua) +{ + // init table + lua_newtable(lua); + + // get logical drives + tb_bool_t ok = tb_false; + tb_char_t* data = tb_null; + do + { + // get buffer size + DWORD size = GetLogicalDriveStringsA(0, tb_null); + tb_assert_and_check_break(size); + + // make data buffer + data = (tb_char_t*)tb_malloc0(size + 1); + tb_assert_and_check_break(data); + + // get logical drives + size = GetLogicalDriveStringsA(size, data); + tb_assert_and_check_break(size); + + // parse logical drives + tb_size_t i = 1; + tb_char_t const* p = data; + while (*p) + { + // save drive + lua_pushinteger(lua, i++); + lua_pushstring(lua, p); + lua_settable(lua, -3); + + // next drive + p += tb_strlen(p) + 1; + } + + // ok + ok = tb_true; + + } while (0); + + // exit data + if (data) tb_free(data); + data = tb_null; + + // ok + return 1; +} diff --git a/core/src/xmake/winreg/prefix.h b/core/src/xmake/winos/prefix.h index 530b240ca..01a423c6a 100644 --- a/core/src/xmake/winreg/prefix.h +++ b/core/src/xmake/winos/prefix.h @@ -18,19 +18,19 @@ * * Copyright (C) 2015 - 2018, TBOOX Open Source Group. * - * @author TitanSnow + * @author ruki * @file prefix.h * */ -#ifndef XM_WINREG_PREFIX_H -#define XM_WINREG_PREFIX_H +#ifndef XM_WINOS_PREFIX_H +#define XM_WINOS_PREFIX_H /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "../prefix.h" #ifdef TB_CONFIG_OS_WINDOWS -#include <windows.h> +# include <windows.h> #endif diff --git a/core/src/xmake/winreg/query.c b/core/src/xmake/winos/registry_query.c index 1e8ed513b..1476107cb 100644 --- a/core/src/xmake/winreg/query.c +++ b/core/src/xmake/winos/registry_query.c @@ -19,14 +19,14 @@ * Copyright (C) 2015 - 2018, TBOOX Open Source Group. * * @author TitanSnow, ruki - * @file query.c + * @file registry_query.c * */ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "query" +#define TB_TRACE_MODULE_NAME "registry_query" #define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// @@ -37,22 +37,18 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * types */ -#ifdef TB_CONFIG_OS_WINDOWS // the RegGetValueA func type typedef BOOL (WINAPI* xm_RegGetValueA_t)(HKEY hkey, LPCSTR lpSubKey, LPCSTR lpValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData); -#endif /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -#ifdef TB_CONFIG_OS_WINDOWS - /* query registry * - * local value, errors = winreg.query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger") + * local value, errors = winos.registry_query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger") */ -tb_int_t xm_winreg_query(lua_State* lua) +tb_int_t xm_winos_registry_query(lua_State* lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -226,4 +222,3 @@ tb_int_t xm_winreg_query(lua_State* lua) // ok? return ok? 1 : 2; } -#endif diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua index d394b483c..7e1f55e95 100644 --- a/core/src/xmake/xmake.lua +++ b/core/src/xmake/xmake.lua @@ -23,7 +23,10 @@ target("xmake") add_packages("tbox") -- add the common source files - add_files("**.c") + add_files("**.c|winos/*.c") + if is_plat("windows") then + add_files("winos/*.c") + end -- add readline add_options("readline") diff --git a/xmake/core/base/filter.lua b/xmake/core/base/filter.lua index 9decdddc5..18e4c8e3d 100644 --- a/xmake/core/base/filter.lua +++ b/xmake/core/base/filter.lua @@ -27,6 +27,7 @@ local filter = filter or {} -- load modules local os = require("base/os") +local winos = require("base/winos") local table = require("base/table") local utils = require("base/utils") local string = require("base/string") @@ -91,7 +92,7 @@ function filter.reg(path) end -- query registry value - return (winreg.query(path)) + return (winos.registry_query(path)) end -- set handlers diff --git a/xmake/core/base/winos.lua b/xmake/core/base/winos.lua new file mode 100644 index 000000000..c9ab70be3 --- /dev/null +++ b/xmake/core/base/winos.lua @@ -0,0 +1,29 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file winos.lua +-- + +-- define module: winos +local winos = winos or {} + +-- return module: winos +return winos diff --git a/xmake/core/sandbox/modules/import/core/base/winos.lua b/xmake/core/sandbox/modules/import/core/base/winos.lua new file mode 100644 index 000000000..e581fe177 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/base/winos.lua @@ -0,0 +1,37 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file winos.lua +-- + +-- load modules +local winos = require("base/winos") + +-- define module +local sandbox_core_base_winos = sandbox_core_base_winos or {} + +-- inherit some builtin interfaces +sandbox_core_base_winos.registry_query = winos.registry_query +sandbox_core_base_winos.logical_drives = winos.logical_drives + +-- return module +return sandbox_core_base_winos + diff --git a/xmake/modules/detect/sdks/find_qt.lua b/xmake/modules/detect/sdks/find_qt.lua index f671931e1..0e99245e2 100644 --- a/xmake/modules/detect/sdks/find_qt.lua +++ b/xmake/modules/detect/sdks/find_qt.lua @@ -25,6 +25,7 @@ -- imports import("lib.detect.cache") import("lib.detect.find_file") +import("core.base.winos") import("core.base.option") import("core.base.global") import("core.project.config") @@ -59,7 +60,9 @@ function _find_sdkdir(sdkdir, sdkver) if sdkdir then table.insert(pathes, sdkdir) end - if os.host() == "windows" then + if is_host("windows") then + + -- add pathes from registry local regs = { "HKEY_CLASSES_ROOT\\Applications\\QtProject.QtCreator.c\\shell\\Open\\Command", @@ -78,12 +81,21 @@ function _find_sdkdir(sdkdir, sdkver) end end) end + + -- add root logical drive pates, .e.g C:/Qt/Qtx.x.x, D:/Qtx.x.x .. + for idx, drive in ipairs(winos.logical_drives()) do + if idx < 5 then + table.insert(pathes, path.join(drive, "Qt", "Qt*")) + else + break + end + end else table.insert(pathes, "~/Qt") end -- attempt to find qmake - local qmake = find_file(os.host() == "windows" and "qmake.exe" or "qmake", pathes, {suffixes = subdirs}) + local qmake = find_file(is_host("windows") and "qmake.exe" or "qmake", pathes, {suffixes = subdirs}) if qmake then return path.directory(path.directory(qmake)) end |
