From 22ee4e17de8f06f5c8dcd76c80867b1b06b2d201 Mon Sep 17 00:00:00 2001 From: bakabaka9405 <2677423642@qq.com> Date: Thu, 14 May 2026 17:35:52 +0800 Subject: fix: expand builtin variables before calling path.is_absolute in add_moduledirs --- xmake/core/project/project.lua | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'xmake/core/project/project.lua') diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 2ea22e655..ff770ced0 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -168,27 +168,28 @@ function project._api_get_config(interp, name) return value end +-- translate directory path for custom project apis +function project._translate_directory(interp, dir) + dir = interp:filter():handle(dir) + if not path.is_absolute(dir) then + dir = path.absolute(dir, interp:scriptdir()) + end + return dir +end + -- add module directories 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 + local dir = project._translate_directory(interp, dir) sandbox_module.add_directories(dir) end end -- add plugin directories load all plugins from the given directories 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 + local dir = project._translate_directory(interp, dir) table.insert(plugindirs, dir .. "/*") end interp:api_builtin_includes(plugindirs) @@ -196,24 +197,16 @@ end -- add platform directories 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 + local dir = project._translate_directory(interp, dir) platform.add_directories(dir) end end -- add toolchain directories 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 + local dir = project._translate_directory(interp, dir) toolchain.add_directories(dir) -- auto-register modules directories under each toolchain -- e.g. toolchains/my-c6000/modules/ will be added as module search path -- cgit v1.3.1