diff options
| -rw-r--r-- | xmake/core/sandbox/modules/io.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/package/manager/clib/find_package.lua | 22 | ||||
| -rw-r--r-- | xmake/modules/package/manager/clib/install_package.lua | 18 |
3 files changed, 45 insertions, 5 deletions
diff --git a/xmake/core/sandbox/modules/io.lua b/xmake/core/sandbox/modules/io.lua index 53d8399f4..7f93f020d 100644 --- a/xmake/core/sandbox/modules/io.lua +++ b/xmake/core/sandbox/modules/io.lua @@ -77,6 +77,16 @@ function sandbox_io.gsub(filepath, pattern, replace) return data, count end +-- check if file exists +function sandbox_io.exists(filepath) + local file, _ = io.open(filepath, "r") + if file then + file:close() + return true + end + return false +end + -- open file function sandbox_io.open(filepath, mode) diff --git a/xmake/modules/package/manager/clib/find_package.lua b/xmake/modules/package/manager/clib/find_package.lua index 414093e33..d64884429 100644 --- a/xmake/modules/package/manager/clib/find_package.lua +++ b/xmake/modules/package/manager/clib/find_package.lua @@ -23,5 +23,25 @@ import("core.base.option") import("core.project.config") function main(name, opt) --- TODO: Implement clib package search + -- check if a package marker file with install directory exists + local cache_dir = path.join(os.projectdir(), ".xmake", "cache", "packages") + local marker_filename = string.gsub(name, "%/", "=") + local marker_path = path.join(cache_dir, marker_filename) + dprint("reading clib marker file for %s from %s", name, marker_filename) + + if not io.exists(marker_filename) then + return + end + + local marker_file = io.open(marker_path, "r") + if marker_file then + local install_path = marker_file:read("*all") + marker_file:close() + dprint("%s is installed to %s", name, install_path) + + return { + headerdirs = { install_path }, + includedirs = { install_path } + } + end end
\ No newline at end of file diff --git a/xmake/modules/package/manager/clib/install_package.lua b/xmake/modules/package/manager/clib/install_package.lua index b7f76cbce..250ef8b66 100644 --- a/xmake/modules/package/manager/clib/install_package.lua +++ b/xmake/modules/package/manager/clib/install_package.lua @@ -23,8 +23,8 @@ import("core.base.option") import("core.project.config") import("lib.detect.find_tool") -- install package --- @param name the package name, e.g. clib::clibs/[email protected] --- @param opt the options, .e.g { verbose = true, out_dir = "deps", +-- @param name the package name, e.g. clib::clibs/[email protected] +-- @param opt the options, .e.g { verbose = true, out_dir = "myDir", -- save = false, save_dev = false } -- -- @return true or false @@ -35,10 +35,11 @@ function main(name, opt) if not clib then raise("clib not found!") end + -- default options local all_opts = { verbose = true, - out_dir = "deps", + out_dir = path.join(".xmake", "cache", "packages", ".clib"), save = false, save_dev = false } @@ -51,7 +52,7 @@ function main(name, opt) local argv = {"install", name} - local abs_out = all_opts.out_dir + local abs_out = path.join(os.projectdir(), all_opts.out_dir) dprint("installing %s to %s", name, abs_out) table.insert(argv, "-o " .. abs_out) @@ -67,4 +68,13 @@ function main(name, opt) -- do install os.vrunv(clib.program, argv) + + -- add a package marker file with install directory + local cache_dir = path.join(os.projectdir(), ".xmake", "cache", "packages") + local marker_filename = string.gsub(name, "%/", "=") + local marker_path = path.join(cache_dir, marker_filename) + dprint("writing clib marker file for %s to %s", name, marker_filename) + local marker_file = io.open(marker_path, "w") + marker_file:write(abs_out) + marker_file:close() end
\ No newline at end of file |
