diff options
| author | ruki <[email protected]> | 2021-07-20 22:47:58 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-07-20 22:47:58 +0800 |
| commit | 801cc4d75f3aee6f845f69e9be7c55d70614071c (patch) | |
| tree | 2d99f35493aa1f63e5335fa6ca5dae31dbf7b2fb | |
| parent | 4451461655f1f725aa1667a9287fb9a0367c291b (diff) | |
set allowed modes and archs
| -rw-r--r-- | xmake/actions/config/main.lua | 48 | ||||
| -rw-r--r-- | xmake/actions/config/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/private/detect/find_platform.lua | 53 |
4 files changed, 81 insertions, 27 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 68f8ab531..d96f32a9e 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -191,6 +191,47 @@ function _config_targets(targetname) end end +-- find default mode +function _find_default_mode() + local mode = config.mode() + if not mode then + local allowedmodes = table.wrap(project.get("allowedmodes")) + if #allowedmodes > 0 then + mode = allowedmodes[1] + end + if not mode then + mode = "release" + end + config.set("mode", mode) + end + return mode +end + +-- check configs +function _check_configs() + -- check allowed modes + local mode = config.mode() + local allowedmodes = table.wrap(project.get("allowedmodes")) + if #allowedmodes > 0 then + local allowedmodes_set = hashset.from(allowedmodes) + if not allowedmodes_set:has(mode) then + local allowedmodes_str = table.concat(allowedmodes, ", ") + raise("`%s` is not a valid complation mode for this project, please use one of %s", mode, allowedmodes_str) + end + end + + -- check allowed archs + local arch = config.arch() + local allowedarchs = table.wrap(project.get("allowedarchs")) + if #allowedarchs > 0 then + local allowedarchs_set = hashset.from(allowedarchs) + if not allowedarchs_set:has(arch) then + local allowedarchs_str = table.concat(allowedarchs, ", ") + raise("`%s` is not a valid complation arch for this project, please use one of %s", arch, allowedarchs_str) + end + end +end + -- export configs function _export_configs() local exportfile = option.get("export") @@ -309,6 +350,10 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) end end + -- find default mode + local mode = _find_default_mode() + assert(mode == config.mode()) + -- find default platform and save to configuration local plat, arch = find_platform({global = true}) assert(plat == config.plat()) @@ -382,6 +427,9 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) config.dump() end + -- check configs + _check_configs() + -- export configs if option.get("export") then _export_configs() diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 6b58698d6..c34f68708 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -110,7 +110,7 @@ task("config") end return archset:to_array() end } - , {'m', "mode", "kv", "release" , "Compile for the given mode." + , {'m', "mode", "kv", "auto" , "Compile for the given mode." , values = function (complete) if complete then local modes = (try { function() diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 9bdb4ca4d..5bda50f05 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -650,8 +650,9 @@ function project.apis() { -- set_xxx "set_project" - , "set_modes" -- TODO deprecated , "set_description" + , "set_allowedmodes" + , "set_allowedarchs" -- add_xxx , "add_requires" , "add_requireconfs" @@ -1081,7 +1082,7 @@ end -- get the project modes function project.modes() - local modes = project.get("modes") or {} + local modes = project.get("allowedmodes") or {} for _, target in pairs(table.wrap(project.targets())) do for _, rule in ipairs(target:orderules()) do local name = rule:name() diff --git a/xmake/modules/private/detect/find_platform.lua b/xmake/modules/private/detect/find_platform.lua index 590ff9b11..317d11ce9 100644 --- a/xmake/modules/private/detect/find_platform.lua +++ b/xmake/modules/private/detect/find_platform.lua @@ -20,6 +20,7 @@ -- imports import("core.project.config") +import("core.project.project") import("detect.sdks.find_cross_toolchain") -- find platform @@ -81,28 +82,30 @@ end function _find_arch(plat, arch) arch = arch or config.get("arch") if not arch then - if plat == "android" then - arch = "armeabi-v7a" - elseif plat == "iphoneos" or plat == "appletvos" then - arch = "arm64" - elseif plat == "watchos" then - arch = "armv7k" - elseif plat == "wasm" then - arch = "wasm32" - elseif plat == "mingw" then - local mingw_chost = nil - if is_subhost("msys") then - mingw_chost = os.getenv("MINGW_CHOST") - end - if mingw_chost == "i686-w64-mingw32" then - arch = "i386" + if not arch then + if plat == "android" then + arch = "armeabi-v7a" + elseif plat == "iphoneos" or plat == "appletvos" then + arch = "arm64" + elseif plat == "watchos" then + arch = "armv7k" + elseif plat == "wasm" then + arch = "wasm32" + elseif plat == "mingw" then + local mingw_chost = nil + if is_subhost("msys") then + mingw_chost = os.getenv("MINGW_CHOST") + end + if mingw_chost == "i686-w64-mingw32" then + arch = "i386" + else + arch = "x86_64" + end + elseif plat == "cross" then + arch = _find_arch_from_cross() else - arch = "x86_64" + arch = os.subarch() end - elseif plat == "cross" then - arch = _find_arch_from_cross() - else - arch = os.subarch() end end return arch @@ -126,17 +129,19 @@ end -- function main(opt) - -- find plat and arch + -- find platform opt = opt or {} local plat = _find_plat(opt.plat) - local arch = _find_arch(plat, opt.arch) - - -- save the local configuration if be global if opt.global then if not opt.plat and not config.get("plat") then config.set("plat", plat) cprint("checking for platform ... ${color.success}%s", plat) end + end + + -- find architecture + local arch = _find_arch(plat, opt.arch) + if opt.global then if not opt.arch and not config.get("arch") then config.set("arch", arch) cprint("checking for architecture ... ${color.success}%s", arch) |
