diff options
| author | ruki <[email protected]> | 2021-12-17 00:51:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-12-17 00:51:02 +0800 |
| commit | 8512b8200ac982c4075c4707c3b2971c73159c9f (patch) | |
| tree | 74783b7373a40a2812458a4bedcc36ac987872b7 | |
| parent | 9af42bcb37bde188b60d64d36c4e86873c2ece0b (diff) | |
modify package configurations
| -rw-r--r-- | tests/projects/package/conan/.gitignore | 8 | ||||
| -rw-r--r-- | tests/projects/package/conan/src/main.cpp | 9 | ||||
| -rw-r--r-- | tests/projects/package/conan/xmake.lua | 9 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/package/manager/cargo/configurations.lua | 28 | ||||
| -rw-r--r-- | xmake/modules/package/manager/cargo/install_package.lua | 15 | ||||
| -rw-r--r-- | xmake/modules/package/manager/clib/configurations.lua | 30 | ||||
| -rw-r--r-- | xmake/modules/package/manager/clib/install_package.lua | 21 | ||||
| -rw-r--r-- | xmake/modules/package/manager/cmake/configurations.lua | 33 | ||||
| -rw-r--r-- | xmake/modules/package/manager/cmake/find_package.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/package/manager/conan/configurations.lua | 33 | ||||
| -rw-r--r-- | xmake/modules/package/manager/conan/install_package.lua | 44 |
12 files changed, 189 insertions, 59 deletions
diff --git a/tests/projects/package/conan/.gitignore b/tests/projects/package/conan/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/package/conan/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/package/conan/src/main.cpp b/tests/projects/package/conan/src/main.cpp new file mode 100644 index 000000000..7c435d251 --- /dev/null +++ b/tests/projects/package/conan/src/main.cpp @@ -0,0 +1,9 @@ +#include <iostream> + +using namespace std; + +int main(int argc, char** argv) +{ + cout << "hello world!" << endl; + return 0; +} diff --git a/tests/projects/package/conan/xmake.lua b/tests/projects/package/conan/xmake.lua new file mode 100644 index 000000000..69f7d2052 --- /dev/null +++ b/tests/projects/package/conan/xmake.lua @@ -0,0 +1,9 @@ +add_requires("conan::zlib/1.2.11", {alias = "zlib", debug = true}) +add_requires("conan::openssl/1.1.1g", {alias = "openssl", + configs = {options = "OpenSSL:shared=True"}}) + +target("test") + set_kind("binary") + add_files("src/*.cpp") + add_packages("openssl", "zlib") + diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 3b778d617..602b0e58d 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1895,7 +1895,8 @@ function package.load_from_system(packagename) -- on install script local on_install = function (pkg) - local opt = table.copy(pkg:configs()) + local opt = {} + opt.pkgconfigs = pkg:configs() opt.mode = pkg:is_debug() and "debug" or "release" opt.plat = pkg:plat() opt.arch = pkg:arch() @@ -1930,9 +1931,9 @@ function package.load_from_system(packagename) if is_thirdparty then -- add configurations for the 3rd package - local install_package = sandbox_module.import("package.manager." .. packagename:split("::")[1]:lower() .. ".install_package", {try = true, anonymous = true}) - if install_package and install_package.configurations then - for name, conf in pairs(install_package.configurations()) do + local configurations = sandbox_module.import("package.manager." .. packagename:split("::")[1]:lower() .. ".configurations", {try = true, anonymous = true}) + if configurations then + for name, conf in pairs(configurations()) do instance:add("configs", name, conf) end end diff --git a/xmake/modules/package/manager/cargo/configurations.lua b/xmake/modules/package/manager/cargo/configurations.lua new file mode 100644 index 000000000..a3f85a0ea --- /dev/null +++ b/xmake/modules/package/manager/cargo/configurations.lua @@ -0,0 +1,28 @@ +--!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 configurations.lua +-- + +-- get configurations +function main() + return + { + features = {description = "set the features of dependency."}, + default_features = {description = "enables or disables any defaults provided by the dependency.", default = true}, + } +end diff --git a/xmake/modules/package/manager/cargo/install_package.lua b/xmake/modules/package/manager/cargo/install_package.lua index 0f06a8f6b..dd2fde7e9 100644 --- a/xmake/modules/package/manager/cargo/install_package.lua +++ b/xmake/modules/package/manager/cargo/install_package.lua @@ -23,15 +23,6 @@ import("core.base.option") import("core.project.config") import("lib.detect.find_tool") --- get configurations -function configurations() - return - { - features = {description = "set the features of dependency."}, - default_features = {description = "enables or disables any defaults provided by the dependency.", default = true}, - } -end - -- install package -- -- e.g. @@ -53,6 +44,8 @@ function main(name, opt) end -- get required version + opt = opt or {} + local pkgconfigs = opt.pkgconfigs or {} local require_version = opt.require_version if not require_version or require_version == "latest" then require_version = "*" @@ -69,10 +62,10 @@ function main(name, opt) tomlfile:print("edition = \"2018\"") tomlfile:print("") tomlfile:print("[dependencies]") - local features = opt.features + local features = pkgconfigs.features if features then features = table.wrap(features) - tomlfile:print("%s = {version = \"%s\", features = [\"%s\"], default-features = %s}", name, require_version, table.concat(features, "\", \""), opt.default_features) + tomlfile:print("%s = {version = \"%s\", features = [\"%s\"], default-features = %s}", name, require_version, table.concat(features, "\", \""), pkgconfigs.default_features) else tomlfile:print("%s = \"%s\"", name, require_version) end diff --git a/xmake/modules/package/manager/clib/configurations.lua b/xmake/modules/package/manager/clib/configurations.lua new file mode 100644 index 000000000..4f59ea70d --- /dev/null +++ b/xmake/modules/package/manager/clib/configurations.lua @@ -0,0 +1,30 @@ +--!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 Adel Vilkov (aka RaZeR-RBI) +-- @file configurations.lua +-- + +-- get configurations +function main() + return + { + save = {description = "save dependency in project's package.json", default = false, type = "boolean"}, + save_dev = {description = "save as development dependency in project's package.json", default = false, type = "boolean"}, + outputdir = {description = "package installation directory relative to project root", default = "clib"}, + } +end + diff --git a/xmake/modules/package/manager/clib/install_package.lua b/xmake/modules/package/manager/clib/install_package.lua index 1b61af5b4..8ebac7829 100644 --- a/xmake/modules/package/manager/clib/install_package.lua +++ b/xmake/modules/package/manager/clib/install_package.lua @@ -23,42 +23,35 @@ import("core.base.option") import("core.project.config") import("lib.detect.find_tool") --- get configurations -function configurations() - return - { - save = {description = "save dependency in project's package.json", default = false, type = "boolean"}, - save_dev = {description = "save as development dependency in project's package.json", default = false, type = "boolean"}, - outputdir = {description = "package installation directory relative to project root", default = "clib"}, - } -end - -- install package -- @param name the package name, e.g. clib::clibs/[email protected] -- @param opt the options, e.g. { verbose = true, --- settings = {outputdir = "clib", save = false, save_dev = false}} +-- pkgconfigs = {outputdir = "clib", save = false, save_dev = false}} -- -- @return true or false -- function main(name, opt) + -- find clib local clib = find_tool("clib") if not clib then raise("clib not found!") end + opt = opt or {} + local pkgconfigs = opt.pkgconfigs or {} local argv = {"install", name} - local abs_out = path.join(os.projectdir(), opt.outputdir) + local abs_out = path.join(os.projectdir(), pkgconfigs.outputdir) dprint("installing %s to %s", name, abs_out) table.insert(argv, "-o " .. abs_out) if not option.get("verbose") then table.insert(argv, "-q") end - if opt.save then + if pkgconfigs.save then table.insert(argv, "--save") end - if opt.save_dev then + if pkgconfigs.save_dev then table.insert(argv, "--save-dev") end diff --git a/xmake/modules/package/manager/cmake/configurations.lua b/xmake/modules/package/manager/cmake/configurations.lua new file mode 100644 index 000000000..ce9b21e17 --- /dev/null +++ b/xmake/modules/package/manager/cmake/configurations.lua @@ -0,0 +1,33 @@ +--!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 configurations.lua +-- + +-- get configurations +function main() + return + { + build = {description = "use it to choose if you want to build from sources.", default = "missing", values = {"all", "never", "missing", "outdated"}}, + remote = {description = "Set the conan remote server."}, + options = {description = "Set the options values, e.g. OpenSSL:shared=True"}, + imports = {description = "Set the imports for conan."}, + settings = {description = "Set the build settings for conan."}, + build_requires = {description = "Set the build requires for conan.", default = "xmake_generator/0.1.0@bincrafters/testing"} + } +end + diff --git a/xmake/modules/package/manager/cmake/find_package.lua b/xmake/modules/package/manager/cmake/find_package.lua index 22ebc711b..e0e767145 100644 --- a/xmake/modules/package/manager/cmake/find_package.lua +++ b/xmake/modules/package/manager/cmake/find_package.lua @@ -243,10 +243,11 @@ end -- -- @param name the package name -- @param opt the options, e.g. {verbose = true, required_version = "1.0", --- components = {"regex", "system"}, --- moduledirs = "xxx", --- presets = {Boost_USE_STATIC_LIB = true}, --- envs = {CMAKE_PREFIX_PATH = "xxx"}) +-- pkgconfigs = { +-- components = {"regex", "system"}, +-- moduledirs = "xxx", +-- presets = {Boost_USE_STATIC_LIB = true}, +-- envs = {CMAKE_PREFIX_PATH = "xxx"}}) -- function main(name, opt) opt = opt or {} diff --git a/xmake/modules/package/manager/conan/configurations.lua b/xmake/modules/package/manager/conan/configurations.lua new file mode 100644 index 000000000..ce9b21e17 --- /dev/null +++ b/xmake/modules/package/manager/conan/configurations.lua @@ -0,0 +1,33 @@ +--!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 configurations.lua +-- + +-- get configurations +function main() + return + { + build = {description = "use it to choose if you want to build from sources.", default = "missing", values = {"all", "never", "missing", "outdated"}}, + remote = {description = "Set the conan remote server."}, + options = {description = "Set the options values, e.g. OpenSSL:shared=True"}, + imports = {description = "Set the imports for conan."}, + settings = {description = "Set the build settings for conan."}, + build_requires = {description = "Set the build requires for conan.", default = "xmake_generator/0.1.0@bincrafters/testing"} + } +end + diff --git a/xmake/modules/package/manager/conan/install_package.lua b/xmake/modules/package/manager/conan/install_package.lua index 97af3b4b8..d7f730e14 100644 --- a/xmake/modules/package/manager/conan/install_package.lua +++ b/xmake/modules/package/manager/conan/install_package.lua @@ -49,15 +49,15 @@ function _conan_get_build_directory(name) end -- generate conanfile.txt -function _conan_generate_conanfile(name, opt) +function _conan_generate_conanfile(name, pkgconfigs) -- trace dprint("generate %s ..", path.join(_conan_get_build_directory(name), "conanfile.txt")) -- get conan options, imports and build_requires - local options = table.wrap(opt.options) - local imports = table.wrap(opt.imports) - local build_requires = table.wrap(opt.build_requires) + local options = table.wrap(pkgconfigs.options) + local imports = table.wrap(pkgconfigs.imports) + local build_requires = table.wrap(pkgconfigs.build_requires) -- @see https://docs.conan.io/en/latest/systems_cross_building/cross_building.html -- generate it @@ -109,30 +109,22 @@ function _conan_install_xmake_generator(conan) end end --- get configurations -function configurations() - return - { - build = {description = "use it to choose if you want to build from sources.", default = "missing", values = {"all", "never", "missing", "outdated"}}, - remote = {description = "Set the conan remote server."}, - options = {description = "Set the options values, e.g. OpenSSL:shared=True"}, - imports = {description = "Set the imports for conan."}, - settings = {description = "Set the build settings for conan."}, - build_requires = {description = "Set the build requires for conan.", default = "xmake_generator/0.1.0@bincrafters/testing"} - } -end - -- install package -- -- @param name the package name, e.g. conan::OpenSSL/1.0.2n@conan/stable -- @param opt the options, e.g. { verbose = true, mode = "release", plat = , arch = , --- remote = "", build = "all", options = {}, imports = {}, build_requires = {}, --- settings = {"compiler=Visual Studio", "compiler.version=10", "compiler.runtime=MD"}} +-- pkgconfigs = { +-- remote = "", build = "all", options = {}, imports = {}, build_requires = {}, +-- settings = {"compiler=Visual Studio", "compiler.version=10", "compiler.runtime=MD"}}} -- -- @return true or false -- function main(name, opt) + -- get pkgconfigs + opt = opt or {} + local pkgconfigs = opt.pkgconfigs or {} + -- find conan local conan = find_tool("conan") if not conan then @@ -155,15 +147,15 @@ function main(name, opt) _conan_install_xmake_generator(conan) -- generate conanfile.txt - _conan_generate_conanfile(name, opt) + _conan_generate_conanfile(name, pkgconfigs) -- install package local argv = {"install", "."} - if opt.build then - if opt.build == "all" then + if pkgconfigs.build then + if pkgconfigs.build == "all" then table.insert(argv, "--build") else - table.insert(argv, "--build=" .. opt.build) + table.insert(argv, "--build=" .. pkgconfigs.build) end end @@ -241,15 +233,15 @@ function main(name, opt) end -- set custom settings - for _, setting in ipairs(opt.settings) do + for _, setting in ipairs(pkgconfigs.settings) do table.insert(argv, "-s") table.insert(argv, setting) end -- set remote - if opt.remote then + if pkgconfigs.remote then table.insert(argv, "-r") - table.insert(argv, opt.remote) + table.insert(argv, pkgconfigs.remote) end -- TODO set environments |
