diff options
| author | ruki <[email protected]> | 2018-09-19 22:41:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-09-19 10:06:08 +0800 |
| commit | b2609ac657e482c68cf27977174bc9080d34eee9 (patch) | |
| tree | caec92a62a0fc7d9800898e94568eb96b40ccac4 | |
| parent | 89e82f8a4c620dae78ebae08e00adbc6d17a3e18 (diff) | |
install package to prefix
| -rw-r--r-- | xmake/actions/require/action/install.lua | 80 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 25 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/package/package.lua | 5 |
3 files changed, 101 insertions, 9 deletions
diff --git a/xmake/actions/require/action/install.lua b/xmake/actions/require/action/install.lua index fcfcbb1b7..9f0d7c258 100644 --- a/xmake/actions/require/action/install.lua +++ b/xmake/actions/require/action/install.lua @@ -29,8 +29,8 @@ import("build") import("test") import("filter") --- make package -function _make_package(package) +-- generate package +function _generate_package(package) -- the package name local name = package:name() @@ -108,6 +108,70 @@ option("%s") end end +-- uninstall package from the prefix directory +function _uninstall_prefix(package) + + -- TODO +end + +-- install package to the prefix directory +function _install_prefix(package) + + -- uninstall the prefix package files first + _uninstall_prefix(package) + + -- get prefix and install directory + local prefixdir = package:prefixdir() + local installdir = package:installdir() + + -- scan all installed files + local installfiles = {} + 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 + + -- trace + vprint("installing %s to %s ..", installdir, prefixdir) + + -- install to the prefix directory + local relativefiles = {} + try + { + function () + for _, installfile in ipairs(installfiles) do + + -- get relative file + local relativefile = path.relative(installfile, installdir) + + -- trace + vprint("installing %s ..", relativefile) + + -- copy file + os.cp(installfile, path.absolute(relativefile, prefixdir)) + + -- save this relative file + table.insert(relativefiles, relativefile) + end + end, + catch + { + function (errors) + raise(errors) + end + }, + finally + { + function () + -- save the prefix info to file + io.save(package:prefixfile(), relativefiles) + end + } + } +end + -- install the given package function main(package) @@ -169,14 +233,14 @@ function main(package) end end - -- add search path for program - if package:kind() == "binary" then - os.addenv("PATH", package:installdir("bin")) - else - -- make package from the install directory - _make_package(package) + -- generate package(.pkg) from the install directory + if package:kind() ~= "binary" then + _generate_package(package) end + -- install to the prefix directory + _install_prefix(package) + -- test it test(package) end diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 9a69ddc58..f6afc7845 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -182,7 +182,7 @@ end function _instance:installdir(...) -- make the given install directory - local dir = path.join(self:directory(), "install", ...) + local dir = path.join(self:cachedir(), "install", ...) -- ensure the install directory if not os.isdir(dir) then @@ -191,6 +191,16 @@ function _instance:installdir(...) return dir end +-- get the prefix directory +function _instance:prefixdir(...) + return package.prefixdir(self:from("global"), ...) +end + +-- get the prefix info file +function _instance:prefixfile() + return path.join(self:prefixdir(".info"), self:name() .. "-" .. (self:version_str() or "") .. ".txt") +end + -- get the downloaded original file function _instance:originfile() return self._ORIGINFILE @@ -540,6 +550,19 @@ function package.cachedir() return path.join(global.directory(), "cache", "packages") end +-- get the prefix directory +function package.prefixdir(is_global, ...) + + -- make the given prefix directory + local dir = path.join(package.directory(is_global), "prefix", config.get("plat") or os.host(), config.get("arch") or os.arch(), ...) + + -- ensure the prefix directory + if not os.isdir(dir) then + os.mkdir(dir) + end + return dir +end + -- load the package from the system directories function package.load_from_system(packagename) diff --git a/xmake/core/sandbox/modules/import/core/package/package.lua b/xmake/core/sandbox/modules/import/core/package/package.lua index 5eed04499..0c286be72 100644 --- a/xmake/core/sandbox/modules/import/core/package/package.lua +++ b/xmake/core/sandbox/modules/import/core/package/package.lua @@ -40,6 +40,11 @@ function sandbox_core_package_package.directory(is_global) return package.directory(is_global) end +-- get the prefix directory +function sandbox_core_package_package.prefixdir(is_global, ...) + return package.prefixdir(is_global, ...) +end + -- load the package from the project file function sandbox_core_package_package.load_from_project(packagename) |
