summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-03-14 23:37:07 +0800
committerruki <[email protected]>2024-03-14 23:37:07 +0800
commit5af56d8d7d820a3b7c88e337bdc3a397499bd06a (patch)
treeffc852a6e995e2a92f3a94f07ce65a9bc1868a02
parentc440c24e61bba613a9e9880f76588efca2b1ccfe (diff)
add match copyfiles
-rw-r--r--xmake/core/base/private/match_copyfiles.lua120
-rw-r--r--xmake/core/project/target.lua94
2 files changed, 124 insertions, 90 deletions
diff --git a/xmake/core/base/private/match_copyfiles.lua b/xmake/core/base/private/match_copyfiles.lua
new file mode 100644
index 000000000..06a773fd2
--- /dev/null
+++ b/xmake/core/base/private/match_copyfiles.lua
@@ -0,0 +1,120 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file match_copyfiles.lua
+--
+
+-- load modules
+local table = require("base/table")
+local utils = require("base/utils")
+local path = require("base/path")
+local os = require("base/os")
+
+-- match the copyfiles for instance
+-- e.g.
+--
+-- add_headerfiles
+-- add_configfiles
+-- add_installfiles
+-- add_extrafiles
+function match_copyfiles(instance, filetype, outputdir, pathfilter)
+
+ -- no copied files?
+ local copyfiles = instance:get(filetype)
+ if not copyfiles then return end
+
+ -- get the extra information
+ local extrainfo = table.wrap(instance:extraconf(filetype))
+
+ -- get the source paths and destinate paths
+ local srcfiles = {}
+ local dstfiles = {}
+ local fileinfos = {}
+ for _, copyfile in ipairs(table.wrap(copyfiles)) do
+
+ -- get the root directory
+ local rootdir, count = copyfile:gsub("|.*$", ""):gsub("%(.*%)$", "")
+ if count == 0 then
+ rootdir = nil
+ end
+ if rootdir and rootdir:trim() == "" then
+ rootdir = "."
+ end
+
+ -- remove '(' and ')'
+ local srcpaths = copyfile:gsub("[%(%)]", "")
+ if srcpaths then
+
+ -- get the source paths
+ srcpaths = os.match(srcpaths)
+ if srcpaths and #srcpaths > 0 then
+
+ -- add the source copied files
+ table.join2(srcfiles, srcpaths)
+
+ -- the copied directory exists?
+ if outputdir then
+
+ -- get the file info
+ local fileinfo = extrainfo[copyfile] or {}
+
+ -- get the prefix directory
+ local prefixdir = fileinfo.prefixdir
+ if fileinfo.rootdir then
+ rootdir = fileinfo.rootdir
+ end
+
+ -- add the destinate copied files
+ for _, srcpath in ipairs(srcpaths) do
+
+ -- get the destinate directory
+ local dstdir = outputdir
+ if prefixdir then
+ dstdir = path.join(dstdir, prefixdir)
+ end
+
+ -- the destinate file
+ local dstfile = nil
+ if rootdir then
+ dstfile = path.absolute(path.relative(srcpath, rootdir), dstdir)
+ else
+ dstfile = path.join(dstdir, path.filename(srcpath))
+ end
+ assert(dstfile)
+
+ -- modify filename
+ if fileinfo.filename then
+ dstfile = path.join(path.directory(dstfile), fileinfo.filename)
+ end
+
+ -- filter the destinate file path
+ if pathfilter then
+ dstfile = pathfilter(dstfile, fileinfo)
+ end
+
+ -- add it
+ table.insert(dstfiles, dstfile)
+ table.insert(fileinfos, fileinfo)
+ end
+ end
+ end
+ end
+ end
+ return srcfiles, dstfiles, fileinfos
+end
+
+return match_copyfiles
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 82be209de..228c046f9 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -33,6 +33,7 @@ local baseoption = require("base/option")
local hashset = require("base/hashset")
local deprecated = require("base/deprecated")
local select_script = require("base/private/select_script")
+local match_copyfiles = require("base/private/match_copyfiles")
local instance_deps = require("base/private/instance_deps")
local is_cross = require("base/private/is_cross")
local memcache = require("cache/memcache")
@@ -174,93 +175,6 @@ function _instance:_load_after()
return true
end
--- get the copied files
-function _instance:_copiedfiles(filetype, outputdir, pathfilter)
-
- -- no copied files?
- local copiedfiles = self:get(filetype)
- if not copiedfiles then return end
-
- -- get the extra information
- local extrainfo = table.wrap(self:extraconf(filetype))
-
- -- get the source paths and destinate paths
- local srcfiles = {}
- local dstfiles = {}
- local fileinfos = {}
- for _, copiedfile in ipairs(table.wrap(copiedfiles)) do
-
- -- get the root directory
- local rootdir, count = copiedfile:gsub("|.*$", ""):gsub("%(.*%)$", "")
- if count == 0 then
- rootdir = nil
- end
- if rootdir and rootdir:trim() == "" then
- rootdir = "."
- end
-
- -- remove '(' and ')'
- local srcpaths = copiedfile:gsub("[%(%)]", "")
- if srcpaths then
-
- -- get the source paths
- srcpaths = os.match(srcpaths)
- if srcpaths and #srcpaths > 0 then
-
- -- add the source copied files
- table.join2(srcfiles, srcpaths)
-
- -- the copied directory exists?
- if outputdir then
-
- -- get the file info
- local fileinfo = extrainfo[copiedfile] or {}
-
- -- get the prefix directory
- local prefixdir = fileinfo.prefixdir
- if fileinfo.rootdir then
- rootdir = fileinfo.rootdir
- end
-
- -- add the destinate copied files
- for _, srcpath in ipairs(srcpaths) do
-
- -- get the destinate directory
- local dstdir = outputdir
- if prefixdir then
- dstdir = path.join(dstdir, prefixdir)
- end
-
- -- the destinate file
- local dstfile = nil
- if rootdir then
- dstfile = path.absolute(path.relative(srcpath, rootdir), dstdir)
- else
- dstfile = path.join(dstdir, path.filename(srcpath))
- end
- assert(dstfile)
-
- -- modify filename
- if fileinfo.filename then
- dstfile = path.join(path.directory(dstfile), fileinfo.filename)
- end
-
- -- filter the destinate file path
- if pathfilter then
- dstfile = pathfilter(dstfile, fileinfo)
- end
-
- -- add it
- table.insert(dstfiles, dstfile)
- table.insert(fileinfos, fileinfo)
- end
- end
- end
- end
- end
- return srcfiles, dstfiles, fileinfos
-end
-
-- get the visibility, private: 1, interface: 2, public: 3 = 1 | 2
function _instance:_visibility(opt)
local visibility = 1
@@ -2136,7 +2050,7 @@ end
-- get the configuration files
function _instance:configfiles(outputdir)
- return self:_copiedfiles("configfiles", outputdir or self:configdir(), function (dstpath, fileinfo)
+ return match_copyfiles(self, "configfiles", outputdir or self:configdir(), function (dstpath, fileinfo)
if dstpath:endswith(".in") then
dstpath = dstpath:sub(1, -4)
end
@@ -2146,12 +2060,12 @@ end
-- get the install files
function _instance:installfiles(outputdir)
- return self:_copiedfiles("installfiles", outputdir or self:installdir())
+ return match_copyfiles(self, "installfiles", outputdir or self:installdir())
end
-- get the extra files
function _instance:extrafiles()
- return (self:_copiedfiles("extrafiles"))
+ return (match_copyfiles(self, "extrafiles"))
end
-- get depend file from object file