diff options
| author | bakabaka9405 <[email protected]> | 2026-05-14 17:35:52 +0800 |
|---|---|---|
| committer | bakabaka9405 <[email protected]> | 2026-05-14 17:53:22 +0800 |
| commit | 22ee4e17de8f06f5c8dcd76c80867b1b06b2d201 (patch) | |
| tree | df94f6a5dbe4ff39dfff2232392a222758db5e05 | |
| parent | 027524d15cb05aad924b6cdc0a35c1d2b54551d8 (diff) | |
fix: expand builtin variables before calling path.is_absolute in add_moduledirs
| -rw-r--r-- | tests/apis/add_moduledirs/test.lua | 3 | ||||
| -rw-r--r-- | tests/apis/add_moduledirs/xmake.lua | 15 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 33 |
3 files changed, 31 insertions, 20 deletions
diff --git a/tests/apis/add_moduledirs/test.lua b/tests/apis/add_moduledirs/test.lua new file mode 100644 index 000000000..8910e4e96 --- /dev/null +++ b/tests/apis/add_moduledirs/test.lua @@ -0,0 +1,3 @@ +function main() + os.exec("xmake foo") +end diff --git a/tests/apis/add_moduledirs/xmake.lua b/tests/apis/add_moduledirs/xmake.lua new file mode 100644 index 000000000..9508ce94c --- /dev/null +++ b/tests/apis/add_moduledirs/xmake.lua @@ -0,0 +1,15 @@ +add_moduledirs("$(projectdir)/test") +add_moduledirs("test") + +task("foo") + set_category("plugin") + on_run(function() + local modules = import("core.sandbox.module") + for _, dir in ipairs(modules.directories()) do + print(dir) + end + end) + set_menu { + usage = "xmake foo", + description = "Print all modules" + }
\ No newline at end of file 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 |
