diff options
| author | ruki <[email protected]> | 2021-02-08 23:24:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-02-08 23:24:25 +0800 |
| commit | b4420e51c372cd46367852a354855555b044b21c (patch) | |
| tree | d146572d440f815dccfc0df938b7b60c50e800bd /xmake/core/tool/toolchain.lua | |
| parent | 21f54de18ca93ef952e5c5711fa491330cf9f49f (diff) | |
support toolchain@packages syntax
Diffstat (limited to 'xmake/core/tool/toolchain.lua')
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index cd71245bf..ee3412f07 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -274,8 +274,8 @@ function _instance:packages() local packages = self._PACKAGES if packages == nil then local project = require("project/project") - -- we will get packages from `set_toolchains("", {packages})` or `toolchain().add_packages()` - for _, pkgname in ipairs(table.wrap(self:config("packages") or self:info():get("packages"))) do + -- we will get packages from `set_toolchains("foo", {packages})` or `set_toolchains("foo@packages")` + for _, pkgname in ipairs(table.wrap(self:config("packages"))) do local requires = project.requires() if requires then local pkginfo = requires[pkgname] @@ -456,6 +456,24 @@ function toolchain._cachekey(name, opt) return cachekey end +-- parse toolchain and package name +-- +-- format: toolchain@package +-- e.g. "clang@llvm-10", "@muslcc", zig +-- +function toolchain._parsename(name) + local splitinfo = name:split('@', {plain = true, strict = true}) + local toolchain_name = splitinfo[1] + if toolchain_name == "" then + toolchain_name = nil + end + local packages = splitinfo[2] + if packages == "" then + packages = nil + end + return toolchain_name or packages, packages +end + -- get toolchain apis function toolchain.apis() return @@ -467,10 +485,8 @@ function toolchain.apis() , "toolchain.set_bindir" , "toolchain.set_sdkdir" , "toolchain.set_archs" - , "toolchain.set_packages" , "toolchain.set_homepage" , "toolchain.set_description" - , "toolchain.add_packages" } , keyvalues = { @@ -502,8 +518,13 @@ end -- load toolchain function toolchain.load(name, opt) - -- init cache key + -- get toolchain name and packages opt = opt or {} + local packages + name, packages = toolchain._parsename(name) + opt.packages = opt.packages or packages + + -- get cache key opt.plat = opt.plat or config.get("plat") or os.host() opt.arch = opt.arch or config.get("arch") or os.arch() local cachekey = toolchain._cachekey(name, opt) @@ -556,8 +577,13 @@ end -- load toolchain from the give toolchain info function toolchain.load_withinfo(name, info, opt) - -- init cache key + -- get toolchain name and packages opt = opt or {} + local packages + name, packages = toolchain._parsename(name) + opt.packages = opt.packages or packages + + -- get cache key opt.plat = opt.plat or config.get("plat") or os.host() opt.arch = opt.arch or config.get("arch") or os.arch() local cachekey = toolchain._cachekey(name, opt) |
