diff options
| author | ruki <[email protected]> | 2018-10-02 21:01:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-10-02 00:09:57 +0800 |
| commit | 4248b37344ac119834ed633fabe94673caeb46d0 (patch) | |
| tree | c00550663382509981693f40fd0552d178ff9fdf | |
| parent | 661909c4299c0b4eb511921269a2948c0aa9ad7c (diff) | |
improve to link and copy package
| -rw-r--r-- | xmake/actions/require/impl/action/prefix/install.lua | 160 | ||||
| -rw-r--r-- | xmake/modules/devel/git/checkurl.lua | 2 |
2 files changed, 117 insertions, 45 deletions
diff --git a/xmake/actions/require/impl/action/prefix/install.lua b/xmake/actions/require/impl/action/prefix/install.lua index 0c79352cf..d1464b0e5 100644 --- a/xmake/actions/require/impl/action/prefix/install.lua +++ b/xmake/actions/require/impl/action/prefix/install.lua @@ -25,63 +25,135 @@ -- imports import("uninstall") +-- copy files to the prefix directory +function _copy(mode, pattern) + + -- do install + local prefixdir = _g.prefixdir + local installdir = _g.installdir + local relative_pathes = _g.relative_pathes + for _, sourcepath in ipairs(os.match(path.join(installdir, pattern), mode)) do + + -- get relative path + local relative_path = path.relative(sourcepath, installdir) + + -- trace + vprint("copying %s ..", relative_path) + + -- copy file to the prefix directory + os.cp(sourcepath, path.absolute(relative_path, prefixdir)) + + -- save this relative path + table.insert(relative_pathes, relative_path) + end +end + +-- copy directories to the prefix directory +function _copy_dirs(pattern) + _copy('d', pattern) +end + +-- copy files to the prefix directory +function _copy_files(pattern) + _copy('f', pattern) +end + +-- copy files and directories to the prefix directory +function _copy_filedirs(pattern) + _copy('a', pattern) +end + +-- link files to the prefix directory +function _link(mode, pattern) + + -- do install + local prefixdir = _g.prefixdir + local installdir = _g.installdir + local relative_pathes = _g.relative_pathes + for _, sourcepath in ipairs(os.match(path.join(installdir, pattern), mode)) do + + -- get relative path + local relative_path = path.relative(sourcepath, installdir) + + -- trace + vprint("linking %s ..", relative_path) + + -- link file to the prefix directory + os.ln(sourcepath, path.absolute(relative_path, prefixdir)) + + -- save this relative path + table.insert(relative_pathes, relative_path) + end +end + +-- link directories to the prefix directory +function _link_dirs(pattern) + _link('d', pattern) +end + +-- link files to the prefix directory +function _link_files(pattern) + _link('f', pattern) +end + +-- link files and directories to the prefix directory +function _link_filedirs(pattern) + _link('a', pattern) +end + +-- install package with link +function _install_with_link(package) + _link_files("bin/*") + _link_files("sbin/*") + _link_filedirs("include/*") + _link_filedirs("lib/*|pkgconfig|cmake|lua") + _link_filedirs("lib/pkgconfig/*") + _link_filedirs("lib/cmake/*") + _link_filedirs("lib/lua/*") + _link_filedirs("share/*|aclocal|doc|info|man|icons|locale") + _link_filedirs("share/aclocal/*") + _link_filedirs("share/doc/*") + _link_filedirs("share/info/*") + _link_filedirs("share/man/*") + _link_filedirs("share/icons/*") + _link_filedirs("share/locale/*") +end + +-- install package without link (windows) +function _install_without_link(package) + if package:kind() == "binary" then + _copy_filedirs("**") + else + _copy_filedirs("lib/**") + _copy_filedirs("include/**") + end +end + -- install package to the prefix directory function main(package) -- uninstall the prefix package files first uninstall(package) - -- get prefix and install directory - local prefixdir = package:prefixdir() - local installdir = package:installdir() - - -- scan all installed files - local installfiles = {} - if is_host("windows") then - if package:kind() == "binary" then - table.join2(installfiles, (os.files(path.join(installdir, "**")))) - else - table.join2(installfiles, (os.files(path.join(package:installdir("lib"), "**")))) - table.join2(installfiles, (os.files(path.join(package:installdir("include"), "**")))) - end - else - if package:kind() == "binary" then - table.join2(installfiles, (os.files(path.join(package:installdir("bin"), "*")))) - else - table.join2(installfiles, (os.files(path.join(package:installdir("lib"), "**.a")))) - table.join2(installfiles, (os.files(path.join(package:installdir("lib"), is_plat("macosx") and "**.dylib" or "**.so")))) - table.join2(installfiles, (os.files(path.join(package:installdir("lib", "pkgconfig"), "**.pc")))) - table.join2(installfiles, (os.filedirs(path.join(package:installdir("include"), "*")))) - end - end + -- init some pathes + _g.prefixdir = package:prefixdir() + _g.installdir = package:installdir() + _g.relative_pathes = {} -- trace - vprint("installing %s to %s ..", installdir, prefixdir) + vprint("installing %s to %s ..", _g.installdir, _g.prefixdir) -- install to the prefix directory - local relativefiles = {} + local relative_pathes = {} try { function () - for _, installfile in ipairs(installfiles) do - - -- get relative file - local relativefile = path.relative(installfile, installdir) - - -- trace - vprint("installing %s ..", relativefile) - - -- install file - if is_host("windows") then - -- copy the whole file to the prefix directory - os.cp(installfile, path.absolute(relativefile, prefixdir)) - else - -- only link file to the prefix directory - os.ln(installfile, path.absolute(relativefile, prefixdir)) - end - -- save this relative file - table.insert(relativefiles, relativefile) + -- install package + if is_host("windows") then + _install_without_link(package) + else + _install_with_link(package) end end, catch @@ -95,7 +167,7 @@ function main(package) function () -- save the prefix info to file local prefixinfo = package:prefixinfo() - prefixinfo.installed = relativefiles + prefixinfo.installed = _g.relative_pathes io.save(package:prefixfile(), prefixinfo) -- register this package diff --git a/xmake/modules/devel/git/checkurl.lua b/xmake/modules/devel/git/checkurl.lua index d0b937e1c..df7441e81 100644 --- a/xmake/modules/devel/git/checkurl.lua +++ b/xmake/modules/devel/git/checkurl.lua @@ -29,5 +29,5 @@ -- @return true or false -- function main(url) - return url:endswith(".git") or os.isdir(url .. ".git") + return url:endswith(".git") or url:startswith("git://") or os.isdir(url .. ".git") end |
