diff options
| author | ruki <[email protected]> | 2024-03-14 23:37:37 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-03-14 23:37:37 +0800 |
| commit | e971dacae2e572575b5ef11d37cbfde2785b4daf (patch) | |
| tree | ead9d9688e4fedb2fc4c36476e69b27069c8c65b | |
| parent | 5af56d8d7d820a3b7c88e337bdc3a397499bd06a (diff) | |
improve xpack
| -rw-r--r-- | xmake/core/sandbox/modules/import/private/core/base/match_copyfiles.lua | 23 | ||||
| -rw-r--r-- | xmake/plugins/pack/xpack.lua | 87 | ||||
| -rw-r--r-- | xmake/plugins/pack/xpack_component.lua | 87 |
3 files changed, 29 insertions, 168 deletions
diff --git a/xmake/core/sandbox/modules/import/private/core/base/match_copyfiles.lua b/xmake/core/sandbox/modules/import/private/core/base/match_copyfiles.lua new file mode 100644 index 000000000..efdda2d1b --- /dev/null +++ b/xmake/core/sandbox/modules/import/private/core/base/match_copyfiles.lua @@ -0,0 +1,23 @@ +--!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 +-- + +return require("base/private/match_copyfiles") + + diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua index 484aa3e2a..0afc62868 100644 --- a/xmake/plugins/pack/xpack.lua +++ b/xmake/plugins/pack/xpack.lua @@ -26,6 +26,7 @@ import("core.base.hashset") import("core.project.config") import("core.project.project") import("private.core.base.select_script") +import("private.core.base.match_copyfiles") import("lib.detect.find_tool") import("filter") import("xpack_component") @@ -382,91 +383,9 @@ function xpack:version() return version, version_build end --- get the copied files -function xpack:_copiedfiles(filetype, outputdir) - - -- 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 - - -- add it - table.insert(dstfiles, dstfile) - table.insert(fileinfos, fileinfo) - end - end - end - end - end - return srcfiles, dstfiles, fileinfos -end - -- get the install files function xpack:installfiles() - return self:_copiedfiles("installfiles", self:installdir()) + return match_copyfiles(self, "installfiles", self:installdir()) end -- get the installed root directory, this is just a temporary sandbox installation path, @@ -487,7 +406,7 @@ end -- get the source files function xpack:sourcefiles() - return self:_copiedfiles("sourcefiles", self:sourcedir()) + return match_copyfiles(self, "sourcefiles", self:sourcedir()) end -- get the source root directory diff --git a/xmake/plugins/pack/xpack_component.lua b/xmake/plugins/pack/xpack_component.lua index 5dc6ec10f..2cca2485f 100644 --- a/xmake/plugins/pack/xpack_component.lua +++ b/xmake/plugins/pack/xpack_component.lua @@ -24,6 +24,7 @@ import("core.base.option") import("core.project.config") import("core.project.project") import("private.core.base.select_script") +import("private.core.base.match_copyfiles") -- define module local xpack_component = xpack_component or object {_init = {"_name", "_info", "_package"}} @@ -107,88 +108,6 @@ function xpack_component:target(name) end end --- get the copied files -function xpack_component:_copiedfiles(filetype, outputdir) - - -- 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 - - -- add it - table.insert(dstfiles, dstfile) - table.insert(fileinfos, fileinfo) - end - end - end - end - end - return srcfiles, dstfiles, fileinfos -end - -- get the package function xpack_component:package() return self._package @@ -196,7 +115,7 @@ end -- get the install files function xpack_component:installfiles() - return self:_copiedfiles("installfiles", self:package():installdir()) + return match_copyfiles(self, "installfiles", self:package():installdir()) end -- get the installed root directory, this is just a temporary sandbox installation path, @@ -212,7 +131,7 @@ end -- get the source files function xpack_component:sourcefiles() - return self:_copiedfiles("sourcefiles", self:package():sourcedir()) + return match_copyfiles(self, "sourcefiles", self:package():sourcedir()) end -- get the source root directory |
