diff options
| author | ruki <[email protected]> | 2023-11-24 00:52:07 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-11-24 00:52:07 +0800 |
| commit | 9217b528138fe4384403c0b573e8617bdcc18358 (patch) | |
| tree | c7bbecddbd23c01a8a02f59d9526cee68a171d33 /xmake/plugins/pack/runself/main.lua | |
| parent | e680f0fbac744bce8488af3479c14d835705176d (diff) | |
add install cmds
Diffstat (limited to 'xmake/plugins/pack/runself/main.lua')
| -rw-r--r-- | xmake/plugins/pack/runself/main.lua | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/xmake/plugins/pack/runself/main.lua b/xmake/plugins/pack/runself/main.lua index f8a646427..91d1f9426 100644 --- a/xmake/plugins/pack/runself/main.lua +++ b/xmake/plugins/pack/runself/main.lua @@ -58,6 +58,50 @@ function _get_specvars(package) return specvars end +-- write install command +function _write_installcmd(package, scriptfile, cmd) + local opt = cmd.opt or {} + local kind = cmd.kind + if kind == "cp" then + local srcfiles = os.files(cmd.srcpath) + for _, srcfile in ipairs(srcfiles) do + -- the destination is directory? append the filename + local dstfile = 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 + scriptfile:print("cp -p \"%s\" \"%s\"", srcfile, dstfile) + end + elseif kind == "rm" then + local filepath = cmd.filepath + scriptfile:print("rm -f \"%s\"", filepath) + elseif kind == "rmdir" then + local dir = cmd.dir + scriptfile:print("rm -rf \"%s\"", dir) + elseif kind == "mv" then + local srcpath = cmd.srcpath + local dstpath = cmd.dstpath + scriptfile:print("mv \"%s\" \"%s\"", srcfile, dstfile) + elseif kind == "cd" then + local dir = cmd.dir + scriptfile:print("cd \"%s\"", dir) + elseif kind == "mkdir" then + local dir = cmd.dir + scriptfile:print("mkdir -p \"%s\"", dir) + end +end + +-- write install commands +function _write_installcmds(package, scriptfile, cmds) + for _, cmd in ipairs(cmds) do + _write_installcmd(package, scriptfile, cmd) + end +end + -- pack runself package function _pack_runself(makeself, package) @@ -90,6 +134,16 @@ function _pack_runself(makeself, package) local installdir = package:installdir() local setupfile = path.join(installdir, "__setup__.sh") os.cp(path.join(os.programdir(), "scripts", "xpack", "runself", "setup.sh"), setupfile) + local scriptfile = io.open(setupfile, "a+") + if scriptfile then + _write_installcmds(package, scriptfile, batchcmds.get_installcmds(package):cmds()) + for _, component in table.orderpairs(package:components()) do + if component:get("default") ~= false then + _write_installcmds(package, scriptfile, batchcmds.get_installcmds(component):cmds()) + end + end + scriptfile:close() + end -- make package os.vrunv(makeself, {"--gzip", "--sha256", "--lsm", specfile, |
