Skip to content

Commit

Permalink
translate path
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Dec 18, 2023
1 parent 92a0f01 commit cc7b17a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/plugins/pack/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ xpack("test")
end)

after_installcmd(function (package, batchcmds)
if package:from_source() then
if package:format() == "runself" then
batchcmds:runv("echo", {"hello"})
else
batchcmds:mkdir(package:installdir("resources"))
Expand Down
21 changes: 13 additions & 8 deletions xmake/plugins/pack/srpm/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ function _get_archivefile(package)
return path.absolute(path.join(package:buildir(), package:basename() .. ".tar.gz"))
end

-- translate the file path
function _translate_filepath(package, filepath)
return filepath:replace(package:install_rootdir(), "%{buildroot}", {plain = true})
end

-- get install command
function _get_installcmd(package, installcmds, cmd)
local opt = cmd.opt or {}
Expand All @@ -66,31 +71,31 @@ function _get_installcmd(package, installcmds, cmd)
local srcfiles = os.files(cmd.srcpath)
for _, srcfile in ipairs(srcfiles) do
-- the destination is directory? append the filename
local dstfile = cmd.dstpath
local dstfile = _translate_filepath(package, cmd.dstpath)
if #srcfiles > 1 or path.islastsep(dstfile) then
if opt.rootdir then
dstfile = path.join(dstfile, path.relative(srcfile, opt.rootdir))
else
dstfile = path.join(dstfile, path.filename(srcfile))
end
end
table.insert(installcmds, string.format("cp -p \"%s\" \"%s\"", srcfile, dstfile))
table.insert(installcmds, string.format("install -Dpm0644 \"%s\" \"%s\"", srcfile, dstfile))
end
elseif kind == "rm" then
local filepath = cmd.filepath
local filepath = _translate_filepath(package, cmd.filepath)
table.insert(installcmds, string.format("rm -f \"%s\"", filepath))
elseif kind == "rmdir" then
local dir = cmd.dir
local dir = _translate_filepath(package, cmd.dir)
table.insert(installcmds, string.format("rm -rf \"%s\"", dir))
elseif kind == "mv" then
local srcpath = cmd.srcpath
local dstpath = cmd.dstpath
local srcpath = _translate_filepath(package, cmd.srcpath)
local dstpath = _translate_filepath(package, cmd.dstpath)
table.insert(installcmds, string.format("mv \"%s\" \"%s\"", srcfile, dstfile))
elseif kind == "cd" then
local dir = cmd.dir
local dir = _translate_filepath(package, cmd.dir)
table.insert(installcmds, string.format("cd \"%s\"", dir))
elseif kind == "mkdir" then
local dir = cmd.dir
local dir = _translate_filepath(package, cmd.dir)
table.insert(installcmds, string.format("mkdir -p \"%s\"", dir))
elseif cmd.program then
table.insert(installcmds, string.format("%s", os.args(table.join(cmd.program, cmd.argv))))
Expand Down
2 changes: 2 additions & 0 deletions xmake/scripts/xpack/srpm/srpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ ${PACKAGE_INSTALLCMDS}
%check

%files
/resources/assets/file1.txt
/resources/assets/file2.txt

%changelog
* ${PACKAGE_DATE} ${PACKAGE_MAINTAINER} - ${PACKAGE_VERSION}-1
Expand Down

0 comments on commit cc7b17a

Please sign in to comment.