diff options
| author | ruki <[email protected]> | 2018-09-01 00:56:55 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-08-31 23:41:32 +0800 |
| commit | 86e6cab8a48f728be6f12a5b147f696735572b80 (patch) | |
| tree | 6c5c57a8671b79c5995321fe07a322ffbf4d8db3 | |
| parent | ac21734c1d1ae754146754f2656451091ff22014 (diff) | |
improve to install package
| -rw-r--r-- | xmake/actions/require/action/install.lua | 110 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 16 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 2 |
3 files changed, 25 insertions, 103 deletions
diff --git a/xmake/actions/require/action/install.lua b/xmake/actions/require/action/install.lua index 791a82f01..08782d20f 100644 --- a/xmake/actions/require/action/install.lua +++ b/xmake/actions/require/action/install.lua @@ -29,68 +29,41 @@ import("build") import("test") import("filter") --- install for xmake file -function _install_for_xmakefile(package) - - -- package to install directory - os.vrunv("xmake", {"p", "-o", package:installdir()}) -end - --- install for generic -function _install_for_generic(package) +-- make package +function _make_package(package) -- the package name local name = package:name() - -- the install directory - local installdir = path.join(package:installdir(), name .. ".pkg") + -- the package directory + local packagedir = path.join(package:directory(), name .. ".pkg") -- the linkdir - local linkdir = path.join(installdir, "lib/$(mode)/$(plat)/$(arch)") - os.mkdir(linkdir) + local linkdir = path.join(packagedir, "lib/$(mode)/$(plat)/$(arch)") -- the includedir - local includedir = path.join(installdir, "inc") - os.mkdir(includedir) + local includedir = path.join(packagedir, "inc") - -- the prefix directory exists? - local prefixdir = "" - if os.isdir(".prefix") and not os.emptydir(".prefix") then - prefixdir = ".prefix" .. path.seperator() - end + -- the installdir + local installdir = package:installdir() -- install the library files and ignore hidden files (.xxx) - if not os.trycp(prefixdir .. "**" .. target.filename("*", "static"), linkdir) and - not os.trycp(prefixdir .. "**" .. target.filename("*", "shared"), linkdir) then - raise("the library files not found in package %s", name) - end + os.cp(path.join(installdir, "lib"), linkdir) -- install the header files - for _, headerfile in ipairs(table.join((os.files(prefixdir .. "**.h")), (os.files(prefixdir .. "**.hpp")))) do - - -- the destinate header - local dstheaderfile = nil - if #prefixdir > 0 then - dstheaderfile = path.absolute(path.relative(headerfile, path.join(prefixdir, "include")), includedir) - else - dstheaderfile = path.join(includedir, path.filename(headerfile)) - end - - -- install header file - os.cp(headerfile, dstheaderfile) - end + os.cp(path.join(installdir, "include"), includedir) -- get links local links = {} for _, filename in ipairs(os.files(path.join(linkdir, target.filename("*", "static"))), path.filename) do - local link, count = filename:gsub(target.filename("([%w%-_]+)", "static"):gsub("%.", "%%.") .. "$", "%1") + local link, count = filename:gsub(target.filename("([%%w%%-_]+)", "static"):gsub("%.", "%%.") .. "$", "%1") if count > 0 then table.insert(links, link) end end if #links == 0 then for _, filename in ipairs(os.files(path.join(linkdir, target.filename("*", "shared"))), path.filename) do - local link, count = filename:gsub(target.filename("([%w%-_]+)", "shared"):gsub("%.", "%%.") .. "$", "%1") + local link, count = filename:gsub(target.filename("([%%w%%-_]+)", "shared"):gsub("%.", "%%.") .. "$", "%1") if count > 0 then table.insert(links, link) end @@ -99,7 +72,7 @@ function _install_for_generic(package) assert(#links > 0, "the library files not found in package %s", name) -- make xmake.lua - local file = io.open(path.join(installdir, "xmake.lua"), "w") + local file = io.open(path.join(packagedir, "xmake.lua"), "w") if file then -- the xmake.lua content @@ -137,58 +110,6 @@ option("%s") end end --- on install the given package -function _on_install_package(package) - - -- init install scripts - local installscripts = - { - {"xmake.lua", _install_for_xmakefile } - , {"*", _install_for_generic } - } - - -- attempt to install it - for _, installscript in pairs(installscripts) do - - -- save the current directory - local oldir = os.curdir() - - -- try installing - local ok = try - { - function () - - -- attempt to install it if file exists - local files = os.files(installscript[1]) - if #files > 0 then - installscript[2](package) - return true - end - end, - - catch - { - function (errors) - - -- trace verbose info - if errors then - vprint(errors) - end - end - } - } - - -- restore directory - os.cd(oldir) - - -- ok? - if ok then return end - end - - -- failed - raise("attempt to install package %s failed!", package:name()) -end - -- install the given package function main(package) @@ -228,7 +149,7 @@ function main(package) local scripts = { package:script("install_before") - , package:script("install", _on_install_package) + , package:script("install") , package:script("install_after") } @@ -246,6 +167,9 @@ function main(package) end end + -- make package from the install directory + _make_package(package) + -- test it test(package) end diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 52b4e374f..8c54c941b 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -169,13 +169,11 @@ end -- get the installed directory of this package function _instance:installdir() + return path.join(self:cachedir(), "install") +end - -- only be a system package without urls, no installdir - if self:from("system") then - return - end - - -- make install directory +-- get the directory of this package +function _instance:directory() return path.join(package.installdir(self:from("global")), self:name():sub(1, 1):lower(), self:name(), self:version_str()) end @@ -331,9 +329,9 @@ function _instance:fetch(force) self._find_package = self._find_package or sandbox_module.import("lib.detect.find_package", {anonymous = true}) -- fetch it from the package directories first - local installdir = self:installdir() - if not fetchinfo and installdir then - fetchinfo = self._find_package(self:name(), {packagedirs = installdir, system = false, cachekey = "package:fetch", force = force}) + local packagedir = self:directory() + if not fetchinfo and packagedir then + fetchinfo = self._find_package(self:name(), {packagedirs = packagedir, system = false, cachekey = "package:fetch", force = force}) if fetchinfo then fetchfrom = self._FROMKIND end end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 1d8a8fb24..9e48ec3c2 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -806,7 +806,7 @@ end function target:objectfile(sourcefile) -- translate: [lib]xxx*.[a|lib] => xxx/*.[o|obj] object file - sourcefile = sourcefile:gsub(target.filename("([%w%-_]+)", "static"):gsub("%.", "%%.") .. "$", "%1/*") + sourcefile = sourcefile:gsub(target.filename("([%%w%%-_]+)", "static"):gsub("%.", "%%.") .. "$", "%1/*") -- translate path -- |
