diff options
| author | ruki <[email protected]> | 2021-01-01 21:02:28 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-01-01 21:02:28 +0800 |
| commit | e1e70e4d1867f92f5591e7dd068ca13819955ed4 (patch) | |
| tree | 9c4ddbf7c91099b36def727dd578188fc53b4da4 | |
| parent | 99126a6271f7ed8a4712d5cd5c060210090b8d1c (diff) | |
add after_load to add_requires
| -rw-r--r-- | tests/projects/package/depconfigs/xmake.lua | 14 | ||||
| -rw-r--r-- | xmake/actions/require/impl/package.lua | 59 | ||||
| -rw-r--r-- | xmake/core/base/scopeinfo.lua | 29 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 24 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 13 | ||||
| -rw-r--r-- | xmake/core/project/requireinfo.lua | 19 |
6 files changed, 71 insertions, 87 deletions
diff --git a/tests/projects/package/depconfigs/xmake.lua b/tests/projects/package/depconfigs/xmake.lua index c8527c801..54a25e738 100644 --- a/tests/projects/package/depconfigs/xmake.lua +++ b/tests/projects/package/depconfigs/xmake.lua @@ -1,6 +1,18 @@ -add_requires("libpng", {system = false, configs = {vs_runtime = "MD"}, depconfigs = {cxflags = "-DTEST"}}) +add_requires("libpng", {system = false, configs = {vs_runtime = "MD"}, + after_load = function (package) + --package:set("deps", "zlib 1.2.10", {system = false, configs = {cxflags = "-DTEST"}}) + package:extraconf_set("deps", "zlib", {system = false, configs = {cxflags = "-DTEST"}}) + end}) + +add_requires("libtiff", {system = false, configs = {vs_runtime = "MD"}, + depconfigs = {cxflags = "-DTEST2"}}) target("test") set_kind("binary") add_files("src/*.c") add_packages("libpng") + +target("test2") + set_kind("binary") + add_files("src/*.c") + add_packages("libtiff") diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua index d0daaa3a8..142a48756 100644 --- a/xmake/actions/require/impl/package.lua +++ b/xmake/actions/require/impl/package.lua @@ -179,7 +179,9 @@ function _parse_require(require_str, requires_extra, parentinfo) default = require_extra.default, -- default: true, we can set it to disable package manually optional = parentinfo.optional or require_extra.optional, -- default: false, inherit parentinfo.optional verify = require_extra.verify, -- default: true, we can set false to ignore sha256sum and select any version - external = require_extra.external -- default: true, we use sysincludedirs/-isystem instead of -I/xxx + external = require_extra.external, -- default: true, we use sysincludedirs/-isystem instead of -I/xxx + on_load = require_extra.on_load, -- optional, we use it to override package().on_load + after_load = require_extra.after_load -- optional, we use it to load some user custom configuration after loading package() } -- save this required item to cache @@ -418,12 +420,18 @@ function _load_package(packagename, requireinfo, opt) -- check package configurations _check_package_configurations(package) - -- do load for package - local on_load = package:script("load") + -- do load + local on_load = requireinfo.on_load or package:script("load") if on_load then on_load(package) end + -- do after_load + local after_load = requireinfo.after_load + if after_load then + after_load(package) + end + -- load environments from the manifest to enable the environments of on_install() package:envs_load() @@ -458,8 +466,6 @@ function _load_package_depconfigs(package) end end end - -- TODO disable system deps --- print(requireinfo) -- inherit some builtin configs of root package -- e.g. add_requires("libpng", {configs = {vs_runtime = "MD"}}) @@ -477,7 +483,6 @@ function _load_package_depconfigs(package) end end end --- print(extraconfs) return extraconfs end @@ -491,11 +496,12 @@ function _load_packages(requires, opt) -- load packages local packages = {} - for _, requireinfo in ipairs(load_requires(requires, opt.requires_extra, opt.parentinfo)) do + for _, requireitem in ipairs(load_requires(requires, opt.requires_extra, opt.parentinfo)) do -- load package - local rootkey = opt.rootkey or requireinfo.name - local package = _load_package(requireinfo.name, requireinfo.info, table.join(opt, {rootkey = rootkey})) + local rootkey = opt.rootkey or requireitem.name + local requireinfo = requireitem.info + local package = _load_package(requireitem.name, requireinfo, table.join(opt, {rootkey = rootkey})) -- maybe package not found and optional if package then @@ -510,7 +516,7 @@ function _load_packages(requires, opt) -- load dependent packages and do not load system/3rd packages for package/deps() local packagedeps = {} - for _, dep in ipairs(_load_packages(deps, {rootkey = rootkey, requires_extra = extraconfs, parentinfo = requireinfo.info, nodeps = opt.nodeps, system = false})) do + for _, dep in ipairs(_load_packages(deps, {rootkey = rootkey, requires_extra = extraconfs, parentinfo = requireinfo, nodeps = opt.nodeps, system = false})) do dep:parents_add(package) table.insert(packages, dep) packagedeps[dep:name()] = dep @@ -611,36 +617,6 @@ function _get_confirm(packages) return confirm end --- patch some builtin dependent packages -function _patch_packages(packages_install, packages_download) - - -- @NOTE use git.apply instead of patch - -- we can add some builtin packages like this - --[[ - -- add package(patch) - local patched_package = nil - for _, package in ipairs(packages_install) do - if package:patches() then - patched_package = package - break - end - end - if patched_package then - local packages = load_packages("patch") - if packages and #packages > 0 then - -- install patch package - local package = packages[1] - if not package:fetch() then - packages_download[tostring(package)] = package - table.insert(packages_install, 1, package) - end - -- add dependences to ensure to be installed first - patched_package:deps_add(package) - end - end - ]] -end - -- install packages function _install_packages(packages_install, packages_download) @@ -885,9 +861,6 @@ function install_packages(requires, opt) raise() end - -- patch some dependent builtin packages - _patch_packages(packages_install, packages_download) - -- get user confirm if not _get_confirm(packages_install) then local packages_must = {} diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua index 45a7761f2..70755e14a 100644 --- a/xmake/core/base/scopeinfo.lua +++ b/xmake/core/base/scopeinfo.lua @@ -519,7 +519,7 @@ end -- function (target) -- _instance:extraconf("includedirs", "inc", "public") -> true -- _instance:extraconf("includedirs", "inc") -> {public = true} --- _instance:extraconf("includedirs") -> {["inc"] = {public = true}} +-- _instance:extraconf("includedirs") -> {inc = {public = true}} -- end -- function _instance:extraconf(name, item, key) @@ -549,6 +549,33 @@ function _instance:extraconf(name, item, key) return value end +-- set the extra configuration +-- +-- e.g. +-- +-- add_includedirs("inc", {public = true}) +-- +-- function (target) +-- _instance:extraconf_set("includedirs", "inc", "public", true) +-- _instance:extraconf_set("includedirs", "inc", {public = true}) +-- _instance:extraconf_set("includedirs", {inc = {public = true}}) +-- end +-- +function _instance:extraconf_set(name, item, key, value) + if key ~= nil then + local extraconf = self:get("__extra_" .. name) or {} + if value ~= nil then + extraconf[item] = extraconf[item] or {} + extraconf[item][key] = value + else + extraconf[item] = key + end + self:set("__extra_" .. name, extraconf) + else + self:set("__extra_" .. name, item) + end +end + -- clone a new instance from the current function _instance:clone() return _instance.new(self:kind(), self:info(), {interpreter = self:interpreter(), remove_repeat = self._REMOVE_REPEAT, enable_filter = self._ENABLE_FILTER}) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 52c9a0c7c..416315490 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -83,6 +83,11 @@ function _instance:extraconf(name, item, key) return self._INFO:extraconf(name, item, key) end +-- set the extra configuration +function _instance:extraconf_set(name, item, key, value) + return self._INFO:extraconf_set(name, item, key, value) +end + -- get the package license function _instance:license() return self:get("license") @@ -219,17 +224,6 @@ function _instance:orderdeps() return self._ORDERDEPS end --- add deps -function _instance:deps_add(...) - for _, dep in ipairs({...}) do - self:add("deps", dep:name()) - self._DEPS = self._DEPS or {} - self._DEPS[dep:name()] = dep - self._ORDERDEPS = self._ORDERDEPS or {} - table.insert(self._ORDERDEPS, dep) - end -end - -- get parents function _instance:parents() return self._PARENTS @@ -685,6 +679,14 @@ function _instance:config(name) end end +-- set configuration value +function _instance:config_set(name, value) + local configs = self:configs() + if configs then + configs[name] = value + end +end + -- get the configurations of package function _instance:configs() local configs = self._CONFIGS diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index db00493ea..6bb8d8b07 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -614,29 +614,18 @@ function project._load_requires() -- load it from cache first (@note will discard scripts in extrainfo) local instance = requireinfo.load(alias or packagename) if not instance then - - -- init a require info instance instance = table.inherit(requireinfo) - - -- save name and info instance._NAME = alias or packagename instance._INFO = { __requirestr = requirestr, __extrainfo = extrainfo } end - -- move scripts of extrainfo (e.g. on_load ..) + -- discard scripts in extrainfo, we need not it now (e.g. on_load ..) if extrainfo then for k, v in pairs(extrainfo) do if type(v) == "function" then - instance._SCRIPTS = instance._SCRIPTS or {} - instance._SCRIPTS[k] = v extrainfo[k] = nil end end - - -- TODO exists deprecated option? show tips - if extrainfo.option then - os.raise("`option = {}` is no longger supported in add_requires(), please update xmake.lua") - end end -- add require info diff --git a/xmake/core/project/requireinfo.lua b/xmake/core/project/requireinfo.lua index 205b7f6e9..0c90e6fb5 100644 --- a/xmake/core/project/requireinfo.lua +++ b/xmake/core/project/requireinfo.lua @@ -39,20 +39,6 @@ end -- save the requires info to the cache function requireinfo:save() - - -- To ensure that the full information (version, ..) is obtained, delay loading it - if not self._LOADED then - local on_load = self:script("on_load") - if on_load then - local ok, errors = sandbox.load(on_load, self) - if not ok then - os.raise(errors) - end - end - self._LOADED = true - end - - -- save it requireinfo._cache():set(self:name(), self._INFO) requireinfo._cache():save() end @@ -84,11 +70,6 @@ function requireinfo:name() return self._NAME end --- get the given script -function requireinfo:script(name) - return self._SCRIPTS and self._SCRIPTS[name] or nil -end - -- get the package version function requireinfo:version() |
