diff options
| author | ruki <[email protected]> | 2017-09-13 00:27:09 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-09-12 20:42:58 +0800 |
| commit | 71606410bdf3ca069f069f4f0f9c14f55a4721c5 (patch) | |
| tree | d1ada4c25d82c2fbcb20fc1b875d38e9b75811ca | |
| parent | 499e3c952fd155350ac3486a83de3ab9491a2688 (diff) | |
fix system and optional problem for package
| -rw-r--r-- | tests/projects/requires/xmake.lua | 7 | ||||
| -rw-r--r-- | xmake/actions/require/install.lua | 22 | ||||
| -rw-r--r-- | xmake/actions/require/list.lua | 4 | ||||
| -rw-r--r-- | xmake/actions/require/package.lua | 12 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 15 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 5 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_package.lua | 14 |
7 files changed, 49 insertions, 30 deletions
diff --git a/tests/projects/requires/xmake.lua b/tests/projects/requires/xmake.lua index 1ff3daed3..9f03b9e13 100644 --- a/tests/projects/requires/xmake.lua +++ b/tests/projects/requires/xmake.lua @@ -6,13 +6,14 @@ package_end() -- group packages package("zlib-mbedtls") - add_deps("zlib >=1.2.11") - add_deps("mbedtls", {optional = true}) + add_deps("zlib >=1.2.11", {system = false}) + add_deps("mbedtls") package_end() -- requires add_requires("zlib-mbedtls") -add_requires("[email protected] ~1.6.0", {optional = true}) +add_requires("[email protected] ~1.6.0") +add_requires("unknown", {optional = true}) -- the debug mode if is_mode("debug") then diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua index baa5b5315..4078ff5fb 100644 --- a/xmake/actions/require/install.lua +++ b/xmake/actions/require/install.lua @@ -66,6 +66,25 @@ function _attach_to_targets(packages) end end +-- check missing packages +function _check_missing_packages(packages) + + -- get all missing packages + local packages_missing = {} + for _, instance in ipairs(packages) do + if not instance:exists() and not instance:requireinfo().optional then + if #instance:urls() > 0 or instance:from("system") then + table.insert(packages_missing, instance:fullname()) + end + end + end + + -- raise tips + if #packages_missing > 0 then + raise("The packages(%s) not found", table.concat(packages_missing, ", ")) + end +end + -- install packages function main(requires) @@ -146,6 +165,9 @@ function main(requires) action.install(instance) end + -- check missing packages + _check_missing_packages(packages) + -- attach required local package to targets _attach_to_targets(packages) diff --git a/xmake/actions/require/list.lua b/xmake/actions/require/list.lua index 5b9440bf7..231b7629b 100644 --- a/xmake/actions/require/list.lua +++ b/xmake/actions/require/list.lua @@ -66,10 +66,10 @@ function main() local requireinfo = instance:requireinfo() or {} local packageopt = project.option(instance:fullname()) if packageopt then - cprint(" ${magenta}require${clear}(%s): %s%s%s", requireinfo.originstr, ifelse(instance:version_str(), instance:version_str(), ""), _from(instance), ifelse(requireinfo.optional, ", ${yellow}optional${clear}", "")) + cprint(" ${magenta}require${clear}(%s): %s%s%s", requireinfo.originstr, ifelse(instance:version_str(), instance:version_str(), "no version"), _from(instance), ifelse(requireinfo.optional, ", ${yellow}optional${clear}", "")) for _, dep in ipairs(instance:orderdeps()) do requireinfo = dep:requireinfo() or {} - cprint(" -> ${magenta}dep${clear}(%s): %s%s%s", requireinfo.originstr, ifelse(dep:version_str(), dep:version_str(), ""), _from(dep), ifelse(requireinfo.optional, ", ${yellow}optional${clear}", "")) + cprint(" -> ${magenta}dep${clear}(%s): %s%s%s", requireinfo.originstr, ifelse(dep:version_str(), dep:version_str(), "no version"), _from(dep), ifelse(requireinfo.optional, ", ${yellow}optional${clear}", "")) end end end diff --git a/xmake/actions/require/package.lua b/xmake/actions/require/package.lua index c262050ce..9df334a6e 100644 --- a/xmake/actions/require/package.lua +++ b/xmake/actions/require/package.lua @@ -40,7 +40,7 @@ import("repository") -- add_requires("zlib master") -- add_requires("[email protected] >=1.5.1") -- add_requires("https://github.com/tboox/[email protected] >=1.5.1") --- add_requires("tboox.tbox >=1.5.1 <1.6.0 optional") +-- add_requires("tboox.tbox >=1.5.1 <1.6.0") -- function _parse_require(require_str, requires_extra) @@ -114,9 +114,10 @@ function _parse_require(require_str, requires_extra) reponame = reponame, packageurl = packageurl, version = version, - optional = require_extra.optional, system = require_extra.system, - option = require_extra.option + option = require_extra.option, + default = require_extra.default, + optional = require_extra.optional } -- save this required item to cache @@ -190,11 +191,6 @@ function _load_package(packagename, requireinfo) end end - -- no this package and optional? - if not instance and requireinfo.optional then - return - end - -- check assert(instance, "package(%s) not found!", packagename) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index e35c4eb5d..04a1fedb6 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -165,11 +165,6 @@ function _instance:from(kind) return self._FROMKIND == kind end --- is optional package? -function _instance:optional() - return self._REQUIREINFO.mode == "optional" -end - -- get the cached directory of this package function _instance:cachedir() local version_str = self:version_str() @@ -295,8 +290,14 @@ function _instance:fetch() -- fetch it from the system directories if not fetchinfo then - fetchinfo = self._find_package(self:name()) - if fetchinfo then fetchfrom = "system" end + local system = self:requireinfo().system + if system == nil then -- enable by default + system = true + end + if system then + fetchinfo = self._find_package(self:name()) + if fetchinfo then fetchfrom = "system" end + end end -- save to cache diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 5823d05f6..fda0fc5f9 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -529,11 +529,6 @@ function project._load_options(disable_filter) local require_extra = requires_extra[require_str] if require_extra then - -- disable it if be optional - if require_extra.optional then - packageopt.default = false - end - -- override values from the extra option for name, value in pairs(table.wrap(require_extra.option)) do packageopt[name] = value diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua index 985d83537..4b27209c4 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua @@ -302,7 +302,11 @@ function sandbox_lib_detect_find_package.main(name, opt) opt.plat = opt.plat or config.get("plat") or os.host() opt.arch = opt.arch or config.get("arch") or os.arch() opt.mode = opt.mode or config.get("mode") - opt.system = opt.system or true + + -- enable system package by default + if opt.system == nil then + opt.system = true + end -- init cache key local key = "find_package_" .. opt.plat .. "_" .. opt.arch @@ -318,10 +322,10 @@ function sandbox_lib_detect_find_package.main(name, opt) result = sandbox_lib_detect_find_package._find(name, opt) -- cache result - cacheinfo[name] = utils.ifelse(result, result, false) - - -- save cache info - cache.save(key, cacheinfo) + if not opt.force then + cacheinfo[name] = utils.ifelse(result, result, false) + cache.save(key, cacheinfo) + end -- trace if opt.verbose or option.get("verbose") then |
