diff options
| author | ruki <[email protected]> | 2020-06-21 19:59:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-06-21 19:59:25 +0800 |
| commit | 47dc42384030e04d7eabf8eda2bb58a72dad4b23 (patch) | |
| tree | 3f5397174d81cbafdd29ffb5c412c5a2821117fe | |
| parent | 24bb3a42898069d28b4713d73d95c3f158eeaed3 (diff) | |
improve target
| -rw-r--r-- | xmake/core/platform/platform.lua | 20 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 34 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/platform/platform.lua | 24 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 13 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_library.lua | 2 |
5 files changed, 56 insertions, 37 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index b15a4b4c7..5f75a7588 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -492,8 +492,8 @@ function platform.load(plat, arch) end -- get the given platform configuration -function platform.get(name, plat) - local instance, errors = platform.load(plat) +function platform.get(name, plat, arch) + local instance, errors = platform.load(plat, arch) if instance then return instance:get(name) else @@ -544,8 +544,8 @@ function platform.tool(toolkind, plat, arch) end -- get the given tool configuration -function platform.toolconfig(name, plat) - local instance, errors = platform.load(plat) +function platform.toolconfig(name, plat, arch) + local instance, errors = platform.load(plat, arch) if instance then return instance:toolconfig(name) else @@ -604,20 +604,20 @@ function platform.toolchains() end -- get the platform os -function platform.os(plat) - return platform.get("os", plat) +function platform.os(plat, arch) + return platform.get("os", plat, arch) end -- get the platform archs -function platform.archs(plat) - return platform.get("archs", plat) +function platform.archs(plat, arch) + return platform.get("archs", plat, arch) end -- get the format of the given target kind for platform -function platform.format(targetkind) +function platform.format(targetkind, plat, arch) -- get platform instance - local instance, errors = platform.load(plat) + local instance, errors = platform.load(plat, arch) if not instance then os.raise(errors) end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 4e7f50a02..14409fec4 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -454,6 +454,19 @@ function _instance:arch() return self:get("arch") or config.get("arch") or os.arch() end +-- get the platform instance +function _instance:platform() + local platform_inst = self._PLATFORM + if platform_inst == nil then + platform_inst, errors = platform.load(self:plat(), self:arch()) + if not platform_inst then + os.raise(errors) + end + self._PLATFORM = platform_inst + end + return platform_inst +end + -- get the cache key function _instance:cachekey() return string.format("%s_%d", tostring(self), self._CACHEID) @@ -903,7 +916,7 @@ function _instance:targetfile() end -- make the target file name and attempt to use the format of linker first - local filename = self:get("filename") or target.filename(self:basename(), targetkind, self:linker():format(targetkind)) + local filename = self:get("filename") or target.filename(self:basename(), targetkind, {plat = self:plat(), arch = self:arch(), format = self:linker():format(targetkind)}) assert(filename) -- make the target file path @@ -918,7 +931,7 @@ function _instance:symbolfile() assert(targetdir and type(targetdir) == "string") -- the symbol file name - local filename = target.filename(self:basename(), "symbol") + local filename = target.filename(self:basename(), "symbol", {plat = self:plat(), arch = self:arch()}) assert(filename) -- make the symbol file path @@ -1145,7 +1158,7 @@ end -- get object file from source file function _instance:objectfile(sourcefile) - return self:autogenfile(sourcefile, {rootdir = self:objectdir(), filename = target.filename(path.filename(sourcefile), "object")}) + return self:autogenfile(sourcefile, {rootdir = self:objectdir(), filename = target.filename(path.filename(sourcefile), "object", {plat = self:plat(), arch = self:arch()})}) end -- get the object files @@ -1684,11 +1697,7 @@ end function _instance:toolchains() local toolchains = self._TOOLCHAINS if toolchains == nil then - local instance, errors = platform.load(self:plat(), self:arch()) - if not instance then - os.raise(errors) - end - toolchains = instance:toolchains() + toolchains = self:platform():toolchains() self._TOOLCHAINS = toolchains end return toolchains @@ -1899,13 +1908,14 @@ function target.apis() end -- get the filename from the given target name and kind -function target.filename(targetname, targetkind, targetformat) +function target.filename(targetname, targetkind, opt) -- check + opt = opt or {} assert(targetname and targetkind) -- make filename by format - local format = targetformat or platform.format(targetkind) + local format = opt.format or platform.format(targetkind, opt.plat, opt.arch) return format and (format:gsub("%$%(name%)", targetname)) or targetname end @@ -1918,9 +1928,9 @@ function target.linkname(filename) if count == 0 and config.is_plat("mingw") then -- for the mingw platform, it is compatible with the libxxx.a and xxx.lib local formats = {static = "lib$(name).a", shared = "lib$(name).so"} - linkname, count = filename:gsub(target.filename("__pattern__", "static", formats["static"]):gsub("%.", "%%."):gsub("__pattern__", "(.+)") .. "$", "%1") + linkname, count = filename:gsub(target.filename("__pattern__", "static", {format = formats["static"]}):gsub("%.", "%%."):gsub("__pattern__", "(.+)") .. "$", "%1") if count == 0 then - linkname, count = filename:gsub(target.filename("__pattern__", "shared", formats["shared"]):gsub("%.", "%%."):gsub("__pattern__", "(.+)") .. "$", "%1") + linkname, count = filename:gsub(target.filename("__pattern__", "shared", {format = formats["shared"]}):gsub("%.", "%%."):gsub("__pattern__", "(.+)") .. "$", "%1") end end return count > 0 and linkname or nil diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua index d9730f830..627e4c02c 100644 --- a/xmake/core/sandbox/modules/import/core/platform/platform.lua +++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua @@ -26,18 +26,18 @@ local platform = require("platform/platform") local raise = require("sandbox/modules/raise") -- load the current platform -function sandbox_core_platform.load(plat) +function sandbox_core_platform.load(plat, arch) -- load the platform configure - local ok, errors = platform.load(plat) + local ok, errors = platform.load(plat, arch) if not ok then raise(errors) end end -- get the platform os -function sandbox_core_platform.os() - return platform.os() +function sandbox_core_platform.os(plat, arch) + return platform.os(plat, arch) end -- get the all platforms @@ -51,26 +51,26 @@ function sandbox_core_platform.toolchains() end -- get the all architectures for the given platform -function sandbox_core_platform.archs(plat) - return platform.archs(plat) +function sandbox_core_platform.archs(plat, arch) + return platform.archs(plat, arch) end -- get the current platform configuration -function sandbox_core_platform.get(name, plat) - return platform.get(name, plat) +function sandbox_core_platform.get(name, plat, arch) + return platform.get(name, plat, arch) end -- get the platform tool from the kind -- -- e.g. cc, cxx, mm, mxx, as, ar, ld, sh, .. -- -function sandbox_core_platform.tool(toolkind) - return platform.tool(toolkind) +function sandbox_core_platform.tool(toolkind, plat, arch) + return platform.tool(toolkind, plat, arch) end -- get the current platform tool configuration -function sandbox_core_platform.toolconfig(name, plat) - return platform.toolconfig(name, plat) +function sandbox_core_platform.toolconfig(name, plat, arch) + return platform.toolconfig(name, plat, arch) end -- return module diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 7075a86bc..b89c19f93 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -121,8 +121,17 @@ function sandbox_core_project.check() for _, target in pairs(targets) do if target:get("enabled") ~= false and (target:get("toolchains") or target:plat() ~= config.get("plat")) then for _, toolchain_inst in pairs(target:toolchains()) do - if not toolchain_inst:check() then - raise("toolchain(\"%s\"): not found!", toolchain_inst:name()) + -- check toolchains for `target/set_toolchains()` + if target:get("toolchains") then + if not toolchain_inst:check() then + raise("toolchain(\"%s\"): not found!", toolchain_inst:name()) + end + else + -- check platform toolchains for `target/set_plat()` + local ok, errors = target:platform():check() + if not ok then + raise(errors) + end end end end diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_library.lua b/xmake/core/sandbox/modules/import/lib/detect/find_library.lua index c277364bb..2b4f9996a 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_library.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_library.lua @@ -67,7 +67,7 @@ function sandbox_lib_detect_find_library.main(names, pathes, opt) if not filepath and config.is_plat("mingw") then -- for the mingw platform, it is compatible with the libxxx.a and xxx.lib local formats = {static = "lib$(name).a", shared = "lib$(name).so"} - filepath = find_file(target.filename(name, kind, formats[kind]), pathes, opt) + filepath = find_file(target.filename(name, kind, {format = formats[kind]}), pathes, opt) end if filepath then local filename = path.filename(filepath) |
