diff options
| author | ruki <[email protected]> | 2026-04-01 21:02:03 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-04-01 21:02:03 +0800 |
| commit | 39fd35ea9d5d14079e4669b85423d488c9097cd4 (patch) | |
| tree | 7d4452174422931fe8a56f49b2d349b4b7cc90b3 | |
| parent | 75b084fa57f2fe00f369d9cac3878c03da43a68a (diff) | |
| parent | c63ac2d50545f2f58872c5be9a46d8fb5b3e8016 (diff) | |
Merge pull request #7437 from xmake-io/lua55
update to lua5.5
122 files changed, 367 insertions, 132 deletions
@@ -1649,6 +1649,41 @@ _get_target_librarydeps() { _ret="${librarydeps}" } +# sanitize file path for use as map key +_sanitize_filekey() { + local key="${1}" + string_replace "${key}" "/" "__"; key="${_ret}" + string_replace "${key}" "." "_"; key="${_ret}" + string_replace "${key}" "-" "_"; key="${_ret}" + string_replace "${key}" "+" "_"; key="${_ret}" + _ret="${key}" +} + +# add file replace rule for target +# stores sed patterns like "s|search|replace|g" per source file +_add_target_file_replace() { + local target="${1}" + local sourcefile="${2}" + local search="${3}" + local replace="${4}" + _sanitize_filekey "${sourcefile}"; local filekey="${_ret}" + _map_get "targets" "${target}_replaces_${filekey}"; local patterns="${_ret}" + if test_nz "${patterns}"; then + patterns="${patterns};s|${search}|${replace}|g" + else + patterns="s|${search}|${replace}|g" + fi + _map_set "targets" "${target}_replaces_${filekey}" "${patterns}" +} + +# get file replace sed patterns for target +_get_target_file_replaces() { + local target="${1}" + local sourcefile="${2}" + _sanitize_filekey "${sourcefile}"; local filekey="${_ret}" + _map_get "targets" "${target}_replaces_${filekey}" +} + # get sourcefiles in target _get_target_sourcefiles() { local name="${1}" @@ -2063,6 +2098,7 @@ _add_target_filepaths() { _targets_toolkinds="${_targets_toolkinds} ${sourcekind}" done fi + _xmake_sh_last_resolved_files="" for file in ${list}; do string_replace "${file}" "?" "*"; file="${_ret}" if ! path_is_absolute "${file}"; then @@ -2083,6 +2119,7 @@ _add_target_filepaths() { for file in ${files}; do path_relative "${xmake_sh_projectdir}" "${file}"; file="${_ret}" _add_target_item "${_xmake_sh_target_current}" "${key}" "${file}" + _xmake_sh_last_resolved_files="${_xmake_sh_last_resolved_files} ${file}" done done } @@ -2273,7 +2310,40 @@ add_files() { if ! ${_loading_targets}; then return fi - _add_target_filepaths "files" "$@" + + # separate file patterns from replace rules + local has_replaces=false + local fileargs="" + for arg in "$@"; do + case "${arg}" in + \{replace*) has_replaces=true ;; + *) fileargs="${fileargs} ${arg}" ;; + esac + done + + _add_target_filepaths "files" ${fileargs} + + # store replace rules for resolved files + if ${has_replaces}; then + local sourcefile="" + for sourcefile in ${_xmake_sh_last_resolved_files}; do + for arg in "$@"; do + case "${arg}" in + \{replace*\}) + # parse {replace = {search, replace}} + local content="${arg#\{replace = \{}" + content="${content%\}\}}" + local search="${content%%,*}" + local rep="${content#*,}" + # trim spaces + search="${search# }"; search="${search% }" + rep="${rep# }"; rep="${rep% }" + _add_target_file_replace "${_xmake_sh_target_current}" "${sourcefile}" "${search}" "${rep}" + ;; + esac + done + done + fi } # add install files in target @@ -4196,9 +4266,14 @@ _gmake_add_build_object_for_gcc_clang() { local sourcefile="${2}" local objectfile="${3}" local flagname="${4}" + local replace_cmd="${5}" + local extra_flags="${6}" path_directory "${objectfile}"; local objectdir="${_ret}" + if test_nz "${replace_cmd}"; then + print "\t@${replace_cmd}" >> "${xmake_sh_makefile}" + fi print "\t@mkdir -p ${objectdir}" >> "${xmake_sh_makefile}" - print "\t\$(VV)\$(${kind}) -c \$(${flagname}) -o ${objectfile} ${sourcefile}" >> "${xmake_sh_makefile}" + print "\t\$(VV)\$(${kind}) -c ${extra_flags}\$(${flagname}) -o ${objectfile} ${sourcefile}" >> "${xmake_sh_makefile}" } _gmake_add_build_object() { @@ -4210,18 +4285,37 @@ _gmake_add_build_object() { path_toolname "${program}"; local toolname="${_ret}" _get_flagname "${sourcekind}"; local flagname="${_ret}" flagname="${target}_${flagname}" + + # check for file replace rules + local actual_sourcefile="${sourcefile}" + _get_target_file_replaces "${target}" "${sourcefile}"; local replace_patterns="${_ret}" + local replace_cmd="" + local extra_flags="" + if test_nz "${replace_patterns}"; then + local replacefile="${xmake_sh_builddir}/.replace/${target}/${sourcefile}" + path_directory "${replacefile}"; local replacefile_dir="${_ret}" + replace_cmd="mkdir -p \"${replacefile_dir}\" && sed '${replace_patterns}' \"${sourcefile}\" > \"${replacefile}\"" + actual_sourcefile="${replacefile}" + # add original source directory to include path for resolving relative #include + path_directory "${sourcefile}"; local source_dir="${_ret}" + extra_flags="-I${source_dir} " + fi + echo "${objectfile}: ${sourcefile}" >> "${xmake_sh_makefile}" + if test_nz "${replace_cmd}"; then + print "\t@echo replacing.${_target_mode} ${sourcefile}" >> "${xmake_sh_makefile}" + fi print "\t@echo compiling.${_target_mode} ${sourcefile}" >> "${xmake_sh_makefile}" case "${toolname}" in - gcc) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";; - gxx) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";; - clang) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";; - clangxx) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";; - emcc) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";; - emxx) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";; - cosmocc) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";; - cosmocxx) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";; - tcc) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";; + gcc) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${actual_sourcefile}" "${objectfile}" "${flagname}" "${replace_cmd}" "${extra_flags}";; + gxx) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${actual_sourcefile}" "${objectfile}" "${flagname}" "${replace_cmd}" "${extra_flags}";; + clang) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${actual_sourcefile}" "${objectfile}" "${flagname}" "${replace_cmd}" "${extra_flags}";; + clangxx) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${actual_sourcefile}" "${objectfile}" "${flagname}" "${replace_cmd}" "${extra_flags}";; + emcc) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${actual_sourcefile}" "${objectfile}" "${flagname}" "${replace_cmd}" "${extra_flags}";; + emxx) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${actual_sourcefile}" "${objectfile}" "${flagname}" "${replace_cmd}" "${extra_flags}";; + cosmocc) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${actual_sourcefile}" "${objectfile}" "${flagname}" "${replace_cmd}" "${extra_flags}";; + cosmocxx) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${actual_sourcefile}" "${objectfile}" "${flagname}" "${replace_cmd}" "${extra_flags}";; + tcc) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${actual_sourcefile}" "${objectfile}" "${flagname}" "${replace_cmd}" "${extra_flags}";; *) raise "unknown toolname(${toolname})!" ;; esac echo "" >> "${xmake_sh_makefile}" @@ -4683,10 +4777,30 @@ _ninja_add_build_object() { local objectfile="${3}" path_sourcekind "${sourcefile}"; local sourcekind="${_ret}" _get_target_flags "${target}" "${sourcekind}"; local flags="${_ret}" - _toolchain_compcmd "${sourcekind}" "${objectfile}" "${sourcefile}" "${flags}"; local compcmd="${_ret}" + + # check for file replace rules + local actual_sourcefile="${sourcefile}" + _get_target_file_replaces "${target}" "${sourcefile}"; local replace_patterns="${_ret}" + local replace_cmd="" + if test_nz "${replace_patterns}"; then + local replacefile="${xmake_sh_builddir}/.replace/${target}/${sourcefile}" + path_directory "${replacefile}"; local replacefile_dir="${_ret}" + replace_cmd="mkdir -p \"${replacefile_dir}\" && sed '${replace_patterns}' \"${sourcefile}\" > \"${replacefile}\"" + actual_sourcefile="${replacefile}" + # add original source directory to include path for resolving relative #include + path_directory "${sourcefile}"; local source_dir="${_ret}" + flags="-I${source_dir} ${flags}" + fi + + _toolchain_compcmd "${sourcekind}" "${objectfile}" "${actual_sourcefile}" "${flags}"; local compcmd="${_ret}" path_directory "${objectfile}"; local objectdir="${_ret}" local use_shell_wrapper=false - local command="mkdir -p \"${objectdir}\" && ${compcmd}" + local command="" + if test_nz "${replace_cmd}"; then + command="echo replacing.${_target_mode} ${sourcefile} && ${replace_cmd} && mkdir -p \"${objectdir}\" && ${compcmd}" + else + command="mkdir -p \"${objectdir}\" && ${compcmd}" + fi if is_host "msys" "cygwin" "mingw"; then use_shell_wrapper=true fi diff --git a/core/src/lua/lua b/core/src/lua/lua -Subproject 1ab3208a1fceb12fca8f24ba57d6e13c5bff15e +Subproject a5522f06d2679b8f18534fd6a9968f7eb539dc3 diff --git a/core/src/lua/xmake.lua b/core/src/lua/xmake.lua index 006480397..d732b89fb 100644 --- a/core/src/lua/xmake.lua +++ b/core/src/lua/xmake.lua @@ -14,13 +14,19 @@ target("lua") add_includedirs("lua", {public = true}) -- add the common source files - add_files("lua/*.c|lua.c|onelua.c|loslib.c") + add_files("lua/*.c|lua.c|onelua.c|loslib.c|lparser.c") + + -- allow reassignment of for-loop control variables (lua 5.4 compatible) + add_files("lua/lparser.c", {rules = "utils.replace", replaces = { + {"RDKCONST%);", "VDKREG);"}, + }}) if not is_plat("iphoneos") then add_files("lua/loslib.c") end -- add definitions add_defines("LUA_COMPAT_5_1", "LUA_COMPAT_5_2", "LUA_COMPAT_5_3", {public = true}) + if is_plat("windows", "mingw") then -- it has been defined in luaconf.h --add_defines("LUA_USE_WINDOWS") diff --git a/core/src/lua/xmake.sh b/core/src/lua/xmake.sh index 59eff5dd3..754cbcdb3 100755 --- a/core/src/lua/xmake.sh +++ b/core/src/lua/xmake.sh @@ -30,7 +30,8 @@ target "lua" add_files "lua/lobject.c" add_files "lua/lopcodes.c" add_files "lua/loslib.c" - add_files "lua/lparser.c" + # allow reassignment of for-loop control variables (lua 5.4 compatible) + add_files "lua/lparser.c" "{replace = {RDKCONST);, VDKREG);}}" add_files "lua/lstate.c" add_files "lua/lstring.c" add_files "lua/lstrlib.c" @@ -44,6 +45,7 @@ target "lua" # add definitions add_defines "LUA_COMPAT_5_1" "LUA_COMPAT_5_2" "LUA_COMPAT_5_3" "{public}" + if is_plat "mingw"; then true # it has been defined in luaconf.h #add_defines "LUA_USE_WINDOWS" diff --git a/core/src/xmake/curses/curses.c b/core/src/xmake/curses/curses.c index 95a0fcdac..6736ec05e 100644 --- a/core/src/xmake/curses/curses.c +++ b/core/src/xmake/curses/curses.c @@ -228,8 +228,8 @@ static int xm_curses_window_tostring(lua_State *lua) { // window:move(y, x) static int xm_curses_window_move(lua_State *lua) { WINDOW *w = xm_curses_window_check(lua, 1); - int y = luaL_checkint(lua, 2); - int x = luaL_checkint(lua, 3); + int y = (int)luaL_checkinteger(lua, 2); + int x = (int)luaL_checkinteger(lua, 3); lua_pushboolean(lua, XM_CURSES_OK(wmove(w, y, x))); return 1; } @@ -276,7 +276,7 @@ static int xm_curses_window_addch(lua_State *lua) { static int xm_curses_window_addnstr(lua_State *lua) { WINDOW *w = xm_curses_window_check(lua, 1); const char *str = luaL_checkstring(lua, 2); - int n = luaL_optint(lua, 3, -1); + int n = (int)luaL_optinteger(lua, 3, -1); if (n < 0) n = (int)lua_strlen(lua, 2); lua_pushboolean(lua, XM_CURSES_OK(waddnstr(w, str, n))); @@ -333,7 +333,7 @@ static int xm_curses_window_getch(lua_State *lua) { // window:attroff(attrs) static int xm_curses_window_attroff(lua_State *lua) { WINDOW *w = xm_curses_window_check(lua, 1); - int attrs = luaL_checkint(lua, 2); + int attrs = (int)luaL_checkinteger(lua, 2); lua_pushboolean(lua, XM_CURSES_OK(wattroff(w, attrs))); return 1; } @@ -341,7 +341,7 @@ static int xm_curses_window_attroff(lua_State *lua) { // window:attron(attrs) static int xm_curses_window_attron(lua_State *lua) { WINDOW *w = xm_curses_window_check(lua, 1); - int attrs = luaL_checkint(lua, 2); + int attrs = (int)luaL_checkinteger(lua, 2); lua_pushboolean(lua, XM_CURSES_OK(wattron(w, attrs))); return 1; } @@ -349,7 +349,7 @@ static int xm_curses_window_attron(lua_State *lua) { // window:attrset(attrs) static int xm_curses_window_attrset(lua_State *lua) { WINDOW *w = xm_curses_window_check(lua, 1); - int attrs = luaL_checkint(lua, 2); + int attrs = (int)luaL_checkinteger(lua, 2); lua_pushboolean(lua, XM_CURSES_OK(wattrset(w, attrs))); return 1; } @@ -358,12 +358,12 @@ static int xm_curses_window_attrset(lua_State *lua) { static int xm_curses_window_copywin(lua_State *lua) { WINDOW *srcwin = xm_curses_window_check(lua, 1); WINDOW *dstwin = xm_curses_window_check(lua, 2); - int sminrow = luaL_checkint(lua, 3); - int smincol = luaL_checkint(lua, 4); - int dminrow = luaL_checkint(lua, 5); - int dmincol = luaL_checkint(lua, 6); - int dmaxrow = luaL_checkint(lua, 7); - int dmaxcol = luaL_checkint(lua, 8); + int sminrow = (int)luaL_checkinteger(lua, 3); + int smincol = (int)luaL_checkinteger(lua, 4); + int dminrow = (int)luaL_checkinteger(lua, 5); + int dmincol = (int)luaL_checkinteger(lua, 6); + int dmaxrow = (int)luaL_checkinteger(lua, 7); + int dmaxcol = (int)luaL_checkinteger(lua, 8); int overlay = lua_toboolean(lua, 9); lua_pushboolean(lua, XM_CURSES_OK( @@ -646,7 +646,7 @@ static int xm_curses_getmouse(lua_State *lua) { } static int xm_curses_mousemask(lua_State *lua) { - mmask_t m = luaL_checkint(lua, 1); + mmask_t m = (mmask_t)luaL_checkinteger(lua, 1); mmask_t om; m = mousemask(m, &om); lua_pushinteger(lua, m); @@ -656,22 +656,22 @@ static int xm_curses_mousemask(lua_State *lua) { #endif static int xm_curses_init_pair(lua_State *lua) { - short pair = luaL_checkint(lua, 1); - short f = luaL_checkint(lua, 2); - short b = luaL_checkint(lua, 3); + short pair = (short)luaL_checkinteger(lua, 1); + short f = (short)luaL_checkinteger(lua, 2); + short b = (short)luaL_checkinteger(lua, 3); lua_pushboolean(lua, XM_CURSES_OK(init_pair(pair, f, b))); return 1; } static int xm_curses_COLOR_PAIR(lua_State *lua) { - int n = luaL_checkint(lua, 1); + int n = (int)luaL_checkinteger(lua, 1); lua_pushnumber(lua, COLOR_PAIR(n)); return 1; } static int xm_curses_curs_set(lua_State *lua) { - int vis = luaL_checkint(lua, 1); + int vis = (int)luaL_checkinteger(lua, 1); int state = curs_set(vis); if (state == ERR) return 0; @@ -681,7 +681,7 @@ static int xm_curses_curs_set(lua_State *lua) { } static int xm_curses_napms(lua_State *lua) { - int ms = luaL_checkint(lua, 1); + int ms = (int)luaL_checkinteger(lua, 1); lua_pushboolean(lua, XM_CURSES_OK(napms(ms))); return 1; } @@ -714,8 +714,8 @@ static int xm_curses_nl(lua_State *lua) { } static int xm_curses_newpad(lua_State *lua) { - int nlines = luaL_checkint(lua, 1); - int ncols = luaL_checkint(lua, 2); + int nlines = (int)luaL_checkinteger(lua, 1); + int ncols = (int)luaL_checkinteger(lua, 2); xm_curses_window_new(lua, newpad(nlines, ncols)); return 1; } diff --git a/core/src/xmake/os/sleep.c b/core/src/xmake/os/sleep.c index 0c8fa135e..384121981 100644 --- a/core/src/xmake/os/sleep.c +++ b/core/src/xmake/os/sleep.c @@ -35,7 +35,7 @@ */ tb_int_t xm_os_sleep(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - tb_long_t interval = (tb_long_t)luaL_checklong(lua, 1); + tb_long_t interval = (tb_long_t)luaL_checkinteger(lua, 1); if (interval >= 0) { tb_msleep(interval); } diff --git a/xmake/actions/build/build_files.lua b/xmake/actions/build/build_files.lua index 26b389ba6..2b353fbe1 100644 --- a/xmake/actions/build/build_files.lua +++ b/xmake/actions/build/build_files.lua @@ -44,7 +44,7 @@ function _get_file_patterns(sourcefiles) if excludes then local _excludes = {} for _, exclude in ipairs(excludes) do - exclude = path.translate(exclude) + local exclude = path.translate(exclude) exclude = path.pattern(exclude) table.insert(_excludes, exclude) end diff --git a/xmake/actions/build/deprecated/build_files.lua b/xmake/actions/build/deprecated/build_files.lua index db1492bd8..247dbdced 100644 --- a/xmake/actions/build/deprecated/build_files.lua +++ b/xmake/actions/build/deprecated/build_files.lua @@ -142,7 +142,7 @@ function _get_file_patterns(sourcefiles) if excludes then local _excludes = {} for _, exclude in ipairs(excludes) do - exclude = path.translate(exclude) + local exclude = path.translate(exclude) exclude = path.pattern(exclude) table.insert(_excludes, exclude) end diff --git a/xmake/actions/config/configfiles.lua b/xmake/actions/config/configfiles.lua index 78ff3ebec..8f4cb07ff 100644 --- a/xmake/actions/config/configfiles.lua +++ b/xmake/actions/config/configfiles.lua @@ -300,6 +300,7 @@ function _generate_configfile(srcfile, dstfile, fileinfo, targets, preprocessors -- get variables from the target for name, value in pairs(target:get("configvar")) do + local value = value if variables[name] == nil then value = table.unwrap(value) variables[name] = value @@ -319,6 +320,7 @@ function _generate_configfile(srcfile, dstfile, fileinfo, targets, preprocessors -- get the builtin variables from the target for name, value in pairs(_get_builtinvars_target(target)) do + local value = value if type(value) == "function" then value = value() end @@ -329,6 +331,7 @@ function _generate_configfile(srcfile, dstfile, fileinfo, targets, preprocessors end -- get the global builtin variables for name, value in pairs(_get_builtinvars_global()) do + local value = value if type(value) == "function" then value = value() end diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 6908e21c3..99019757b 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -292,7 +292,7 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) -- merge the project options after default options for name, value in pairs(project.get("config")) do - value = table.unwrap(value) + local value = table.unwrap(value) assert(type(value) == "string" or type(value) == "boolean" or type(value) == "number", "set_config(%s): unsupported value type(%s)", name, type(value)) if not config.readonly(name) then config.set(name, value) diff --git a/xmake/actions/test/main.lua b/xmake/actions/test/main.lua index 7dcf3201c..0a00b76f1 100644 --- a/xmake/actions/test/main.lua +++ b/xmake/actions/test/main.lua @@ -520,7 +520,7 @@ function get_tests() local scriptdir = target:scriptdir() target_new:name_set(target:name() .. "_" .. name) for _, file in ipairs(extra.files) do - file = path.absolute(file, scriptdir) + local file = path.absolute(file, scriptdir) file = path.relative(file, os.projectdir()) target_new:add("files", file, {defines = extra.defines, cflags = extra.cflags, @@ -531,7 +531,7 @@ function get_tests() project.target_add(target_new) end for _, file in ipairs(extra.remove_files) do - file = path.absolute(file, scriptdir) + local file = path.absolute(file, scriptdir) file = path.relative(file, os.projectdir()) target_new:remove("files", file) end @@ -586,7 +586,7 @@ function main() if test_patterns then local tests_new = {} for _, pattern in ipairs(test_patterns) do - pattern = "^" .. path.pattern(pattern) .. "$" + local pattern = "^" .. path.pattern(pattern) .. "$" for name, testinfo in pairs(tests) do if name:match(pattern) then tests_new[name] = testinfo diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index f325ec3d2..bcf446309 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -117,6 +117,7 @@ end -- and we will only use the child values if be override mode function interpreter:_fetch_root_scope(root) for scope_kind_and_name, _ in pairs(root or {}) do + local scope_kind_and_name = scope_kind_and_name -- is scope_kind@@scope_name? scope_kind_and_name = scope_kind_and_name:split("@@", {plain = true}) @@ -340,6 +341,7 @@ function interpreter:_api_register_xxx_script(scope_kind, action, ...) if #patterns > 0 then local scripts = scope[name] or {} for _, pattern in ipairs(patterns) do + local pattern = pattern -- check assert(type(pattern) == "string") @@ -460,7 +462,7 @@ function interpreter:_filter(values, level) if table.is_dictionary(values) then local results = {} for key, value in pairs(values) do - key = (type(key) == "string" and filter:handle(key) or key) + local key = (type(key) == "string" and filter:handle(key) or key) if type(value) == "string" then results[key] = filter:handle(value) elseif type(value) == "table" and level < 1 then @@ -501,6 +503,7 @@ function interpreter:_handle(scope, deduplicate, enable_filter) -- remove repeat values and unwrap it local results = {} for name, values in pairs(scope) do + local values = values -- filter values -- @@ -1665,6 +1668,7 @@ function interpreter:api_define(apis) local definitions = self._API_DEFINITIONS or {} for apitype, apifuncs in pairs(apis) do for _, apifunc in ipairs(apifuncs) do + local apifunc = apifunc -- is {"apifunc", apiscript}? local apiscript = nil diff --git a/xmake/core/base/linuxos.lua b/xmake/core/base/linuxos.lua index 32af1ccad..dc1fa529f 100644 --- a/xmake/core/base/linuxos.lua +++ b/xmake/core/base/linuxos.lua @@ -145,6 +145,7 @@ function linuxos.version() if os_release then os_release = os_release:trim():lower():split("\n") for _, line in ipairs(os_release) do + local line = line -- ubuntu: VERSION="16.04.7 LTS (Xenial Xerus)" -- fedora: VERSION="32 (Container Image)" -- debian: VERSION="9 (stretch)" diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua index decb1e842..e8f6a4fb8 100644 --- a/xmake/core/base/option.lua +++ b/xmake/core/base/option.lua @@ -755,6 +755,7 @@ function option.show_options(options, taskname) -- transform description local desp_strs = table.new(#description, 0) for _, v in ipairs(description) do + local v = v if type(v) == "function" then v = v() end diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 9ba469505..005f18a70 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -437,7 +437,7 @@ function os.match(pattern, mode, opt) if excludes then local _excludes = {} for _, exclude in ipairs(excludes) do - exclude = path.translate(exclude) + local exclude = path.translate(exclude) exclude = path.pattern(exclude) table.insert(_excludes, exclude) end @@ -988,9 +988,9 @@ function os.execv(program, argv, opt) filename = os._get_shell_path(opt) or "sh" argv = table.join(shellfile, argv) else - line = line:sub(3) + local shebang = line:sub(3) local shellargv = {} - local splitinfo = line:split("%s") + local splitinfo = shebang:split("%s") filename = splitinfo[1] if #splitinfo > 1 then shellargv = table.slice(splitinfo, 2) @@ -1013,6 +1013,7 @@ function os.execv(program, argv, opt) local envars = os.getenvs() if setenvs then for k, v in pairs(setenvs) do + local v = v if type(v) == "table" then v = path.joinenv(v) end @@ -1021,6 +1022,7 @@ function os.execv(program, argv, opt) end if addenvs then for k, v in pairs(addenvs) do + local v = v if type(v) == "table" then v = path.joinenv(v) end @@ -1033,6 +1035,7 @@ function os.execv(program, argv, opt) end envs = {} for k, v in pairs(envars) do + local v = v -- we try to fix too long value before running process if type(v) == "string" and #v > 4096 and os.host() == "windows" then v = os._deduplicate_pathenv(v) diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua index 0d2dadfba..ee154147f 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -388,6 +388,7 @@ function path.splitenv(env_path) -- see https://git.kernel.org/pub/scm/utils/dash/dash.git/tree/src/exec.c?h=v0.5.9.1&id=afe0e0152e4dc12d84be3c02d6d62b0456d68580#n173 -- no escape sequences, so `:` and `%` is invalid in environment variable for _, v in ipairs(env_path:split(path.envsep(), { plain = true })) do + local v = v -- flag for shells, style `<path>%<flag>` local flag = v:find("%", 1, true) if flag then @@ -416,6 +417,7 @@ function path.joinenv(paths, envsep) if xmake._HOST == "windows" then local tab = {} for _, v in ipairs(paths) do + local v = v if v ~= "" then if v:find(envsep, 1, true) then v = '"' .. v .. '"' diff --git a/xmake/core/base/private/match_copyfiles.lua b/xmake/core/base/private/match_copyfiles.lua index 9570a8c4b..594ac6cdf 100644 --- a/xmake/core/base/private/match_copyfiles.lua +++ b/xmake/core/base/private/match_copyfiles.lua @@ -50,6 +50,7 @@ function match_copyfiles(instance, filetype, outputdir, opt) local srcfiles_removed = {} local removed_count = 0 for _, copyfile in ipairs(table.wrap(copyfiles)) do + local copyfile = copyfile -- mark as removed files? local removed = false diff --git a/xmake/core/base/text.lua b/xmake/core/base/text.lua index 9d4294ee6..558b1eb5e 100644 --- a/xmake/core/base/text.lua +++ b/xmake/core/base/text.lua @@ -182,6 +182,7 @@ function text.wordwrap(str, width, opt) -- handle lines for _, v in ipairs(lines) do + local v = v -- remove tailing spaces, include "\r", which will be produced by `("l1\r\nl2"):split(...)` v = v:rtrim() diff --git a/xmake/core/base/thread.lua b/xmake/core/base/thread.lua index 067b92f3f..187f98d53 100644 --- a/xmake/core/base/thread.lua +++ b/xmake/core/base/thread.lua @@ -103,6 +103,7 @@ function _thread:start() -- translate arguments (mutex, ...) local argv = {} for _, arg in ipairs(self._ARGV) do + local arg = arg if type(arg) == "table" then -- try to serialize thread object (mutex, event, semaphore, queue, sharedata) local serialized = thread._serialize_object(arg) @@ -927,6 +928,7 @@ function thread._run_thread(callback_str, callinfo_str) if argv then local newargv = {} for _, arg in ipairs(argv) do + local arg = arg if type(arg) == "table" and arg.caddr then -- try to deserialize thread object local obj = thread._deserialize_object(arg) diff --git a/xmake/core/base/winos.lua b/xmake/core/base/winos.lua index d43f08262..17b0e5d6a 100644 --- a/xmake/core/base/winos.lua +++ b/xmake/core/base/winos.lua @@ -178,7 +178,7 @@ function winos.cmdargv(argv, opt) local limit = 4096 local argn = 0 for _, arg in ipairs(argv) do - arg = tostring(arg) + local arg = tostring(arg) argn = argn + #arg if argn > limit then break diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 1107e03b0..7e20a1cda 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1206,6 +1206,7 @@ end function _instance:envs() local envs = {} for name, values in pairs(self:_rawenvs()) do + local values = values if self:_pathenvs():has(name) then local newvalues = {} for _, value in ipairs(values) do @@ -1713,6 +1714,7 @@ function _instance:buildhash() -- We cannot directly deserialize the table, so the result may be different each time local configs_order = {} for k, v in pairs(table.wrap(configs)) do + local v = v if type(v) == "table" then v = string.serialize(v, {strip = true, indent = false, orderkeys = true}) end diff --git a/xmake/core/package/scheme.lua b/xmake/core/package/scheme.lua index a1baa7301..1d0b54b16 100644 --- a/xmake/core/package/scheme.lua +++ b/xmake/core/package/scheme.lua @@ -198,6 +198,7 @@ function _instance:versions() -- https://github.com/xmake-io/xmake/issues/6953 local versions = {} for version, _ in table.orderpairs(self:_versions_list()) do + local version = version -- remove the url alias prefix if exists local pos = version:find(':', 1, true) if pos then @@ -217,6 +218,7 @@ function _instance:_versions_list() local versionfiles = self:get("versionfiles") if versionfiles then for _, versionfile in ipairs(table.wrap(versionfiles)) do + local versionfile = versionfile if not path.is_absolute(versionfile) then local subpath = versionfile versionfile = path.join(self:scriptdir(), subpath) @@ -363,6 +365,7 @@ function _instance:patches() else -- match semver, e.g add_patches(">=1.0.0", url, sha256) for range, patchinfo in pairs(patchinfos) do + local patchinfo = patchinfo if semver.satisfies(version_str, range) then patches = patches or {} patchinfo = table.wrap(patchinfo) @@ -397,6 +400,7 @@ function _instance:resources() else -- match semver, e.g add_resources(">=1.0.0", name, url, sha256) for range, resourceinfo in pairs(resourceinfos) do + local resourceinfo = resourceinfo if semver.satisfies(version_str, range) then resources = resources or {} resourceinfo = table.wrap(resourceinfo) diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index 451bfe8ae..a2e26d699 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -60,6 +60,7 @@ function config._is_value(value, ...) value = tostring(value) for _, v in ipairs(table.pack(...)) do + local v = v -- escape '-' v = tostring(v) if value == v or value:find("^" .. v:gsub("%-", "%%-") .. "$") then diff --git a/xmake/core/project/package.lua b/xmake/core/project/package.lua index c24e97d70..b990c11e3 100644 --- a/xmake/core/project/package.lua +++ b/xmake/core/project/package.lua @@ -351,7 +351,7 @@ function _instance:rules() -- make rule instances rules = {} for rulename, ruleinfo in pairs(ruleinfos) do - rulename = "@" .. self:name() .. "/" .. rulename + local rulename = "@" .. self:name() .. "/" .. rulename local instance = rule.new(rulename, ruleinfo, {package = self}) if instance:script("load") then utils.warning("we cannot add `on_load()` in package rule(%s), please use `on_config()` instead of it!", rulename) diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index f9e199a1b..beab21a22 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -172,6 +172,7 @@ end function project._api_add_moduledirs(interp, ...) local scriptdir = project.interpreter():scriptdir() for _, dir in ipairs({...}) do + local dir = dir if not path.is_absolute(dir) then dir = path.absolute(dir, scriptdir) end @@ -184,6 +185,7 @@ function project._api_add_plugindirs(interp, ...) local scriptdir = project.interpreter():scriptdir() local plugindirs = {} for _, dir in ipairs({...}) do + local dir = dir if not path.is_absolute(dir) then dir = path.absolute(dir, scriptdir) end @@ -196,6 +198,7 @@ end function project._api_add_platformdirs(interp, ...) local scriptdir = project.interpreter():scriptdir() for _, dir in ipairs({...}) do + local dir = dir if not path.is_absolute(dir) then dir = path.absolute(dir, scriptdir) end @@ -207,6 +210,7 @@ end function project._api_add_toolchaindirs(interp, ...) local scriptdir = project.interpreter():scriptdir() for _, dir in ipairs({...}) do + local dir = dir if not path.is_absolute(dir) then dir = path.absolute(dir, scriptdir) end diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index 790f715fa..332844ca4 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -431,6 +431,7 @@ function rule.new(name, info, opt) -- local deps = {} for _, depname in ipairs(table.wrap(instance:get("deps"))) do + local depname = depname -- @xxx -> @package/xxx if depname:startswith("@") and not depname:find("/", 1, true) then depname = "@" .. opt.package:name() .. "/" .. depname:sub(2) @@ -442,6 +443,7 @@ function rule.new(name, info, opt) instance:set("deps", deps) end for depname, extraconf in pairs(table.wrap(instance:extraconf("deps"))) do + local depname = depname if depname:startswith("@") and not depname:find("/", 1, true) then depname = "@" .. opt.package:name() .. "/" .. depname:sub(2) instance:extraconf_set("deps", depname, extraconf) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 1c568de65..6861ba2e6 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1497,6 +1497,7 @@ function _instance:pkgenvs() local envs = pkg:envs() if envs then for name, values in table.orderpairs(envs) do + local values = values if type(values) == "table" then values = path.joinenv(values) end @@ -1992,7 +1993,7 @@ function _instance:filerules(sourcefile) -- we can also get extensions from add_rules("xxx", {extensions = ".cpp"}) local rule_extensions = self:extraconf("rules", r:name(), "extensions") or r:get("extensions") for _, extension in ipairs(table.wrap(rule_extensions)) do - extension = extension:lower() + local extension = extension:lower() key2rules[extension] = key2rules[extension] or {} table.insert(key2rules[extension], r) end @@ -2047,6 +2048,7 @@ function _instance:fileconfig(sourcefile, opt) local results = os.match(filepath) if #results > 0 then for _, file in ipairs(results) do + local file = file if path.is_absolute(file) then file = path.relative(file, os.projectdir()) end @@ -2147,6 +2149,7 @@ function _instance:sourcefiles() local removed_count = 0 local targetcache = memcache.cache("core.project.target") for _, file in ipairs(table.wrap(files)) do + local file = file -- mark as removed files? local removed = false @@ -2194,6 +2197,7 @@ function _instance:sourcefiles() -- process source files for _, sourcefile in ipairs(results) do + local sourcefile = sourcefile -- convert to the relative path if path.is_absolute(sourcefile) then diff --git a/xmake/core/sandbox/modules/import/core/sandbox/module.lua b/xmake/core/sandbox/modules/import/core/sandbox/module.lua index dd7dac16e..2090c1f52 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/module.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/module.lua @@ -168,6 +168,7 @@ function core_sandbox_module._load_from_scriptdir(module_fullpath, opt) -- save module local scope = module for _, modulename in ipairs(path.split(modulepath)) do + local modulename = modulename local pos = modulename:find(".lua", 1, true) if pos then modulename = modulename:sub(1, pos - 1) diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_directory.lua b/xmake/core/sandbox/modules/import/lib/detect/find_directory.lua index ec737785b..63392a751 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_directory.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_directory.lua @@ -34,6 +34,7 @@ local xmake = require("base/xmake") function sandbox_lib_detect_find_directory._expand_paths(paths) local results = {} for _, _path in ipairs(table.wrap(paths)) do + local _path = _path if type(_path) == "function" then local ok, result_or_errors = sandbox.load(_path) if ok then @@ -45,7 +46,7 @@ function sandbox_lib_detect_find_directory._expand_paths(paths) _path = vformat(_path) end for _, _s_path in ipairs(table.wrap(_path)) do - _s_path = tostring(_s_path) + local _s_path = tostring(_s_path) if #_s_path > 0 then table.insert(results, _s_path) end @@ -58,7 +59,7 @@ end function sandbox_lib_detect_find_directory._normalize_suffixes(suffixes) local results = {} for _, suffix in ipairs(table.wrap(suffixes)) do - suffix = tostring(suffix) + local suffix = tostring(suffix) if #suffix > 0 then table.insert(results, suffix) end diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_file.lua b/xmake/core/sandbox/modules/import/lib/detect/find_file.lua index 71e580ba1..e642f45b7 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_file.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_file.lua @@ -35,6 +35,7 @@ local xmake = require("base/xmake") function sandbox_lib_detect_find_file._expand_paths(paths) local results = {} for _, _path in ipairs(table.wrap(paths)) do + local _path = _path if type(_path) == "function" then local ok, result_or_errors = sandbox.load(_path) if ok then @@ -50,7 +51,7 @@ function sandbox_lib_detect_find_file._expand_paths(paths) end end for _, _s_path in ipairs(table.wrap(_path)) do - _s_path = tostring(_s_path) + local _s_path = tostring(_s_path) if #_s_path > 0 then table.insert(results, _s_path) end @@ -63,7 +64,7 @@ end function sandbox_lib_detect_find_file._normalize_suffixes(suffixes) local results = {} for _, suffix in ipairs(table.wrap(suffixes)) do - suffix = tostring(suffix) + local suffix = tostring(suffix) if #suffix > 0 then table.insert(results, suffix) end diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_path.lua b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua index cd7413fb7..159d7dbdc 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_path.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua @@ -34,6 +34,7 @@ local xmake = require("base/xmake") function sandbox_lib_detect_find_path._expand_paths(paths) local results = {} for _, _path in ipairs(table.wrap(paths)) do + local _path = _path if type(_path) == "function" then local ok, result_or_errors = sandbox.load(_path) if ok then @@ -45,7 +46,7 @@ function sandbox_lib_detect_find_path._expand_paths(paths) _path = vformat(_path) end for _, _s_path in ipairs(table.wrap(_path)) do - _s_path = tostring(_s_path) + local _s_path = tostring(_s_path) if #_s_path > 0 then table.insert(results, _s_path) end @@ -58,7 +59,7 @@ end function sandbox_lib_detect_find_path._normalize_suffixes(suffixes) local results = {} for _, suffix in ipairs(table.wrap(suffixes)) do - suffix = tostring(suffix) + local suffix = tostring(suffix) if #suffix > 0 then table.insert(results, suffix) end diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua index 288a9089e..0ca3f8d19 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua @@ -108,6 +108,7 @@ function sandbox_lib_detect_find_program._find_from_paths(name, paths, opt) -- attempt to check it from the given directories if not path.is_absolute(name) then for _, _path in ipairs(table.wrap(paths)) do + local _path = _path -- format path for builtin variables if type(_path) == "function" then @@ -269,7 +270,7 @@ function sandbox_lib_detect_find_program._find(name, paths, opt) local ok, wherepaths = os.iorunv("where.exe", {program_name}) if ok and wherepaths then for _, program_path in ipairs(wherepaths:split("\n")) do - program_path = program_path:trim() + local program_path = program_path:trim() if #program_path > 0 then local program_path_real = sandbox_lib_detect_find_program._check(program_path, opt) if program_path_real then diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index a91b24ede..6aba67fc7 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -165,7 +165,7 @@ function builder:_add_flags_from_flagkind(flags, target, flagkind, opt) local targetflags = target:get(flagkind, opt) local extraconf = target:extraconf(flagkind) for _, flag in ipairs(table.wrap(targetflags)) do - flag = target_utils.flag_belong_to_tool(flag, self, extraconf) + local flag = target_utils.flag_belong_to_tool(flag, self, extraconf) if flag then if extraconf then local flagconf = extraconf[flag] @@ -390,6 +390,7 @@ function builder:_add_items_from_target(items, name, opt) local result, sources = target:get_from(name, "*") if result then for idx, values in ipairs(result) do + local values = values local source = sources[idx] local extras = target:extraconf_from(name, source) values = table.wrap(values) @@ -691,6 +692,7 @@ function builder:_sort_links_of_items(items, opt) -- re-generate links to items list if sortlinks or makegroups then for _, link in ipairs(links) do + local link = link if link:startswith("framework::") then link = link:sub(12) table.insert(items, {name = "frameworks", values = table.wrap(link), check = false, multival = false, mapper = framework_mapper}) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 1491f34f3..f6704cf28 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -253,6 +253,7 @@ function _instance:runenvs() if toolchain_runenvs then runenvs = {} for name, values in pairs(toolchain_runenvs) do + local values = values if type(values) == "table" then values = path.joinenv(values) end @@ -685,6 +686,7 @@ function toolchain.parsename(name) toolchain_name = toolchain_name_raw local splitinfo = configs_str:split(",", {plain = true}) for _, v in ipairs(splitinfo) do + local v = v local parts = v:split("=", {plain = true}) local k = parts[1] v = parts[2] diff --git a/xmake/modules/cli/amalgamate.lua b/xmake/modules/cli/amalgamate.lua index 72c7e8f2f..b76f60b6e 100644 --- a/xmake/modules/cli/amalgamate.lua +++ b/xmake/modules/cli/amalgamate.lua @@ -89,7 +89,7 @@ function _generate_file(target, inputpaths, outputpath, uniqueid) -- generate include graph local gh = graph.new(true) for idx, inputpath in ipairs(inputpaths) do - inputpath = path.normalize(path.absolute(inputpath, os.projectdir())) + local inputpath = path.normalize(path.absolute(inputpath, os.projectdir())) inputpaths[idx] = inputpath gh:add_edge("__root__", inputpath) end diff --git a/xmake/modules/core/tools/armcc/parse_deps.lua b/xmake/modules/core/tools/armcc/parse_deps.lua index 560bca40b..28a4f797c 100644 --- a/xmake/modules/core/tools/armcc/parse_deps.lua +++ b/xmake/modules/core/tools/armcc/parse_deps.lua @@ -59,6 +59,7 @@ function main(depsdata) local plain = {plain = true} line = line:replace("\\ ", space_placeholder, plain) for _, includefile in ipairs(line:split('\n', plain)) do + local includefile = includefile if is_host("windows") and includefile:match("^%w\\:") then includefile = includefile:replace("\\:", ":", plain) end diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index a28d049c3..02a562e06 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -536,6 +536,7 @@ function _preprocess(program, argv, opt) local sourcefile = argv[#argv] local extension = path.extension(sourcefile) for _, flag in ipairs(argv) do + local flag = flag if flag:startswith("-Fo") or flag:startswith("/Fo") then objectfile = flag:sub(4) break @@ -703,7 +704,7 @@ function _show_warnings(self, output, sourcefile) local has_warnings = false local has_source_dependencies = _has_source_dependencies(self) for _, line in ipairs(output:split("\n", {plain = true})) do - line = line:rtrim() + local line = line:rtrim() if #line > 0 then local skip = false @@ -806,7 +807,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) else -- filter includes notes: "Note: including file: xxx.h", @note maybe not english language for _, line in ipairs(tostring(errors):split("\n", {plain = true})) do - line = line:rtrim() + local line = line:rtrim() if not parse_include.has_include_note(line) then results = results .. line .. "\r\n" end diff --git a/xmake/modules/core/tools/cl/parse_deps_json.lua b/xmake/modules/core/tools/cl/parse_deps_json.lua index 651f795ac..890868dcb 100644 --- a/xmake/modules/core/tools/cl/parse_deps_json.lua +++ b/xmake/modules/core/tools/cl/parse_deps_json.lua @@ -134,7 +134,7 @@ function main(depsdata) local results = hashset.new() local projectdir = os.projectdir():lower() -- we need to generate lower string, because json values are all lower for _, includefile in ipairs(includes) do - includefile = _normailize_dep(includefile, projectdir) + local includefile = _normailize_dep(includefile, projectdir) if includefile then results:insert(includefile) end diff --git a/xmake/modules/core/tools/cl6x/parse_deps.lua b/xmake/modules/core/tools/cl6x/parse_deps.lua index 301d696aa..ef1b79860 100644 --- a/xmake/modules/core/tools/cl6x/parse_deps.lua +++ b/xmake/modules/core/tools/cl6x/parse_deps.lua @@ -65,7 +65,7 @@ function main(depsdata, opt) local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first local plain = {plain = true} for _, includefile in ipairs(line:split('\n', plain)) do -- it will trim all internal spaces without `{strict = true}` - includefile = includefile:split(": ", plain)[2] + local includefile = includefile:split(": ", plain)[2] if includefile and #includefile > 0 then includefile = _normailize_dep(includefile, projectdir) if includefile then diff --git a/xmake/modules/core/tools/cl_json/parse_deps.lua b/xmake/modules/core/tools/cl_json/parse_deps.lua index 2b84122b3..29dc2c5eb 100644 --- a/xmake/modules/core/tools/cl_json/parse_deps.lua +++ b/xmake/modules/core/tools/cl_json/parse_deps.lua @@ -134,7 +134,7 @@ function main(depsdata) local results = hashset.new() local projectdir = os.projectdir():lower() -- we need to generate lower string, because json values are all lower for _, includefile in ipairs(includes) do - includefile = _normailize_dep(includefile, projectdir) + local includefile = _normailize_dep(includefile, projectdir) if includefile then results:insert(includefile) end diff --git a/xmake/modules/core/tools/gcc/parse_deps.lua b/xmake/modules/core/tools/gcc/parse_deps.lua index 5adf69b91..b8d55e844 100644 --- a/xmake/modules/core/tools/gcc/parse_deps.lua +++ b/xmake/modules/core/tools/gcc/parse_deps.lua @@ -92,6 +92,7 @@ function main(depsdata, opt) local plain = {plain = true} line = line:replace("\\ ", space_placeholder, plain) for _, includefile in ipairs(line:split(' ', plain)) do -- it will trim all internal spaces without `{strict = true}` + local includefile = includefile -- some gcc toolchains will some invalid paths (e.g. `d\:\xxx`), we need to fix it -- https://github.com/xmake-io/xmake/issues/1196 if is_host("windows") and includefile:match("^%w\\:") then diff --git a/xmake/modules/core/tools/link/has_flags.lua b/xmake/modules/core/tools/link/has_flags.lua index 9d44b7b1c..80e7e2417 100644 --- a/xmake/modules/core/tools/link/has_flags.lua +++ b/xmake/modules/core/tools/link/has_flags.lua @@ -88,7 +88,7 @@ end function _ignore_flags(flags) local results = {} for _, flag in ipairs(flags) do - flag = flag:lower() + local flag = flag:lower() if not flag:find("[%-/]def:.+%.def") and not flag:find("[%-/]export:") then table.insert(results, flag) end diff --git a/xmake/modules/core/tools/rc/parse_deps.lua b/xmake/modules/core/tools/rc/parse_deps.lua index bd526823f..66f0dcdc2 100644 --- a/xmake/modules/core/tools/rc/parse_deps.lua +++ b/xmake/modules/core/tools/rc/parse_deps.lua @@ -41,6 +41,7 @@ function main(depsdata) local results = hashset.new() local projectdir = os.projectdir() for _, includefile in ipairs(depsdata:split('\n', {plain = true})) do + local includefile = includefile if #includefile > 0 then includefile = _normailize_dep(includefile, projectdir) if includefile then diff --git a/xmake/modules/detect/sdks/find_cross_toolchain.lua b/xmake/modules/detect/sdks/find_cross_toolchain.lua index e4acdfa3e..5560e6d8c 100644 --- a/xmake/modules/detect/sdks/find_cross_toolchain.lua +++ b/xmake/modules/detect/sdks/find_cross_toolchain.lua @@ -34,6 +34,7 @@ function _find_bindir(sdkdir, opt) -- attempt to find *-[gcc|clang|ld] for _, toolname in ipairs({"gcc", "clang", "ld"}) do + local toolname = toolname if is_host("windows") then toolname = toolname .. ".exe" end diff --git a/xmake/modules/detect/sdks/find_dotnet.lua b/xmake/modules/detect/sdks/find_dotnet.lua index f64acacd3..af17f1d65 100644 --- a/xmake/modules/detect/sdks/find_dotnet.lua +++ b/xmake/modules/detect/sdks/find_dotnet.lua @@ -49,7 +49,7 @@ function _find_dotnet_cli(sdkdir) if sdklist then local sdks = {} for _, line in ipairs(sdklist:split("\n", {plain = true})) do - line = line:trim() + local line = line:trim() local ver, dir = line:match("^(%S+)%s+%[(.-)%]") if ver and dir then table.insert(sdks, {version = ver, directory = path.join(dir, ver)}) @@ -72,7 +72,7 @@ function _find_dotnet_cli(sdkdir) if runtimelist then local runtimes = {} for _, line in ipairs(runtimelist:split("\n", {plain = true})) do - line = line:trim() + local line = line:trim() local name, ver = line:match("^(%S+)%s+(%S+)%s+%[") if name and ver then table.insert(runtimes, {name = name, version = ver}) diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua index 8a805aae6..e7699ee0d 100644 --- a/xmake/modules/detect/sdks/find_vstudio.lua +++ b/xmake/modules/detect/sdks/find_vstudio.lua @@ -395,6 +395,7 @@ function _check_vcvarsall_env(vars) if value_org and value_new and #value_org > 0 then local values_new = hashset.from(path.splitenv(value_new)) for _, p in ipairs(value_org) do + local p = p if not values_new:has(p) then if #p > 256 then p = p:sub(1, 256) .. "..." @@ -518,6 +519,7 @@ function _find_vstudio(opt) -- find vs2017 -> vs4.2 local results = {} for _, version in ipairs(order_vsvers) do + local version = version -- find VC install path (and aux build path) using `vswhere` (for version >= 15.0) -- * version > 15.0 eschews registry entries; but `vswhere` (included with version >= 15.2) can be used to find VC install path diff --git a/xmake/modules/lib/detect/check_importfiles.lua b/xmake/modules/lib/detect/check_importfiles.lua index 844939891..d8c12d387 100644 --- a/xmake/modules/lib/detect/check_importfiles.lua +++ b/xmake/modules/lib/detect/check_importfiles.lua @@ -34,6 +34,7 @@ function main(names, opt) verbose = true end for _, name in ipairs(names) do + local name = name local kind local parts = name:split("::") if #parts == 2 then diff --git a/xmake/modules/lib/detect/find_toolname.lua b/xmake/modules/lib/detect/find_toolname.lua index 37f468c73..0b7ad1a9b 100644 --- a/xmake/modules/lib/detect/find_toolname.lua +++ b/xmake/modules/lib/detect/find_toolname.lua @@ -49,6 +49,7 @@ function _find_with_whole_name(program) local partnames = {} local names = path.filename(program):lower():split("%s") for _, name in ipairs(names) do + local name = name -- remove suffix: ".exe", e.g. "zig.exe cc" name = _remove_suffix(name) -- "zig c++" -> zig_cxx diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua index 8ac8e3385..a28b3e41a 100644 --- a/xmake/modules/lib/detect/has_flags.lua +++ b/xmake/modules/lib/detect/has_flags.lua @@ -106,7 +106,7 @@ function main(name, flags, opt) -- split flag group, e.g. "-I /xxx" => {"-I", "/xxx"} local results = {} for _, flag in ipairs(checkflags) do - flag = flag:trim() + local flag = flag:trim() if #flag > 0 then if flag:find(" ", 1, true) then table.join2(results, os.argv(flag)) diff --git a/xmake/modules/net/proxy.lua b/xmake/modules/net/proxy.lua index 1ab9779e6..050188b33 100644 --- a/xmake/modules/net/proxy.lua +++ b/xmake/modules/net/proxy.lua @@ -163,7 +163,7 @@ function config(url) if host and proxy_hosts then host = host:lower() for _, proxy_host in ipairs(proxy_hosts) do - proxy_host = proxy_host:lower() + local proxy_host = proxy_host:lower() if host == proxy_hosts or host:match(_host_pattern(proxy_host)) then return _global_proxy() end diff --git a/xmake/modules/package/manager/apt/find_package.lua b/xmake/modules/package/manager/apt/find_package.lua index f9bec605d..9f3941980 100644 --- a/xmake/modules/package/manager/apt/find_package.lua +++ b/xmake/modules/package/manager/apt/find_package.lua @@ -33,7 +33,7 @@ function _find_package(dpkg, name, opt) local listinfo = try {function () return os.iorunv(dpkg.program, {"--listfiles", name}) end} if listinfo then for _, line in ipairs(listinfo:split('\n', {plain = true})) do - line = line:trim() + local line = line:trim() -- get includedirs local pos = line:find("include/", 1, true) diff --git a/xmake/modules/package/manager/cmake/find_package.lua b/xmake/modules/package/manager/cmake/find_package.lua index 7192843a9..dba4cae04 100644 --- a/xmake/modules/package/manager/cmake/find_package.lua +++ b/xmake/modules/package/manager/cmake/find_package.lua @@ -203,6 +203,7 @@ function _find_package(cmake, name, opt) io.write(linkdata .. "\n") end for _, line in ipairs(os.argv(linkdata)) do + local line = line local is_ldflags = false local is_library = false for _, suffix in ipairs({".so", ".dylib", ".dylib", ".tbd", ".lib"}) do diff --git a/xmake/modules/package/manager/conan/v1/install_package.lua b/xmake/modules/package/manager/conan/v1/install_package.lua index d96727eb7..9d36400ac 100644 --- a/xmake/modules/package/manager/conan/v1/install_package.lua +++ b/xmake/modules/package/manager/conan/v1/install_package.lua @@ -77,6 +77,7 @@ function _conan_generate_conanfile(name, configs, opt) if #options > 0 then conanfile:print("[options]") for _, item in ipairs(options) do + local item = item if not item:find(":", 1, true) then item = name .. ":" .. item end diff --git a/xmake/modules/package/manager/conan/v2/install_package.lua b/xmake/modules/package/manager/conan/v2/install_package.lua index ff834e1b6..fae6d7ff4 100644 --- a/xmake/modules/package/manager/conan/v2/install_package.lua +++ b/xmake/modules/package/manager/conan/v2/install_package.lua @@ -77,6 +77,7 @@ function _conan_generate_conanfile(name, configs, opt) if #options > 0 then conanfile:print("[options]") for _, item in ipairs(options) do + local item = item if not item:find(":", 1, true) then item = name .. "/*:" .. item end diff --git a/xmake/modules/package/manager/conda/find_package.lua b/xmake/modules/package/manager/conda/find_package.lua index 608d85f3b..87ecd817b 100644 --- a/xmake/modules/package/manager/conda/find_package.lua +++ b/xmake/modules/package/manager/conda/find_package.lua @@ -107,7 +107,7 @@ function main(name, opt) local result = nil local packagedir = metainfo.extracted_package_dir for _, line in ipairs(metainfo.files) do - line = line:trim() + local line = line:trim() -- get includedirs local pos = line:find("include/", 1, true) diff --git a/xmake/modules/package/manager/nix/search_package.lua b/xmake/modules/package/manager/nix/search_package.lua index 3ad66610c..e5e40aa8c 100644 --- a/xmake/modules/package/manager/nix/search_package.lua +++ b/xmake/modules/package/manager/nix/search_package.lua @@ -75,7 +75,7 @@ function _search_with_env(name) -- nixpkgs.cmakeWithGui cmake-3.27.7 for _, line in ipairs(searchdata:split("\n", {plain = true})) do - line = line:trim() + local line = line:trim() if line ~= "" then local parts = line:split("%s+", {limit = 2}) if #parts >= 2 then diff --git a/xmake/modules/package/manager/nuget/find_package.lua b/xmake/modules/package/manager/nuget/find_package.lua index 4a27eed19..c9fa2b712 100644 --- a/xmake/modules/package/manager/nuget/find_package.lua +++ b/xmake/modules/package/manager/nuget/find_package.lua @@ -188,6 +188,7 @@ function _find_package(name, result, opt) local libarch = libarchs[arch] or "x64" local libmode = configs.debug and "Debug" or "Release" for _, file in ipairs(libinfo.files) do + local file = file local filepath = path.join(installdir, file) file = file:trim() diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua index 3b200db26..2a609505b 100644 --- a/xmake/modules/package/manager/pacman/find_package.lua +++ b/xmake/modules/package/manager/pacman/find_package.lua @@ -50,7 +50,7 @@ function _find_package_from_list(list, name, pacman, opt) -- iterate over each file path inside the pacman package local result = {} for _, line in ipairs(list:split('\n', {plain = true})) do -- on msys cygpath should be used to convert local path to windows path - line = line:trim():split('%s+')[2] + local line = line:trim():split('%s+')[2] if line:find("/include/", 1, true) and (line:endswith(".h") or line:endswith(".hpp")) then if not line:startswith("/usr/include/") then if not (msystem and line:startswith("/" .. msystem .. "/include/")) then @@ -133,7 +133,7 @@ function _find_libfiles_from_list(list, name, pacman, opt) -- iterate over each file path inside the pacman package local libfiles for _, line in ipairs(list:split('\n', {plain = true})) do -- on msys cygpath should be used to convert local path to windows path - line = line:trim():split('%s+')[2] + local line = line:trim():split('%s+')[2] if line:endswith(".dll.a") then -- only for mingw local apath = path.join(pathtomsys, line) apath = apath:trim() @@ -185,7 +185,7 @@ function main(name, opt) local linkdirs = {} local pkgconfig_files = {} for _, line in ipairs(list:split('\n', {plain = true})) do - line = line:trim():split('%s+')[2] + local line = line:trim():split('%s+')[2] if line:find("/pkgconfig/", 1, true) and line:endswith(".pc") then table.insert(pkgconfig_files, line) end diff --git a/xmake/modules/package/manager/portage/find_package.lua b/xmake/modules/package/manager/portage/find_package.lua index 4f6ae5d32..6f4feef48 100644 --- a/xmake/modules/package/manager/portage/find_package.lua +++ b/xmake/modules/package/manager/portage/find_package.lua @@ -63,7 +63,7 @@ function main(name, opt) local has_includes = false local pkgconfig_files = {} for _, line in ipairs(list) do - line = line:trim():split('%s+')[1] + local line = line:trim():split('%s+')[1] if line:find("/pkgconfig/", 1, true) and line:endswith(".pc") then pkgconfig_files[path.basename(line)] = line end diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua index f3dc740bd..d14092854 100644 --- a/xmake/modules/package/manager/vcpkg/find_package.lua +++ b/xmake/modules/package/manager/vcpkg/find_package.lua @@ -35,14 +35,14 @@ function _required_features(name, configs) local features_str = name:match("%[(.-)%]") if features_str then for _, feature in ipairs(features_str:split(",", {plain = true})) do - feature = feature:trim() + local feature = feature:trim() if #feature > 0 then table.insert(features, feature) end end end for _, feature in ipairs(table.wrap(configs and configs.features)) do - feature = tostring(feature):trim() + local feature = tostring(feature):trim() if #feature > 0 then table.insert(features, feature) end @@ -102,7 +102,7 @@ function _get_package_info(name, triplet, infodirs, arch, plat, mode) local info = io.readfile(infofile) if info then for _, line in ipairs(info:split('\n')) do - line = line:trim() + local line = line:trim() if plat == "windows" then line = line:lower() end diff --git a/xmake/modules/package/manager/zypper/find_package.lua b/xmake/modules/package/manager/zypper/find_package.lua index 2f0d5fc88..e44a70a9d 100644 --- a/xmake/modules/package/manager/zypper/find_package.lua +++ b/xmake/modules/package/manager/zypper/find_package.lua @@ -38,7 +38,7 @@ function _find_package(rpm, name, opt) end } if listinfo then for _, line in ipairs(listinfo:split('\n', { plain = true })) do - line = line:trim() + local line = line:trim() -- get includedirs local pos = line:find("include/", 1, true) diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index c2fc26954..181fc8295 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -667,7 +667,7 @@ function configure(package, configs, opt) -- pass configurations local argv = {} for name, value in pairs(_get_configs(package, configs)) do - value = tostring(value):trim() + local value = tostring(value):trim() if value ~= "" then if type(name) == "number" then table.insert(argv, value) @@ -721,7 +721,7 @@ function build(package, configs, opt) end if opt.makeconfigs then for name, value in pairs(opt.makeconfigs) do - value = tostring(value):trim() + local value = tostring(value):trim() if value ~= "" then if type(name) == "number" then table.insert(argv, value) @@ -748,7 +748,7 @@ function install(package, configs, opt) end if opt.makeconfigs then for name, value in pairs(opt.makeconfigs) do - value = tostring(value):trim() + local value = tostring(value):trim() if value ~= "" then if type(name) == "number" then table.insert(argv, value) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 1557aebeb..360a0f700 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -1307,7 +1307,7 @@ function configure(package, configs, opt) -- pass configurations local argv = {} for name, value in pairs(_get_configs(package, configs, opt)) do - value = tostring(value):trim() + local value = tostring(value):trim() if type(name) == "number" then if value ~= "" then table.insert(argv, value) diff --git a/xmake/modules/package/tools/jom.lua b/xmake/modules/package/tools/jom.lua index e712ca8dd..470502300 100644 --- a/xmake/modules/package/tools/jom.lua +++ b/xmake/modules/package/tools/jom.lua @@ -69,7 +69,7 @@ function build(package, configs, opt) end configs = table.join(jom_argv, configs) for name, value in pairs(configs) do - value = tostring(value):trim() + local value = tostring(value):trim() if value ~= "" then if type(name) == "number" then table.insert(argv, value) diff --git a/xmake/modules/package/tools/make.lua b/xmake/modules/package/tools/make.lua index 485426119..13869a236 100644 --- a/xmake/modules/package/tools/make.lua +++ b/xmake/modules/package/tools/make.lua @@ -138,7 +138,7 @@ function build(package, configs, opt) table.insert(argv, "V=1") end for name, value in pairs(configs) do - value = tostring(value):trim() + local value = tostring(value):trim() if value ~= "" then if type(name) == "number" then table.insert(argv, value) diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua index ec95c4f42..598370997 100644 --- a/xmake/modules/package/tools/meson.lua +++ b/xmake/modules/package/tools/meson.lua @@ -566,7 +566,7 @@ function generate(package, configs, opt) -- TODO: support more backends https://mesonbuild.com/Commands.html#setup local argv = {"setup"} for name, value in pairs(_get_configs(package, configs, opt)) do - value = tostring(value):trim() + local value = tostring(value):trim() if value ~= "" then if type(name) == "number" then table.insert(argv, value) diff --git a/xmake/modules/package/tools/msbuild.lua b/xmake/modules/package/tools/msbuild.lua index 633ce4e14..d36be1b6a 100644 --- a/xmake/modules/package/tools/msbuild.lua +++ b/xmake/modules/package/tools/msbuild.lua @@ -95,7 +95,7 @@ function build(package, configs, opt) -- pass configurations local argv = {} for name, value in pairs(_get_configs(package, configs, opt)) do - value = tostring(value):trim() + local value = tostring(value):trim() if value ~= "" then if type(name) == "number" then table.insert(argv, value) diff --git a/xmake/modules/package/tools/nmake.lua b/xmake/modules/package/tools/nmake.lua index 85182ac61..78ff8d9bb 100644 --- a/xmake/modules/package/tools/nmake.lua +++ b/xmake/modules/package/tools/nmake.lua @@ -57,7 +57,7 @@ function build(package, configs, opt) table.insert(argv, "VERBOSE=1") end for name, value in pairs(configs) do - value = tostring(value):trim() + local value = tostring(value):trim() if value ~= "" then if type(name) == "number" then table.insert(argv, value) diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index 4ff3c6239..133de5f39 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -539,7 +539,7 @@ function install(package, configs, opt) table.insert(argv, "-y") table.insert(argv, "-c") for name, value in pairs(_get_configs(package, configs, opt)) do - value = tostring(value):trim() + local value = tostring(value):trim() if type(name) == "number" then if value ~= "" then table.insert(argv, value) diff --git a/xmake/modules/private/action/require/impl/actions/download.lua b/xmake/modules/private/action/require/impl/actions/download.lua index 5930b3cbb..55e43a3db 100644 --- a/xmake/modules/private/action/require/impl/actions/download.lua +++ b/xmake/modules/private/action/require/impl/actions/download.lua @@ -356,6 +356,7 @@ function main(package, opt) local ok = false local urls_failed = {} for idx, url in ipairs(urls) do + local url = url local url_alias = package:url_alias(url) local url_excludes = package:url_excludes(url) local url_includes = package:url_includes(url) diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index 3789573b6..57257b7f6 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -79,7 +79,7 @@ function _patch_pkgconfig(package) -- get libs local libs = "" for _, linkdir in ipairs(fetchinfo.linkdirs) do - linkdir = path.unix(path.normalize(linkdir)):replace(installdir, "${exec_prefix}", {plain = true}) + local linkdir = path.unix(path.normalize(linkdir)):replace(installdir, "${exec_prefix}", {plain = true}) if linkdir ~= "${exec_prefix}/lib" then libs = libs .. " -L" .. linkdir end @@ -95,7 +95,7 @@ function _patch_pkgconfig(package) -- cflags local cflags = "" for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do - includedir = path.unix(path.normalize(includedir)):replace(installdir, "${prefix}", {plain = true}) + local includedir = path.unix(path.normalize(includedir)):replace(installdir, "${prefix}", {plain = true}) if includedir ~= "${prefix}/include" then cflags = cflags .. " -I" .. includedir end diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index bd7d59606..f0da9eb2e 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -152,7 +152,7 @@ function _get_confirm_from_3rd(packages) local confirmed_extpackages = {} if result and result ~= "n" then for _, idx in ipairs(result:split(',')) do - idx = tonumber(idx) + local idx = tonumber(idx) if extpackages_list[idx] then table.insert(confirmed_extpackages, extpackages_list[idx]) end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 4e2d70e5f..53c3d627d 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -70,6 +70,7 @@ function _load_require(require_str, requires_extra, opt) packagename = packagename_raw local splitinfo = configs_str:split(",", {plain = true}) for _, v in ipairs(splitinfo) do + local v = v local parts = v:split("=", {plain = true}) local k = parts[1] v = parts[2] @@ -1216,6 +1217,7 @@ function _get_package_compatkey(dep) if configs then local configs_order = {} for k, v in pairs(configs) do + local v = v if type(v) == "table" then v = string.serialize(v, {strip = true, indent = false, orderkeys = true}) end @@ -1594,6 +1596,7 @@ function get_configs_str(package) local ignored_configs_for_buildhash = hashset.from(requireinfo.ignored_configs_for_buildhash or {}) local configs_overrided = requireinfo.configs_overrided or {} for k, v in pairs(requireinfo.configs) do + local v = v if not ignored_configs_for_buildhash:has(k) then v = configs_overrided[k] or v if type(v) == "boolean" then diff --git a/xmake/modules/private/action/require/impl/utils/requirekey.lua b/xmake/modules/private/action/require/impl/utils/requirekey.lua index 5fd228ecf..f86806490 100644 --- a/xmake/modules/private/action/require/impl/utils/requirekey.lua +++ b/xmake/modules/private/action/require/impl/utils/requirekey.lua @@ -66,6 +66,7 @@ function main(requireinfo, opt) if configs then local configs_order = {} for k, v in pairs(configs) do + local v = v if type(v) == "table" then v = string.serialize(v, {strip = true, indent = false, orderkeys = true}) end diff --git a/xmake/modules/private/action/require/info.lua b/xmake/modules/private/action/require/info.lua index f1be7a01b..4ef702a2c 100644 --- a/xmake/modules/private/action/require/info.lua +++ b/xmake/modules/private/action/require/info.lua @@ -165,7 +165,7 @@ function main(requires_raw) cprint(" -> ${color.dump.string_quote}searchdirs${clear}: %s", table.concat(table.wrap(core_package.searchdirs()), path.envsep())) local searchnames = hashset.new() for _, url in ipairs(urls) do - url = filter.handle(url, instance) + local url = filter.handle(url, instance) if git.checkurl(url) then searchnames:insert(instance:name() .. archive.extension(url) .. " ${dim}(git)${clear}") searchnames:insert(path.basename(url_filename(url)) .. " ${dim}(git)${clear}") @@ -193,7 +193,7 @@ function main(requires_raw) local fetchinfo = instance:fetch() if fetchinfo then for name, info in pairs(fetchinfo) do - info = table.unwrap(info) + local info = table.unwrap(info) if type(info) ~= "table" then info = tostring(info) end diff --git a/xmake/modules/private/action/run/runenvs.lua b/xmake/modules/private/action/run/runenvs.lua index 43d150e66..dfcd181b7 100644 --- a/xmake/modules/private/action/run/runenvs.lua +++ b/xmake/modules/private/action/run/runenvs.lua @@ -98,7 +98,7 @@ function _add_target_pkgenvs(addenvs, target, targets_added) local pkgenvs = target:pkgenvs() if pkgenvs then for name, values in pairs(pkgenvs) do - values = path.splitenv(values) + local values = path.splitenv(values) local oldenvs = addenvs[name] if oldenvs then table.join2(oldenvs, values) diff --git a/xmake/modules/private/async/jobpool.lua b/xmake/modules/private/async/jobpool.lua index 3d9bd7819..b3ee5893b 100644 --- a/xmake/modules/private/async/jobpool.lua +++ b/xmake/modules/private/async/jobpool.lua @@ -269,7 +269,7 @@ function jobpool:_gentree(job, refs) -- strip tree local smalltree = hashset.new() for _, item in ipairs(tree) do - item = table.unwrap(item) + local item = table.unwrap(item) if smalltree:size() < 16 or type(item) == "table" then smalltree:insert(item) else diff --git a/xmake/modules/private/service/remote_build/filesync.lua b/xmake/modules/private/service/remote_build/filesync.lua index e984d3968..fa9ba1fde 100644 --- a/xmake/modules/private/service/remote_build/filesync.lua +++ b/xmake/modules/private/service/remote_build/filesync.lua @@ -137,7 +137,7 @@ function filesync:_ignorefiles_load(ignorefiles) local gitroot = path.directory(gitignore_file) local gitignore = io.open(gitignore_file, "r") for line in gitignore:lines() do - line = line:trim() + local line = line:trim() if #line > 0 and not line:startswith("#") then local filepath = path.join(gitroot, line) local pattern = path.relative(filepath, rootdir) diff --git a/xmake/modules/private/utils/package.lua b/xmake/modules/private/utils/package.lua index 6df309f5f..c964c3ad3 100644 --- a/xmake/modules/private/utils/package.lua +++ b/xmake/modules/private/utils/package.lua @@ -22,6 +22,7 @@ function _concat_packages(a, b) local result = table.copy(a) for k, v in pairs(b) do + local v = v local o = result[k] if o ~= nil then v = table.join(o, v) @@ -29,6 +30,7 @@ function _concat_packages(a, b) result[k] = v end for k, v in pairs(result) do + local v = v if k == "links" or k == "syslinks" or k == "frameworks" or k == "ldflags" or k == "shflags" then if type(v) == "table" and #v > 1 then -- we need to ensure link orders when removing repeat values diff --git a/xmake/modules/private/utils/target.lua b/xmake/modules/private/utils/target.lua index 217daad52..5ec96c918 100644 --- a/xmake/modules/private/utils/target.lua +++ b/xmake/modules/private/utils/target.lua @@ -42,6 +42,7 @@ function has_tool(toolname, tools) trim_xx = true end for _, v in ipairs(tools) do + local v = v if trim_xx then v = v:rtrim("xx") end @@ -126,7 +127,7 @@ function translate_flags_in_tool(target, flagkind, flags) -- local result = {} for _, flag in ipairs(flags) do - flag = flag_belong_to_tool(flag, toolinst, extraconf) + local flag = flag_belong_to_tool(flag, toolinst, extraconf) if flag then table.insert(result, flag) end diff --git a/xmake/modules/private/utils/trim_trailing_spaces.lua b/xmake/modules/private/utils/trim_trailing_spaces.lua index a0279a261..155c36c92 100644 --- a/xmake/modules/private/utils/trim_trailing_spaces.lua +++ b/xmake/modules/private/utils/trim_trailing_spaces.lua @@ -24,7 +24,7 @@ function main(pattern) if filedata then local filedata2 = {} for _, line in ipairs(filedata:split('\n', {strict = true})) do - line = line:rtrim() + local line = line:rtrim() table.insert(filedata2, line) end io.writefile(filepath, table.concat(filedata2, "\n")) diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua index 2ba6068df..f42d079b6 100644 --- a/xmake/modules/private/xrepo/action/env.lua +++ b/xmake/modules/private/xrepo/action/env.lua @@ -149,7 +149,7 @@ function _get_boundenvs(opt) if bind then local envfiles = _get_envfiles() for _, binditem in ipairs(bind:split(',', {plain = true})) do - binditem = binditem:trim() + local binditem = binditem:trim() if envfiles[binditem] then table.insert(files, envfiles[binditem]) else diff --git a/xmake/modules/target/action/install/pkgconfig_importfiles.lua b/xmake/modules/target/action/install/pkgconfig_importfiles.lua index b0b91efa4..c0daa30c3 100644 --- a/xmake/modules/target/action/install/pkgconfig_importfiles.lua +++ b/xmake/modules/target/action/install/pkgconfig_importfiles.lua @@ -50,7 +50,7 @@ function main(target, opt) -- get libs local libs = "" for _, linkdir in ipairs(linkdirs) do - linkdir = path.unix(path.normalize(linkdir)):replace(installdir, "${exec_prefix}", {plain = true}) + local linkdir = path.unix(path.normalize(linkdir)):replace(installdir, "${exec_prefix}", {plain = true}) if linkdir ~= "${exec_prefix}/lib" then libs = libs .. " -L" .. linkdir end @@ -66,7 +66,7 @@ function main(target, opt) -- get cflags local cflags = "" for _, includedir in ipairs(includedirs) do - includedir = path.unix(path.normalize(includedir)):replace(installdir, "${prefix}", {plain = true}) + local includedir = path.unix(path.normalize(includedir)):replace(installdir, "${prefix}", {plain = true}) if includedir ~= "${prefix}/include" then cflags = cflags .. " -I" .. includedir end diff --git a/xmake/modules/utils/binary/deplibs.lua b/xmake/modules/utils/binary/deplibs.lua index 1de8056fd..56029ef20 100644 --- a/xmake/modules/utils/binary/deplibs.lua +++ b/xmake/modules/utils/binary/deplibs.lua @@ -44,7 +44,7 @@ function _get_depends_by_dumpbin(binaryfile, opt) local result = try { function () return os.iorunv(dumpbin.program, {"/dependents", "/nologo", binaryfile}) end } if result then for _, line in ipairs(result:split("\n")) do - line = line:trim() + local line = line:trim() if not line:startswith("Dump of file") and line:endswith(".dll") then depends = depends or {} table.insert(depends, line) @@ -71,7 +71,7 @@ function _get_depends_by_objdump(binaryfile, opt) local result = try { function () return os.iorunv(objdump.program, argv) end } if result then for _, line in ipairs(result:split("\n")) do - line = line:trim() + local line = line:trim() if not line:endswith(":") then if plat == "windows" or plat == "mingw" then if line:startswith("DLL Name:") then @@ -126,6 +126,7 @@ function _get_depends_by_ldd(binaryfile, opt) local result = try { function () return os.iorunv(ldd.program, {binaryfile}) end } if result then for _, line in ipairs(result:split("\n")) do + local line = line local splitinfo = line:split("=>") line = splitinfo[2] if not line or line:find("not found", 1, true) then @@ -202,7 +203,7 @@ function _get_depends_by_otool(binaryfile, opt) local result = try { function () return os.iorunv(otool.program, {"-L", binaryfile}) end } if result then for _, line in ipairs(result:split("\n")) do - line = line:trim() + local line = line:trim() if not line:endswith(":") then local filename = line:match(".-%.dylib") or line:match(".-%.framework") if filename then @@ -344,7 +345,7 @@ function _get_plain_depends(binaryfile, opt) if depends and opt.resolve_path then local result = {} for _, dependfile in ipairs(depends) do - dependfile = _resolve_filepath(binaryfile, dependfile, opt) + local dependfile = _resolve_filepath(binaryfile, dependfile, opt) if dependfile then table.insert(result, dependfile) end diff --git a/xmake/modules/utils/binary/rpath.lua b/xmake/modules/utils/binary/rpath.lua index 33cab5a43..2e74443ad 100644 --- a/xmake/modules/utils/binary/rpath.lua +++ b/xmake/modules/utils/binary/rpath.lua @@ -55,7 +55,7 @@ function _get_rpath_list_by_objdump(binaryfile, opt) if result then local cmd = false for _, line in ipairs(result:split("\n")) do - line = line:trim() + local line = line:trim() if plat == "macosx" or plat == "iphoneos" or plat == "appletvos" or plat == "watchos" then if not cmd and line:find("cmd LC_RPATH", 1, true) then cmd = true diff --git a/xmake/modules/utils/run_script.lua b/xmake/modules/utils/run_script.lua index e6f8469f6..057ea57cd 100644 --- a/xmake/modules/utils/run_script.lua +++ b/xmake/modules/utils/run_script.lua @@ -191,6 +191,7 @@ function main(script, opt) if opt.thread then local argv for _, arg in ipairs(opt.arguments) do + local arg = arg argv = argv or {} if path.instance_of(arg) then arg = tostring(arg) diff --git a/xmake/plugins/format/main.lua b/xmake/plugins/format/main.lua index 2d0913c20..fe05d86c6 100644 --- a/xmake/plugins/format/main.lua +++ b/xmake/plugins/format/main.lua @@ -63,7 +63,7 @@ function _get_file_patterns(sourcefiles) if excludes then local _excludes = {} for _, exclude in ipairs(excludes) do - exclude = path.translate(exclude) + local exclude = path.translate(exclude) exclude = path.pattern(exclude) table.insert(_excludes, exclude) end diff --git a/xmake/plugins/pack/deb/main.lua b/xmake/plugins/pack/deb/main.lua index cfcdb0dfd..3f7fa4e82 100644 --- a/xmake/plugins/pack/deb/main.lua +++ b/xmake/plugins/pack/deb/main.lua @@ -81,6 +81,7 @@ function _get_customcmd(package, installcmds, cmd) elseif cmd.program then local argv = {} for _, arg in ipairs(cmd.argv) do + local arg = arg if path.instance_of(arg) then arg = arg:clone():set(_translate_filepath(package, arg:rawstr())):str() elseif path.is_absolute(arg) then @@ -206,7 +207,7 @@ function _pack_deb(debuild, package) end) end for _, name in ipairs(specvars_names) do - name = name:trim() + local name = name:trim() if specvars_values[name] == nil then local value = specvars[name] if type(value) == "function" then diff --git a/xmake/plugins/pack/nsis/main.lua b/xmake/plugins/pack/nsis/main.lua index 3dc579608..420a1458c 100644 --- a/xmake/plugins/pack/nsis/main.lua +++ b/xmake/plugins/pack/nsis/main.lua @@ -99,6 +99,7 @@ function _get_command_strings(package, cmd, opt) -- match files and directories local srcitems = os.filedirs(srcpath) for _, srcitem in ipairs(srcitems) do + local srcitem = srcitem if os.isdir(srcitem) then -- copy directory recursively srcitem = path.normalize(srcitem) @@ -283,7 +284,7 @@ function _pack_nsis(makensis, package) table.insert(specvars_names, name) end, {encoding = "ansi"}) for _, name in ipairs(specvars_names) do - name = name:trim() + local name = name:trim() if specvars_values[name] == nil then local value = specvars[name] if type(value) == "function" then diff --git a/xmake/plugins/pack/runself/main.lua b/xmake/plugins/pack/runself/main.lua index 31f88f9dd..42eb8bc67 100644 --- a/xmake/plugins/pack/runself/main.lua +++ b/xmake/plugins/pack/runself/main.lua @@ -123,7 +123,7 @@ function _pack_runself(makeself, package) table.insert(specvars_names, name) end) for _, name in ipairs(specvars_names) do - name = name:trim() + local name = name:trim() if specvars_values[name] == nil then local value = specvars[name] if type(value) == "function" then diff --git a/xmake/plugins/pack/srpm/main.lua b/xmake/plugins/pack/srpm/main.lua index 5b570844d..49e27fca3 100644 --- a/xmake/plugins/pack/srpm/main.lua +++ b/xmake/plugins/pack/srpm/main.lua @@ -102,6 +102,7 @@ function _get_customcmd(package, installcmds, cmd) elseif cmd.program then local argv = {} for _, arg in ipairs(cmd.argv) do + local arg = arg if path.instance_of(arg) then arg = arg:clone():set(_translate_filepath(package, arg:rawstr())):str() elseif path.is_absolute(arg) then @@ -218,7 +219,7 @@ function _pack_srpm(rpmbuild, package) table.insert(specvars_names, name) end) for _, name in ipairs(specvars_names) do - name = name:trim() + local name = name:trim() if specvars_values[name] == nil then local value = specvars[name] if type(value) == "function" then diff --git a/xmake/plugins/pack/wix/main.lua b/xmake/plugins/pack/wix/main.lua index 896ea2339..e12461883 100644 --- a/xmake/plugins/pack/wix/main.lua +++ b/xmake/plugins/pack/wix/main.lua @@ -82,11 +82,13 @@ function _get_cp_kind_table(package, cmds, opt) -- match files and directories local srcitems = os.filedirs(cmd.srcpath) for _, srcitem in ipairs(srcitems) do + local srcitem = srcitem if os.isdir(srcitem) then -- for directory, recursively collect all files in it local rootdir = option.rootdir or srcitem local files = os.files(path.join(srcitem, "**")) for _, srcfile in ipairs(files) do + local srcfile = srcfile -- the destination is directory? append the relative path local dstfile = cmd.dstpath if option.rootdir then @@ -300,7 +302,7 @@ function _pack_wix(wix, package) table.insert(specvars_names, name) end) for _, name in ipairs(specvars_names) do - name = name:trim() + local name = name:trim() if specvars_values[name] == nil then local value = specvars[name] if type(value) == "function" then diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index 909184800..e38c1cef1 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -90,6 +90,7 @@ function _translate_arguments(arguments) local is_include = false local lsp = _get_lsp() for idx, arg in ipairs(arguments) do + local arg = arg -- convert path to string, maybe we need to convert path, but not supported now. arg = tostring(arg) diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index 167d4bb5f..d089cf805 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -562,6 +562,7 @@ function _add_target_source_groups(cmakelists, target, outputdir) rootdir = string.format("${CMAKE_CURRENT_SOURCE_DIR}/%s", _get_relative_unix_path(rootdir, outputdir)) end for _, filepattern in ipairs(files) do + local filepattern = filepattern if filepattern:find("**", 1, true) then filepattern = filepattern:gsub("%*%*", "*") table.insert(recurse_sources, _get_relative_unix_path(path.join(rootdir, filepattern), outputdir)) @@ -734,6 +735,7 @@ function _add_target_compile_options(cmakelists, target, outputdir) if #cflags > 0 or #cxflags > 0 or #cxxflags > 0 or #cuflags > 0 then cmakelists:print("target_compile_options(%s PRIVATE", target:name()) for _, flag in ipairs(_translate_flags(cflags, outputdir)) do + local flag = flag local prefix prefix, flag = _split_flag_with_tool_prefix(flag) if prefix == toolname then @@ -745,6 +747,7 @@ function _add_target_compile_options(cmakelists, target, outputdir) end end for _, flag in ipairs(_translate_flags(cxflags, outputdir)) do + local flag = flag local prefix prefix, flag = _split_flag_with_tool_prefix(flag) if prefix == toolname then @@ -757,6 +760,7 @@ function _add_target_compile_options(cmakelists, target, outputdir) end end for _, flag in ipairs(_translate_flags(cxxflags, outputdir)) do + local flag = flag local prefix prefix, flag = _split_flag_with_tool_prefix(flag) if prefix == toolname then @@ -768,6 +772,7 @@ function _add_target_compile_options(cmakelists, target, outputdir) end end for _, flag in ipairs(_translate_flags(cuflags, outputdir)) do + local flag = flag local prefix prefix, flag = _split_flag_with_tool_prefix(flag) if prefix == toolname then @@ -883,6 +888,7 @@ function _add_target_languages(cmakelists, target) local languages = target:get("languages") if languages then for _, lang in ipairs(languages) do + local lang = lang local has_ext = false -- c | c++ | gnu | gnu++ local flag = lang:replace('xx', '++'):replace('latest', ''):gsub('%d', '') @@ -1150,6 +1156,7 @@ function _add_target_link_options(cmakelists, target, outputdir) cmakelists:print("target_link_libraries(%s PRIVATE", target:name()) end for _, flag in ipairs(flags) do + local flag = flag local prefix prefix, flag = _split_flag_with_tool_prefix(flag) if prefix == toolname then diff --git a/xmake/plugins/project/make/makefile.lua b/xmake/plugins/project/make/makefile.lua index 3128a1c96..ed179e177 100644 --- a/xmake/plugins/project/make/makefile.lua +++ b/xmake/plugins/project/make/makefile.lua @@ -276,7 +276,7 @@ end -- remove the given files or directories function _add_remove_files(makefile, filedirs, outputdir) for _, filedir in ipairs(filedirs) do - filedir = _get_relative_unix_path(filedir, outputdir) + local filedir = _get_relative_unix_path(filedir, outputdir) makefile:print("\t%s", _get_cmd_rm(filedir)) end end @@ -554,7 +554,7 @@ function _add_build_target(makefile, target, targetflags, outputdir) local objectfiles = target:objectfiles() local objectfiles_translated = {} for _, objectfile in ipairs(objectfiles) do - objectfile = _get_relative_unix_path(objectfile, outputdir) + local objectfile = _get_relative_unix_path(objectfile, outputdir) table.insert(objectfiles_translated, objectfile) makefile:write(" " .. objectfile) end diff --git a/xmake/plugins/project/ninja/build_ninja.lua b/xmake/plugins/project/ninja/build_ninja.lua index e53745a86..f89915e02 100644 --- a/xmake/plugins/project/ninja/build_ninja.lua +++ b/xmake/plugins/project/ninja/build_ninja.lua @@ -78,6 +78,7 @@ function _translate_compflags(compflags, outputdir) local flags = {} local last_flag = nil; for _, flag in ipairs(compflags) do + local flag = flag if flag == "-I" or flag == "-isystem" then last_flag = flag else @@ -103,6 +104,7 @@ end function _translate_linkflags(linkflags, outputdir) local flags = {} for _, flag in ipairs(linkflags) do + local flag = flag for _, pattern in ipairs({"[%-](L)(.*)", "[%-](F)(.*)"}) do flag = flag:gsub(pattern, function (flag, dir) dir = _get_relative_unix_path(dir, outputdir) diff --git a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua index 78bee84f8..b1bade847 100644 --- a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua @@ -33,6 +33,7 @@ function _make_compflags(sourcefile, target, vcprojdir) -- replace -Idir or /Idir, -Fdsymbol.pdb or /Fdsymbol.pdb local flags = {} for _, flag in ipairs(compflags) do + local flag = flag -- replace -Idir or /Idir flag = flag:gsub("[%-|/]I(.*)", function (dir) @@ -75,6 +76,7 @@ function _make_linkflags(target, vcprojdir) -- replace -libpath:dir or /libpath:dir, -pdb:symbol.pdb or /pdb:symbol.pdb local flags = {} for _, flag in ipairs(linkflags) do + local flag = flag -- replace -libpath:dir or /libpath:dir flag = flag:gsub("[%-|/]libpath:(.*)", function (dir) diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 0a1b0955e..4da7a5d2e 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -93,6 +93,7 @@ function _get_command_string(cmd, vcxprojdir) if cmd.program then local argv = {} for _, v in ipairs(table.join(cmd.program, cmd.argv)) do + local v = v if path.instance_of(v) then v = v:clone():set(_translate_path(v:rawstr(), vcxprojdir)):str() elseif path.is_absolute(v) then @@ -276,6 +277,7 @@ function _make_targetinfo(mode, arch, target, vcxprojdir) end end for k, v in table.orderpairs(setrunenvs) do + local v = v if #v == 1 then v = v[1] if path.is_absolute(v) and v:startswith(project.directory()) then diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index fd62b0859..f1f44c3a8 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -137,6 +137,7 @@ end function _make_compcmd(compargv, sourcefile, objectfile, vcxprojdir) local argv = {} for i, v in ipairs(compargv) do + local v = v if i == 1 then v = path.filename(v) -- C:\xxx\ml.exe -> ml.exe end @@ -163,6 +164,7 @@ function _make_compflags(sourcefile, targetinfo, vcxprojdir) -- translate path for -Idir or /Idir local flags = {} for _, flag in ipairs(targetinfo.compflags[sourcefile]) do + local flag = flag for _, pattern in ipairs({"[%-/](I)(.*)", "[%-/](external:I)(.*)"}) do -- -Idir or /Idir @@ -186,6 +188,7 @@ function _make_linkflags(targetinfo, vcxprojdir) -- replace -libpath:dir or /libpath:dir local flags = {} for _, flag in ipairs(targetinfo.linkflags) do + local flag = flag -- replace -libpath:dir or /libpath:dir flag = flag:gsub(string.ipattern("[%-/]libpath:(.*)"), function (dir) @@ -932,7 +935,7 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo) local cstandard local cxxstandard for _, lang in pairs(targetinfo.languages) do - lang = lang:replace("c++", "cxx", {plain = true}) + local lang = lang:replace("c++", "cxx", {plain = true}) if cxxlangflags[lang] then cxxstandard = cxxlangflags[lang] elseif clangflags[lang] then diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua index e3d29e946..ed9002662 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua @@ -77,6 +77,7 @@ function _make_filter(filepath, target, vcxprojdir) local rootdir = extraconf.rootdir assert(rootdir, "please set root directory, e.g. add_filegroups(%s, {rootdir = 'xxx'})", filegroup) for _, rootdir in ipairs(table.wrap(rootdir)) do + local rootdir = rootdir if not path.is_absolute(rootdir) then rootdir = path.absolute(rootdir, scriptdir) end @@ -84,7 +85,7 @@ function _make_filter(filepath, target, vcxprojdir) local files = extraconf.files or "**" local mode = extraconf.mode for _, filepattern in ipairs(files) do - filepattern = path.pattern(path.absolute(path.join(rootdir, filepattern))) + local filepattern = path.pattern(path.absolute(path.join(rootdir, filepattern))) if filepath:match(filepattern) then if mode == "plain" then filter = path.normalize(filegroup) diff --git a/xmake/plugins/project/vstudio/impl/vsutils.lua b/xmake/plugins/project/vstudio/impl/vsutils.lua index 98fbfd39f..30832ae3f 100644 --- a/xmake/plugins/project/vstudio/impl/vsutils.lua +++ b/xmake/plugins/project/vstudio/impl/vsutils.lua @@ -79,7 +79,7 @@ function reset_config_and_caches(mode, arch) end -- merge the project options after default options for name, value in pairs(project.get("config")) do - value = table.unwrap(value) + local value = table.unwrap(value) assert(type(value) == "string" or type(value) == "boolean" or type(value) == "number", "set_config(%s): unsupported value type(%s)", name, type(value)) if not config.readonly(name) then config.set(name, value) diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 585383872..9395657fd 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -185,6 +185,7 @@ function _make_targetinfo(mode, arch, target) end end for k, v in table.orderpairs(addrunenvs) do + local v = v -- https://github.com/xmake-io/xmake/issues/3391 v = table.unique(v) if k:upper() == "PATH" then @@ -194,6 +195,7 @@ function _make_targetinfo(mode, arch, target) end end for k, v in table.orderpairs(setrunenvs) do + local v = v if #v == 1 then v = v[1] if path.is_absolute(v) and v:startswith(project.directory()) then @@ -342,6 +344,7 @@ function _make_filter(filepath, target, vcxprojdir) local rootdir = extraconf.rootdir assert(rootdir, "please set root directory, e.g. add_filegroups(%s, {rootdir = 'xxx'})", filegroup) for _, rootdir in ipairs(table.wrap(rootdir)) do + local rootdir = rootdir if not path.is_absolute(rootdir) then rootdir = path.absolute(rootdir, scriptdir) end @@ -349,7 +352,7 @@ function _make_filter(filepath, target, vcxprojdir) local files = extraconf.files or "**" local mode = extraconf.mode for _, filepattern in ipairs(files) do - filepattern = path.pattern(path.absolute(path.join(rootdir, filepattern))) + local filepattern = path.pattern(path.absolute(path.join(rootdir, filepattern))) if filepath:match(filepattern) then if mode == "plain" then filter = path.normalize(filegroup) diff --git a/xmake/plugins/show/info/target.lua b/xmake/plugins/show/info/target.lua index 62d8b6ddd..e63a51ea7 100644 --- a/xmake/plugins/show/info/target.lua +++ b/xmake/plugins/show/info/target.lua @@ -272,6 +272,7 @@ function _collect_target_info(target) end end for _, sourcekind in sourcekinds:keys() do + local sourcekind = sourcekind local compinst = target:compiler(sourcekind) if compinst then info.compilers = info.compilers or {} diff --git a/xmake/plugins/show/lists/apis.lua b/xmake/plugins/show/lists/apis.lua index 5011d39ae..475535a1e 100644 --- a/xmake/plugins/show/lists/apis.lua +++ b/xmake/plugins/show/lists/apis.lua @@ -92,6 +92,7 @@ function description_package_scope_apis() local result = {} for _, names in pairs(package.apis()) do for _, name in ipairs(names) do + local name = name if type(name) == "table" then name = "package." .. name[1] end @@ -145,6 +146,7 @@ function description_builtin_apis() -- add root project apis for _, names in pairs(project.apis()) do for _, name in ipairs(names) do + local name = name if type(name) == "table" then name = name[1] end @@ -287,7 +289,7 @@ function script_extension_module_apis() local result = {} local moduledirs = module.directories() for _, moduledir in ipairs(moduledirs) do - moduledir = path.absolute(moduledir) + local moduledir = path.absolute(moduledir) local modulefiles = os.files(path.join(moduledir, "**.lua|**/xmake.lua|private/**.lua|core/tools/**.lua|detect/tools/**.lua")) if modulefiles then for _, modulefile in ipairs(modulefiles) do diff --git a/xmake/rules/c++/modules/builder.lua b/xmake/rules/c++/modules/builder.lua index 761b2cf6c..6d82cca0b 100644 --- a/xmake/rules/c++/modules/builder.lua +++ b/xmake/rules/c++/modules/builder.lua @@ -91,6 +91,7 @@ function _get_jobdeps(target, module, jobgraph, buildfilejob) local jobdeps = {} local moduletype = support.has_two_phase_compilation_support(target) and "bmi" or "onephase" for dep_name, dep in pairs(module.deps) do + local dep_name = dep_name if dep.headerunit then dep_name = dep_name .. dep.key end @@ -347,6 +348,7 @@ function build_modules_for_batchjobs(target, batchjobs, built_modules, opt) local jobs local moduletype = has_two_phase_compilation_support and "bmi" or "onephase" for _, sourcefile in ipairs(_built_modules) do + local sourcefile = sourcefile jobs = jobs or {} local bmionly = support.is_bmionly(target, sourcefile) local module = mapper.get(target, sourcefile) @@ -354,6 +356,7 @@ function build_modules_for_batchjobs(target, batchjobs, built_modules, opt) local buildfilejob = _get_module_buildfilejob_for(target, sourcefile, moduletype) local deps = {} for dep_name, dep in pairs(module.deps) do + local dep_name = dep_name if dep.headerunit then dep_name = dep_name .. dep.key end @@ -409,6 +412,7 @@ function build_objectfiles_for_batchjobs(target, batchjobs, built_modules, opt) local jobs for _, sourcefile in ipairs(_built_modules) do + local sourcefile = sourcefile if not support.is_bmionly(target, sourcefile) then jobs = jobs or {} local module = mapper.get(target, sourcefile) diff --git a/xmake/rules/c++/modules/clang/builder.lua b/xmake/rules/c++/modules/clang/builder.lua index 60f2186e5..4839733e0 100644 --- a/xmake/rules/c++/modules/clang/builder.lua +++ b/xmake/rules/c++/modules/clang/builder.lua @@ -234,6 +234,7 @@ function _get_requiresflags(target, module) if not requiresflags or requires_changed then requiresflags = {} for required, dep in table.orderpairs(module.deps) do + local required = required if dep.headerunit then required = required .. dep.key end diff --git a/xmake/rules/c++/modules/clang/support.lua b/xmake/rules/c++/modules/clang/support.lua index 4bf5832a6..b1699d21a 100644 --- a/xmake/rules/c++/modules/clang/support.lua +++ b/xmake/rules/c++/modules/clang/support.lua @@ -49,7 +49,7 @@ function _get_toolchain_includedirs_for_stlheaders(target, includedirs, clang) local result = try {function () return os.iorunv(clang, argv, {envs = compinst:runenvs()}) end} if result then for _, line in ipairs(result:split("\n", {plain = true})) do - line = line:trim() + local line = line:trim() if line:startswith("#") and line:find("/vector\"", 1, true) then local includedir = line:match("\"(.+)/vector\"") if includedir and os.isdir(includedir) then @@ -164,7 +164,7 @@ function toolchain_includedirs(target) local _, result = try {function () return os.iorunv(clang, table.join({"-E", "-Wp,-v", "-xc++", os.nuldev()}, runtime_flag or {})) end} if result then for _, line in ipairs(result:split("\n", {plain = true})) do - line = line:trim() + local line = line:trim() if os.isdir(line) then table.insert(includedirs, path.normalize(line)) elseif line:startswith("End") then diff --git a/xmake/rules/c++/modules/gcc/support.lua b/xmake/rules/c++/modules/gcc/support.lua index 4de7d6eab..1204d207d 100644 --- a/xmake/rules/c++/modules/gcc/support.lua +++ b/xmake/rules/c++/modules/gcc/support.lua @@ -38,7 +38,7 @@ function _get_toolchain_includedirs_for_stlheaders(includedirs, gcc) local result = try {function () return os.iorunv(gcc, {"-E", "-x", "c++", tmpfile}) end} if result then for _, line in ipairs(result:split("\n", {plain = true})) do - line = line:trim() + local line = line:trim() if line:startswith("#") and line:find("/vector\"", 1, true) then local includedir = line:match("\"(.+)/vector\"") if includedir and os.isdir(includedir) then @@ -114,7 +114,7 @@ function toolchain_includedirs(target) local _, result = try {function () return os.iorunv(gcc, {"-E", "-Wp,-v", "-xc", os.nuldev()}) end} if result then for _, line in ipairs(result:split("\n", {plain = true})) do - line = line:trim() + local line = line:trim() if os.isdir(line) then table.insert(includedirs, path.normalize(line)) elseif line:startswith("End") then diff --git a/xmake/rules/c++/modules/msvc/builder.lua b/xmake/rules/c++/modules/msvc/builder.lua index b59115477..46496609c 100644 --- a/xmake/rules/c++/modules/msvc/builder.lua +++ b/xmake/rules/c++/modules/msvc/builder.lua @@ -189,6 +189,7 @@ function _get_requiresflags(target, module) if not requiresflags or requires_changed then local deps_flags = {} for required, dep in pairs(module.deps) do + local required = required if dep.headerunit then required = required .. dep.key end diff --git a/xmake/rules/c++/unity_build/unity_build.lua b/xmake/rules/c++/unity_build/unity_build.lua index d5f5b060c..bf5ee55b3 100644 --- a/xmake/rules/c++/unity_build/unity_build.lua +++ b/xmake/rules/c++/unity_build/unity_build.lua @@ -32,7 +32,7 @@ function _merge_unityfile(target, sourcefile_unity, sourcefiles, opt) local uniqueid = target:data("unity_build.uniqueid") local unityfile = io.open(sourcefile_unity, "w") for _, sourcefile in ipairs(sourcefiles) do - sourcefile = path.absolute(sourcefile) + local sourcefile = path.absolute(sourcefile) sourcefile_unity = path.absolute(sourcefile_unity) sourcefile = path.relative(sourcefile, path.directory(sourcefile_unity)) if uniqueid then diff --git a/xmake/rules/nim/build/target.lua b/xmake/rules/nim/build/target.lua index 52599b74d..6fe58be80 100644 --- a/xmake/rules/nim/build/target.lua +++ b/xmake/rules/nim/build/target.lua @@ -53,7 +53,7 @@ function _generate_dependinfo(compinst, compflags, sourcefiles, dependinfo) local depsdata = io.readfile(depsfile) if depsdata then for _, line in ipairs(depsdata:split("\n")) do - line = line:trim() + local line = line:trim() if #line > 0 then table.insert(dependinfo.files, line) end diff --git a/xmake/rules/platform/linux/module/driver_modules.lua b/xmake/rules/platform/linux/module/driver_modules.lua index 689e3d0c7..e7a0dda49 100644 --- a/xmake/rules/platform/linux/module/driver_modules.lua +++ b/xmake/rules/platform/linux/module/driver_modules.lua @@ -117,10 +117,11 @@ module_exit(hello_exit); if result then -- we can also split ';' for the muliple commands for _, line in ipairs(result:split("[\n;]")) do - line = line:trim() + local line = line:trim() if line:endswith("stub.c") then local include_cflag = false for _, cflag in ipairs(line:split("%s+")) do + local cflag = cflag local has_cflag = false if cflag:startswith("-fplugin=") then -- @see https://github.com/xmake-io/xmake/issues/3279 @@ -172,6 +173,7 @@ module_exit(hello_exit); if ldflags then local ko = ldflags:find("-T ", 1, true) for _, ldflag in ipairs(os.argv(ldflags)) do + local ldflag = ldflag if ldflag:endswith(".lds") then if not path.is_absolute(ldflag) then ldflag = path.absolute(ldflag, builddir or sdkdir) diff --git a/xmake/rules/qt/load.lua b/xmake/rules/qt/load.lua index dff70f52e..6b362e306 100644 --- a/xmake/rules/qt/load.lua +++ b/xmake/rules/qt/load.lua @@ -180,6 +180,7 @@ function _add_qmakeprllibs(target, prlfile, qt) end if envs.QMAKE_PRL_LIBS_FOR_CMAKE then for _, lib in ipairs(envs.QMAKE_PRL_LIBS_FOR_CMAKE:split(';', {plain = true})) do + local lib = lib if lib:startswith("-L") then local libdir = lib:sub(3) target:add("linkdirs", libdir) diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua index dfd194ffe..509770576 100644 --- a/xmake/rules/qt/moc/xmake.lua +++ b/xmake/rules/qt/moc/xmake.lua @@ -87,6 +87,7 @@ rule("qt.moc") } for _, pathmap in ipairs(pathmaps) do for _, item in ipairs(_get_values_from_target(target, pathmap[1])) do + local item = item local pathitem = path(item, function (p) local item = table.unwrap(compiler.map_flags("cxx", pathmap[2], p)) if item then diff --git a/xmake/rules/swift/xmake.lua b/xmake/rules/swift/xmake.lua index e124865f2..0e8821c63 100644 --- a/xmake/rules/swift/xmake.lua +++ b/xmake/rules/swift/xmake.lua @@ -80,6 +80,7 @@ rule("swift.interop") if cpp_langflags == nil then local languages = target:get("languages") for _, language in ipairs(languages) do + local language = language if language:startswith("c++") or language:startswith("cxx") or language:startswith("gnu++") diff --git a/xmake/rules/utils/symbols/export_all/export_all.lua b/xmake/rules/utils/symbols/export_all/export_all.lua index 851450371..8c3a5b241 100644 --- a/xmake/rules/utils/symbols/export_all/export_all.lua +++ b/xmake/rules/utils/symbols/export_all/export_all.lua @@ -90,6 +90,7 @@ function _get_allsymbols_by_dumpbin(target, dumpbin, opt) _get_sourcefiles_map(target, sourcefiles_map) end for _, objectfile in ipairs(target:objectfiles()) do + local objectfile = objectfile local objectsymbols = try { function () return os.iorunv(dumpbin, {"/symbols", "/nologo", objectfile}) end } if objectsymbols then local sourcefile = sourcefiles_map[objectfile] @@ -125,6 +126,7 @@ function _get_allsymbols_by_objdump(target, objdump, opt) _get_sourcefiles_map(target, sourcefiles_map) end for _, objectfile in ipairs(target:objectfiles()) do + local objectfile = objectfile local objectsymbols = try { function () return os.iorunv(objdump, {"--syms", objectfile}) end } if objectsymbols then local sourcefile = sourcefiles_map[objectfile] diff --git a/xmake/rules/utils/symbols/export_list/xmake.lua b/xmake/rules/utils/symbols/export_list/xmake.lua index 84878fe7b..6759ee3ec 100644 --- a/xmake/rules/utils/symbols/export_list/xmake.lua +++ b/xmake/rules/utils/symbols/export_list/xmake.lua @@ -115,6 +115,7 @@ rule("utils.symbols.export_list") elseif exportkind == "apple" then local file = io.open(exportfile_tmp, 'w') for _, symbol in ipairs(exportsymbols) do + local symbol = symbol if not symbol:startswith("_") then symbol = "_" .. symbol end diff --git a/xmake/rules/verilator/verilator.lua b/xmake/rules/verilator/verilator.lua index 25ee1968f..e1535ecd8 100644 --- a/xmake/rules/verilator/verilator.lua +++ b/xmake/rules/verilator/verilator.lua @@ -40,7 +40,7 @@ function _get_sourcefiles_from_cmake(target, cmakefile) -- get global class source files -- set(hello_GLOBAL "${VERILATOR_ROOT}/include/verilated.cpp" "${VERILATOR_ROOT}/include/verilated_threads.cpp") for classfile in values:gmatch("\"(.-)\"") do - classfile = classfile:gsub("%${VERILATOR_ROOT}", verilator_root) + local classfile = classfile:gsub("%${VERILATOR_ROOT}", verilator_root) if os.isfile(classfile) then table.insert(global_classes, classfile) end @@ -312,6 +312,7 @@ function build_cppfiles(target, jobgraph, sourcebatch, opt) end local sourcefiles = sourcebatch.sourcefiles for _, sourcefile in ipairs(sourcefiles) do + local sourcefile = sourcefile progress.show(opt.progress or 0, "${color.build.object}compiling.verilog %s", sourcefile) -- we need to use slashes to fix it on windows -- @see https://github.com/verilator/verilator/issues/3873 diff --git a/xmake/rules/wdk/load.lua b/xmake/rules/wdk/load.lua index 637ea9f80..4943340d7 100644 --- a/xmake/rules/wdk/load.lua +++ b/xmake/rules/wdk/load.lua @@ -62,7 +62,7 @@ function driver_umdf(target) -- set default driver entry if does not exist local entry = false for _, ldflag in ipairs(target:get("shflags")) do - ldflag = ldflag:lower() + local ldflag = ldflag:lower() if ldflag:find("[/%-]entry:") then entry = true break @@ -111,6 +111,7 @@ function _kernel_driver_base(target, default_entrypoint) -- set default driver entry if does not exist local has_entry = false for _, ldflag in ipairs(target:get("ldflags")) do + local ldflag = ldflag if type(ldflag) == "string" then ldflag = ldflag:lower() if ldflag:find("[/%-]entry:") then diff --git a/xmake/rules/winsdk/mfc/mfc.lua b/xmake/rules/winsdk/mfc/mfc.lua index 671d74f2d..5bcd41072 100644 --- a/xmake/rules/winsdk/mfc/mfc.lua +++ b/xmake/rules/winsdk/mfc/mfc.lua @@ -107,7 +107,7 @@ function application(target, mfc_kind) -- set startup entry local unicode = false for _, define in ipairs(target:get("defines")) do - define = define:lower():trim() + local define = define:lower():trim() if define:find("^[_]?unicode$") then unicode = true break diff --git a/xmake/rules/xcode/application/run.lua b/xmake/rules/xcode/application/run.lua index 249558ffc..7debb8fc4 100644 --- a/xmake/rules/xcode/application/run.lua +++ b/xmake/rules/xcode/application/run.lua @@ -61,6 +61,7 @@ function _run_on_simulator(target, opt) -- find the booted devices local name, deviceid for _, line in ipairs(list:split('\n', {plain = true})) do + local line = line if line:find("(Booted)", 1, true) then line = line:trim() name, deviceid = line:match("(.-)%s+%(([%w%-]+)%)") diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index 56689e068..17c46bbe5 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -67,7 +67,7 @@ # define XMI_LUA_GLOBALSINDEX (-10002) # define xmi_lua_upvalueindex(i) (XMI_LUA_GLOBALSINDEX - (i)) #else -# define XMI_LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000) +# define XMI_LUA_REGISTRYINDEX (-(INT_MAX/2 + 1000)) # define xmi_lua_upvalueindex(i) (XMI_LUA_REGISTRYINDEX - (i)) #endif |
