summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-04-15 00:55:20 +0800
committerruki <[email protected]>2021-04-15 00:55:20 +0800
commit86a42da7addf4b0aa482f7504c0dd8b834472418 (patch)
tree7f42e3170e3073d87665d0724332b49af71b2617
parent8d0bbc7f0dd19c61931cf1d22a147b199a5fe8e2 (diff)
add import packages
-rw-r--r--xmake/actions/require/main.lua6
-rw-r--r--xmake/actions/require/xmake.lua8
-rw-r--r--xmake/modules/private/action/require/export.lua20
-rw-r--r--xmake/modules/private/action/require/impl/export_packages.lua12
-rw-r--r--xmake/modules/private/action/require/impl/import_packages.lua48
-rw-r--r--xmake/modules/private/action/require/import.lua68
-rw-r--r--xmake/modules/private/xrepo/action/export.lua71
-rw-r--r--xmake/modules/private/xrepo/action/import.lua214
8 files changed, 415 insertions, 32 deletions
diff --git a/xmake/actions/require/main.lua b/xmake/actions/require/main.lua
index f87e8c11c..eb0e2014e 100644
--- a/xmake/actions/require/main.lua
+++ b/xmake/actions/require/main.lua
@@ -31,6 +31,7 @@ import("private.action.require.fetch")
import("private.action.require.clean")
import("private.action.require.search")
import("private.action.require.export")
+import("private.action.require.import", {alias = "import_packages"})
import("private.action.require.install")
import("private.action.require.uninstall")
@@ -92,6 +93,11 @@ function main()
export(option.get("requires"))
+ -- import the installed packages
+ elseif option.get("import") then
+
+ import_packages(option.get("requires"))
+
-- show the given package info
elseif option.get("info") then
diff --git a/xmake/actions/require/xmake.lua b/xmake/actions/require/xmake.lua
index f8487939e..696658abe 100644
--- a/xmake/actions/require/xmake.lua
+++ b/xmake/actions/require/xmake.lua
@@ -79,8 +79,14 @@ task("require")
"e.g.",
" $ xmake require --export",
" $ xmake require --export tbox zlib",
- " $ xmake require --export --exportdir=packagesdir zlib",
+ " $ xmake require --export --packagedir=packagesdir zlib",
" $ xmake require --export --extra=\"{debug=true}\" tbox" }
+ , {nil, "import", "k", nil, "Import the installed packages and their dependencies.",
+ "e.g.",
+ " $ xmake require --import",
+ " $ xmake require --import tbox zlib",
+ " $ xmake require --import --packagedir=packagesdir zlib",
+ " $ xmake require --import --extra=\"{debug=true}\" tbox" }
, {nil, "packagedir", "kv", "packages","Set the packages directory for exporting and importing." }
, {nil, "extra", "kv", nil, "Set the extra info of packages." }
, { }
diff --git a/xmake/modules/private/action/require/export.lua b/xmake/modules/private/action/require/export.lua
index 34052d71e..45ead32fd 100644
--- a/xmake/modules/private/action/require/export.lua
+++ b/xmake/modules/private/action/require/export.lua
@@ -48,15 +48,17 @@ function main(requires_raw)
local packagedir = option.get("packagedir")
local packages = export_packages(requires, {requires_extra = requires_extra, packagedir = packagedir})
if not packages or #packages == 0 then
- cprint("${bright}packages(%s) not found, maybe they don’t exactly match the configuration.", table.concat(requires_raw, ", "))
- if os.getenv("XREPO_WORKING") then
- print("please attempt to export them with `-f/--configs=` option, e.g.")
- print(" - xrepo export -f \"name=value, ...\" package")
- print(" - xrepo export -m debug -k shared -f \"name=value, ...\" package")
- else
- print("please attempt to export them with `--extra=` option, e.g.")
- print(" - xmake require --export --extra=\"{configs={...}}\" package")
- print(" - xmake require --export --extra=\"{debug=true,configs={shared=true}}\" package")
+ if requires_raw then
+ cprint("${bright}packages(%s) not found, maybe they don’t exactly match the configuration ", table.concat(requires_raw, ", "))
+ if os.getenv("XREPO_WORKING") then
+ print("please attempt to export them with `-f/--configs=` option, e.g.")
+ print(" - xrepo export -f \"name=value, ...\" package")
+ print(" - xrepo export -m debug -k shared -f \"name=value, ...\" package")
+ else
+ print("please attempt to export them with `--extra=` option, e.g.")
+ print(" - xmake require --export --extra=\"{configs={...}}\" package")
+ print(" - xmake require --export --extra=\"{debug=true,configs={shared=true}}\" package")
+ end
end
end
diff --git a/xmake/modules/private/action/require/impl/export_packages.lua b/xmake/modules/private/action/require/impl/export_packages.lua
index 36f9fc792..b2053319a 100644
--- a/xmake/modules/private/action/require/impl/export_packages.lua
+++ b/xmake/modules/private/action/require/impl/export_packages.lua
@@ -24,15 +24,9 @@ import("private.action.require.impl.package")
-- export packages
function main(requires, opt)
-
- -- init options
opt = opt or {}
-
- -- get the package directory
- local packagedir = assert(opt.packagedir)
-
- -- export all packages
local packages = {}
+ local packagedir = assert(opt.packagedir)
for _, instance in ipairs(package.load_packages(requires, opt)) do
-- get export path
@@ -41,10 +35,10 @@ function main(requires, opt)
local exportpath, count = installdir:replace(rootdir, packagedir, {plain = true})
-- export this package
- if exportpath and count == 1 and instance:fetch() then
+ if exportpath and count == 1 and instance:fetch({force = true}) then
print("exporting %s-%s %s", instance:displayname(), instance:version_str(), package.get_configs_str(instance))
cprint(" ${yellow}->${clear} %s", exportpath)
- os.cp(instance:installdir(), exportpath)
+ os.cp(installdir, exportpath)
table.insert(packages, instance)
end
end
diff --git a/xmake/modules/private/action/require/impl/import_packages.lua b/xmake/modules/private/action/require/impl/import_packages.lua
new file mode 100644
index 000000000..1b875314e
--- /dev/null
+++ b/xmake/modules/private/action/require/impl/import_packages.lua
@@ -0,0 +1,48 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed 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-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file import_packages.lua
+--
+
+-- imports
+import("core.package.package", {alias = "core_package"})
+import("private.action.require.impl.package")
+
+-- import packages
+function main(requires, opt)
+ opt = opt or {}
+ local packages = {}
+ local packagedir = assert(opt.packagedir)
+ for _, instance in ipairs(package.load_packages(requires, opt)) do
+
+ -- get import path
+ local installdir = instance:installdir()
+ local rootdir = core_package.installdir()
+ local importpath, count = installdir:replace(rootdir, packagedir, {plain = true})
+
+ -- import this package
+ if importpath and count == 1 and not instance:fetch({force = true}) then
+ print("importing %s-%s %s", instance:displayname(), instance:version_str(), package.get_configs_str(instance))
+ cprint(" ${yellow}<-${clear} %s", importpath)
+ os.tryrm(installdir)
+ os.cp(importpath, installdir)
+ table.insert(packages, instance)
+ end
+ end
+ return packages
+end
+
diff --git a/xmake/modules/private/action/require/import.lua b/xmake/modules/private/action/require/import.lua
new file mode 100644
index 000000000..cf6cb85c7
--- /dev/null
+++ b/xmake/modules/private/action/require/import.lua
@@ -0,0 +1,68 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed 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-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file import.lua
+--
+
+-- imports
+import("core.base.task")
+import("core.base.option")
+import("private.action.require.impl.repository")
+import("private.action.require.impl.environment")
+import("private.action.require.impl.import_packages")
+import("private.action.require.impl.utils.get_requires")
+
+-- import the given packages
+function main(requires_raw)
+
+ -- enter environment
+ environment.enter()
+
+ -- pull all repositories first if not exists
+ if not repository.pulled() then
+ task.run("repo", {update = true})
+ end
+
+ -- get requires and extra config
+ local requires_extra = nil
+ local requires, requires_extra = get_requires(requires_raw)
+ if not requires or #requires == 0 then
+ return
+ end
+
+ -- import packages
+ local packagedir = option.get("packagedir")
+ local packages = import_packages(requires, {requires_extra = requires_extra, packagedir = packagedir})
+ if not packages or #packages == 0 then
+ if requires_raw then
+ cprint("${bright}packages(%s) cannot be imported, maybe they don’t exactly match the configuration.", table.concat(requires_raw, ", "))
+ if os.getenv("XREPO_WORKING") then
+ print("please attempt to import them with `-f/--configs=` option, e.g.")
+ print(" - xrepo import -f \"name=value, ...\" package")
+ print(" - xrepo import -m debug -k shared -f \"name=value, ...\" package")
+ else
+ print("please attempt to import them with `--extra=` option, e.g.")
+ print(" - xmake require --import --extra=\"{configs={...}}\" package")
+ print(" - xmake require --import --extra=\"{debug=true,configs={shared=true}}\" package")
+ end
+ end
+ end
+
+ -- leave environment
+ environment.leave()
+end
+
diff --git a/xmake/modules/private/xrepo/action/export.lua b/xmake/modules/private/xrepo/action/export.lua
index ccd829328..e8054afcb 100644
--- a/xmake/modules/private/xrepo/action/export.lua
+++ b/xmake/modules/private/xrepo/action/export.lua
@@ -20,6 +20,7 @@
-- imports
import("core.base.option")
+import("core.base.task")
-- get menu options
function menu_options()
@@ -72,15 +73,13 @@ function _export_packages(packages)
-- enter working project directory
local oldir = os.curdir()
- if packages or not os.isfile(os.projectfile()) then
- local workdir = path.join(os.tmpdir(), "xrepo", "working")
- if not os.isdir(workdir) then
- os.mkdir(workdir)
- os.cd(workdir)
- os.vrunv("xmake", {"create", "-P", "."})
- else
- os.cd(workdir)
- end
+ local workdir = path.join(os.tmpdir(), "xrepo", "working")
+ if not os.isdir(workdir) then
+ os.mkdir(workdir)
+ os.cd(workdir)
+ os.vrunv("xmake", {"create", "-P", "."})
+ else
+ os.cd(workdir)
end
-- do configure first
@@ -151,17 +150,63 @@ function _export_packages(packages)
local extra_str = string.serialize(extra, {indent = false, strip = true})
table.insert(require_argv, "--extra=" .. extra_str)
end
- if packages then
- table.join2(require_argv, packages)
- end
+ table.join2(require_argv, packages)
os.vexecv("xmake", require_argv)
end
+-- export packages in current project
+function _export_current_packages(packages)
+
+ -- do export
+ local require_argv = {export = true}
+ if option.get("yes") then
+ require_argv.yes = true
+ end
+ if option.get("verbose") then
+ require_argv.verbose = true
+ end
+ if option.get("diagnosis") then
+ require_argv.diagnosis = true
+ end
+ local packagedir = option.get("packagedir")
+ if packagedir and not path.is_absolute(packagedir) then
+ packagedir = path.absolute(packagedir, oldir)
+ end
+ if packagedir then
+ require_argv.packagedir = packagedir
+ end
+ local extra = {system = false}
+ if mode == "debug" then
+ extra.debug = true
+ end
+ if kind == "shared" then
+ extra.configs = extra.configs or {}
+ extra.configs.shared = true
+ end
+ local configs = option.get("configs")
+ if configs then
+ extra.configs = extra.configs or {}
+ local extra_configs, errors = ("{" .. configs .. "}"):deserialize()
+ if extra_configs then
+ table.join2(extra.configs, extra_configs)
+ else
+ raise(errors)
+ end
+ end
+ if extra then
+ local extra_str = string.serialize(extra, {indent = false, strip = true})
+ require_argv.extra = extra_str
+ end
+ task.run("require", require_argv)
+end
+
-- main entry
function main()
local packages = option.get("packages")
- if packages or os.isfile(os.projectfile()) then
+ if packages then
_export_packages(packages)
+ elseif os.isfile(os.projectfile()) then
+ _export_current_packages()
else
raise("please specify the packages to be exported.")
end
diff --git a/xmake/modules/private/xrepo/action/import.lua b/xmake/modules/private/xrepo/action/import.lua
new file mode 100644
index 000000000..e3805135d
--- /dev/null
+++ b/xmake/modules/private/xrepo/action/import.lua
@@ -0,0 +1,214 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed 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-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file import.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.base.task")
+
+-- get menu options
+function menu_options()
+
+ -- description
+ local description = "Import the given packages."
+
+ -- menu options
+ local options =
+ {
+ {'k', "kind", "kv", nil, "Enable static/shared library.",
+ values = {"static", "shared"} },
+ {'p', "plat", "kv", nil, "Set the given platform." },
+ {'a', "arch", "kv", nil, "Set the given architecture." },
+ {'m', "mode", "kv", nil, "Set the given mode.",
+ values = {"release", "debug"} },
+ {'f', "configs", "kv", nil, "Set the given extra package configs.",
+ "e.g.",
+ " - xrepo import -f \"vs_runtime=MD\" zlib",
+ " - xrepo import -f \"regex=true,thread=true\" boost"},
+ {},
+ {'i', "packagedir", "kv", "packages","Set the imported packages directory."},
+ {nil, "packages", "vs", nil, "The packages list.",
+ "e.g.",
+ " - xrepo import zlib boost",
+ " - xrepo import -p iphoneos -a arm64 \"zlib >=1.2.0\"",
+ " - xrepo import -p android -m debug \"pcre2 10.x\"",
+ " - xrepo import -p mingw -k shared zlib",
+ " - xrepo import conan::zlib/1.2.11 vcpkg::zlib"}
+ }
+
+ -- show menu options
+ local function show_options()
+
+ -- show usage
+ cprint("${bright}Usage: $${clear cyan}xrepo import [options] packages")
+
+ -- show description
+ print("")
+ print(description)
+
+ -- show options
+ option.show_options(options, "import")
+ end
+ return options, show_options, description
+end
+
+-- import packages
+function _import_packages(packages)
+
+ -- enter working project directory
+ local oldir = os.curdir()
+ local workdir = path.join(os.tmpdir(), "xrepo", "working")
+ if not os.isdir(workdir) then
+ os.mkdir(workdir)
+ os.cd(workdir)
+ os.vrunv("xmake", {"create", "-P", "."})
+ else
+ os.cd(workdir)
+ end
+
+ -- do configure first
+ local config_argv = {"f", "-c"}
+ if option.get("verbose") then
+ table.insert(config_argv, "-v")
+ end
+ if option.get("diagnosis") then
+ table.insert(config_argv, "-D")
+ end
+ if option.get("plat") then
+ table.insert(config_argv, "-p")
+ table.insert(config_argv, option.get("plat"))
+ end
+ if option.get("arch") then
+ table.insert(config_argv, "-a")
+ table.insert(config_argv, option.get("arch"))
+ end
+ local mode = option.get("mode")
+ if mode then
+ table.insert(config_argv, "-m")
+ table.insert(config_argv, mode)
+ end
+ local kind = option.get("kind")
+ if kind then
+ table.insert(config_argv, "-k")
+ table.insert(config_argv, kind)
+ end
+ os.vrunv("xmake", config_argv)
+
+ -- do import
+ local require_argv = {"require", "--import"}
+ if option.get("yes") then
+ table.insert(require_argv, "-y")
+ end
+ if option.get("verbose") then
+ table.insert(require_argv, "-v")
+ end
+ if option.get("diagnosis") then
+ table.insert(require_argv, "-D")
+ end
+ local packagedir = option.get("packagedir")
+ if packagedir and not path.is_absolute(packagedir) then
+ packagedir = path.absolute(packagedir, oldir)
+ end
+ if packagedir then
+ table.insert(require_argv, "--packagedir=" .. packagedir)
+ end
+ local extra = {system = false}
+ if mode == "debug" then
+ extra.debug = true
+ end
+ if kind == "shared" then
+ extra.configs = extra.configs or {}
+ extra.configs.shared = true
+ end
+ local configs = option.get("configs")
+ if configs then
+ extra.configs = extra.configs or {}
+ local extra_configs, errors = ("{" .. configs .. "}"):deserialize()
+ if extra_configs then
+ table.join2(extra.configs, extra_configs)
+ else
+ raise(errors)
+ end
+ end
+ if extra then
+ local extra_str = string.serialize(extra, {indent = false, strip = true})
+ table.insert(require_argv, "--extra=" .. extra_str)
+ end
+ table.join2(require_argv, packages)
+ os.vexecv("xmake", require_argv)
+end
+
+-- import packages in current project
+function _import_current_packages(packages)
+
+ -- do import
+ local require_argv = {import = true}
+ if option.get("yes") then
+ require_argv.yes = true
+ end
+ if option.get("verbose") then
+ require_argv.verbose = true
+ end
+ if option.get("diagnosis") then
+ require_argv.diagnosis = true
+ end
+ local packagedir = option.get("packagedir")
+ if packagedir and not path.is_absolute(packagedir) then
+ packagedir = path.absolute(packagedir, oldir)
+ end
+ if packagedir then
+ require_argv.packagedir = packagedir
+ end
+ local extra = {system = false}
+ if mode == "debug" then
+ extra.debug = true
+ end
+ if kind == "shared" then
+ extra.configs = extra.configs or {}
+ extra.configs.shared = true
+ end
+ local configs = option.get("configs")
+ if configs then
+ extra.configs = extra.configs or {}
+ local extra_configs, errors = ("{" .. configs .. "}"):deserialize()
+ if extra_configs then
+ table.join2(extra.configs, extra_configs)
+ else
+ raise(errors)
+ end
+ end
+ if extra then
+ local extra_str = string.serialize(extra, {indent = false, strip = true})
+ require_argv.extra = extra_str
+ end
+ task.run("require", require_argv)
+end
+
+-- main entry
+function main()
+ local packages = option.get("packages")
+ if packages then
+ _import_packages(packages)
+ elseif os.isfile(os.projectfile()) then
+ _import_current_packages()
+ else
+ raise("please specify the packages to be imported.")
+ end
+end
+