diff options
| author | ruki <[email protected]> | 2018-09-30 11:46:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-09-30 11:46:06 +0800 |
| commit | eb47c9efc487ac55da8d8ecaf9d9bb9534376a19 (patch) | |
| tree | a3b7232e5142c4d81a75dc3fa2f67cd27ebbad80 | |
| parent | d003fe0a57e65fe71a2853bd6a33aa9d1c42636c (diff) | |
add prefix module to package
| -rw-r--r-- | xmake/actions/require/impl/action/install.lua | 112 | ||||
| -rw-r--r-- | xmake/actions/require/impl/action/prefix/install.lua | 107 | ||||
| -rw-r--r-- | xmake/actions/require/impl/action/prefix/uninstall.lua | 53 | ||||
| -rw-r--r-- | xmake/actions/require/impl/package.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/repo/main.lua | 2 |
5 files changed, 164 insertions, 112 deletions
diff --git a/xmake/actions/require/impl/action/install.lua b/xmake/actions/require/impl/action/install.lua index 5beb0e8f1..8885889fa 100644 --- a/xmake/actions/require/impl/action/install.lua +++ b/xmake/actions/require/impl/action/install.lua @@ -27,115 +27,7 @@ import("core.base.option") import("core.project.target") import("test") import(".utils.filter") - --- uninstall package from the prefix directory -function uninstall_prefix(package) - - -- remove the previous installed files - local prefixdir = package:prefixdir() - for _, relativefile in ipairs(package:prefixinfo().installed) do - - -- trace - vprint("removing %s ..", relativefile) - - -- remove file - local prefixfile = path.absolute(relativefile, prefixdir) - os.tryrm(prefixfile) - - -- remove it if the parent directory is empty - local parentdir = path.directory(prefixfile) - while parentdir and os.isdir(parentdir) and os.emptydir(parentdir) do - os.tryrm(parentdir) - parentdir = path.directory(parentdir) - end - end - - -- unregister this package - package:unregister() - - -- remove the prefix file - os.tryrm(package:prefixfile()) -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 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 - - -- 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) - - -- 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) - end - end, - catch - { - function (errors) - raise(errors) - end - }, - finally - { - function () - -- save the prefix info to file - local prefixinfo = package:prefixinfo() - prefixinfo.installed = relativefiles - io.save(package:prefixfile(), prefixinfo) - - -- register this package - package:register() - end - } - } -end +import("prefix") -- install the given package function main(package) @@ -199,7 +91,7 @@ function main(package) end -- install to the prefix directory - install_prefix(package) + prefix.install(package) -- test it test(package) diff --git a/xmake/actions/require/impl/action/prefix/install.lua b/xmake/actions/require/impl/action/prefix/install.lua new file mode 100644 index 000000000..0c79352cf --- /dev/null +++ b/xmake/actions/require/impl/action/prefix/install.lua @@ -0,0 +1,107 @@ +--!The Make-like install Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file install.lua +-- + +-- imports +import("uninstall") + +-- 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 + + -- 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) + + -- 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) + end + end, + catch + { + function (errors) + raise(errors) + end + }, + finally + { + function () + -- save the prefix info to file + local prefixinfo = package:prefixinfo() + prefixinfo.installed = relativefiles + io.save(package:prefixfile(), prefixinfo) + + -- register this package + package:register() + end + } + } +end + diff --git a/xmake/actions/require/impl/action/prefix/uninstall.lua b/xmake/actions/require/impl/action/prefix/uninstall.lua new file mode 100644 index 000000000..420524fd2 --- /dev/null +++ b/xmake/actions/require/impl/action/prefix/uninstall.lua @@ -0,0 +1,53 @@ +--!The Make-like install Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file uninstall.lua +-- + +-- uninstall package from the prefix directory +function main(package) + + -- remove the previous installed files + local prefixdir = package:prefixdir() + for _, relativefile in ipairs(package:prefixinfo().installed) do + + -- trace + vprint("removing %s ..", relativefile) + + -- remove file + local prefixfile = path.absolute(relativefile, prefixdir) + os.tryrm(prefixfile) + + -- remove it if the parent directory is empty + local parentdir = path.directory(prefixfile) + while parentdir and os.isdir(parentdir) and os.emptydir(parentdir) do + os.tryrm(parentdir) + parentdir = path.directory(parentdir) + end + end + + -- unregister this package + package:unregister() + + -- remove the prefix file + os.tryrm(package:prefixfile()) +end + diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua index fc67ea232..8bafb6041 100644 --- a/xmake/actions/require/impl/package.lua +++ b/xmake/actions/require/impl/package.lua @@ -517,7 +517,7 @@ function remove_packages(requires, opt) if os.isfile(instance:prefixfile()) then -- uninstall package from the prefix directory - action.install.uninstall_prefix(instance) + action.prefix.uninstall(instance) -- remove the install files os.tryrm(instance:installdir()) diff --git a/xmake/plugins/repo/main.lua b/xmake/plugins/repo/main.lua index 494cb66f5..10a279cfe 100644 --- a/xmake/plugins/repo/main.lua +++ b/xmake/plugins/repo/main.lua @@ -29,7 +29,7 @@ import("core.project.project") import("core.platform.platform") import("core.package.repository") import("devel.git") -import("actions.require.environment", {rootdir = os.programdir()}) +import("actions.require.impl.environment", {rootdir = os.programdir()}) -- add repository url function _add(name, url, is_global) |
