From 18f193ed0b7da9eaa2d62794de30a0a923776616 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 12 Sep 2018 23:56:41 +0800 Subject: improve to install package --- xmake/actions/require/action/install.lua | 8 ++++---- xmake/core/project/target.lua | 9 +++++++++ .../core/sandbox/modules/import/core/project/target.lua | 7 +++++-- .../sandbox/modules/import/lib/detect/find_library.lua | 17 +---------------- 4 files changed, 19 insertions(+), 22 deletions(-) (limited to 'xmake') diff --git a/xmake/actions/require/action/install.lua b/xmake/actions/require/action/install.lua index a270b538c..123521004 100644 --- a/xmake/actions/require/action/install.lua +++ b/xmake/actions/require/action/install.lua @@ -56,15 +56,15 @@ function _make_package(package) -- get links local links = {} for _, filename in ipairs(os.files(path.join(linkdir, target.filename("*", "static"))), path.filename) do - local link, count = filename:gsub(target.filename("([%%w%%-_]+)", "static"):gsub("%.", "%%.") .. "$", "%1") - if count > 0 then + local link = target.linkname(filename) + if link then table.insert(links, link) end end if #links == 0 then for _, filename in ipairs(os.files(path.join(linkdir, target.filename("*", "shared"))), path.filename) do - local link, count = filename:gsub(target.filename("([%%w%%-_]+)", "shared"):gsub("%.", "%%.") .. "$", "%1") - if count > 0 then + local link = target.linkname(filename) + if link then table.insert(links, link) end end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 9e48ec3c2..b35c80ae4 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -132,6 +132,15 @@ function target.filename(targetname, targetkind, targetformat) return format and (format:gsub("%$%(name%)", targetname)) or targetname end +-- get the link name of the target file +function target.linkname(filename) + local linkname, count = filename:gsub(target.filename("__pattern__", "static"):gsub("%.", "%%."):gsub("__pattern__", "(.+)") .. "$", "%1") + if count == 0 then + linkname, count = filename:gsub(target.filename("__pattern__", "shared"):gsub("%.", "%%."):gsub("__pattern__", "(.+)") .. "$", "%1") + end + return count > 0 and linkname or nil +end + -- new a target instance function target.new(name, info, project) diff --git a/xmake/core/sandbox/modules/import/core/project/target.lua b/xmake/core/sandbox/modules/import/core/project/target.lua index 0f08e3875..06c50dcb6 100644 --- a/xmake/core/sandbox/modules/import/core/project/target.lua +++ b/xmake/core/sandbox/modules/import/core/project/target.lua @@ -31,10 +31,13 @@ local raise = require("sandbox/modules/raise") -- get the filename from the given name and kind function sandbox_core_project_target.filename(name, kind) - - -- get it return target.filename(name, kind) end +-- get the link name of the target file +function sandbox_core_project_target.linkname(filename) + return target.linkname(filename) +end + -- return module return sandbox_core_project_target diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_library.lua b/xmake/core/sandbox/modules/import/lib/detect/find_library.lua index 4e173fc54..25c6dc60a 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_library.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_library.lua @@ -35,21 +35,6 @@ local raise = require("sandbox/modules/raise") local import = require("sandbox/modules/import") local find_file = import("lib.detect.find_file") --- get link name from the file name -function sandbox_lib_detect_find_library._link(filename) - - -- get link, @note need %%w to escape to %w because gsub was called in target.filename - local link, count = filename:gsub(target.filename("([%%w%%-_]+)", "static"):gsub("%.", "%%.") .. "$", "%1") - if count == 0 then - link, count = filename:gsub(target.filename("([%%w%%-_]+)", "shared"):gsub("%.", "%%.") .. "$", "%1") - end - - -- ok? - if count > 0 then - return link - end -end - -- find library -- -- @param names the library names @@ -84,7 +69,7 @@ function sandbox_lib_detect_find_library.main(names, pathes, opt) local filepath = find_file(target.filename(name, kind), pathes, opt) if filepath then local filename = path.filename(filepath) - return {kind = kind, filename = filename, linkdir = path.directory(filepath), link = sandbox_lib_detect_find_library._link(filename)} + return {kind = kind, filename = filename, linkdir = path.directory(filepath), link = target.linkname(filename)} end end end -- cgit v1.3.1