diff options
| author | ruki <[email protected]> | 2021-03-20 00:50:56 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-03-20 00:50:56 +0800 |
| commit | 7556e19a1193841aa49871ffab35bc3e56bd481e (patch) | |
| tree | 2a72103ca495abb12797a6a4ee08a3fbaa81da64 | |
| parent | c1261619d8e7330a1a99e50a73b5baddf2dd66f4 (diff) | |
pass extraconf to package
| -rw-r--r-- | xmake/core/package/package.lua | 30 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 26 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 1 |
3 files changed, 43 insertions, 14 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index f2c437924..a59ee7c5d 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -677,11 +677,14 @@ end function _instance:toolchains() local toolchains = self._TOOLCHAINS if toolchains == nil then + local project = package._project() for _, name in ipairs(table.wrap(self:config("toolchains"))) do - local toolchain_opt = {plat = self:plat(), arch = self:arch()} + local toolchain_opt = project and project.extraconf("target.toolchains", name) or {} + toolchain_opt.plat = self:plat() + toolchain_opt.arch = self:arch() local toolchain_inst, errors = toolchain.load(name, toolchain_opt) - if not toolchain_inst and os.isfile(os.projectfile()) then - toolchain_inst = require("base/project").toolchain(name, toolchain_opt) + if not toolchain_inst and project then + toolchain_inst = project.toolchain(name, toolchain_opt) end if not toolchain_inst then os.raise(errors) @@ -1550,13 +1553,23 @@ function package._memcache() return memcache.cache("core.base.package") end +-- get project +function package._project() + local project = package._PROJECT + if not project then + if os.isfile(os.projectfile()) then + project = require("project/project") + end + end + return project +end + -- get global target platform of package function package._target_plat() local plat = package._memcache():get("target_plat") if plat == nil then - if not plat and os.isfile(os.projectfile()) then - local project = require("project/project") - local targetplat_root = project.get("target.plat") + if not plat and package._project() then + local targetplat_root = package._project().get("target.plat") if targetplat_root then plat = targetplat_root end @@ -1573,9 +1586,8 @@ end function package._target_arch() local arch = package._memcache():get("target_arch") if arch == nil then - if not arch and os.isfile(os.projectfile()) then - local project = require("project/project") - local targetarch_root = project.get("target.arch") + if not arch and package._project() then + local targetarch_root = package._project().get("target.arch") if targetarch_root then arch = targetarch_root end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index aa2c36ff2..e1e328914 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -194,10 +194,8 @@ function project._load(force, disable_filter) end -- save the root info - for name, value in pairs(rootinfo_target:info()) do - rootinfo:set("target." .. name, value) - end project._memcache():set("rootinfo", rootinfo) + project._memcache():set("rootinfo_target", rootinfo_target) -- leave the project directory oldir, errors = os.cd(oldir) @@ -844,12 +842,30 @@ function project.filelock() return filelock, errors end --- get the project info from the given name +-- get the root configuration function project.get(name) - local rootinfo = project._memcache():get("rootinfo") + local rootinfo + if name and name:startswith("target.") then + name = name:sub(8) + rootinfo = project._memcache():get("rootinfo_target") + else + rootinfo = project._memcache():get("rootinfo") + end return rootinfo and rootinfo:get(name) or nil end +-- get the root extra configuration +function project.extraconf(name, item, key) + local rootinfo + if name and name:startswith("target.") then + name = name:sub(8) + rootinfo = project._memcache():get("rootinfo_target") + else + rootinfo = project._memcache():get("rootinfo") + end + return rootinfo and rootinfo:extraconf(name, item, key) or nil +end + -- get the project name function project.name() local name = project.get("project") diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 3d36e7463..52f38e68c 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -37,6 +37,7 @@ local import = require("sandbox/modules/import") -- export some readonly interfaces sandbox_core_project.get = project.get +sandbox_core_project.extraconf = project.extraconf sandbox_core_project.rule = project.rule sandbox_core_project.rules = project.rules sandbox_core_project.toolchain = project.toolchain |
