From 181d5cd4f96ee5975427d7f92efe71625ada3ac1 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:47:15 +0800 Subject: add custom toolchain support --- tests/apis/custom_toolchain/src/foo.cpp | 5 ++++ tests/apis/custom_toolchain/src/foo.h | 16 +++++++++++++ tests/apis/custom_toolchain/src/test.cpp | 5 ++++ .../custom_toolchain/toolchains/my-c6000/xmake.lua | 27 ++++++++++++++++++++++ tests/apis/custom_toolchain/xmake.lua | 15 ++++++++++++ tests/apis/set_toolchains/src/foo.cpp | 5 ++++ tests/apis/set_toolchains/src/foo.h | 16 +++++++++++++ tests/apis/set_toolchains/src/interface.cpp | 6 ----- tests/apis/set_toolchains/src/interface.h | 16 ------------- tests/apis/set_toolchains/src/test.cpp | 7 +++--- tests/apis/set_toolchains/xmake.lua | 6 +---- 11 files changed, 93 insertions(+), 31 deletions(-) create mode 100644 tests/apis/custom_toolchain/src/foo.cpp create mode 100644 tests/apis/custom_toolchain/src/foo.h create mode 100644 tests/apis/custom_toolchain/src/test.cpp create mode 100644 tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua create mode 100644 tests/apis/custom_toolchain/xmake.lua create mode 100644 tests/apis/set_toolchains/src/foo.cpp create mode 100644 tests/apis/set_toolchains/src/foo.h delete mode 100644 tests/apis/set_toolchains/src/interface.cpp delete mode 100644 tests/apis/set_toolchains/src/interface.h diff --git a/tests/apis/custom_toolchain/src/foo.cpp b/tests/apis/custom_toolchain/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/tests/apis/custom_toolchain/src/foo.cpp @@ -0,0 +1,5 @@ +#include "foo.h" + +int add(int a, int b) { + return a + b; +} diff --git a/tests/apis/custom_toolchain/src/foo.h b/tests/apis/custom_toolchain/src/foo.h new file mode 100644 index 000000000..4a41e9597 --- /dev/null +++ b/tests/apis/custom_toolchain/src/foo.h @@ -0,0 +1,16 @@ +#ifdef __cplusplus +extern "C" { +#endif + +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +int add(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/tests/apis/custom_toolchain/src/test.cpp b/tests/apis/custom_toolchain/src/test.cpp new file mode 100644 index 000000000..7cdb7d93f --- /dev/null +++ b/tests/apis/custom_toolchain/src/test.cpp @@ -0,0 +1,5 @@ +#include "foo.h" + +int main(int argc, char** argv) { + return add(1, 2); +} diff --git a/tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua b/tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua new file mode 100644 index 000000000..8298b33c9 --- /dev/null +++ b/tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua @@ -0,0 +1,27 @@ +toolchain("my-c6000") + set_kind("standalone") + set_homepage("https://www.ti.com") + set_description("TI-CGT C6000 compiler") + + set_toolset("cc", "cl6x") + set_toolset("cxx", "cl6x") + set_toolset("ld", "cl6x") + set_toolset("sh", "cl6x") + set_toolset("ar", "ar6x") + set_toolset("strip", "strip6x") + set_toolset("as", "cl6x") + + on_check(function (toolchain) + return import("lib.detect.find_tool")("cl6x") + end) + + on_load(function (toolchain) + local march = "-mv64+" + if march then + toolchain:add("cxflags", march) + toolchain:add("mxflags", march) + toolchain:add("asflags", march) + toolchain:add("ldflags", march) + toolchain:add("shflags", march) + end + end) diff --git a/tests/apis/custom_toolchain/xmake.lua b/tests/apis/custom_toolchain/xmake.lua new file mode 100644 index 000000000..acd68d4ad --- /dev/null +++ b/tests/apis/custom_toolchain/xmake.lua @@ -0,0 +1,15 @@ +includes("toolchains/my-c6000") +add_rules("mode.debug", "mode.release") + +set_toolchains("my-c6000") + +target("test") + set_kind("static") + add_files("src/foo.cpp") + +target("demo") + set_kind("binary") + add_deps("test") + add_files("src/test.cpp") + + diff --git a/tests/apis/set_toolchains/src/foo.cpp b/tests/apis/set_toolchains/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/tests/apis/set_toolchains/src/foo.cpp @@ -0,0 +1,5 @@ +#include "foo.h" + +int add(int a, int b) { + return a + b; +} diff --git a/tests/apis/set_toolchains/src/foo.h b/tests/apis/set_toolchains/src/foo.h new file mode 100644 index 000000000..4a41e9597 --- /dev/null +++ b/tests/apis/set_toolchains/src/foo.h @@ -0,0 +1,16 @@ +#ifdef __cplusplus +extern "C" { +#endif + +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +int add(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/tests/apis/set_toolchains/src/interface.cpp b/tests/apis/set_toolchains/src/interface.cpp deleted file mode 100644 index 598d07560..000000000 --- a/tests/apis/set_toolchains/src/interface.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "interface.h" - -int add(int a, int b) -{ - return a + b; -} diff --git a/tests/apis/set_toolchains/src/interface.h b/tests/apis/set_toolchains/src/interface.h deleted file mode 100644 index 4a41e9597..000000000 --- a/tests/apis/set_toolchains/src/interface.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifdef __cplusplus -extern "C" { -#endif - -/*! calculate add(a, b) - * - * @param a the first argument - * @param b the second argument - * - * @return the result - */ -int add(int a, int b); - -#ifdef __cplusplus -} -#endif diff --git a/tests/apis/set_toolchains/src/test.cpp b/tests/apis/set_toolchains/src/test.cpp index 72e03272b..ed1924789 100644 --- a/tests/apis/set_toolchains/src/test.cpp +++ b/tests/apis/set_toolchains/src/test.cpp @@ -1,10 +1,9 @@ -#include "interface.h" +#include "foo.h" #include using namespace std; -int main(int argc, char** argv) -{ - cout << "add(1, 2) = " << add(1, 2) << endl; +int main(int argc, char** argv) { + cout << "add(1, 2) = " << add(1, 2) << endl; return 0; } diff --git a/tests/apis/set_toolchains/xmake.lua b/tests/apis/set_toolchains/xmake.lua index 9db80f107..75f866fbd 100644 --- a/tests/apis/set_toolchains/xmake.lua +++ b/tests/apis/set_toolchains/xmake.lua @@ -1,10 +1,6 @@ --- define toolchain toolchain("myclang") - - -- mark as standalone toolchain set_kind("standalone") - -- set toolset set_toolset("cc", "clang") set_toolset("cxx", "clang", "clang++") set_toolset("ld", "clang++", "clang") @@ -23,7 +19,7 @@ add_rules("mode.debug", "mode.release") target("test") set_kind("static") - add_files("src/interface.cpp") + add_files("src/foo.cpp") set_toolset("ar", "ar") target("demo") -- cgit v1.3.1 From 2d3944ab6162717fc252483351705230b5dd773e Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:47:46 +0800 Subject: remove comments --- tests/apis/custom_toolchain/src/foo.h | 9 +-------- tests/apis/set_toolchains/src/foo.h | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/tests/apis/custom_toolchain/src/foo.h b/tests/apis/custom_toolchain/src/foo.h index 4a41e9597..d2506bca9 100644 --- a/tests/apis/custom_toolchain/src/foo.h +++ b/tests/apis/custom_toolchain/src/foo.h @@ -2,14 +2,7 @@ extern "C" { #endif -/*! calculate add(a, b) - * - * @param a the first argument - * @param b the second argument - * - * @return the result - */ -int add(int a, int b); +int add(int a, int b); #ifdef __cplusplus } diff --git a/tests/apis/set_toolchains/src/foo.h b/tests/apis/set_toolchains/src/foo.h index 4a41e9597..d2506bca9 100644 --- a/tests/apis/set_toolchains/src/foo.h +++ b/tests/apis/set_toolchains/src/foo.h @@ -2,14 +2,7 @@ extern "C" { #endif -/*! calculate add(a, b) - * - * @param a the first argument - * @param b the second argument - * - * @return the result - */ -int add(int a, int b); +int add(int a, int b); #ifdef __cplusplus } -- cgit v1.3.1 From db6074a3f94d5af4bd79ecfbf6d58f7ede2bf8c7 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:50:04 +0800 Subject: update comments --- tests/apis/custom_toolchain/xmake.lua | 2 +- xmake/core/platform/platform.lua | 8 -------- xmake/core/project/project.lua | 38 +++++++++++++++++++++++------------ xmake/core/tool/toolchain.lua | 9 +++++++++ 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/tests/apis/custom_toolchain/xmake.lua b/tests/apis/custom_toolchain/xmake.lua index acd68d4ad..dc15f1a05 100644 --- a/tests/apis/custom_toolchain/xmake.lua +++ b/tests/apis/custom_toolchain/xmake.lua @@ -1,7 +1,7 @@ -includes("toolchains/my-c6000") add_rules("mode.debug", "mode.release") set_toolchains("my-c6000") +add_toolchaindirs("toolchains") target("test") set_kind("static") diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index a58d225e5..6778596d0 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -397,27 +397,19 @@ end -- get platform directories function platform.directories() - - -- init directories local dirs = platform._DIRS or { path.join(global.directory(), "platforms") , path.join(os.programdir(), "platforms") } - - -- save directories to cache platform._DIRS = dirs return dirs end -- add platform directories function platform.add_directories(...) - - -- add directories local dirs = platform.directories() for _, dir in ipairs({...}) do table.insert(dirs, 1, dir) end - - -- remove unique directories platform._DIRS = table.unique(dirs) end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 43271c7b0..7b42d47ea 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -202,6 +202,17 @@ function project._api_add_platformdirs(interp, ...) end end +-- add toolchain directories +function project._api_add_toolchaindirs(interp, ...) + local scriptdir = project.interpreter():scriptdir() + for _, dir in ipairs({...}) do + if not path.is_absolute(dir) then + dir = path.absolute(dir, scriptdir) + end + toolchain.add_directories(dir) + end +end + -- load the project file function project._load(force, disable_filter) @@ -642,22 +653,23 @@ function project.apis() , custom = { -- is_xxx - {"is_os", project._api_is_os } - , {"is_kind", project._api_is_kind } - , {"is_arch", project._api_is_arch } - , {"is_mode", project._api_is_mode } - , {"is_plat", project._api_is_plat } - , {"is_cross", project._api_is_cross } - , {"is_config", project._api_is_config } + {"is_os", project._api_is_os } + , {"is_kind", project._api_is_kind } + , {"is_arch", project._api_is_arch } + , {"is_mode", project._api_is_mode } + , {"is_plat", project._api_is_plat } + , {"is_cross", project._api_is_cross } + , {"is_config", project._api_is_config } -- get_xxx - , {"get_config", project._api_get_config } + , {"get_config", project._api_get_config } -- has_xxx - , {"has_config", project._api_has_config } - , {"has_package", project._api_has_package } + , {"has_config", project._api_has_config } + , {"has_package", project._api_has_package } -- add_xxx - , {"add_moduledirs", project._api_add_moduledirs } - , {"add_plugindirs", project._api_add_plugindirs } - , {"add_platformdirs", project._api_add_platformdirs } + , {"add_moduledirs", project._api_add_moduledirs } + , {"add_plugindirs", project._api_add_plugindirs } + , {"add_platformdirs", project._api_add_platformdirs } + , {"add_toolchaindirs", project._api_add_toolchaindirs } } } end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index a19413d34..1085df198 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -640,6 +640,15 @@ function toolchain.directories() return dirs end +-- add toolchain directories +function toolchain.add_directories(...) + local dirs = toolchain.directories() + for _, dir in ipairs({...}) do + table.insert(dirs, 1, dir) + end + toolchain._DIRS = table.unique(dirs) +end + -- load toolchain function toolchain.load(name, opt) -- cgit v1.3.1 From 512fe920b09fed3611a41227ba09ad92c40bc6b3 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:50:30 +0800 Subject: improve my-c6000 --- tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua b/tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua index 8298b33c9..2de2275a7 100644 --- a/tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua +++ b/tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua @@ -16,12 +16,5 @@ toolchain("my-c6000") end) on_load(function (toolchain) - local march = "-mv64+" - if march then - toolchain:add("cxflags", march) - toolchain:add("mxflags", march) - toolchain:add("asflags", march) - toolchain:add("ldflags", march) - toolchain:add("shflags", march) - end + toolchain:add("cxflags", "-Dxxx") end) -- cgit v1.3.1 From 4758d5fb50863ebefc7c7cdb3d3bf3670843cd82 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:51:41 +0800 Subject: get toolchain dirs --- xmake/core/sandbox/modules/import/core/tool/toolchain.lua | 3 ++- xmake/modules/lib/detect/find_tool.lua | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/xmake/core/sandbox/modules/import/core/tool/toolchain.lua b/xmake/core/sandbox/modules/import/core/tool/toolchain.lua index 46bd9fb1d..48867300e 100644 --- a/xmake/core/sandbox/modules/import/core/tool/toolchain.lua +++ b/xmake/core/sandbox/modules/import/core/tool/toolchain.lua @@ -28,7 +28,8 @@ local project = require("project/project") local raise = require("sandbox/modules/raise") -- inherit some builtin interfaces -sandbox_core_tool_toolchain.apis = toolchain.apis +sandbox_core_tool_toolchain.apis = toolchain.apis +sandbox_core_tool_toolchain.directories = toolchain.directories -- get all toolchains list function sandbox_core_tool_toolchain.list() diff --git a/xmake/modules/lib/detect/find_tool.lua b/xmake/modules/lib/detect/find_tool.lua index e761cb9a7..8b5892483 100644 --- a/xmake/modules/lib/detect/find_tool.lua +++ b/xmake/modules/lib/detect/find_tool.lua @@ -23,9 +23,13 @@ import("lib.detect.find_program") import("lib.detect.find_programver") import("lib.detect.find_toolname") import("core.base.semver") +import("core.tool.toolchain") -- find tool from modules function _find_from_modules(name, opt) + -- TODO + print(toolchain.directories()) + local find_tool = import("detect.tools.find_" .. name, {try = true}) if find_tool then local program, version, toolname = find_tool(opt) -- cgit v1.3.1 From 04c8ea3b4ea7dca2bb60c64057c6e9d43862696c Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:53:59 +0800 Subject: add cl6x modules --- .../toolchains/modules/core/tools/ar6x.lua | 27 +++ .../toolchains/modules/core/tools/cl6x.lua | 207 +++++++++++++++++++++ .../modules/detect/tools/cl6x/has_flags.lua | 121 ++++++++++++ .../toolchains/modules/detect/tools/find_ar6x.lua | 58 ++++++ .../toolchains/modules/detect/tools/find_cl6x.lua | 48 +++++ tests/apis/custom_toolchain/xmake.lua | 4 +- xmake/core/project/project.lua | 12 -- .../sandbox/modules/import/core/tool/toolchain.lua | 3 +- xmake/core/tool/toolchain.lua | 9 - xmake/modules/lib/detect/find_tool.lua | 3 - 10 files changed, 465 insertions(+), 27 deletions(-) create mode 100644 tests/apis/custom_toolchain/toolchains/modules/core/tools/ar6x.lua create mode 100644 tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x.lua create mode 100644 tests/apis/custom_toolchain/toolchains/modules/detect/tools/cl6x/has_flags.lua create mode 100644 tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_ar6x.lua create mode 100644 tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_cl6x.lua diff --git a/tests/apis/custom_toolchain/toolchains/modules/core/tools/ar6x.lua b/tests/apis/custom_toolchain/toolchains/modules/core/tools/ar6x.lua new file mode 100644 index 000000000..821b955e3 --- /dev/null +++ b/tests/apis/custom_toolchain/toolchains/modules/core/tools/ar6x.lua @@ -0,0 +1,27 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file ar6x.lua +-- + +inherit("core.tools.ar") + +-- init it +function init(self) + self:set("arflags", "-r") +end + diff --git a/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x.lua b/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x.lua new file mode 100644 index 000000000..f350808da --- /dev/null +++ b/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x.lua @@ -0,0 +1,207 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cl6x.lua +-- + +-- imports +import("core.base.option") +import("core.base.global") +import("core.project.policy") +import("core.language.language") +import("utils.progress") + +-- init it +function init(self) +end + +-- make the symbol flag +function nf_symbol(self, level) + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = _g.symbol_maps + if not maps then + maps = + { + debug = "-g" + } + _g.symbol_maps = maps + end + return maps[level .. '_' .. kind] or maps[level] + end +end + +-- make the optimize flag +function nf_optimize(self, level) + local maps = + { + none = "-O0" + , fast = "-O1" + , faster = "-O2" + , fastest = "-O3" + , smallest = "-m3" + , aggressive = "-O3" + } + return maps[level] +end + +-- make the define flag +function nf_define(self, macro) + return "-D" .. macro +end + +-- make the undefine flag +function nf_undefine(self, macro) + return "-U" .. macro +end + +-- make the includedir flag +function nf_includedir(self, dir) + return {"-I" .. dir} +end + +-- make the sysincludedir flag +function nf_sysincludedir(self, dir) + return nf_includedir(self, dir) +end + +-- make the link flag +function nf_link(self, lib) + if not lib:endswith(".a") and not lib:endswith(".so") then + lib = "lib" .. lib .. ".a" + end + return "-l" .. lib +end + +-- make the syslink flag +function nf_syslink(self, lib) + return nf_link(self, lib) +end + +-- make the linkdir flag +function nf_linkdir(self, dir) + return {"-i" .. path.translate(dir)} +end + +-- make the rpathdir flag +function nf_rpathdir(self, dir, opt) + opt = opt or {} + local extra = opt.extra + if extra and extra.installonly then + return + end + dir = path.translate(dir) + return {"-rpath=" .. dir} +end + +-- make the link arguments list +function linkargv(self, objectfiles, targetkind, targetfile, flags, opt) + local argv = table.join("-z", "--output_file=" .. targetfile, objectfiles, flags) + return self:program(), argv +end + +-- link the target file +-- +-- maybe we need to use os.vrunv() to show link output when enable verbose information +-- @see https://github.com/xmake-io/xmake/discussions/2916 +-- +function link(self, objectfiles, targetkind, targetfile, flags, opt) + opt = opt or {} + os.mkdir(path.directory(targetfile)) + local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags) + if option.get("verbose") then + os.execv(program, argv, {envs = self:runenvs(), shell = opt.shell}) + else + os.vrunv(program, argv, {envs = self:runenvs(), shell = opt.shell}) + end +end + +-- make the compile arguments list +function compargv(self, sourcefile, objectfile, flags) + return self:program(), table.join("-c", "--preproc_with_compile", flags, "--output_file=" .. objectfile, sourcefile) +end + +-- compile the source file +function compile(self, sourcefile, objectfile, dependinfo, flags, opt) + os.mkdir(path.directory(objectfile)) + local depfile = dependinfo and os.tmpfile() or nil + try + { + function () + local compflags = flags + if depfile then + compflags = table.join(compflags, "-ppd=" .. depfile) + end + local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, compflags)) + return (outdata or "") .. (errdata or "") + end, + catch + { + function (errors) + + -- try removing the old object file for forcing to rebuild this source file + os.tryrm(objectfile) + + -- find the start line of error + local lines = tostring(errors):split("\n") + local start = 0 + for index, line in ipairs(lines) do + if line:find("error:", 1, true) or line:find("错误:", 1, true) then + start = index + break + end + end + + -- get 16 lines of errors + if start > 0 or not option.get("verbose") then + if start == 0 then start = 1 end + errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n") + end + + -- raise compiling errors + raise(errors) + end + }, + finally + { + function (ok, warnings) + + -- print some warnings + if warnings and #warnings > 0 and policy.build_warnings(opt) then + if progress.showing_without_scroll() then + print("") + end + cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n')) + end + + -- generate the dependent includes + if depfile and os.isfile(depfile) then + if dependinfo then + dependinfo.depfiles_format = "cl6x" + dependinfo.depfiles = io.readfile(depfile, {continuation = "\\"}) + end + + -- remove the temporary dependent file + os.tryrm(depfile) + end + end + } + } +end + + diff --git a/tests/apis/custom_toolchain/toolchains/modules/detect/tools/cl6x/has_flags.lua b/tests/apis/custom_toolchain/toolchains/modules/detect/tools/cl6x/has_flags.lua new file mode 100644 index 000000000..d18d9b233 --- /dev/null +++ b/tests/apis/custom_toolchain/toolchains/modules/detect/tools/cl6x/has_flags.lua @@ -0,0 +1,121 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from known flags +function _check_from_knownargs(flags, opt, islinker) + local flag = flags[1] + if not islinker then + if flag:startswith("-D") or + flag:startswith("-U") or + flag:startswith("-I") then + return true + end + end +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + local key = "detect.tools.cl6x." .. (islinker and "has_ldflags" or "has_cflags") + local flagskey = opt.program .. "_" .. (opt.programver or "") + local allflags = detectcache:get2(key, flagskey) + if not allflags then + allflags = {} + local arglist = try {function () return os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) end} + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + local flag = flags[1] + return allflags[flag] +end + +-- get extension +function _get_extension(opt) + -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] + return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" + local sourcefile = os.tmpfile("cl6x_has_flags:" .. snippet) .. _get_extension(opt) + if not os.isfile(sourcefile) then + io.writefile(sourcefile, snippet) + end + + -- check flags for linker + local tmpfile = os.tmpfile() + if islinker then + return _try_running(opt.program, table.join(flags, "-z", "--output_file=" .. tmpfile, sourcefile), opt) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-c", "--output_file=" .. tmpfile, sourcefile), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + opt = opt or {} + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if not opt.tryrun then + if _check_from_arglist(flags, opt, islinker) then + return true + end + if _check_from_knownargs(flags, opt, islinker) then + return true + end + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_ar6x.lua b/tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_ar6x.lua new file mode 100644 index 000000000..823a1f220 --- /dev/null +++ b/tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_ar6x.lua @@ -0,0 +1,58 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_ar6x.lua +-- + +-- imports +import("lib.detect.find_program") + +-- check +function _check(program) + + -- make a stub object file + local libraryfile = os.tmpfile() .. ".a" + local objectfile = os.tmpfile() .. ".o" + io.writefile(objectfile, "") + + -- archive it + os.execv(program, {"-r", libraryfile, objectfile}) + + -- remove files + os.rm(objectfile) + os.rm(libraryfile) +end + +-- find ar +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local ar = find_ar6x() +-- local ar, version = find_ar6x({program = "xcrun -sdk macosx g++", version = true}) +-- +-- @endcode +-- +function main(opt) + opt = opt or {} + opt.check = opt.check or _check + return find_program(opt.program or "ar6x", opt) +end + diff --git a/tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_cl6x.lua b/tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_cl6x.lua new file mode 100644 index 000000000..c961326ad --- /dev/null +++ b/tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_cl6x.lua @@ -0,0 +1,48 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_cl6x.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find cl6x +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local cl6x = find_cl6x() +-- local cl6x, version = find_cl6x({program = "cl6x", version = true}) +-- +-- @endcode +-- +function main(opt) + opt = opt or {} + opt.check = "--help" + opt.command = "--help" + local program = find_program(opt.program or "cl6x", opt) + local version = nil + if program and opt.version then + version = find_programver(program, opt) + end + return program, version +end diff --git a/tests/apis/custom_toolchain/xmake.lua b/tests/apis/custom_toolchain/xmake.lua index dc15f1a05..dc772417b 100644 --- a/tests/apis/custom_toolchain/xmake.lua +++ b/tests/apis/custom_toolchain/xmake.lua @@ -1,7 +1,9 @@ add_rules("mode.debug", "mode.release") +add_moduledirs("toolchains/modules") +includes("toolchains/my-c6000") + set_toolchains("my-c6000") -add_toolchaindirs("toolchains") target("test") set_kind("static") diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 7b42d47ea..20b0a171b 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -202,17 +202,6 @@ function project._api_add_platformdirs(interp, ...) end end --- add toolchain directories -function project._api_add_toolchaindirs(interp, ...) - local scriptdir = project.interpreter():scriptdir() - for _, dir in ipairs({...}) do - if not path.is_absolute(dir) then - dir = path.absolute(dir, scriptdir) - end - toolchain.add_directories(dir) - end -end - -- load the project file function project._load(force, disable_filter) @@ -669,7 +658,6 @@ function project.apis() , {"add_moduledirs", project._api_add_moduledirs } , {"add_plugindirs", project._api_add_plugindirs } , {"add_platformdirs", project._api_add_platformdirs } - , {"add_toolchaindirs", project._api_add_toolchaindirs } } } end diff --git a/xmake/core/sandbox/modules/import/core/tool/toolchain.lua b/xmake/core/sandbox/modules/import/core/tool/toolchain.lua index 48867300e..46bd9fb1d 100644 --- a/xmake/core/sandbox/modules/import/core/tool/toolchain.lua +++ b/xmake/core/sandbox/modules/import/core/tool/toolchain.lua @@ -28,8 +28,7 @@ local project = require("project/project") local raise = require("sandbox/modules/raise") -- inherit some builtin interfaces -sandbox_core_tool_toolchain.apis = toolchain.apis -sandbox_core_tool_toolchain.directories = toolchain.directories +sandbox_core_tool_toolchain.apis = toolchain.apis -- get all toolchains list function sandbox_core_tool_toolchain.list() diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 1085df198..a19413d34 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -640,15 +640,6 @@ function toolchain.directories() return dirs end --- add toolchain directories -function toolchain.add_directories(...) - local dirs = toolchain.directories() - for _, dir in ipairs({...}) do - table.insert(dirs, 1, dir) - end - toolchain._DIRS = table.unique(dirs) -end - -- load toolchain function toolchain.load(name, opt) diff --git a/xmake/modules/lib/detect/find_tool.lua b/xmake/modules/lib/detect/find_tool.lua index 8b5892483..fa2b7b3bb 100644 --- a/xmake/modules/lib/detect/find_tool.lua +++ b/xmake/modules/lib/detect/find_tool.lua @@ -27,9 +27,6 @@ import("core.tool.toolchain") -- find tool from modules function _find_from_modules(name, opt) - -- TODO - print(toolchain.directories()) - local find_tool = import("detect.tools.find_" .. name, {try = true}) if find_tool then local program, version, toolname = find_tool(opt) -- cgit v1.3.1 From e71b918b8ece418286f25a291f28521e640875ba Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:54:49 +0800 Subject: add parse deps --- .../modules/private/tools/cl6x/parse_deps.lua | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/apis/custom_toolchain/toolchains/modules/private/tools/cl6x/parse_deps.lua diff --git a/tests/apis/custom_toolchain/toolchains/modules/private/tools/cl6x/parse_deps.lua b/tests/apis/custom_toolchain/toolchains/modules/private/tools/cl6x/parse_deps.lua new file mode 100644 index 000000000..a5d5ecd40 --- /dev/null +++ b/tests/apis/custom_toolchain/toolchains/modules/private/tools/cl6x/parse_deps.lua @@ -0,0 +1,77 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps.lua +-- + +-- imports +import("core.project.config") +import("core.project.project") +import("core.base.hashset") + +-- normailize path of a dependecy +function _normailize_dep(dep, projectdir) + -- escape characters, e.g. \#Qt.Widget_pch.h -> #Qt.Widget_pch.h + -- @see https://github.com/xmake-io/xmake/issues/4134 + -- https://github.com/xmake-io/xmake/issues/4273 + if not is_host("windows") then + dep = dep:gsub("\\(.)", "%1") + end + if path.is_absolute(dep) then + dep = path.translate(dep) + else + dep = path.absolute(dep, projectdir) + end + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) + else + -- we also need to check header files outside project + -- https://github.com/xmake-io/xmake/issues/1154 + return dep + end +end + +-- parse depsfiles from string +-- +-- parse_deps(io.readfile(depfile, {continuation = "\\"})) +-- +-- eg. +-- +-- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.c +-- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.h +-- +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/main.c +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/foo.h +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/bar.h +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/zoo.h +-- +function main(depsdata, opt) + local results = hashset.new() + local projectdir = os.projectdir() + local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first + local plain = {plain = true} + for _, includefile in ipairs(line:split('\n', plain)) do -- it will trim all internal spaces without `{strict = true}` + includefile = includefile:split(": ", plain)[2] + if includefile and #includefile > 0 then + includefile = _normailize_dep(includefile, projectdir) + if includefile then + results:insert(includefile) + end + end + end + return results:to_array() +end -- cgit v1.3.1 From d52893b18d6f837b10a61ac21b52da26238b201f Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:55:00 +0800 Subject: improve xmake.lua --- tests/apis/custom_toolchain/xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/apis/custom_toolchain/xmake.lua b/tests/apis/custom_toolchain/xmake.lua index dc772417b..729f9fd81 100644 --- a/tests/apis/custom_toolchain/xmake.lua +++ b/tests/apis/custom_toolchain/xmake.lua @@ -1,7 +1,7 @@ add_rules("mode.debug", "mode.release") -add_moduledirs("toolchains/modules") includes("toolchains/my-c6000") +add_moduledirs("toolchains/modules") set_toolchains("my-c6000") -- cgit v1.3.1 From d1b1492b07d370f9cf06414490fc489c1dda6ed8 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:57:44 +0800 Subject: move parse_deps.lua --- .../modules/core/tools/cl6x/parse_deps.lua | 77 +++++++++++ .../modules/private/tools/cl6x/parse_deps.lua | 77 ----------- xmake/modules/core/project/depend.lua | 2 +- xmake/modules/core/tools/armcc/parse_deps.lua | 82 ++++++++++++ xmake/modules/core/tools/cl/parse_deps.lua | 96 ++++++++++++++ xmake/modules/core/tools/cl/parse_deps_json.lua | 144 +++++++++++++++++++++ xmake/modules/core/tools/cl/parse_include.lua | 104 +++++++++++++++ xmake/modules/core/tools/cl2000/parse_deps.lua | 23 ++++ xmake/modules/core/tools/cl6x/parse_deps.lua | 77 +++++++++++ xmake/modules/core/tools/cl_json/parse_deps.lua | 144 +++++++++++++++++++++ xmake/modules/core/tools/gcc/parse_deps.lua | 143 ++++++++++++++++++++ xmake/modules/core/tools/rc/parse_deps.lua | 52 ++++++++ xmake/modules/private/tools/armcc/parse_deps.lua | 82 ------------ xmake/modules/private/tools/cl/parse_deps.lua | 96 -------------- xmake/modules/private/tools/cl/parse_deps_json.lua | 144 --------------------- xmake/modules/private/tools/cl/parse_include.lua | 104 --------------- xmake/modules/private/tools/cl2000/parse_deps.lua | 23 ---- xmake/modules/private/tools/cl6x/parse_deps.lua | 77 ----------- xmake/modules/private/tools/cl_json/parse_deps.lua | 144 --------------------- xmake/modules/private/tools/gcc/parse_deps.lua | 143 -------------------- xmake/modules/private/tools/rc/parse_deps.lua | 52 -------- 21 files changed, 943 insertions(+), 943 deletions(-) create mode 100644 tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/parse_deps.lua delete mode 100644 tests/apis/custom_toolchain/toolchains/modules/private/tools/cl6x/parse_deps.lua create mode 100644 xmake/modules/core/tools/armcc/parse_deps.lua create mode 100644 xmake/modules/core/tools/cl/parse_deps.lua create mode 100644 xmake/modules/core/tools/cl/parse_deps_json.lua create mode 100644 xmake/modules/core/tools/cl/parse_include.lua create mode 100644 xmake/modules/core/tools/cl2000/parse_deps.lua create mode 100644 xmake/modules/core/tools/cl6x/parse_deps.lua create mode 100644 xmake/modules/core/tools/cl_json/parse_deps.lua create mode 100644 xmake/modules/core/tools/gcc/parse_deps.lua create mode 100644 xmake/modules/core/tools/rc/parse_deps.lua delete mode 100644 xmake/modules/private/tools/armcc/parse_deps.lua delete mode 100644 xmake/modules/private/tools/cl/parse_deps.lua delete mode 100644 xmake/modules/private/tools/cl/parse_deps_json.lua delete mode 100644 xmake/modules/private/tools/cl/parse_include.lua delete mode 100644 xmake/modules/private/tools/cl2000/parse_deps.lua delete mode 100644 xmake/modules/private/tools/cl6x/parse_deps.lua delete mode 100644 xmake/modules/private/tools/cl_json/parse_deps.lua delete mode 100644 xmake/modules/private/tools/gcc/parse_deps.lua delete mode 100644 xmake/modules/private/tools/rc/parse_deps.lua diff --git a/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/parse_deps.lua b/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/parse_deps.lua new file mode 100644 index 000000000..a5d5ecd40 --- /dev/null +++ b/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/parse_deps.lua @@ -0,0 +1,77 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps.lua +-- + +-- imports +import("core.project.config") +import("core.project.project") +import("core.base.hashset") + +-- normailize path of a dependecy +function _normailize_dep(dep, projectdir) + -- escape characters, e.g. \#Qt.Widget_pch.h -> #Qt.Widget_pch.h + -- @see https://github.com/xmake-io/xmake/issues/4134 + -- https://github.com/xmake-io/xmake/issues/4273 + if not is_host("windows") then + dep = dep:gsub("\\(.)", "%1") + end + if path.is_absolute(dep) then + dep = path.translate(dep) + else + dep = path.absolute(dep, projectdir) + end + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) + else + -- we also need to check header files outside project + -- https://github.com/xmake-io/xmake/issues/1154 + return dep + end +end + +-- parse depsfiles from string +-- +-- parse_deps(io.readfile(depfile, {continuation = "\\"})) +-- +-- eg. +-- +-- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.c +-- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.h +-- +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/main.c +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/foo.h +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/bar.h +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/zoo.h +-- +function main(depsdata, opt) + local results = hashset.new() + local projectdir = os.projectdir() + local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first + local plain = {plain = true} + for _, includefile in ipairs(line:split('\n', plain)) do -- it will trim all internal spaces without `{strict = true}` + includefile = includefile:split(": ", plain)[2] + if includefile and #includefile > 0 then + includefile = _normailize_dep(includefile, projectdir) + if includefile then + results:insert(includefile) + end + end + end + return results:to_array() +end diff --git a/tests/apis/custom_toolchain/toolchains/modules/private/tools/cl6x/parse_deps.lua b/tests/apis/custom_toolchain/toolchains/modules/private/tools/cl6x/parse_deps.lua deleted file mode 100644 index a5d5ecd40..000000000 --- a/tests/apis/custom_toolchain/toolchains/modules/private/tools/cl6x/parse_deps.lua +++ /dev/null @@ -1,77 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file parse_deps.lua --- - --- imports -import("core.project.config") -import("core.project.project") -import("core.base.hashset") - --- normailize path of a dependecy -function _normailize_dep(dep, projectdir) - -- escape characters, e.g. \#Qt.Widget_pch.h -> #Qt.Widget_pch.h - -- @see https://github.com/xmake-io/xmake/issues/4134 - -- https://github.com/xmake-io/xmake/issues/4273 - if not is_host("windows") then - dep = dep:gsub("\\(.)", "%1") - end - if path.is_absolute(dep) then - dep = path.translate(dep) - else - dep = path.absolute(dep, projectdir) - end - if dep:startswith(projectdir) then - return path.relative(dep, projectdir) - else - -- we also need to check header files outside project - -- https://github.com/xmake-io/xmake/issues/1154 - return dep - end -end - --- parse depsfiles from string --- --- parse_deps(io.readfile(depfile, {continuation = "\\"})) --- --- eg. --- --- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.c --- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.h --- --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/main.c --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/foo.h --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/bar.h --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/zoo.h --- -function main(depsdata, opt) - local results = hashset.new() - local projectdir = os.projectdir() - local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first - local plain = {plain = true} - for _, includefile in ipairs(line:split('\n', plain)) do -- it will trim all internal spaces without `{strict = true}` - includefile = includefile:split(": ", plain)[2] - if includefile and #includefile > 0 then - includefile = _normailize_dep(includefile, projectdir) - if includefile then - results:insert(includefile) - end - end - end - return results:to_array() -end diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua index 4f81481bb..05b93acf1 100644 --- a/xmake/modules/core/project/depend.lua +++ b/xmake/modules/core/project/depend.lua @@ -44,7 +44,7 @@ function _get_depfiles_parser(depfiles_format) end local parser = depfiles_parsers[depfiles_format] if parser == nil then - parser = import("private.tools." .. depfiles_format .. ".parse_deps", {anonymous = true}) + parser = import("core.tools." .. depfiles_format .. ".parse_deps", {anonymous = true}) depfiles_parsers[depfiles_format] = parser or false end return parser or nil diff --git a/xmake/modules/core/tools/armcc/parse_deps.lua b/xmake/modules/core/tools/armcc/parse_deps.lua new file mode 100644 index 000000000..afde0a575 --- /dev/null +++ b/xmake/modules/core/tools/armcc/parse_deps.lua @@ -0,0 +1,82 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author smalli +-- @file parse_deps_armcc.lua +-- + +-- imports +import("core.project.project") +import("core.base.hashset") + +-- a placeholder for spaces in path +local space_placeholder = "\001" + +-- normailize path of a dependecy +function _normailize_dep(dep, projectdir) + if path.is_absolute(dep) then + dep = path.translate(dep) + else + dep = path.absolute(dep, projectdir) + end + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) + else + return dep + end +end + +-- parse depsfiles from string +-- +-- parse_deps(io.readfile(depfile, {continuation = "\\"})) +-- +-- eg. +-- build\\.objs\\apps\\cross\\cortex-m3\\release\\APPS\\main.c.o: APPS\\main.c\ +-- build\\.objs\\apps\\cross\\cortex-m3\\release\\APPS\\main.c.o: D:\\Keil533\\ARM\\ARMCC\\bin\\..\\include\\stdarg.h\ +-- build\\.objs\\apps\\cross\\cortex-m3\\release\\APPS\\main.c.o: D:\\Keil533\\ARM\\ARMCC\\bin\\..\\include\\stdio.h\ +-- build\\.objs\\apps\\cross\\cortex-m3\\release\\APPS\\main.c.o: D:\\Keil533\\ARM\\ARMCC\\bin\\..\\include\\string.h\ +-- build\\.objs\\apps\\cross\\cortex-m3\\release\\APPS\\main.c.o: APPS\\main.h\ +-- +-- +function main(depsdata) + local block = 0 + local results = hashset.new() + local projectdir = os.projectdir() + local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first + local plain = {plain = true} + line = line:replace("\\ ", space_placeholder, plain) + for _, includefile in ipairs(line:split('\n', plain)) do + if is_host("windows") and includefile:match("^%w\\:") then + includefile = includefile:replace("\\:", ":", plain) + end + includefile = includefile:replace(space_placeholder, ' ', plain) + local splitinfo = includefile:split(".o:", {plain = true}) + if #splitinfo < 2 then + splitinfo = includefile:split(".obj:", {plain = true}) + end + includefile = splitinfo[2] + if includefile then + includefile = includefile:replace(' ', '', plain) + if #includefile > 0 then + includefile = _normailize_dep(includefile, projectdir) + if includefile then + results:insert(includefile) + end + end + end + end + return results:to_array() +end diff --git a/xmake/modules/core/tools/cl/parse_deps.lua b/xmake/modules/core/tools/cl/parse_deps.lua new file mode 100644 index 000000000..187d655cd --- /dev/null +++ b/xmake/modules/core/tools/cl/parse_deps.lua @@ -0,0 +1,96 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps.lua +-- + +-- imports +import("core.project.project") +import("core.base.hashset") +import("parse_include") +import("core.tool.toolchain") + +-- get $VCInstallDir +function _VCInstallDir() + local VCInstallDir = _g.VCInstallDir + if not VCInstallDir then + local msvc = toolchain.load("msvc") + if msvc then + local vcvars = msvc:config("vcvars") + if vcvars and vcvars.VCInstallDir then + VCInstallDir = vcvars.VCInstallDir + _g.VCInstallDir = VCInstallDir + end + end + end + return VCInstallDir +end + +-- get $WindowsSdkDir +function _WindowsSdkDir() + local WindowsSdkDir = _g.WindowsSdkDir + if not WindowsSdkDir then + local msvc = toolchain.load("msvc") + if msvc then + local vcvars = msvc:config("vcvars") + if vcvars and vcvars.WindowsSdkDir then + WindowsSdkDir = vcvars.WindowsSdkDir + _g.WindowsSdkDir = WindowsSdkDir + end + end + end + return WindowsSdkDir +end + + +-- normailize path of a dependecy +function _normailize_dep(dep, projectdir) + if path.is_absolute(dep) then + dep = path.translate(dep) + else + dep = path.absolute(dep, projectdir) + end + local VCInstallDir = _VCInstallDir() + local WindowsSdkDir = _WindowsSdkDir() + if (VCInstallDir and dep:startswith(VCInstallDir)) or (WindowsSdkDir and dep:startswith(WindowsSdkDir)) then + -- we ignore headerfiles in vc install directory + return + end + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) + else + -- we also need to check header files outside project + -- https://github.com/xmake-io/xmake/issues/1154 + return dep + end +end + +-- parse depsfiles from string +function main(depsdata) + local results = hashset.new() + for _, line in ipairs(depsdata:split("\n", {plain = true})) do + local includefile = parse_include(line:trim()) + if includefile then + includefile = _normailize_dep(includefile, os.projectdir()) + if includefile then + results:insert(includefile) + end + end + end + return results:to_array() +end + diff --git a/xmake/modules/core/tools/cl/parse_deps_json.lua b/xmake/modules/core/tools/cl/parse_deps_json.lua new file mode 100644 index 000000000..50f728815 --- /dev/null +++ b/xmake/modules/core/tools/cl/parse_deps_json.lua @@ -0,0 +1,144 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps_json.lua +-- + +-- imports +import("core.project.project") +import("core.base.hashset") +import("core.base.json") +import("core.tool.toolchain") + +-- get $VCInstallDir +function _VCInstallDir() + local VCInstallDir = _g.VCInstallDir + if not VCInstallDir then + local msvc = toolchain.load("msvc") + if msvc then + local vcvars = msvc:config("vcvars") + if vcvars and vcvars.VCInstallDir then + VCInstallDir = vcvars.VCInstallDir:lower() -- @note we need lower case for json/deps + _g.VCInstallDir = VCInstallDir + end + end + end + return VCInstallDir +end + +-- get $WindowsSdkDir +function _WindowsSdkDir() + local WindowsSdkDir = _g.WindowsSdkDir + if not WindowsSdkDir then + local msvc = toolchain.load("msvc") + if msvc then + local vcvars = msvc:config("vcvars") + if vcvars and vcvars.WindowsSdkDir then + WindowsSdkDir = vcvars.WindowsSdkDir:lower() -- @note we need lower case for json/deps + _g.WindowsSdkDir = WindowsSdkDir + end + end + end + return WindowsSdkDir +end + +-- normailize path of a dependecy +function _normailize_dep(dep, projectdir) + if path.is_absolute(dep) then + dep = path.translate(dep) + else + dep = path.absolute(dep, projectdir) + end + dep = dep:lower() + local VCInstallDir = _VCInstallDir() + local WindowsSdkDir = _WindowsSdkDir() + if (VCInstallDir and dep:startswith(VCInstallDir)) or (WindowsSdkDir and dep:startswith(WindowsSdkDir)) then + -- we ignore headerfiles in vc install directory + return + end + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) + else + -- we also need to check header files outside project + -- https://github.com/xmake-io/xmake/issues/1154 + return dep + end +end + +-- parse depsfiles from string +-- +--[[ +{ + "Version": "1.2", + "Data": { + "Source": "c:\users\ruki\desktop\user_headerunit\src\main.cpp", + "ProvidedModule": "", + "Includes": [], + "ImportedModules": [ + { + "Name": "hello", + "BMI": "c:\users\ruki\desktop\user_headerunit\src\hello.ifc" + } + ], + "ImportedHeaderUnits": [ + { + "Header": "c:\users\ruki\desktop\user_headerunit\src\header.hpp", + "BMI": "c:\users\ruki\desktop\user_headerunit\src\header.hpp.ifc" + } + ] + } +}]] +function main(depsdata) + + -- decode json data first + depsdata = json.decode(depsdata) + + -- get includes + local data + if depsdata then + data = depsdata.Data + end + if data then + includes = data.Includes + for _, item in ipairs(data.ImportedModules) do + local bmifile = item.BMI + if bmifile then + includes = includes or {} + table.insert(includes, bmifile) + end + end + for _, item in ipairs(data.ImportedHeaderUnits) do + local bmifile = item.BMI + if bmifile then + includes = includes or {} + table.insert(includes, bmifile) + end + end + end + + -- translate it + local results = hashset.new() + local projectdir = os.projectdir():lower() -- we need to generate lower string, because json values are all lower + for _, includefile in ipairs(includes) do + includefile = _normailize_dep(includefile, projectdir) + if includefile then + results:insert(includefile) + end + end + return results:to_array() +end + diff --git a/xmake/modules/core/tools/cl/parse_include.lua b/xmake/modules/core/tools/cl/parse_include.lua new file mode 100644 index 000000000..700f9823f --- /dev/null +++ b/xmake/modules/core/tools/cl/parse_include.lua @@ -0,0 +1,104 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_include.lua +-- + +-- imports +import("core.project.project") +import("core.base.hashset") +import("core.tool.toolchain") +import("core.cache.detectcache") +import("lib.detect.find_tool") +import("private.tools.vstool") + +-- probe include note prefix from cl +function probe_include_note_from_cl() + local key = "cldeps.parse_include.note" + local note = detectcache:get(key) + if not note then + local cl = find_tool("cl") + if cl then + local projectdir = os.tmpfile() .. ".cldeps" + local sourcefile = path.join(projectdir, "main.c") + local headerfile = path.join(projectdir, "foo.h") + local objectfile = sourcefile .. ".obj" + local outdata = try { function() + local runenvs = toolchain.load("msvc"):runenvs() + local argv = {"-nologo", "-showIncludes", "-c", "-Fo" .. objectfile, sourcefile} + io.writefile(headerfile, "\n") + io.writefile(sourcefile, [[ + #include "foo.h" + int main (int argc, char** argv) { + return 0; + } + ]]) + return vstool.iorunv(cl.program, argv, {envs = runenvs, curdir = projectdir}) + end} + if outdata then + for _, line in ipairs(outdata:split('\n', {plain = true})) do + note = line:match("^(.-:.-: )") + if note then + break + end + end + end + os.tryrm(projectdir) + end + detectcache:set(key, note) + detectcache:save() + end + return note +end + +-- get include notes prefix, e.g. "Note: including file: " +-- +-- @note we cannot get better solution to distinguish between `includes` and `error infos` +-- +function get_include_notes() + local notes = _g.notes + if not notes then + notes = {} + local note = probe_include_note_from_cl() + if note then + table.insert(notes, note) + end + table.join2(notes, { + "Note: including file: ", -- en + "注意: 包含文件: ", -- zh + "Remarque : inclusion du fichier : ", -- fr + "メモ: インクルード ファイル: " -- jp + }) + _g.notes = notes + end + return notes +end + +-- main entry +function main(line) + local notes = get_include_notes() + for idx, note in ipairs(notes) do + if line:startswith(note) then + -- optimization: move this note to head + if idx ~= 1 then + table.insert(notes, 1, note) + end + return line:sub(#note):trim() + end + end +end + diff --git a/xmake/modules/core/tools/cl2000/parse_deps.lua b/xmake/modules/core/tools/cl2000/parse_deps.lua new file mode 100644 index 000000000..e02cf0501 --- /dev/null +++ b/xmake/modules/core/tools/cl2000/parse_deps.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps.lua +-- + +-- imports +inherit("private.tools.cl6x.parse_deps") + diff --git a/xmake/modules/core/tools/cl6x/parse_deps.lua b/xmake/modules/core/tools/cl6x/parse_deps.lua new file mode 100644 index 000000000..a5d5ecd40 --- /dev/null +++ b/xmake/modules/core/tools/cl6x/parse_deps.lua @@ -0,0 +1,77 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps.lua +-- + +-- imports +import("core.project.config") +import("core.project.project") +import("core.base.hashset") + +-- normailize path of a dependecy +function _normailize_dep(dep, projectdir) + -- escape characters, e.g. \#Qt.Widget_pch.h -> #Qt.Widget_pch.h + -- @see https://github.com/xmake-io/xmake/issues/4134 + -- https://github.com/xmake-io/xmake/issues/4273 + if not is_host("windows") then + dep = dep:gsub("\\(.)", "%1") + end + if path.is_absolute(dep) then + dep = path.translate(dep) + else + dep = path.absolute(dep, projectdir) + end + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) + else + -- we also need to check header files outside project + -- https://github.com/xmake-io/xmake/issues/1154 + return dep + end +end + +-- parse depsfiles from string +-- +-- parse_deps(io.readfile(depfile, {continuation = "\\"})) +-- +-- eg. +-- +-- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.c +-- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.h +-- +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/main.c +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/foo.h +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/bar.h +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/zoo.h +-- +function main(depsdata, opt) + local results = hashset.new() + local projectdir = os.projectdir() + local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first + local plain = {plain = true} + for _, includefile in ipairs(line:split('\n', plain)) do -- it will trim all internal spaces without `{strict = true}` + includefile = includefile:split(": ", plain)[2] + if includefile and #includefile > 0 then + includefile = _normailize_dep(includefile, projectdir) + if includefile then + results:insert(includefile) + end + end + end + return results:to_array() +end diff --git a/xmake/modules/core/tools/cl_json/parse_deps.lua b/xmake/modules/core/tools/cl_json/parse_deps.lua new file mode 100644 index 000000000..21b3c9a9d --- /dev/null +++ b/xmake/modules/core/tools/cl_json/parse_deps.lua @@ -0,0 +1,144 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps.lua +-- + +-- imports +import("core.project.project") +import("core.base.hashset") +import("core.base.json") +import("core.tool.toolchain") + +-- get $VCInstallDir +function _VCInstallDir() + local VCInstallDir = _g.VCInstallDir + if not VCInstallDir then + local msvc = toolchain.load("msvc") + if msvc then + local vcvars = msvc:config("vcvars") + if vcvars and vcvars.VCInstallDir then + VCInstallDir = vcvars.VCInstallDir:lower() -- @note we need lower case for json/deps + _g.VCInstallDir = VCInstallDir + end + end + end + return VCInstallDir +end + +-- get $WindowsSdkDir +function _WindowsSdkDir() + local WindowsSdkDir = _g.WindowsSdkDir + if not WindowsSdkDir then + local msvc = toolchain.load("msvc") + if msvc then + local vcvars = msvc:config("vcvars") + if vcvars and vcvars.WindowsSdkDir then + WindowsSdkDir = vcvars.WindowsSdkDir:lower() -- @note we need lower case for json/deps + _g.WindowsSdkDir = WindowsSdkDir + end + end + end + return WindowsSdkDir +end + +-- normailize path of a dependecy +function _normailize_dep(dep, projectdir) + if path.is_absolute(dep) then + dep = path.translate(dep) + else + dep = path.absolute(dep, projectdir) + end + dep = dep:lower() + local VCInstallDir = _VCInstallDir() + local WindowsSdkDir = _WindowsSdkDir() + if (VCInstallDir and dep:startswith(VCInstallDir)) or (WindowsSdkDir and dep:startswith(WindowsSdkDir)) then + -- we ignore headerfiles in vc install directory + return + end + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) + else + -- we also need to check header files outside project + -- https://github.com/xmake-io/xmake/issues/1154 + return dep + end +end + +-- parse depsfiles from string +-- +--[[ +{ + "Version": "1.2", + "Data": { + "Source": "c:\users\ruki\desktop\user_headerunit\src\main.cpp", + "ProvidedModule": "", + "Includes": [], + "ImportedModules": [ + { + "Name": "hello", + "BMI": "c:\users\ruki\desktop\user_headerunit\src\hello.ifc" + } + ], + "ImportedHeaderUnits": [ + { + "Header": "c:\users\ruki\desktop\user_headerunit\src\header.hpp", + "BMI": "c:\users\ruki\desktop\user_headerunit\src\header.hpp.ifc" + } + ] + } +}]] +function main(depsdata) + + -- decode json data first + depsdata = json.decode(depsdata) + + -- get includes + local data + if depsdata then + data = depsdata.Data + end + if data then + includes = data.Includes + for _, item in ipairs(data.ImportedModules) do + local bmifile = item.BMI + if bmifile then + includes = includes or {} + table.insert(includes, bmifile) + end + end + for _, item in ipairs(data.ImportedHeaderUnits) do + local bmifile = item.BMI + if bmifile then + includes = includes or {} + table.insert(includes, bmifile) + end + end + end + + -- translate it + local results = hashset.new() + local projectdir = os.projectdir():lower() -- we need to generate lower string, because json values are all lower + for _, includefile in ipairs(includes) do + includefile = _normailize_dep(includefile, projectdir) + if includefile then + results:insert(includefile) + end + end + return results:to_array() +end + diff --git a/xmake/modules/core/tools/gcc/parse_deps.lua b/xmake/modules/core/tools/gcc/parse_deps.lua new file mode 100644 index 000000000..b4b5cba7f --- /dev/null +++ b/xmake/modules/core/tools/gcc/parse_deps.lua @@ -0,0 +1,143 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps.lua +-- + +-- imports +import("core.project.config") +import("core.project.project") +import("core.base.hashset") + +-- a placeholder for spaces in path +local space_placeholder = "\001" + +-- normailize path of a dependecy +function _normailize_dep(dep, projectdir) + -- escape characters, e.g. \#Qt.Widget_pch.h -> #Qt.Widget_pch.h + -- @see https://github.com/xmake-io/xmake/issues/4134 + -- https://github.com/xmake-io/xmake/issues/4273 + if not is_host("windows") then + dep = dep:gsub("\\(.)", "%1") + end + if path.is_absolute(dep) then + dep = path.translate(dep) + else + dep = path.absolute(dep, projectdir) + end + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) + else + -- we also need to check header files outside project + -- https://github.com/xmake-io/xmake/issues/1154 + return dep + end +end + +-- load module mapper +function _load_module_mapper(target) + local mapper = {} + local mapperfile = path.join(config.buildir(), target:name(), "mapper.txt") + for line in io.lines(mapperfile) do + local moduleinfo = line:split(" ", {plain = true}) + if #moduleinfo == 2 then + mapper[moduleinfo[1]] = moduleinfo[2] + end + end + return mapper +end + +-- parse depsfiles from string +-- +-- parse_deps(io.readfile(depfile, {continuation = "\\"})) +-- +-- eg. +-- strcpy.o: src/tbox/libc/string/strcpy.c src/tbox/libc/string/string.h \ +-- src/tbox/libc/string/prefix.h src/tbox/libc/string/../prefix.h \ +-- src/tbox/libc/string/../../prefix.h \ +-- src/tbox/libc/string/../../prefix/prefix.h \ +-- src/tbox/libc/string/../../prefix/config.h \ +-- src/tbox/libc/string/../../prefix/../config.h \ +-- build/iphoneos/x86_64/release/tbox.config.h \ +-- +-- with c++ modules (gcc): +-- build/.objs/dependence/linux/x86_64/release/src/foo.mpp.o: src/foo.mpp\ +-- build/.objs/dependence/linux/x86_64/release/src/foo.mpp.o gcm.cache/foo.gcm: bar.c++m cat.c++m\ +-- foo.c++m: gcm.cache/foo.gcm\ +-- .PHONY: foo.c++m\ +-- gcm.cache/foo.gcm:| build/.objs/dependence/linux/x86_64/release/src/foo.mpp.o\ +-- CXX_IMPORTS += bar.c++m cat.c++m\ +-- +function main(depsdata, opt) + + -- we assume there is only one valid line + local block = 0 + local results = hashset.new() + local projectdir = os.projectdir() + local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first + local plain = {plain = true} + line = line:replace("\\ ", space_placeholder, plain) + for _, includefile in ipairs(line:split(' ', plain)) do -- it will trim all internal spaces without `{strict = true}` + -- some gcc toolchains will some invalid paths (e.g. `d\:\xxx`), we need to fix it + -- https://github.com/xmake-io/xmake/issues/1196 + if is_host("windows") and includefile:match("^%w\\:") then + includefile = includefile:replace("\\:", ":", plain) + end + if includefile:endswith(":") then -- ignore "xxx.o:" prefix + block = block + 1 + if block > 1 then + -- skip other `xxx.o:` block + break + end + else + includefile = includefile:replace(space_placeholder, ' ', plain) + includefile = includefile:split("\n", plain)[1] + if #includefile > 0 then + includefile = _normailize_dep(includefile, projectdir) + if includefile then + results:insert(includefile) + end + end + end + end + + -- translate .c++m module file path + -- with c++ modules (gcc): + -- CXX_IMPORTS += bar.c++m cat.c++m\ + -- + -- @see https://github.com/xmake-io/xmake/issues/3000 + -- https://github.com/xmake-io/xmake/issues/4215 + local target = opt and opt.target + if target and line:find("CXX_IMPORTS += ", 1, true) then + local mapper = _load_module_mapper(target) + local modulefiles = line:split("CXX_IMPORTS += ", plain)[2] + if modulefiles then + for _, modulefile in ipairs(modulefiles:split(' ', plain)) do + if modulefile:endswith(".c++m") then + local modulekey = modulefile:sub(1, #modulefile - 5) + local modulepath = mapper[modulekey] + if modulepath then + modulepath = _normailize_dep(modulepath, projectdir) + results:insert(modulepath) + end + end + end + end + end + + return results:to_array() +end diff --git a/xmake/modules/core/tools/rc/parse_deps.lua b/xmake/modules/core/tools/rc/parse_deps.lua new file mode 100644 index 000000000..778f7b03f --- /dev/null +++ b/xmake/modules/core/tools/rc/parse_deps.lua @@ -0,0 +1,52 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps.lua +-- + +-- imports +import("core.project.project") +import("core.base.hashset") + +-- normailize path of a dependecy +function _normailize_dep(dep, projectdir) + if path.is_absolute(dep) then + dep = path.translate(dep) + else + dep = path.absolute(dep, projectdir) + end + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) + else + return deps + end +end + +-- parse depsfiles from string +function main(depsdata) + local results = hashset.new() + local projectdir = os.projectdir() + for _, includefile in ipairs(depsdata:split('\n', {plain = true})) do + if #includefile > 0 then + includefile = _normailize_dep(includefile, projectdir) + if includefile then + results:insert(includefile) + end + end + end + return results:to_array() +end diff --git a/xmake/modules/private/tools/armcc/parse_deps.lua b/xmake/modules/private/tools/armcc/parse_deps.lua deleted file mode 100644 index afde0a575..000000000 --- a/xmake/modules/private/tools/armcc/parse_deps.lua +++ /dev/null @@ -1,82 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author smalli --- @file parse_deps_armcc.lua --- - --- imports -import("core.project.project") -import("core.base.hashset") - --- a placeholder for spaces in path -local space_placeholder = "\001" - --- normailize path of a dependecy -function _normailize_dep(dep, projectdir) - if path.is_absolute(dep) then - dep = path.translate(dep) - else - dep = path.absolute(dep, projectdir) - end - if dep:startswith(projectdir) then - return path.relative(dep, projectdir) - else - return dep - end -end - --- parse depsfiles from string --- --- parse_deps(io.readfile(depfile, {continuation = "\\"})) --- --- eg. --- build\\.objs\\apps\\cross\\cortex-m3\\release\\APPS\\main.c.o: APPS\\main.c\ --- build\\.objs\\apps\\cross\\cortex-m3\\release\\APPS\\main.c.o: D:\\Keil533\\ARM\\ARMCC\\bin\\..\\include\\stdarg.h\ --- build\\.objs\\apps\\cross\\cortex-m3\\release\\APPS\\main.c.o: D:\\Keil533\\ARM\\ARMCC\\bin\\..\\include\\stdio.h\ --- build\\.objs\\apps\\cross\\cortex-m3\\release\\APPS\\main.c.o: D:\\Keil533\\ARM\\ARMCC\\bin\\..\\include\\string.h\ --- build\\.objs\\apps\\cross\\cortex-m3\\release\\APPS\\main.c.o: APPS\\main.h\ --- --- -function main(depsdata) - local block = 0 - local results = hashset.new() - local projectdir = os.projectdir() - local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first - local plain = {plain = true} - line = line:replace("\\ ", space_placeholder, plain) - for _, includefile in ipairs(line:split('\n', plain)) do - if is_host("windows") and includefile:match("^%w\\:") then - includefile = includefile:replace("\\:", ":", plain) - end - includefile = includefile:replace(space_placeholder, ' ', plain) - local splitinfo = includefile:split(".o:", {plain = true}) - if #splitinfo < 2 then - splitinfo = includefile:split(".obj:", {plain = true}) - end - includefile = splitinfo[2] - if includefile then - includefile = includefile:replace(' ', '', plain) - if #includefile > 0 then - includefile = _normailize_dep(includefile, projectdir) - if includefile then - results:insert(includefile) - end - end - end - end - return results:to_array() -end diff --git a/xmake/modules/private/tools/cl/parse_deps.lua b/xmake/modules/private/tools/cl/parse_deps.lua deleted file mode 100644 index 187d655cd..000000000 --- a/xmake/modules/private/tools/cl/parse_deps.lua +++ /dev/null @@ -1,96 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file parse_deps.lua --- - --- imports -import("core.project.project") -import("core.base.hashset") -import("parse_include") -import("core.tool.toolchain") - --- get $VCInstallDir -function _VCInstallDir() - local VCInstallDir = _g.VCInstallDir - if not VCInstallDir then - local msvc = toolchain.load("msvc") - if msvc then - local vcvars = msvc:config("vcvars") - if vcvars and vcvars.VCInstallDir then - VCInstallDir = vcvars.VCInstallDir - _g.VCInstallDir = VCInstallDir - end - end - end - return VCInstallDir -end - --- get $WindowsSdkDir -function _WindowsSdkDir() - local WindowsSdkDir = _g.WindowsSdkDir - if not WindowsSdkDir then - local msvc = toolchain.load("msvc") - if msvc then - local vcvars = msvc:config("vcvars") - if vcvars and vcvars.WindowsSdkDir then - WindowsSdkDir = vcvars.WindowsSdkDir - _g.WindowsSdkDir = WindowsSdkDir - end - end - end - return WindowsSdkDir -end - - --- normailize path of a dependecy -function _normailize_dep(dep, projectdir) - if path.is_absolute(dep) then - dep = path.translate(dep) - else - dep = path.absolute(dep, projectdir) - end - local VCInstallDir = _VCInstallDir() - local WindowsSdkDir = _WindowsSdkDir() - if (VCInstallDir and dep:startswith(VCInstallDir)) or (WindowsSdkDir and dep:startswith(WindowsSdkDir)) then - -- we ignore headerfiles in vc install directory - return - end - if dep:startswith(projectdir) then - return path.relative(dep, projectdir) - else - -- we also need to check header files outside project - -- https://github.com/xmake-io/xmake/issues/1154 - return dep - end -end - --- parse depsfiles from string -function main(depsdata) - local results = hashset.new() - for _, line in ipairs(depsdata:split("\n", {plain = true})) do - local includefile = parse_include(line:trim()) - if includefile then - includefile = _normailize_dep(includefile, os.projectdir()) - if includefile then - results:insert(includefile) - end - end - end - return results:to_array() -end - diff --git a/xmake/modules/private/tools/cl/parse_deps_json.lua b/xmake/modules/private/tools/cl/parse_deps_json.lua deleted file mode 100644 index 50f728815..000000000 --- a/xmake/modules/private/tools/cl/parse_deps_json.lua +++ /dev/null @@ -1,144 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file parse_deps_json.lua --- - --- imports -import("core.project.project") -import("core.base.hashset") -import("core.base.json") -import("core.tool.toolchain") - --- get $VCInstallDir -function _VCInstallDir() - local VCInstallDir = _g.VCInstallDir - if not VCInstallDir then - local msvc = toolchain.load("msvc") - if msvc then - local vcvars = msvc:config("vcvars") - if vcvars and vcvars.VCInstallDir then - VCInstallDir = vcvars.VCInstallDir:lower() -- @note we need lower case for json/deps - _g.VCInstallDir = VCInstallDir - end - end - end - return VCInstallDir -end - --- get $WindowsSdkDir -function _WindowsSdkDir() - local WindowsSdkDir = _g.WindowsSdkDir - if not WindowsSdkDir then - local msvc = toolchain.load("msvc") - if msvc then - local vcvars = msvc:config("vcvars") - if vcvars and vcvars.WindowsSdkDir then - WindowsSdkDir = vcvars.WindowsSdkDir:lower() -- @note we need lower case for json/deps - _g.WindowsSdkDir = WindowsSdkDir - end - end - end - return WindowsSdkDir -end - --- normailize path of a dependecy -function _normailize_dep(dep, projectdir) - if path.is_absolute(dep) then - dep = path.translate(dep) - else - dep = path.absolute(dep, projectdir) - end - dep = dep:lower() - local VCInstallDir = _VCInstallDir() - local WindowsSdkDir = _WindowsSdkDir() - if (VCInstallDir and dep:startswith(VCInstallDir)) or (WindowsSdkDir and dep:startswith(WindowsSdkDir)) then - -- we ignore headerfiles in vc install directory - return - end - if dep:startswith(projectdir) then - return path.relative(dep, projectdir) - else - -- we also need to check header files outside project - -- https://github.com/xmake-io/xmake/issues/1154 - return dep - end -end - --- parse depsfiles from string --- ---[[ -{ - "Version": "1.2", - "Data": { - "Source": "c:\users\ruki\desktop\user_headerunit\src\main.cpp", - "ProvidedModule": "", - "Includes": [], - "ImportedModules": [ - { - "Name": "hello", - "BMI": "c:\users\ruki\desktop\user_headerunit\src\hello.ifc" - } - ], - "ImportedHeaderUnits": [ - { - "Header": "c:\users\ruki\desktop\user_headerunit\src\header.hpp", - "BMI": "c:\users\ruki\desktop\user_headerunit\src\header.hpp.ifc" - } - ] - } -}]] -function main(depsdata) - - -- decode json data first - depsdata = json.decode(depsdata) - - -- get includes - local data - if depsdata then - data = depsdata.Data - end - if data then - includes = data.Includes - for _, item in ipairs(data.ImportedModules) do - local bmifile = item.BMI - if bmifile then - includes = includes or {} - table.insert(includes, bmifile) - end - end - for _, item in ipairs(data.ImportedHeaderUnits) do - local bmifile = item.BMI - if bmifile then - includes = includes or {} - table.insert(includes, bmifile) - end - end - end - - -- translate it - local results = hashset.new() - local projectdir = os.projectdir():lower() -- we need to generate lower string, because json values are all lower - for _, includefile in ipairs(includes) do - includefile = _normailize_dep(includefile, projectdir) - if includefile then - results:insert(includefile) - end - end - return results:to_array() -end - diff --git a/xmake/modules/private/tools/cl/parse_include.lua b/xmake/modules/private/tools/cl/parse_include.lua deleted file mode 100644 index 700f9823f..000000000 --- a/xmake/modules/private/tools/cl/parse_include.lua +++ /dev/null @@ -1,104 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file parse_include.lua --- - --- imports -import("core.project.project") -import("core.base.hashset") -import("core.tool.toolchain") -import("core.cache.detectcache") -import("lib.detect.find_tool") -import("private.tools.vstool") - --- probe include note prefix from cl -function probe_include_note_from_cl() - local key = "cldeps.parse_include.note" - local note = detectcache:get(key) - if not note then - local cl = find_tool("cl") - if cl then - local projectdir = os.tmpfile() .. ".cldeps" - local sourcefile = path.join(projectdir, "main.c") - local headerfile = path.join(projectdir, "foo.h") - local objectfile = sourcefile .. ".obj" - local outdata = try { function() - local runenvs = toolchain.load("msvc"):runenvs() - local argv = {"-nologo", "-showIncludes", "-c", "-Fo" .. objectfile, sourcefile} - io.writefile(headerfile, "\n") - io.writefile(sourcefile, [[ - #include "foo.h" - int main (int argc, char** argv) { - return 0; - } - ]]) - return vstool.iorunv(cl.program, argv, {envs = runenvs, curdir = projectdir}) - end} - if outdata then - for _, line in ipairs(outdata:split('\n', {plain = true})) do - note = line:match("^(.-:.-: )") - if note then - break - end - end - end - os.tryrm(projectdir) - end - detectcache:set(key, note) - detectcache:save() - end - return note -end - --- get include notes prefix, e.g. "Note: including file: " --- --- @note we cannot get better solution to distinguish between `includes` and `error infos` --- -function get_include_notes() - local notes = _g.notes - if not notes then - notes = {} - local note = probe_include_note_from_cl() - if note then - table.insert(notes, note) - end - table.join2(notes, { - "Note: including file: ", -- en - "注意: 包含文件: ", -- zh - "Remarque : inclusion du fichier : ", -- fr - "メモ: インクルード ファイル: " -- jp - }) - _g.notes = notes - end - return notes -end - --- main entry -function main(line) - local notes = get_include_notes() - for idx, note in ipairs(notes) do - if line:startswith(note) then - -- optimization: move this note to head - if idx ~= 1 then - table.insert(notes, 1, note) - end - return line:sub(#note):trim() - end - end -end - diff --git a/xmake/modules/private/tools/cl2000/parse_deps.lua b/xmake/modules/private/tools/cl2000/parse_deps.lua deleted file mode 100644 index e02cf0501..000000000 --- a/xmake/modules/private/tools/cl2000/parse_deps.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file parse_deps.lua --- - --- imports -inherit("private.tools.cl6x.parse_deps") - diff --git a/xmake/modules/private/tools/cl6x/parse_deps.lua b/xmake/modules/private/tools/cl6x/parse_deps.lua deleted file mode 100644 index a5d5ecd40..000000000 --- a/xmake/modules/private/tools/cl6x/parse_deps.lua +++ /dev/null @@ -1,77 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file parse_deps.lua --- - --- imports -import("core.project.config") -import("core.project.project") -import("core.base.hashset") - --- normailize path of a dependecy -function _normailize_dep(dep, projectdir) - -- escape characters, e.g. \#Qt.Widget_pch.h -> #Qt.Widget_pch.h - -- @see https://github.com/xmake-io/xmake/issues/4134 - -- https://github.com/xmake-io/xmake/issues/4273 - if not is_host("windows") then - dep = dep:gsub("\\(.)", "%1") - end - if path.is_absolute(dep) then - dep = path.translate(dep) - else - dep = path.absolute(dep, projectdir) - end - if dep:startswith(projectdir) then - return path.relative(dep, projectdir) - else - -- we also need to check header files outside project - -- https://github.com/xmake-io/xmake/issues/1154 - return dep - end -end - --- parse depsfiles from string --- --- parse_deps(io.readfile(depfile, {continuation = "\\"})) --- --- eg. --- --- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.c --- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.h --- --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/main.c --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/foo.h --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/bar.h --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/zoo.h --- -function main(depsdata, opt) - local results = hashset.new() - local projectdir = os.projectdir() - local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first - local plain = {plain = true} - for _, includefile in ipairs(line:split('\n', plain)) do -- it will trim all internal spaces without `{strict = true}` - includefile = includefile:split(": ", plain)[2] - if includefile and #includefile > 0 then - includefile = _normailize_dep(includefile, projectdir) - if includefile then - results:insert(includefile) - end - end - end - return results:to_array() -end diff --git a/xmake/modules/private/tools/cl_json/parse_deps.lua b/xmake/modules/private/tools/cl_json/parse_deps.lua deleted file mode 100644 index 21b3c9a9d..000000000 --- a/xmake/modules/private/tools/cl_json/parse_deps.lua +++ /dev/null @@ -1,144 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file parse_deps.lua --- - --- imports -import("core.project.project") -import("core.base.hashset") -import("core.base.json") -import("core.tool.toolchain") - --- get $VCInstallDir -function _VCInstallDir() - local VCInstallDir = _g.VCInstallDir - if not VCInstallDir then - local msvc = toolchain.load("msvc") - if msvc then - local vcvars = msvc:config("vcvars") - if vcvars and vcvars.VCInstallDir then - VCInstallDir = vcvars.VCInstallDir:lower() -- @note we need lower case for json/deps - _g.VCInstallDir = VCInstallDir - end - end - end - return VCInstallDir -end - --- get $WindowsSdkDir -function _WindowsSdkDir() - local WindowsSdkDir = _g.WindowsSdkDir - if not WindowsSdkDir then - local msvc = toolchain.load("msvc") - if msvc then - local vcvars = msvc:config("vcvars") - if vcvars and vcvars.WindowsSdkDir then - WindowsSdkDir = vcvars.WindowsSdkDir:lower() -- @note we need lower case for json/deps - _g.WindowsSdkDir = WindowsSdkDir - end - end - end - return WindowsSdkDir -end - --- normailize path of a dependecy -function _normailize_dep(dep, projectdir) - if path.is_absolute(dep) then - dep = path.translate(dep) - else - dep = path.absolute(dep, projectdir) - end - dep = dep:lower() - local VCInstallDir = _VCInstallDir() - local WindowsSdkDir = _WindowsSdkDir() - if (VCInstallDir and dep:startswith(VCInstallDir)) or (WindowsSdkDir and dep:startswith(WindowsSdkDir)) then - -- we ignore headerfiles in vc install directory - return - end - if dep:startswith(projectdir) then - return path.relative(dep, projectdir) - else - -- we also need to check header files outside project - -- https://github.com/xmake-io/xmake/issues/1154 - return dep - end -end - --- parse depsfiles from string --- ---[[ -{ - "Version": "1.2", - "Data": { - "Source": "c:\users\ruki\desktop\user_headerunit\src\main.cpp", - "ProvidedModule": "", - "Includes": [], - "ImportedModules": [ - { - "Name": "hello", - "BMI": "c:\users\ruki\desktop\user_headerunit\src\hello.ifc" - } - ], - "ImportedHeaderUnits": [ - { - "Header": "c:\users\ruki\desktop\user_headerunit\src\header.hpp", - "BMI": "c:\users\ruki\desktop\user_headerunit\src\header.hpp.ifc" - } - ] - } -}]] -function main(depsdata) - - -- decode json data first - depsdata = json.decode(depsdata) - - -- get includes - local data - if depsdata then - data = depsdata.Data - end - if data then - includes = data.Includes - for _, item in ipairs(data.ImportedModules) do - local bmifile = item.BMI - if bmifile then - includes = includes or {} - table.insert(includes, bmifile) - end - end - for _, item in ipairs(data.ImportedHeaderUnits) do - local bmifile = item.BMI - if bmifile then - includes = includes or {} - table.insert(includes, bmifile) - end - end - end - - -- translate it - local results = hashset.new() - local projectdir = os.projectdir():lower() -- we need to generate lower string, because json values are all lower - for _, includefile in ipairs(includes) do - includefile = _normailize_dep(includefile, projectdir) - if includefile then - results:insert(includefile) - end - end - return results:to_array() -end - diff --git a/xmake/modules/private/tools/gcc/parse_deps.lua b/xmake/modules/private/tools/gcc/parse_deps.lua deleted file mode 100644 index b4b5cba7f..000000000 --- a/xmake/modules/private/tools/gcc/parse_deps.lua +++ /dev/null @@ -1,143 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file parse_deps.lua --- - --- imports -import("core.project.config") -import("core.project.project") -import("core.base.hashset") - --- a placeholder for spaces in path -local space_placeholder = "\001" - --- normailize path of a dependecy -function _normailize_dep(dep, projectdir) - -- escape characters, e.g. \#Qt.Widget_pch.h -> #Qt.Widget_pch.h - -- @see https://github.com/xmake-io/xmake/issues/4134 - -- https://github.com/xmake-io/xmake/issues/4273 - if not is_host("windows") then - dep = dep:gsub("\\(.)", "%1") - end - if path.is_absolute(dep) then - dep = path.translate(dep) - else - dep = path.absolute(dep, projectdir) - end - if dep:startswith(projectdir) then - return path.relative(dep, projectdir) - else - -- we also need to check header files outside project - -- https://github.com/xmake-io/xmake/issues/1154 - return dep - end -end - --- load module mapper -function _load_module_mapper(target) - local mapper = {} - local mapperfile = path.join(config.buildir(), target:name(), "mapper.txt") - for line in io.lines(mapperfile) do - local moduleinfo = line:split(" ", {plain = true}) - if #moduleinfo == 2 then - mapper[moduleinfo[1]] = moduleinfo[2] - end - end - return mapper -end - --- parse depsfiles from string --- --- parse_deps(io.readfile(depfile, {continuation = "\\"})) --- --- eg. --- strcpy.o: src/tbox/libc/string/strcpy.c src/tbox/libc/string/string.h \ --- src/tbox/libc/string/prefix.h src/tbox/libc/string/../prefix.h \ --- src/tbox/libc/string/../../prefix.h \ --- src/tbox/libc/string/../../prefix/prefix.h \ --- src/tbox/libc/string/../../prefix/config.h \ --- src/tbox/libc/string/../../prefix/../config.h \ --- build/iphoneos/x86_64/release/tbox.config.h \ --- --- with c++ modules (gcc): --- build/.objs/dependence/linux/x86_64/release/src/foo.mpp.o: src/foo.mpp\ --- build/.objs/dependence/linux/x86_64/release/src/foo.mpp.o gcm.cache/foo.gcm: bar.c++m cat.c++m\ --- foo.c++m: gcm.cache/foo.gcm\ --- .PHONY: foo.c++m\ --- gcm.cache/foo.gcm:| build/.objs/dependence/linux/x86_64/release/src/foo.mpp.o\ --- CXX_IMPORTS += bar.c++m cat.c++m\ --- -function main(depsdata, opt) - - -- we assume there is only one valid line - local block = 0 - local results = hashset.new() - local projectdir = os.projectdir() - local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first - local plain = {plain = true} - line = line:replace("\\ ", space_placeholder, plain) - for _, includefile in ipairs(line:split(' ', plain)) do -- it will trim all internal spaces without `{strict = true}` - -- some gcc toolchains will some invalid paths (e.g. `d\:\xxx`), we need to fix it - -- https://github.com/xmake-io/xmake/issues/1196 - if is_host("windows") and includefile:match("^%w\\:") then - includefile = includefile:replace("\\:", ":", plain) - end - if includefile:endswith(":") then -- ignore "xxx.o:" prefix - block = block + 1 - if block > 1 then - -- skip other `xxx.o:` block - break - end - else - includefile = includefile:replace(space_placeholder, ' ', plain) - includefile = includefile:split("\n", plain)[1] - if #includefile > 0 then - includefile = _normailize_dep(includefile, projectdir) - if includefile then - results:insert(includefile) - end - end - end - end - - -- translate .c++m module file path - -- with c++ modules (gcc): - -- CXX_IMPORTS += bar.c++m cat.c++m\ - -- - -- @see https://github.com/xmake-io/xmake/issues/3000 - -- https://github.com/xmake-io/xmake/issues/4215 - local target = opt and opt.target - if target and line:find("CXX_IMPORTS += ", 1, true) then - local mapper = _load_module_mapper(target) - local modulefiles = line:split("CXX_IMPORTS += ", plain)[2] - if modulefiles then - for _, modulefile in ipairs(modulefiles:split(' ', plain)) do - if modulefile:endswith(".c++m") then - local modulekey = modulefile:sub(1, #modulefile - 5) - local modulepath = mapper[modulekey] - if modulepath then - modulepath = _normailize_dep(modulepath, projectdir) - results:insert(modulepath) - end - end - end - end - end - - return results:to_array() -end diff --git a/xmake/modules/private/tools/rc/parse_deps.lua b/xmake/modules/private/tools/rc/parse_deps.lua deleted file mode 100644 index 778f7b03f..000000000 --- a/xmake/modules/private/tools/rc/parse_deps.lua +++ /dev/null @@ -1,52 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file parse_deps.lua --- - --- imports -import("core.project.project") -import("core.base.hashset") - --- normailize path of a dependecy -function _normailize_dep(dep, projectdir) - if path.is_absolute(dep) then - dep = path.translate(dep) - else - dep = path.absolute(dep, projectdir) - end - if dep:startswith(projectdir) then - return path.relative(dep, projectdir) - else - return deps - end -end - --- parse depsfiles from string -function main(depsdata) - local results = hashset.new() - local projectdir = os.projectdir() - for _, includefile in ipairs(depsdata:split('\n', {plain = true})) do - if #includefile > 0 then - includefile = _normailize_dep(includefile, projectdir) - if includefile then - results:insert(includefile) - end - end - end - return results:to_array() -end -- cgit v1.3.1 From 35677f50e4eb8ecb5aabe70e6ce900e28fd0adc2 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:59:17 +0800 Subject: move has_flags.lua --- tests/apis/custom_toolchain/3 | Bin 0 -> 4606 bytes .../modules/core/tools/cl6x/has_flags.lua | 121 +++++++++++ .../modules/detect/tools/cl6x/has_flags.lua | 121 ----------- xmake/modules/core/tools/ar/has_flags.lua | 82 ++++++++ .../modules/core/tools/armasm64_msvc/has_flags.lua | 23 +++ xmake/modules/core/tools/armasm_msvc/has_flags.lua | 97 +++++++++ xmake/modules/core/tools/armclang/has_flags.lua | 128 ++++++++++++ xmake/modules/core/tools/circle/has_flags.lua | 23 +++ xmake/modules/core/tools/cl/cfeatures.lua | 49 +++++ xmake/modules/core/tools/cl/cxxfeatures.lua | 151 ++++++++++++++ xmake/modules/core/tools/cl/features.lua | 140 +++++++++++++ xmake/modules/core/tools/cl/has_flags.lua | 119 +++++++++++ xmake/modules/core/tools/cl2000/has_flags.lua | 23 +++ xmake/modules/core/tools/cl6x/has_flags.lua | 121 +++++++++++ xmake/modules/core/tools/clang/cfeatures.lua | 58 ++++++ xmake/modules/core/tools/clang/cxxfeatures.lua | 132 ++++++++++++ xmake/modules/core/tools/clang/features.lua | 44 ++++ xmake/modules/core/tools/clang/has_flags.lua | 23 +++ xmake/modules/core/tools/clang_cl/has_flags.lua | 101 ++++++++++ xmake/modules/core/tools/clangxx/features.lua | 23 +++ xmake/modules/core/tools/clangxx/has_flags.lua | 23 +++ xmake/modules/core/tools/cosmocc/has_flags.lua | 143 +++++++++++++ xmake/modules/core/tools/cosmocxx/has_flags.lua | 23 +++ xmake/modules/core/tools/dmd/has_flags.lua | 119 +++++++++++ xmake/modules/core/tools/dpcpp/cfeatures.lua | 22 ++ xmake/modules/core/tools/dpcpp/cxxfeatures.lua | 22 ++ xmake/modules/core/tools/dpcpp/features.lua | 22 ++ xmake/modules/core/tools/dpcpp/has_flags.lua | 23 +++ xmake/modules/core/tools/emcc/has_flags.lua | 23 +++ xmake/modules/core/tools/emxx/has_flags.lua | 23 +++ xmake/modules/core/tools/fpc/has_flags.lua | 98 +++++++++ xmake/modules/core/tools/gcc/cfeatures.lua | 52 +++++ xmake/modules/core/tools/gcc/cxxfeatures.lua | 222 +++++++++++++++++++++ xmake/modules/core/tools/gcc/features.lua | 130 ++++++++++++ xmake/modules/core/tools/gcc/has_flags.lua | 134 +++++++++++++ xmake/modules/core/tools/gccgo/has_flags.lua | 23 +++ xmake/modules/core/tools/gdc/has_flags.lua | 118 +++++++++++ xmake/modules/core/tools/gfortran/has_flags.lua | 117 +++++++++++ xmake/modules/core/tools/go/has_flags.lua | 130 ++++++++++++ xmake/modules/core/tools/gxx/features.lua | 23 +++ xmake/modules/core/tools/gxx/has_flags.lua | 23 +++ xmake/modules/core/tools/icc/has_flags.lua | 23 +++ xmake/modules/core/tools/icl/has_flags.lua | 23 +++ xmake/modules/core/tools/icpc/has_flags.lua | 23 +++ xmake/modules/core/tools/icpx/features.lua | 23 +++ xmake/modules/core/tools/icpx/has_flags.lua | 23 +++ xmake/modules/core/tools/icx/cfeatures.lua | 22 ++ xmake/modules/core/tools/icx/cxxfeatures.lua | 22 ++ xmake/modules/core/tools/icx/features.lua | 22 ++ xmake/modules/core/tools/icx/has_flags.lua | 23 +++ xmake/modules/core/tools/ifort/has_flags.lua | 27 +++ xmake/modules/core/tools/ifx/has_flags.lua | 23 +++ xmake/modules/core/tools/ldc2/has_flags.lua | 23 +++ xmake/modules/core/tools/link/has_flags.lua | 121 +++++++++++ xmake/modules/core/tools/ml/has_flags.lua | 105 ++++++++++ xmake/modules/core/tools/ml64/has_flags.lua | 23 +++ xmake/modules/core/tools/nim/has_flags.lua | 98 +++++++++ xmake/modules/core/tools/nvc/features.lua | 23 +++ xmake/modules/core/tools/nvc/has_flags.lua | 23 +++ xmake/modules/core/tools/nvcc/has_flags.lua | 161 +++++++++++++++ xmake/modules/core/tools/nvcxx/features.lua | 23 +++ xmake/modules/core/tools/nvcxx/has_flags.lua | 23 +++ xmake/modules/core/tools/nvfortran/has_flags.lua | 23 +++ xmake/modules/core/tools/rc/has_flags.lua | 68 +++++++ xmake/modules/core/tools/rustc/has_flags.lua | 116 +++++++++++ xmake/modules/core/tools/sdcc/has_flags.lua | 123 ++++++++++++ .../core/tools/swift_frontend/has_flags.lua | 22 ++ xmake/modules/core/tools/swiftc/has_flags.lua | 101 ++++++++++ xmake/modules/core/tools/tcc/has_flags.lua | 23 +++ xmake/modules/core/tools/zig/has_flags.lua | 114 +++++++++++ xmake/modules/core/tools/zig_cc/features.lua | 23 +++ xmake/modules/core/tools/zig_cc/has_flags.lua | 23 +++ xmake/modules/core/tools/zig_cxx/features.lua | 23 +++ xmake/modules/core/tools/zig_cxx/has_flags.lua | 23 +++ xmake/modules/detect/tools/ar/has_flags.lua | 82 -------- .../detect/tools/armasm64_msvc/has_flags.lua | 23 --- .../modules/detect/tools/armasm_msvc/has_flags.lua | 97 --------- xmake/modules/detect/tools/armclang/has_flags.lua | 128 ------------ xmake/modules/detect/tools/circle/has_flags.lua | 23 --- xmake/modules/detect/tools/cl/cfeatures.lua | 49 ----- xmake/modules/detect/tools/cl/cxxfeatures.lua | 151 -------------- xmake/modules/detect/tools/cl/features.lua | 140 ------------- xmake/modules/detect/tools/cl/has_flags.lua | 119 ----------- xmake/modules/detect/tools/cl2000/has_flags.lua | 23 --- xmake/modules/detect/tools/cl6x/has_flags.lua | 121 ----------- xmake/modules/detect/tools/clang/cfeatures.lua | 58 ------ xmake/modules/detect/tools/clang/cxxfeatures.lua | 132 ------------ xmake/modules/detect/tools/clang/features.lua | 44 ---- xmake/modules/detect/tools/clang/has_flags.lua | 23 --- xmake/modules/detect/tools/clang_cl/has_flags.lua | 101 ---------- xmake/modules/detect/tools/clangxx/features.lua | 23 --- xmake/modules/detect/tools/clangxx/has_flags.lua | 23 --- xmake/modules/detect/tools/cosmocc/has_flags.lua | 143 ------------- xmake/modules/detect/tools/cosmocxx/has_flags.lua | 23 --- xmake/modules/detect/tools/dmd/has_flags.lua | 119 ----------- xmake/modules/detect/tools/dpcpp/cfeatures.lua | 22 -- xmake/modules/detect/tools/dpcpp/cxxfeatures.lua | 22 -- xmake/modules/detect/tools/dpcpp/features.lua | 22 -- xmake/modules/detect/tools/dpcpp/has_flags.lua | 23 --- xmake/modules/detect/tools/emcc/has_flags.lua | 23 --- xmake/modules/detect/tools/emxx/has_flags.lua | 23 --- xmake/modules/detect/tools/fpc/has_flags.lua | 98 --------- xmake/modules/detect/tools/gcc/cfeatures.lua | 52 ----- xmake/modules/detect/tools/gcc/cxxfeatures.lua | 222 --------------------- xmake/modules/detect/tools/gcc/features.lua | 130 ------------ xmake/modules/detect/tools/gcc/has_flags.lua | 134 ------------- xmake/modules/detect/tools/gccgo/has_flags.lua | 23 --- xmake/modules/detect/tools/gdc/has_flags.lua | 118 ----------- xmake/modules/detect/tools/gfortran/has_flags.lua | 117 ----------- xmake/modules/detect/tools/go/has_flags.lua | 130 ------------ xmake/modules/detect/tools/gxx/features.lua | 23 --- xmake/modules/detect/tools/gxx/has_flags.lua | 23 --- xmake/modules/detect/tools/icc/has_flags.lua | 23 --- xmake/modules/detect/tools/icl/has_flags.lua | 23 --- xmake/modules/detect/tools/icpc/has_flags.lua | 23 --- xmake/modules/detect/tools/icpx/features.lua | 23 --- xmake/modules/detect/tools/icpx/has_flags.lua | 23 --- xmake/modules/detect/tools/icx/cfeatures.lua | 22 -- xmake/modules/detect/tools/icx/cxxfeatures.lua | 22 -- xmake/modules/detect/tools/icx/features.lua | 22 -- xmake/modules/detect/tools/icx/has_flags.lua | 23 --- xmake/modules/detect/tools/ifort/has_flags.lua | 27 --- xmake/modules/detect/tools/ifx/has_flags.lua | 23 --- xmake/modules/detect/tools/ldc2/has_flags.lua | 23 --- xmake/modules/detect/tools/link/has_flags.lua | 121 ----------- xmake/modules/detect/tools/ml/has_flags.lua | 105 ---------- xmake/modules/detect/tools/ml64/has_flags.lua | 23 --- xmake/modules/detect/tools/nim/has_flags.lua | 98 --------- xmake/modules/detect/tools/nvc/features.lua | 23 --- xmake/modules/detect/tools/nvc/has_flags.lua | 23 --- xmake/modules/detect/tools/nvcc/has_flags.lua | 161 --------------- xmake/modules/detect/tools/nvcxx/features.lua | 23 --- xmake/modules/detect/tools/nvcxx/has_flags.lua | 23 --- xmake/modules/detect/tools/nvfortran/has_flags.lua | 23 --- xmake/modules/detect/tools/rc/has_flags.lua | 68 ------- xmake/modules/detect/tools/rustc/has_flags.lua | 116 ----------- xmake/modules/detect/tools/sdcc/has_flags.lua | 123 ------------ .../detect/tools/swift_frontend/has_flags.lua | 22 -- xmake/modules/detect/tools/swiftc/has_flags.lua | 101 ---------- xmake/modules/detect/tools/tcc/has_flags.lua | 23 --- xmake/modules/detect/tools/zig/has_flags.lua | 114 ----------- xmake/modules/detect/tools/zig_cc/features.lua | 23 --- xmake/modules/detect/tools/zig_cc/has_flags.lua | 23 --- xmake/modules/detect/tools/zig_cxx/features.lua | 23 --- xmake/modules/detect/tools/zig_cxx/has_flags.lua | 23 --- xmake/modules/lib/detect/features.lua | 4 +- xmake/modules/lib/detect/has_flags.lua | 4 +- 147 files changed, 4534 insertions(+), 4534 deletions(-) create mode 100644 tests/apis/custom_toolchain/3 create mode 100644 tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/has_flags.lua delete mode 100644 tests/apis/custom_toolchain/toolchains/modules/detect/tools/cl6x/has_flags.lua create mode 100644 xmake/modules/core/tools/ar/has_flags.lua create mode 100644 xmake/modules/core/tools/armasm64_msvc/has_flags.lua create mode 100644 xmake/modules/core/tools/armasm_msvc/has_flags.lua create mode 100644 xmake/modules/core/tools/armclang/has_flags.lua create mode 100644 xmake/modules/core/tools/circle/has_flags.lua create mode 100644 xmake/modules/core/tools/cl/cfeatures.lua create mode 100644 xmake/modules/core/tools/cl/cxxfeatures.lua create mode 100644 xmake/modules/core/tools/cl/features.lua create mode 100644 xmake/modules/core/tools/cl/has_flags.lua create mode 100644 xmake/modules/core/tools/cl2000/has_flags.lua create mode 100644 xmake/modules/core/tools/cl6x/has_flags.lua create mode 100644 xmake/modules/core/tools/clang/cfeatures.lua create mode 100644 xmake/modules/core/tools/clang/cxxfeatures.lua create mode 100644 xmake/modules/core/tools/clang/features.lua create mode 100644 xmake/modules/core/tools/clang/has_flags.lua create mode 100644 xmake/modules/core/tools/clang_cl/has_flags.lua create mode 100644 xmake/modules/core/tools/clangxx/features.lua create mode 100644 xmake/modules/core/tools/clangxx/has_flags.lua create mode 100644 xmake/modules/core/tools/cosmocc/has_flags.lua create mode 100644 xmake/modules/core/tools/cosmocxx/has_flags.lua create mode 100644 xmake/modules/core/tools/dmd/has_flags.lua create mode 100644 xmake/modules/core/tools/dpcpp/cfeatures.lua create mode 100644 xmake/modules/core/tools/dpcpp/cxxfeatures.lua create mode 100644 xmake/modules/core/tools/dpcpp/features.lua create mode 100644 xmake/modules/core/tools/dpcpp/has_flags.lua create mode 100644 xmake/modules/core/tools/emcc/has_flags.lua create mode 100644 xmake/modules/core/tools/emxx/has_flags.lua create mode 100644 xmake/modules/core/tools/fpc/has_flags.lua create mode 100644 xmake/modules/core/tools/gcc/cfeatures.lua create mode 100644 xmake/modules/core/tools/gcc/cxxfeatures.lua create mode 100644 xmake/modules/core/tools/gcc/features.lua create mode 100644 xmake/modules/core/tools/gcc/has_flags.lua create mode 100644 xmake/modules/core/tools/gccgo/has_flags.lua create mode 100644 xmake/modules/core/tools/gdc/has_flags.lua create mode 100644 xmake/modules/core/tools/gfortran/has_flags.lua create mode 100644 xmake/modules/core/tools/go/has_flags.lua create mode 100644 xmake/modules/core/tools/gxx/features.lua create mode 100644 xmake/modules/core/tools/gxx/has_flags.lua create mode 100644 xmake/modules/core/tools/icc/has_flags.lua create mode 100644 xmake/modules/core/tools/icl/has_flags.lua create mode 100644 xmake/modules/core/tools/icpc/has_flags.lua create mode 100644 xmake/modules/core/tools/icpx/features.lua create mode 100644 xmake/modules/core/tools/icpx/has_flags.lua create mode 100644 xmake/modules/core/tools/icx/cfeatures.lua create mode 100644 xmake/modules/core/tools/icx/cxxfeatures.lua create mode 100644 xmake/modules/core/tools/icx/features.lua create mode 100644 xmake/modules/core/tools/icx/has_flags.lua create mode 100644 xmake/modules/core/tools/ifort/has_flags.lua create mode 100644 xmake/modules/core/tools/ifx/has_flags.lua create mode 100644 xmake/modules/core/tools/ldc2/has_flags.lua create mode 100644 xmake/modules/core/tools/link/has_flags.lua create mode 100644 xmake/modules/core/tools/ml/has_flags.lua create mode 100644 xmake/modules/core/tools/ml64/has_flags.lua create mode 100644 xmake/modules/core/tools/nim/has_flags.lua create mode 100644 xmake/modules/core/tools/nvc/features.lua create mode 100644 xmake/modules/core/tools/nvc/has_flags.lua create mode 100644 xmake/modules/core/tools/nvcc/has_flags.lua create mode 100644 xmake/modules/core/tools/nvcxx/features.lua create mode 100644 xmake/modules/core/tools/nvcxx/has_flags.lua create mode 100644 xmake/modules/core/tools/nvfortran/has_flags.lua create mode 100644 xmake/modules/core/tools/rc/has_flags.lua create mode 100644 xmake/modules/core/tools/rustc/has_flags.lua create mode 100644 xmake/modules/core/tools/sdcc/has_flags.lua create mode 100644 xmake/modules/core/tools/swift_frontend/has_flags.lua create mode 100644 xmake/modules/core/tools/swiftc/has_flags.lua create mode 100644 xmake/modules/core/tools/tcc/has_flags.lua create mode 100644 xmake/modules/core/tools/zig/has_flags.lua create mode 100644 xmake/modules/core/tools/zig_cc/features.lua create mode 100644 xmake/modules/core/tools/zig_cc/has_flags.lua create mode 100644 xmake/modules/core/tools/zig_cxx/features.lua create mode 100644 xmake/modules/core/tools/zig_cxx/has_flags.lua delete mode 100644 xmake/modules/detect/tools/ar/has_flags.lua delete mode 100644 xmake/modules/detect/tools/armasm64_msvc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/armasm_msvc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/armclang/has_flags.lua delete mode 100644 xmake/modules/detect/tools/circle/has_flags.lua delete mode 100644 xmake/modules/detect/tools/cl/cfeatures.lua delete mode 100644 xmake/modules/detect/tools/cl/cxxfeatures.lua delete mode 100644 xmake/modules/detect/tools/cl/features.lua delete mode 100644 xmake/modules/detect/tools/cl/has_flags.lua delete mode 100644 xmake/modules/detect/tools/cl2000/has_flags.lua delete mode 100644 xmake/modules/detect/tools/cl6x/has_flags.lua delete mode 100644 xmake/modules/detect/tools/clang/cfeatures.lua delete mode 100644 xmake/modules/detect/tools/clang/cxxfeatures.lua delete mode 100644 xmake/modules/detect/tools/clang/features.lua delete mode 100644 xmake/modules/detect/tools/clang/has_flags.lua delete mode 100644 xmake/modules/detect/tools/clang_cl/has_flags.lua delete mode 100644 xmake/modules/detect/tools/clangxx/features.lua delete mode 100644 xmake/modules/detect/tools/clangxx/has_flags.lua delete mode 100644 xmake/modules/detect/tools/cosmocc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/cosmocxx/has_flags.lua delete mode 100644 xmake/modules/detect/tools/dmd/has_flags.lua delete mode 100644 xmake/modules/detect/tools/dpcpp/cfeatures.lua delete mode 100644 xmake/modules/detect/tools/dpcpp/cxxfeatures.lua delete mode 100644 xmake/modules/detect/tools/dpcpp/features.lua delete mode 100644 xmake/modules/detect/tools/dpcpp/has_flags.lua delete mode 100644 xmake/modules/detect/tools/emcc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/emxx/has_flags.lua delete mode 100644 xmake/modules/detect/tools/fpc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/gcc/cfeatures.lua delete mode 100644 xmake/modules/detect/tools/gcc/cxxfeatures.lua delete mode 100644 xmake/modules/detect/tools/gcc/features.lua delete mode 100644 xmake/modules/detect/tools/gcc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/gccgo/has_flags.lua delete mode 100644 xmake/modules/detect/tools/gdc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/gfortran/has_flags.lua delete mode 100644 xmake/modules/detect/tools/go/has_flags.lua delete mode 100644 xmake/modules/detect/tools/gxx/features.lua delete mode 100644 xmake/modules/detect/tools/gxx/has_flags.lua delete mode 100644 xmake/modules/detect/tools/icc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/icl/has_flags.lua delete mode 100644 xmake/modules/detect/tools/icpc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/icpx/features.lua delete mode 100644 xmake/modules/detect/tools/icpx/has_flags.lua delete mode 100644 xmake/modules/detect/tools/icx/cfeatures.lua delete mode 100644 xmake/modules/detect/tools/icx/cxxfeatures.lua delete mode 100644 xmake/modules/detect/tools/icx/features.lua delete mode 100644 xmake/modules/detect/tools/icx/has_flags.lua delete mode 100644 xmake/modules/detect/tools/ifort/has_flags.lua delete mode 100644 xmake/modules/detect/tools/ifx/has_flags.lua delete mode 100644 xmake/modules/detect/tools/ldc2/has_flags.lua delete mode 100644 xmake/modules/detect/tools/link/has_flags.lua delete mode 100644 xmake/modules/detect/tools/ml/has_flags.lua delete mode 100644 xmake/modules/detect/tools/ml64/has_flags.lua delete mode 100644 xmake/modules/detect/tools/nim/has_flags.lua delete mode 100644 xmake/modules/detect/tools/nvc/features.lua delete mode 100644 xmake/modules/detect/tools/nvc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/nvcc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/nvcxx/features.lua delete mode 100644 xmake/modules/detect/tools/nvcxx/has_flags.lua delete mode 100644 xmake/modules/detect/tools/nvfortran/has_flags.lua delete mode 100644 xmake/modules/detect/tools/rc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/rustc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/sdcc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/swift_frontend/has_flags.lua delete mode 100644 xmake/modules/detect/tools/swiftc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/tcc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/zig/has_flags.lua delete mode 100644 xmake/modules/detect/tools/zig_cc/features.lua delete mode 100644 xmake/modules/detect/tools/zig_cc/has_flags.lua delete mode 100644 xmake/modules/detect/tools/zig_cxx/features.lua delete mode 100644 xmake/modules/detect/tools/zig_cxx/has_flags.lua diff --git a/tests/apis/custom_toolchain/3 b/tests/apis/custom_toolchain/3 new file mode 100644 index 000000000..51405a6f1 Binary files /dev/null and b/tests/apis/custom_toolchain/3 differ diff --git a/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/has_flags.lua b/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/has_flags.lua new file mode 100644 index 000000000..a5f3f4b87 --- /dev/null +++ b/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/has_flags.lua @@ -0,0 +1,121 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from known flags +function _check_from_knownargs(flags, opt, islinker) + local flag = flags[1] + if not islinker then + if flag:startswith("-D") or + flag:startswith("-U") or + flag:startswith("-I") then + return true + end + end +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + local key = "core.tools.cl6x." .. (islinker and "has_ldflags" or "has_cflags") + local flagskey = opt.program .. "_" .. (opt.programver or "") + local allflags = detectcache:get2(key, flagskey) + if not allflags then + allflags = {} + local arglist = try {function () return os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) end} + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + local flag = flags[1] + return allflags[flag] +end + +-- get extension +function _get_extension(opt) + -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] + return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" + local sourcefile = os.tmpfile("cl6x_has_flags:" .. snippet) .. _get_extension(opt) + if not os.isfile(sourcefile) then + io.writefile(sourcefile, snippet) + end + + -- check flags for linker + local tmpfile = os.tmpfile() + if islinker then + return _try_running(opt.program, table.join(flags, "-z", "--output_file=" .. tmpfile, sourcefile), opt) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-c", "--output_file=" .. tmpfile, sourcefile), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + opt = opt or {} + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if not opt.tryrun then + if _check_from_arglist(flags, opt, islinker) then + return true + end + if _check_from_knownargs(flags, opt, islinker) then + return true + end + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/tests/apis/custom_toolchain/toolchains/modules/detect/tools/cl6x/has_flags.lua b/tests/apis/custom_toolchain/toolchains/modules/detect/tools/cl6x/has_flags.lua deleted file mode 100644 index d18d9b233..000000000 --- a/tests/apis/custom_toolchain/toolchains/modules/detect/tools/cl6x/has_flags.lua +++ /dev/null @@ -1,121 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- is linker? -function _islinker(flags, opt) - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") -end - --- try running -function _try_running(program, argv, opt) - local errors = nil - return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from known flags -function _check_from_knownargs(flags, opt, islinker) - local flag = flags[1] - if not islinker then - if flag:startswith("-D") or - flag:startswith("-U") or - flag:startswith("-I") then - return true - end - end -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - local key = "detect.tools.cl6x." .. (islinker and "has_ldflags" or "has_cflags") - local flagskey = opt.program .. "_" .. (opt.programver or "") - local allflags = detectcache:get2(key, flagskey) - if not allflags then - allflags = {} - local arglist = try {function () return os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) end} - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - local flag = flags[1] - return allflags[flag] -end - --- get extension -function _get_extension(opt) - -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] - return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" - local sourcefile = os.tmpfile("cl6x_has_flags:" .. snippet) .. _get_extension(opt) - if not os.isfile(sourcefile) then - io.writefile(sourcefile, snippet) - end - - -- check flags for linker - local tmpfile = os.tmpfile() - if islinker then - return _try_running(opt.program, table.join(flags, "-z", "--output_file=" .. tmpfile, sourcefile), opt) - end - - -- check flags for compiler - -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage - return _try_running(opt.program, table.join(flags, "-c", "--output_file=" .. tmpfile, sourcefile), opt) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - opt = opt or {} - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if not opt.tryrun then - if _check_from_arglist(flags, opt, islinker) then - return true - end - if _check_from_knownargs(flags, opt, islinker) then - return true - end - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - diff --git a/xmake/modules/core/tools/ar/has_flags.lua b/xmake/modules/core/tools/ar/has_flags.lua new file mode 100644 index 000000000..d4742e6e2 --- /dev/null +++ b/xmake/modules/core/tools/ar/has_flags.lua @@ -0,0 +1,82 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.ar.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all allflags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = nil + try + { + function () os.runv(opt.program, {"--help"}) end, + catch + { + function (errors) arglist = errors end + } + } + if arglist then + local found = false + for arg in arglist:gmatch("%-r %[%-(%a+)%]") do + arg:gsub("%a", function (ch) allflags["-" .. ch] = true; allflags["-r" .. ch] = true; allflags["-" .. ch .. "r"] = true end) + found = true + end + if found then + allflags["-r"] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + + -- ok? + return allflags[flags[1]] +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + return _check_from_arglist(flags, opt) +end + diff --git a/xmake/modules/core/tools/armasm64_msvc/has_flags.lua b/xmake/modules/core/tools/armasm64_msvc/has_flags.lua new file mode 100644 index 000000000..8fbab3d9f --- /dev/null +++ b/xmake/modules/core/tools/armasm64_msvc/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.armasm_msvc.has_flags") + diff --git a/xmake/modules/core/tools/armasm_msvc/has_flags.lua b/xmake/modules/core/tools/armasm_msvc/has_flags.lua new file mode 100644 index 000000000..f2aa5abed --- /dev/null +++ b/xmake/modules/core/tools/armasm_msvc/has_flags.lua @@ -0,0 +1,97 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.armasm.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all allflags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"-?"}, {envs = opt.envs}) + if arglist then + for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do + allflags[arg:gsub("/", "-")] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]:gsub("/", "-")] +end + +-- try running to check flags +function _check_try_running(flags, opt) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "armasm_has_flags.asm") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, [[ +END]]) + end + + -- check it + local errors = nil + return try { function () + local _, errs = os.iorunv(opt.program, table.join(flags, "-o", os.nuldev(), sourcefile), {envs = opt.envs}) + if errs and #errs:trim() > 0 then + return false, errs + end + return true + end, + catch { function (errs) errors = errs end } + }, errors +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt) +end + diff --git a/xmake/modules/core/tools/armclang/has_flags.lua b/xmake/modules/core/tools/armclang/has_flags.lua new file mode 100644 index 000000000..0c358e10a --- /dev/null +++ b/xmake/modules/core/tools/armclang/has_flags.lua @@ -0,0 +1,128 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + + -- the flags is "-Wl," or "-Xlinker "? + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then + return true + end + + -- the tool kind is ld or sh? + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + local has_target + for _, v in ipairs(argv) do + if v:startswith("-target=") then + has_target = true + break + end + end + if not has_target then + table.insert(argv, 1, "-mcpu=cortex-m3") + table.insert(argv, 1, "-target=arm-arm-none-eabi") + end + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + local key = "core.tools.armclang." .. (islinker and "has_ldflags" or "has_cflags") + local flagskey = opt.program .. "_" .. (opt.programver or "") + local allflags = detectcache:get2(key, flagskey) + if not allflags then + allflags = {} + local arglist = try {function () return os.iorunv(opt.program, {islinker and "-Wl,--help" or "--help"}, {envs = opt.envs}) end} + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + local flag = flags[1] + if islinker and flag then + if flag:startswith("-Wl,") then + flag = flag:match("-Wl,(.-),") or flag:sub(5) + end + end + return allflags[flag] +end + +-- get extension +function _get_extension(opt) + -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] + return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "armclang_has_flags" .. _get_extension(opt)) + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}\n") + end + + -- check flags for linker + local tmpfile = os.tmpfile() + if islinker then + return _try_running(opt.program, table.join(flags, "-o", tmpfile, sourcefile), opt) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-c", "-o", tmpfile, sourcefile), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + opt = opt or {} + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if not opt.tryrun and _check_from_arglist(flags, opt, islinker) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + + diff --git a/xmake/modules/core/tools/circle/has_flags.lua b/xmake/modules/core/tools/circle/has_flags.lua new file mode 100644 index 000000000..76744a133 --- /dev/null +++ b/xmake/modules/core/tools/circle/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gcc.has_flags") + diff --git a/xmake/modules/core/tools/cl/cfeatures.lua b/xmake/modules/core/tools/cl/cfeatures.lua new file mode 100644 index 000000000..9b043f7e1 --- /dev/null +++ b/xmake/modules/core/tools/cl/cfeatures.lua @@ -0,0 +1,49 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cfeatures.lua +-- + +-- set features +function _set(feature, condition) + _g.features = _g.features or {} + _g.features[feature] = condition +end + +-- get features +function main() + + -- init conditions + local msvc_minver = "_MSC_VER >= 1200" + local msvc_2005 = "_MSC_VER >= 1400" + local msvc_2010 = "_MSC_VER >= 1600" + local msvc_2019 = "_MSC_VER >= 1920" + + -- set language standard supports + _set("c_std_89", msvc_2005) + _set("c_std_99", msvc_2019) + + -- set features + _set("c_static_assert", msvc_2010) + _set("c_restrict", msvc_2005) + _set("c_variadic_macros", msvc_2005) + _set("c_function_prototypes", msvc_minver) + + -- get features + return _g.features +end + diff --git a/xmake/modules/core/tools/cl/cxxfeatures.lua b/xmake/modules/core/tools/cl/cxxfeatures.lua new file mode 100644 index 000000000..c8b683e6f --- /dev/null +++ b/xmake/modules/core/tools/cl/cxxfeatures.lua @@ -0,0 +1,151 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cxxfeatures.lua +-- + +-- set features +function _set(feature, condition) + _g.features = _g.features or {} + _g.features[feature] = condition +end + +-- get features +-- +-- Reference: http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx +-- http://blogs.msdn.com/b/vcblog/archive/2013/06/28/c-11-14-stl-features-fixes-and-breaking-changes-in-vs-2013.aspx +-- http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx +-- http://www.visualstudio.com/en-us/news/vs2015-preview-vs.aspx +-- http://blogs.msdn.com/b/vcblog/archive/2015/04/29/c-11-14-17-features-in-vs-2015-rc.aspx +-- http://blogs.msdn.com/b/vcblog/archive/2015/06/19/c-11-14-17-features-in-vs-2015-rtm.aspx +-- https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-160 +-- +-- porting from Modules/Compiler/MSVC-CXX-FeatureTests.cmake +-- +function main() + + -- init conditions + local msvc_minver = "_MSC_VER >= 1200" + local msvc_60 = "_MSC_VER >= 1200" + local msvc_70 = "_MSC_VER >= 1300" + local msvc_71 = "_MSC_VER >= 1310" + local msvc_2005 = "_MSC_VER >= 1400" + local msvc_2008 = "_MSC_VER >= 1500" + local msvc_2010 = "_MSC_VER >= 1600" + local msvc_2012 = "_MSC_VER >= 1700" + local msvc_2013 = "_MSC_VER >= 1800" + local msvc_2015 = "_MSC_VER >= 1900" + local msvc_2017 = "_MSC_VER >= 1910" + local msvc_2019 = "_MSC_VER >= 1920" + local msvc_2022 = "_MSC_VER >= 1930" + + -- set language standard supports + _set("cxx_std_98", msvc_2005) + _set("cxx_std_11", msvc_2015) + _set("cxx_std_14", msvc_2017) + _set("cxx_std_17", msvc_2019) + _set("cxx_std_20", msvc_2022) + + -- VS version 15 (not 2015) introduces support for aggregate initializers. + _set("cxx_aggregate_default_initializers", "_MSC_FULL_VER >= 190024406") + + -- VS 2015 Update 2 introduces support for variable templates. + -- https://www.visualstudio.com/en-us/news/vs2015-update2-vs.aspx + _set("cxx_variable_templates", "_MSC_FULL_VER >= 190023918") + + _set("cxx_alignas", msvc_2015) + _set("cxx_alignof", msvc_2015) + _set("cxx_attributes", msvc_2015) + _set("cxx_attribute_deprecated", msvc_2015) + _set("cxx_binary_literals", msvc_2015) + _set("cxx_constexpr", msvc_2015) + _set("cxx_decltype_auto", msvc_2015) + _set("cxx_digit_separators", msvc_2015) + _set("cxx_func_identifier", msvc_2015) + _set("cxx_nonstatic_member_init", msvc_2015) + _set("cxx_defaulted_move_initializers", msvc_2015) + _set("cxx_generic_lambdas", msvc_2015) + _set("cxx_inheriting_constructors", msvc_2015) + _set("cxx_inline_namespaces", msvc_2015) + _set("cxx_lambda_init_captures", msvc_2015) + _set("cxx_noexcept", msvc_2015) + _set("cxx_return_type_deduction", msvc_2015) + _set("cxx_sizeof_member", msvc_2015) + _set("cxx_thread_local", msvc_2015) + _set("cxx_unicode_literals", msvc_2015) + _set("cxx_unrestricted_unions", msvc_2015) + _set("cxx_user_literals", msvc_2015) + _set("cxx_reference_qualified_functions", msvc_2015) + + -- "The copies and moves don't interact precisely like the Standard says they + -- should. For example, deletion of moves is specified to also suppress + -- copies, but Visual C++ in Visual Studio 2013 does not." + -- http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx + -- lists this as 'partial' in 2013 + _set("cxx_deleted_functions", msvc_2015) + + -- http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx + -- Note 1. While previous version of VisualStudio said they supported these + -- they silently produced bad code, and are now marked as having partial + -- support in previous versions. The footnote says the support will be complete + -- in msvc 2015, so support the feature for that version, assuming that is true. + -- The blog post also says that VS 2013 Update 3 generates an error in cases + -- that previously produced bad code. + _set("cxx_generalized_initializers", "_MSC_FULL_VER >= 180030723") + + -- Microsoft now states they support contextual conversions in 2013 and above. + -- See footnote 6 at: + -- http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx + _set("cxx_contextual_conversions", msvc_2013) + _set("cxx_default_function_template_args", msvc_2013) + _set("cxx_defaulted_functions", msvc_2013) + _set("cxx_delegating_constructors", msvc_2013) + _set("cxx_explicit_conversions", msvc_2013) + _set("cxx_raw_string_literals", msvc_2013) + _set("cxx_uniform_initialization", msvc_2013) + _set("cxx_alias_templates", msvc_2013) + + -- Support is documented, but possibly partly broken: + -- https://msdn.microsoft.com/en-us/library/hh567368.aspx + -- http://thread.gmane.org/gmane.comp.lib.boost.devel/244986/focus=245333 + _set("cxx_variadic_templates", msvc_2013) + + _set("cxx_enum_forward_declarations", msvc_2012) + _set("cxx_final", msvc_2012) + _set("cxx_range_for", msvc_2012) + _set("cxx_strong_enums", msvc_2012) + + _set("cxx_auto_type", msvc_2010) + _set("cxx_decltype", msvc_2010) + _set("cxx_extended_friend_declarations", msvc_2010) + _set("cxx_extern_templates", msvc_2010) + _set("cxx_lambdas", msvc_2010) + _set("cxx_local_type_template_args", msvc_2010) + _set("cxx_long_long_type", msvc_2010) + _set("cxx_nullptr", msvc_2010) + _set("cxx_override", msvc_2010) + _set("cxx_right_angle_brackets", msvc_2010) + _set("cxx_rvalue_references", msvc_2010) + _set("cxx_static_assert", msvc_2010) + _set("cxx_template_template_parameters", msvc_2010) + _set("cxx_trailing_return_types", msvc_2010) + _set("cxx_variadic_macros", msvc_2010) + + -- get features + return _g.features +end + diff --git a/xmake/modules/core/tools/cl/features.lua b/xmake/modules/core/tools/cl/features.lua new file mode 100644 index 000000000..0957fd7ed --- /dev/null +++ b/xmake/modules/core/tools/cl/features.lua @@ -0,0 +1,140 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +import("cfeatures") +import("cxxfeatures") + +-- get macro defines +function _get_macro_defines(snippets, extension, opt) + + -- make an stub source file + local sourcefile = os.tmpfile() .. extension + local objectfile = sourcefile .. ".obj" + local binaryfile = sourcefile .. ".exe" + io.writefile(sourcefile, "#include \n\nint main(int argc, char** argv)\n{\n" .. table.concat(table.wrap(snippets), "\n") .. "\nreturn 0;\n}\n") + + -- get defines + local results = {} + local defines = try + { + function () + os.runv(opt.program, table.join(opt.flags or {}, {"-nologo", "-Fo" .. objectfile, sourcefile, "-link", "-out:" .. binaryfile}), {envs = opt.envs}) + return os.iorunv(binaryfile, {}, {envs = opt.envs}) + end + } + if defines then + for _, define in ipairs(defines:split("\n")) do + results[define] = true + end + end + + -- remove files + os.tryrm(sourcefile) + os.tryrm(objectfile) + os.tryrm(binaryfile) + return results +end + +-- set feature with condition +function _set_feature(feature, condition) + + -- init features + _g.features = _g.features or {} + + -- get feature kind + local kind = feature:match("^(%w-)_") + assert(kind, "unknown kind for the feature: %s", feature) + + -- init language extensions + _g.extensions = _g.extensions or {c = ".c", cxx = ".cpp", objc = ".m", objcxx = ".mm"} + + -- get extension + local extension = _g.extensions[kind] + assert(extension, "not supported kind for the feature: %s", feature) + + -- make snippet + local snippet = format([[ +#if (%s) + printf("%s\n"); +#endif]], condition, feature) + + -- init features with the given extension + local features = _g.features[extension] or {} + _g.features[extension] = features + + -- set feature and snippet + features[feature] = snippet +end + +-- set features +function set_features(features) + for feature, condition in pairs(features) do + _set_feature(feature, condition) + end +end + +-- check features +function check_features(opt) + + -- check features with all extensions + opt = opt or {} + local results = {} + for extension, features in pairs(_g.features) do + + -- make snippets + local snippets = {} + for _, snippet in pairs(features) do + table.insert(snippets, snippet) + end + + -- get defines + local defines = _get_macro_defines(snippets, extension, opt) + + -- check features + for feature, _ in pairs(features) do + if defines[feature] then + results[feature] = true + end + end + end + + -- ok? + return results +end + +-- get features +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", flags = {}} +-- +-- @return the features +-- +function main(opt) + + -- set features for c + set_features(cfeatures()) + + -- set features for c++ + set_features(cxxfeatures()) + + -- check features + return check_features(opt) +end + diff --git a/xmake/modules/core/tools/cl/has_flags.lua b/xmake/modules/core/tools/cl/has_flags.lua new file mode 100644 index 000000000..d174d84e2 --- /dev/null +++ b/xmake/modules/core/tools/cl/has_flags.lua @@ -0,0 +1,119 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.language.language") +import("core.cache.global_detectcache") + +-- attempt to check it from known flags +function _check_from_knownargs(flags, opt) + local flag = flags[1]:gsub("/", "-") + if flag:startswith("-D") or + flag:startswith("-U") or + flag:startswith("-I") then + return true + end +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + local key = "core.tools.cl.has_flags" + local flagskey = opt.program .. "_" .. (opt.programver or "") + local allflags = global_detectcache:get2(key, flagskey) + if not allflags then + allflags = {} + local arglist = os.iorunv(opt.program, {"-?"}, {envs = opt.envs}) + if arglist then + for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do + allflags[arg:gsub("/", "-")] = true + end + end + global_detectcache:set2(key, flagskey, allflags) + global_detectcache:save() + end + local flag = flags[1]:gsub("/", "-") + if flag:startswith("-D") or flag:startswith("-I") then + return true + end + return allflags[flag] +end + +-- get extension +function _get_extension(opt) + return opt.flagkind == "cxxflags" and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") +end + +-- try running to check flags +function _check_try_running(flags, opt) + + -- make an stub source file + local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" + local sourcefile = os.tmpfile("cl_has_flags:" .. snippet) .. _get_extension(opt) + if not os.isfile(sourcefile) then + io.writefile(sourcefile, snippet) + end + + -- check it + local errors = nil + return try { function () + local tmpdir = os.tmpdir() + local nuldev = os.nuldev() + local tmpfile + if not is_host("windows") then + tmpfile = os.tmpfile() + nuldev = tmpfile + end + local _, errs = os.iorunv(opt.program, table.join("-c", "-nologo", flags, "-Fo" .. nuldev, sourcefile), + {envs = opt.envs, curdir = tmpdir}) -- we need to switch to tmpdir to avoid generating some tmp files, e.g. /Zi -> vc140.pdb + if tmpfile then + os.tryrm(tmpfile) + end + if errs and #errs:trim() > 0 then + return false, errs + end + return true + end, + catch { function (errs) errors = errs end } + }, errors +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- attempt to check it from the argument list + opt = opt or {} + if not opt.tryrun then + if _check_from_arglist(flags, opt) then + return true + end + if _check_from_knownargs(flags, opt) then + return true + end + end + + -- try running to check it + return _check_try_running(flags, opt) +end + diff --git a/xmake/modules/core/tools/cl2000/has_flags.lua b/xmake/modules/core/tools/cl2000/has_flags.lua new file mode 100644 index 000000000..5d331d6b1 --- /dev/null +++ b/xmake/modules/core/tools/cl2000/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.cl6x.has_flags") + diff --git a/xmake/modules/core/tools/cl6x/has_flags.lua b/xmake/modules/core/tools/cl6x/has_flags.lua new file mode 100644 index 000000000..a5f3f4b87 --- /dev/null +++ b/xmake/modules/core/tools/cl6x/has_flags.lua @@ -0,0 +1,121 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from known flags +function _check_from_knownargs(flags, opt, islinker) + local flag = flags[1] + if not islinker then + if flag:startswith("-D") or + flag:startswith("-U") or + flag:startswith("-I") then + return true + end + end +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + local key = "core.tools.cl6x." .. (islinker and "has_ldflags" or "has_cflags") + local flagskey = opt.program .. "_" .. (opt.programver or "") + local allflags = detectcache:get2(key, flagskey) + if not allflags then + allflags = {} + local arglist = try {function () return os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) end} + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + local flag = flags[1] + return allflags[flag] +end + +-- get extension +function _get_extension(opt) + -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] + return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" + local sourcefile = os.tmpfile("cl6x_has_flags:" .. snippet) .. _get_extension(opt) + if not os.isfile(sourcefile) then + io.writefile(sourcefile, snippet) + end + + -- check flags for linker + local tmpfile = os.tmpfile() + if islinker then + return _try_running(opt.program, table.join(flags, "-z", "--output_file=" .. tmpfile, sourcefile), opt) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-c", "--output_file=" .. tmpfile, sourcefile), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + opt = opt or {} + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if not opt.tryrun then + if _check_from_arglist(flags, opt, islinker) then + return true + end + if _check_from_knownargs(flags, opt, islinker) then + return true + end + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/xmake/modules/core/tools/clang/cfeatures.lua b/xmake/modules/core/tools/clang/cfeatures.lua new file mode 100644 index 000000000..a6d10f6e1 --- /dev/null +++ b/xmake/modules/core/tools/clang/cfeatures.lua @@ -0,0 +1,58 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cfeatures.lua +-- + +-- imports +import("core.tools.gcc.cfeatures") + +-- set features +function _set(feature, condition) + _g.features[feature] = condition +end + +-- get features +function main() + + -- init features + _g.features = cfeatures() + + -- init conditions + -- clang -std=c11 -dM -E - < /dev/null | grep __STDC_VERSION__ + local clang_minver = "((__clang_major__ * 100) + __clang_minor__) >= 304" + local c17 = clang_minver .. " && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L" + local c11 = clang_minver .. " && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L" + local c99 = clang_minver .. " && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L" + local c90 = clang_minver + + -- set language standard supports + _set("c_std_89", c90) + _set("c_std_99", c99) + _set("c_std_11", c11) + _set("c_std_17", c17) + + -- set features + _set("c_static_assert", c11) + _set("c_restrict", c99) + _set("c_variadic_macros", c99) + _set("c_function_prototypes", c90) + + -- get features + return _g.features +end + diff --git a/xmake/modules/core/tools/clang/cxxfeatures.lua b/xmake/modules/core/tools/clang/cxxfeatures.lua new file mode 100644 index 000000000..4a98a1e74 --- /dev/null +++ b/xmake/modules/core/tools/clang/cxxfeatures.lua @@ -0,0 +1,132 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cxxfeatures.lua +-- + +-- imports +import("core.tools.gcc.cxxfeatures") + +-- set features +function _set(feature, condition) + _g.features[feature] = condition +end + +-- get features +-- +-- @see http://clang.llvm.org/cxx_status.html +-- +-- porting from Modules/Compiler/Clang-CXX-FeatureTests.cmake +-- +function main() + + -- init features + _g.features = cxxfeatures() + + -- init conditions + -- clang -x c++ -std=c++20 -dM -E - < /dev/null | grep __cplusplus + local clang_minver = "((__clang_major__ * 100) + __clang_minor__) >= 301" + local clang80_cxx20 = "((__clang_major__ * 100) + __clang_minor__) >= 800 && __cplusplus >= 202002L" + local clang50_cxx17 = "((__clang_major__ * 100) + __clang_minor__) >= 500 && __cplusplus >= 201703L" + local clang34_cxx14 = "((__clang_major__ * 100) + __clang_minor__) >= 304 && __cplusplus > 201103L" + local clang31_cxx11 = clang_minver .. " && __cplusplus >= 201103L" + local clang29_cxx11 = clang_minver .. " && __cplusplus >= 201103L" + local clang_cxx98 = clang_minver .. " && __cplusplus >= 199711L" + + -- set language standard supports + _set("cxx_std_98", clang_cxx98) + _set("cxx_std_11", clang29_cxx11) + _set("cxx_std_14", clang34_cxx14) + _set("cxx_std_17", clang50_cxx17) + _set("cxx_std_20", clang80_cxx20) + + -- set features for __has_feature() + local features_of_has_feature = + { + "cxx_alias_templates" + , "cxx_alignas" + , "cxx_attributes" + , "cxx_auto_type" + , "cxx_binary_literals" + , "cxx_constexpr" + , "cxx_contextual_conversions" + , "cxx_decltype" + , "cxx_default_function_template_args" + , "cxx_defaulted_functions" + , "cxx_delegating_constructors" + , "cxx_deleted_functions" + , "cxx_explicit_conversions" + , "cxx_generalized_initializers" + , "cxx_inheriting_constructors" + , "cxx_lambdas" + , "cxx_local_type_template_args" + , "cxx_noexcept" + , "cxx_nonstatic_member_init" + , "cxx_nullptr" + , "cxx_range_for" + , "cxx_raw_string_literals" + , "cxx_reference_qualified_functions" + , "cxx_relaxed_constexpr" + , "cxx_return_type_deduction" + , "cxx_rvalue_references" + , "cxx_static_assert" + , "cxx_strong_enums" + , "cxx_thread_local" + , "cxx_unicode_literals" + , "cxx_unrestricted_unions" + , "cxx_user_literals" + , "cxx_variable_templates" + , "cxx_variadic_templates" + , {"cxx_aggregate_default_initializers", "cxx_aggregate_nsdmi" } + , {"cxx_trailing_return_types", "cxx_trailing_return" } + , {"cxx_alignof", "cxx_alignas" } + , {"cxx_final", "cxx_override_control" } + , {"cxx_override", "cxx_override_control" } + , {"cxx_uniform_initialization", "cxx_generalized_initializers" } + , {"cxx_defaulted_move_initializers", "cxx_defaulted_functions" } + , {"cxx_lambda_init_captures", "cxx_init_captures" } + } + for _, feature in ipairs(features_of_has_feature) do + local name = feature + local test = feature + if type(feature) == "table" then + name = feature[1] + test = feature[2] + end + _set(name, clang_minver .. " && __has_feature(" .. test .. ")") + end + + -- set features + _set("cxx_attribute_deprecated", clang34_cxx14) -- http://llvm.org/bugs/show_bug.cgi?id=19242 + _set("cxx_decltype_auto", clang34_cxx14) -- http://llvm.org/bugs/show_bug.cgi?id=19698 + _set("cxx_digit_separators", clang34_cxx14) + _set("cxx_generic_lambdas", clang34_cxx14) -- http://llvm.org/bugs/show_bug.cgi?id=19674 + _set("cxx_enum_forward_declarations", clang31_cxx11) + _set("cxx_sizeof_member", clang31_cxx11) + _set("cxx_extended_friend_declarations", clang29_cxx11) + _set("cxx_extern_templates", clang29_cxx11) + _set("cxx_func_identifier", clang29_cxx11) + _set("cxx_inline_namespaces", clang29_cxx11) + _set("cxx_long_long_type", clang29_cxx11) + _set("cxx_right_angle_brackets", clang29_cxx11) + _set("cxx_variadic_macros", clang29_cxx11) + _set("cxx_template_template_parameters", clang_cxx98) + + -- get features + return _g.features +end + diff --git a/xmake/modules/core/tools/clang/features.lua b/xmake/modules/core/tools/clang/features.lua new file mode 100644 index 000000000..c2e2bf523 --- /dev/null +++ b/xmake/modules/core/tools/clang/features.lua @@ -0,0 +1,44 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +inherit("core.tools.gcc.features") +import("cfeatures") +import("cxxfeatures") + +-- get features +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", flags = {}} +-- +-- @return the features +-- +function main(opt) + + -- set features for c + set_features(cfeatures()) + + -- set features for c++ + set_features(cxxfeatures()) + + -- check features + return check_features(opt) +end + + diff --git a/xmake/modules/core/tools/clang/has_flags.lua b/xmake/modules/core/tools/clang/has_flags.lua new file mode 100644 index 000000000..76744a133 --- /dev/null +++ b/xmake/modules/core/tools/clang/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gcc.has_flags") + diff --git a/xmake/modules/core/tools/clang_cl/has_flags.lua b/xmake/modules/core/tools/clang_cl/has_flags.lua new file mode 100644 index 000000000..56d83998a --- /dev/null +++ b/xmake/modules/core/tools/clang_cl/has_flags.lua @@ -0,0 +1,101 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.clang_cl.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all allflags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"-?"}) + if arglist then + for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do + allflags[arg:gsub("/", "-")] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]:gsub("/", "-")] +end + +-- try running +function _try_running(...) + + local argv = {...} + local errors = nil + return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- try running to check flags +function _check_try_running(flags, opt) + + -- get extension + -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] + local extension = opt.program:endswith("++") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "clang_cl_has_flags" .. extension) + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}\n") + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join("-Werror=unused-command-line-argument", flags, "-c", "-o", os.tmpfile(), sourcefile)) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt) +end + diff --git a/xmake/modules/core/tools/clangxx/features.lua b/xmake/modules/core/tools/clangxx/features.lua new file mode 100644 index 000000000..08c822cfd --- /dev/null +++ b/xmake/modules/core/tools/clangxx/features.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +inherit("core.tools.gcc.features") + diff --git a/xmake/modules/core/tools/clangxx/has_flags.lua b/xmake/modules/core/tools/clangxx/has_flags.lua new file mode 100644 index 000000000..76744a133 --- /dev/null +++ b/xmake/modules/core/tools/clangxx/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gcc.has_flags") + diff --git a/xmake/modules/core/tools/cosmocc/has_flags.lua b/xmake/modules/core/tools/cosmocc/has_flags.lua new file mode 100644 index 000000000..51a673a4e --- /dev/null +++ b/xmake/modules/core/tools/cosmocc/has_flags.lua @@ -0,0 +1,143 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + + -- the flags is "-Wl," or "-Xlinker "? + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then + return true + end + + -- the tool kind is ld or sh? + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { + function () os.runv(program, argv, table.join(opt or {}, {shell = true})) + return true + end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from known flags +function _check_from_knownargs(flags, opt, islinker) + local flag = flags[1] + if not islinker then + if flag:startswith("-D") or + flag:startswith("-U") or + flag:startswith("-I") then + return true + end + end +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + local key = "core.tools.cosmocc." .. (islinker and "has_ldflags" or "has_cflags") + local flagskey = opt.program .. "_" .. (opt.programver or "") + local allflags = detectcache:get2(key, flagskey) + if not allflags then + allflags = {} + local arglist = try {function () return os.iorunv(opt.program, {islinker and "-Wl,--help" or "--help"}, {envs = opt.envs, shell = true}) end} + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + local flag = flags[1] + if islinker and flag then + if flag:startswith("-Wl,") then + flag = flag:match("-Wl,(.-),") or flag:sub(5) + end + end + return allflags[flag] +end + +-- get extension +function _get_extension(opt) + -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] + return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" + local sourcefile = os.tmpfile("cosmocc_has_flags:" .. snippet) .. _get_extension(opt) + if not os.isfile(sourcefile) then + io.writefile(sourcefile, snippet) + end + if is_host("windows") then + sourcefile = sourcefile:gsub("\\", "/") + end + + -- check flags for linker + local tmpfile = os.tmpfile() + if is_host("windows") then + tmpfile = tmpfile:gsub("\\", "/") + end + if islinker then + return _try_running(opt.program, table.join(flags, "-o", tmpfile, sourcefile), opt) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-o", tmpfile, sourcefile), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + opt = opt or {} + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if not opt.tryrun then + if _check_from_arglist(flags, opt, islinker) then + return true + end + if _check_from_knownargs(flags, opt, islinker) then + return true + end + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/xmake/modules/core/tools/cosmocxx/has_flags.lua b/xmake/modules/core/tools/cosmocxx/has_flags.lua new file mode 100644 index 000000000..3181c0647 --- /dev/null +++ b/xmake/modules/core/tools/cosmocxx/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.cosmocc.has_flags") + diff --git a/xmake/modules/core/tools/dmd/has_flags.lua b/xmake/modules/core/tools/dmd/has_flags.lua new file mode 100644 index 000000000..c69c27166 --- /dev/null +++ b/xmake/modules/core/tools/dmd/has_flags.lua @@ -0,0 +1,119 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") + +-- is linker? +function _islinker(flags, opt) + + -- the flags is "-L=" or "-L"? + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-L=") or flags_str:startswith("-L-") then + return true + end + + -- the tool kind is ld or sh? + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") +end + +-- try running +function _try_running(...) + + local argv = {...} + local errors = nil + return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + + -- only for compiler + if islinker or #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.dmd.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all allflags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"--help"}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "dmd_has_flags.d") + local objectfile = path.join(os.tmpdir(), "detect", "dmd_has_flags.o") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "void main() {\n}") + end + + -- init argv + local argv = table.join(flags, "-of" .. objectfile, sourcefile) + if not islinker then + table.insert(argv, 1, "-c") + end + + -- check it + return _try_running(opt.program, argv) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt, islinker) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/xmake/modules/core/tools/dpcpp/cfeatures.lua b/xmake/modules/core/tools/dpcpp/cfeatures.lua new file mode 100644 index 000000000..9cc3928ce --- /dev/null +++ b/xmake/modules/core/tools/dpcpp/cfeatures.lua @@ -0,0 +1,22 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cfeatures.lua +-- + +-- imports +import("core.tools.clang.cfeatures") diff --git a/xmake/modules/core/tools/dpcpp/cxxfeatures.lua b/xmake/modules/core/tools/dpcpp/cxxfeatures.lua new file mode 100644 index 000000000..4c779fbb8 --- /dev/null +++ b/xmake/modules/core/tools/dpcpp/cxxfeatures.lua @@ -0,0 +1,22 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cxxfeatures.lua +-- + +-- imports +import("core.tools.clang.cxxfeatures") diff --git a/xmake/modules/core/tools/dpcpp/features.lua b/xmake/modules/core/tools/dpcpp/features.lua new file mode 100644 index 000000000..8c04a299c --- /dev/null +++ b/xmake/modules/core/tools/dpcpp/features.lua @@ -0,0 +1,22 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +inherit("core.tools.clang.features") diff --git a/xmake/modules/core/tools/dpcpp/has_flags.lua b/xmake/modules/core/tools/dpcpp/has_flags.lua new file mode 100644 index 000000000..284736424 --- /dev/null +++ b/xmake/modules/core/tools/dpcpp/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.clang.has_flags") + diff --git a/xmake/modules/core/tools/emcc/has_flags.lua b/xmake/modules/core/tools/emcc/has_flags.lua new file mode 100644 index 000000000..76744a133 --- /dev/null +++ b/xmake/modules/core/tools/emcc/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gcc.has_flags") + diff --git a/xmake/modules/core/tools/emxx/has_flags.lua b/xmake/modules/core/tools/emxx/has_flags.lua new file mode 100644 index 000000000..b4d6369d6 --- /dev/null +++ b/xmake/modules/core/tools/emxx/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.emcc.has_flags") + diff --git a/xmake/modules/core/tools/fpc/has_flags.lua b/xmake/modules/core/tools/fpc/has_flags.lua new file mode 100644 index 000000000..8c4e68086 --- /dev/null +++ b/xmake/modules/core/tools/fpc/has_flags.lua @@ -0,0 +1,98 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") + +-- try running +function _try_running(...) + + local argv = {...} + local errors = nil + return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.fpc.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all allflags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"-h"}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "fpc_has_flags.pas") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "program Hello;\nbegin\nend.") + end + + -- check it + local binaryfile = os.tmpfile() + local ok, errors = _try_running(opt.program, table.join(flags, "-o" .. binaryfile, sourcefile)) + os.tryrm(binaryfile) + return ok, errors +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt) +end + diff --git a/xmake/modules/core/tools/gcc/cfeatures.lua b/xmake/modules/core/tools/gcc/cfeatures.lua new file mode 100644 index 000000000..b9ebaa036 --- /dev/null +++ b/xmake/modules/core/tools/gcc/cfeatures.lua @@ -0,0 +1,52 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cfeatures.lua +-- + +-- set features +function _set(feature, condition) + _g.features = _g.features or {} + _g.features[feature] = condition +end + +-- get features +function main() + + -- init conditions + local gcc_minver = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 304" + local gcc10_c17 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 1000 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L" + local gcc46_c11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 406 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201000L" + local gcc34_c99 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 304 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L" + local gcc_c90 = gcc_minver + + -- set language standard supports + _set("c_std_89", gcc46_c90) + _set("c_std_99", gcc34_c99) + _set("c_std_11", gcc46_c11) + _set("c_std_17", gcc46_c17) + + -- set features + _set("c_static_assert", gcc46_c11) -- GNU 4.7 correctly sets __STDC_VERSION__ to 201112L, but GNU 4.6 sets it to 201000L + _set("c_restrict", gcc34_c99) + _set("c_variadic_macros", gcc34_c99) + _set("c_function_prototypes", gcc_c90) + + -- get features + return _g.features +end + diff --git a/xmake/modules/core/tools/gcc/cxxfeatures.lua b/xmake/modules/core/tools/gcc/cxxfeatures.lua new file mode 100644 index 000000000..9d628522c --- /dev/null +++ b/xmake/modules/core/tools/gcc/cxxfeatures.lua @@ -0,0 +1,222 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cxxfeatures.lua +-- + +-- set features +function _set(feature, condition) + _g.features = _g.features or {} + _g.features[feature] = condition +end + +-- get features +-- +-- http://gcc.gnu.org/projects/cxx0x.html +-- http://gcc.gnu.org/projects/cxx1y.html +-- https://gcc.gnu.org/projects/cxx-status.html +-- +-- porting from Modules/Compiler/GNU-CXX-FeatureTests.cmake +-- +function main() + + -- init conditions + -- gcc -x c++ -std=c++20 -dM -E - < /dev/null | grep __cplusplus + local gcc_minver = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 404" + local gcc90_cxx20 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 900 && __cplusplus >= 202002L" + local gcc70_cxx17 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 700 && __cplusplus >= 201703L" + local gcc50_cxx14 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 500 && __cplusplus >= 201402L" + local gcc49_cxx14 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 409 && __cplusplus > 201103L" + local gcc481_cxx11 = "((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40801) && __cplusplus >= 201103L" + local gcc48_cxx11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 408 && __cplusplus >= 201103L" + local gcc47_cxx11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 407 && __cplusplus >= 201103L" + local gcc_cxx0x_defined = "(__cplusplus >= 201103L || (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__))" + local gcc46_cxx11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 406 && " .. gcc_cxx0x_defined + local gcc45_cxx11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 405 && " .. gcc_cxx0x_defined + local gcc44_cxx11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 404 && " .. gcc_cxx0x_defined + local gcc43_cxx11 = gcc_minver .. " && " .. gcc_cxx0x_defined + + -- set language standard supports + _set("cxx_std_98", gcc_minver) + _set("cxx_std_11", gcc43_cxx11) + _set("cxx_std_14", gcc49_cxx14) + _set("cxx_std_17", gcc70_cxx17) + _set("cxx_std_20", gcc90_cxx20) + + -- set features + _set("cxx_variable_templates", gcc50_cxx14) + _set("cxx_relaxed_constexpr", gcc50_cxx14) + _set("cxx_aggregate_default_initializers", gcc50_cxx14) + + -- GNU 4.9 in c++14 mode sets __cplusplus to 201300L, so don't test for the + -- correct value of it below. + -- https://patchwork.ozlabs.org/patch/382470/ + _set("cxx_contextual_conversions", gcc49_cxx14) + _set("cxx_attribute_deprecated", gcc49_cxx14) + _set("cxx_decltype_auto", gcc49_cxx14) + _set("cxx_digit_separators", gcc49_cxx14) + _set("cxx_generic_lambdas", gcc49_cxx14) + _set("cxx_lambda_init_captures", gcc49_cxx14) + + -- GNU 4.3 supports binary literals as an extension, but may warn about + -- use of extensions prior to GNU 4.9 + -- http://stackoverflow.com/questions/16334024/difference-between-gcc-binary-literals-and-c14-ones + _set("cxx_binary_literals", gcc49_cxx14) + + -- The feature below is documented as available in GNU 4.8 (by implementing an + -- earlier draft of the standard paper), but that version of the compiler + -- does not set __cplusplus to a value greater than 201103L until GNU 4.9: + -- http://gcc.gnu.org/onlinedocs/gcc-4.8.2/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros + -- http://gcc.gnu.org/onlinedocs/gcc-4.9.0/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros + -- So, CMake only reports availability for it with GNU 4.9 or later. + _set("cxx_return_type_deduction", gcc49_cxx14) + + -- Introduced in GCC 4.8.1 + _set("cxx_decltype_incomplete_return_types", gcc481_cxx11) + _set("cxx_reference_qualified_functions", gcc481_cxx11) + + -- The alignof feature works with GNU 4.7 and -std=c++11, but it is documented + -- as available with GNU 4.8, so treat that as true. + _set("cxx_alignas", gcc48_cxx11) + _set("cxx_alignof", gcc48_cxx11) + _set("cxx_attributes", gcc48_cxx11) + _set("cxx_inheriting_constructors", gcc48_cxx11) + _set("cxx_thread_local", gcc48_cxx11) + + _set("cxx_alias_templates", gcc47_cxx11) + _set("cxx_delegating_constructors", gcc47_cxx11) + _set("cxx_extended_friend_declarations", gcc47_cxx11) + _set("cxx_final", gcc47_cxx11) + _set("cxx_nonstatic_member_init", gcc47_cxx11) + _set("cxx_override", gcc47_cxx11) + _set("cxx_user_literals", gcc47_cxx11) + + -- NOTE: C++11 was ratified in September 2011. GNU 4.7 is the first minor + -- release following that (March 2012), and the first minor release to + -- support -std=c++11. Prior to that, support for C++11 features is technically + -- experiemental and possibly incomplete (see for example the note below about + -- cxx_variadic_template_template_parameters) + -- GNU does not define __cplusplus correctly before version 4.7. + -- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773 + -- __GXX_EXPERIMENTAL_CXX0X__ is defined in prior versions, but may not be + -- defined in the future. + _set("cxx_constexpr", gcc46_cxx11) + _set("cxx_defaulted_move_initializers", gcc46_cxx11) + _set("cxx_enum_forward_declarations", gcc46_cxx11) + _set("cxx_noexcept", gcc46_cxx11) + _set("cxx_nullptr", gcc46_cxx11) + _set("cxx_range_for", gcc46_cxx11) + _set("cxx_unrestricted_unions", gcc46_cxx11) + + _set("cxx_explicit_conversions", gcc45_cxx11) + _set("cxx_lambdas", gcc45_cxx11) + _set("cxx_local_type_template_args", gcc45_cxx11) + _set("cxx_raw_string_literals", gcc45_cxx11) + + _set("cxx_auto_type", gcc44_cxx11) + _set("cxx_defaulted_functions", gcc44_cxx11) + _set("cxx_deleted_functions", gcc44_cxx11) + _set("cxx_generalized_initializers", gcc44_cxx11) + _set("cxx_inline_namespaces", gcc44_cxx11) + _set("cxx_sizeof_member", gcc44_cxx11) + _set("cxx_strong_enums", gcc44_cxx11) + _set("cxx_trailing_return_types", gcc44_cxx11) + _set("cxx_unicode_literals", gcc44_cxx11) + _set("cxx_uniform_initialization", gcc44_cxx11) + _set("cxx_variadic_templates", gcc44_cxx11) + + -- TODO: If features are ever recorded for GNU 4.3, there should possibly + -- be a new feature added like cxx_variadic_template_template_parameters, + -- which is implemented by GNU 4.4, but not 4.3. cxx_variadic_templates is + -- actually implemented by GNU 4.3, but variadic template template parameters + -- 'completes' it, so that is the version we record as having the variadic + -- templates capability in CMake. See + -- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2555.pdf + -- TODO: Should be supported by GNU 4.3 + _set("cxx_decltype", gcc43_cxx11) + _set("cxx_default_function_template_args", gcc43_cxx11) + _set("cxx_long_long_type", gcc43_cxx11) + _set("cxx_right_angle_brackets", gcc43_cxx11) + _set("cxx_rvalue_references", gcc43_cxx11) + _set("cxx_static_assert", gcc43_cxx11) + + -- TODO: Should be supported since GNU 3.4? + _set("cxx_extern_templates", gcc_minver .. " && " .. gcc_cxx0x_defined) + + -- TODO: Should be supported forever? + _set("cxx_func_identifier", gcc_minver .. " && " .. gcc_cxx0x_defined) + _set("cxx_variadic_macros", gcc_minver .. " && " .. gcc_cxx0x_defined) + _set("cxx_template_template_parameters", gcc_minver .. " && __cplusplus") + + -- c++17 language features with predefined macros + -- https://en.cppreference.com/w/cpp/feature_test + local features_cxx17 = { + "__cpp_aggregate_bases", + "__cpp_aligned_new", + "__cpp_capture_star_this", + "__cpp_constexpr", + "__cpp_deduction_guides", + "__cpp_enumerator_attributes", + "__cpp_fold_expressions", + "__cpp_guaranteed_copy_elision", + "__cpp_hex_float", + "__cpp_if_constexpr", + "__cpp_inheriting_constructors", + "__cpp_inline_variables", + "__cpp_namespace_attributes", + "__cpp_noexcept_function_type", + "__cpp_nontype_template_args", + "__cpp_nontype_template_parameter_auto", + "__cpp_range_based_for", + "__cpp_static_assert", + "__cpp_structured_bindings", + "__cpp_template_template_args", + "__cpp_variadic_using"} + for _, feature in ipairs(features_cxx17) do + _set((feature:gsub("__cpp", "cxx")), "__cplusplus && defined(" .. feature .. ")") + end + + -- c++20 language features with predefined macros + -- https://en.cppreference.com/w/cpp/feature_test + local features_cxx20 = { + "__cpp_aggregate_paren_init", + "__cpp_char8_t", + "__cpp_concepts", + "__cpp_conditional_explicit", + "__cpp_consteval", + "__cpp_constexpr", + "__cpp_constexpr_dynamic_alloc", + "__cpp_constexpr_in_decltype", + "__cpp_constinit", + "__cpp_deduction_guides", + "__cpp_designated_initializers", + "__cpp_generic_lambdas", + "__cpp_impl_coroutine", + "__cpp_impl_destroying_delete", + "__cpp_impl_three_way_comparison", + "__cpp_init_captures", + "__cpp_modules", + "__cpp_nontype_template_args", + "__cpp_using_enum"} + for _, feature in ipairs(features_cxx20) do + _set((feature:gsub("__cpp", "cxx")), "__cplusplus && defined(" .. feature .. ")") + end + + -- get features + return _g.features +end + diff --git a/xmake/modules/core/tools/gcc/features.lua b/xmake/modules/core/tools/gcc/features.lua new file mode 100644 index 000000000..153cc3fb4 --- /dev/null +++ b/xmake/modules/core/tools/gcc/features.lua @@ -0,0 +1,130 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +import("cfeatures") +import("cxxfeatures") +import("core.language.language") + +-- get macro defines +function _get_macro_defines(snippets, extension, opt) + + -- make an stub source file + local sourcefile = os.tmpfile() .. extension + io.writefile(sourcefile, table.concat(table.wrap(snippets), "\n")) + + -- get defines + local results = {} + local defines = try { function () return os.iorunv(opt.program, table.join(opt.flags or {}, {"-dM", "-E", sourcefile}), {envs = opt.envs}) end } + if defines then + for _, define in ipairs(defines:split("\n")) do + local name = define:match("#define%s+(.-)%s+") + if name then + results[name] = true + end + end + end + os.tryrm(sourcefile) + return results +end + +-- set feature with condition +function _set_feature(feature, condition) + + -- init features + _g.features = _g.features or {} + + -- get language kind + local langkind = feature:match("^(%w-)_") + assert(langkind, "unknown language kind for the feature: %s", feature) + + -- get source kind from the language kind + local sourcekind = language.langkinds()[langkind] + assert(sourcekind, "unknown language kind: " .. langkind) + + -- get extension + local extension = table.wrap(language.sourcekinds()[sourcekind])[1] + assert(extension, "not supported kind for the feature: %s", feature) + + -- make snippet + local snippet = format([[ +#if (%s) +# define %s 1 +#endif]], condition, feature) + + -- init features with the given extension + local features = _g.features[extension] or {} + _g.features[extension] = features + + -- set feature and snippet + features[feature] = snippet +end + +-- set features +function set_features(features) + for feature, condition in pairs(features) do + _set_feature(feature, condition) + end +end + +-- check features +function check_features(opt) + + -- check features with all extensions + local results = {} + for extension, features in pairs(_g.features) do + + -- make snippets + local snippets = {} + for _, snippet in pairs(features) do + table.insert(snippets, snippet) + end + + -- get defines + local defines = _get_macro_defines(snippets, extension, opt) + + -- check features + for feature, _ in pairs(features) do + if defines[feature] then + results[feature] = true + end + end + end + return results +end + +-- get features +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", flags = {}} +-- +-- @return the features +-- +function main(opt) + + -- set features for c + set_features(cfeatures()) + + -- set features for c++ + set_features(cxxfeatures()) + + -- check features + return check_features(opt) +end + diff --git a/xmake/modules/core/tools/gcc/has_flags.lua b/xmake/modules/core/tools/gcc/has_flags.lua new file mode 100644 index 000000000..25d08be01 --- /dev/null +++ b/xmake/modules/core/tools/gcc/has_flags.lua @@ -0,0 +1,134 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + + -- the flags is "-Wl," or "-Xlinker "? + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then + return true + end + + -- the tool kind is ld or sh? + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from known flags +function _check_from_knownargs(flags, opt, islinker) + local flag = flags[1] + if not islinker then + if flag:startswith("-D") or + flag:startswith("-U") or + flag:startswith("-I") then + return true + end + end +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + local key = "core.tools.gcc." .. (islinker and "has_ldflags" or "has_cflags") + local flagskey = opt.program .. "_" .. (opt.programver or "") + local allflags = detectcache:get2(key, flagskey) + if not allflags then + allflags = {} + local arglist = try {function () return os.iorunv(opt.program, {islinker and "-Wl,--help" or "--help"}, {envs = opt.envs}) end} + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + local flag = flags[1] + if islinker and flag then + if flag:startswith("-Wl,") then + flag = flag:match("-Wl,(.-),") or flag:sub(5) + end + end + return allflags[flag] +end + +-- get extension +function _get_extension(opt) + -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] + return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" + local sourcefile = os.tmpfile("gcc_has_flags:" .. snippet) .. _get_extension(opt) + if not os.isfile(sourcefile) then + io.writefile(sourcefile, snippet) + end + + -- check flags for linker + local tmpfile = os.tmpfile() + if islinker then + return _try_running(opt.program, table.join(flags, "-o", tmpfile, sourcefile), opt) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-S", "-o", tmpfile, sourcefile), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + opt = opt or {} + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if not opt.tryrun then + if _check_from_arglist(flags, opt, islinker) then + return true + end + if _check_from_knownargs(flags, opt, islinker) then + return true + end + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/xmake/modules/core/tools/gccgo/has_flags.lua b/xmake/modules/core/tools/gccgo/has_flags.lua new file mode 100644 index 000000000..76744a133 --- /dev/null +++ b/xmake/modules/core/tools/gccgo/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gcc.has_flags") + diff --git a/xmake/modules/core/tools/gdc/has_flags.lua b/xmake/modules/core/tools/gdc/has_flags.lua new file mode 100644 index 000000000..e4cc32f65 --- /dev/null +++ b/xmake/modules/core/tools/gdc/has_flags.lua @@ -0,0 +1,118 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + + -- the flags is "-Wl," or "-Xlinker "? + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then + return true + end + + -- the tool kind is ld or sh? + local toolkind = opt.toolkind or "" + return toolkind == "dcld" or toolkind == "dcsh" +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + + -- only for compiler + if islinker or #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.gdc.has_flags" + + -- make flags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all flags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "gdc_has_flags.d") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "void main()\n{}") + end + + -- check flags for linker + if islinker then + return _try_running(opt.program, table.join(flags, "-o", os.tmpfile(), sourcefile), opt) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-S", "-o", os.tmpfile(), sourcefile), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt, islinker) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + + diff --git a/xmake/modules/core/tools/gfortran/has_flags.lua b/xmake/modules/core/tools/gfortran/has_flags.lua new file mode 100644 index 000000000..3552d4d45 --- /dev/null +++ b/xmake/modules/core/tools/gfortran/has_flags.lua @@ -0,0 +1,117 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + + -- the flags is "-Wl," or "-Xlinker "? + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then + return true + end + + -- the tool kind is ld or sh? + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("-ld") or toolkind:endswith("-sh") +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + + -- only for compiler + if islinker or #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.gfortran.has_flags" + + -- make flags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all flags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "gfortran_has_flags.f90") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "program hello\n print *, \"Hello World!\"\nend program hello") + end + + -- check flags for linker + if islinker then + return _try_running(opt.program, table.join(flags, "-o", os.tmpfile(), sourcefile), opt) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-S", "-o", os.tmpfile(), sourcefile), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt, islinker) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/xmake/modules/core/tools/go/has_flags.lua b/xmake/modules/core/tools/go/has_flags.lua new file mode 100644 index 000000000..bf96a1f1f --- /dev/null +++ b/xmake/modules/core/tools/go/has_flags.lua @@ -0,0 +1,130 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + + -- the tool kind is gcld or gcsh? + local toolkind = opt.toolkind or "" + return toolkind:endswith("ld") or toolkind:endswith("sh") +end + +-- try running +function _try_running(...) + + local argv = {...} + local errors = nil + return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + + -- only for compiler + if islinker or #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.go.has_flags" + + -- make flags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all flags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- attempt to get argument list from the error info (help menu) + allflags = {} + try + { + function () os.runv(opt.program, {"tool", "compile", "--help"}) end, + catch + { + function (errors) + local arglist = errors + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + end + } + } + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "go_has_flags.go") + local objectfile = path.join(os.tmpdir(), "detect", "go_has_flags.o") + local targetfile = path.join(os.tmpdir(), "detect", "go_has_flags.bin") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "package main\nfunc main() {\n}") + end + + -- check flags for linker + if islinker then + + -- compile a object file first + if not os.isfile(objectfile) and not _try_running(opt.program, table.join("tool", "compile", "-o", objectfile, sourcefile)) then + return false + end + + -- check it + return _try_running(opt.program, table.join("tool", "link", flags, "-o", targetfile, objectfile)) + end + + -- check flags for compiler + return _try_running(opt.program, table.join("tool", "compile", flags, "-o", objectfile, sourcefile)) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt, islinker) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/xmake/modules/core/tools/gxx/features.lua b/xmake/modules/core/tools/gxx/features.lua new file mode 100644 index 000000000..08c822cfd --- /dev/null +++ b/xmake/modules/core/tools/gxx/features.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +inherit("core.tools.gcc.features") + diff --git a/xmake/modules/core/tools/gxx/has_flags.lua b/xmake/modules/core/tools/gxx/has_flags.lua new file mode 100644 index 000000000..76744a133 --- /dev/null +++ b/xmake/modules/core/tools/gxx/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gcc.has_flags") + diff --git a/xmake/modules/core/tools/icc/has_flags.lua b/xmake/modules/core/tools/icc/has_flags.lua new file mode 100644 index 000000000..76744a133 --- /dev/null +++ b/xmake/modules/core/tools/icc/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gcc.has_flags") + diff --git a/xmake/modules/core/tools/icl/has_flags.lua b/xmake/modules/core/tools/icl/has_flags.lua new file mode 100644 index 000000000..ab189dfd0 --- /dev/null +++ b/xmake/modules/core/tools/icl/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.cl.has_flags") + diff --git a/xmake/modules/core/tools/icpc/has_flags.lua b/xmake/modules/core/tools/icpc/has_flags.lua new file mode 100644 index 000000000..a2d18c48f --- /dev/null +++ b/xmake/modules/core/tools/icpc/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gxx.has_flags") + diff --git a/xmake/modules/core/tools/icpx/features.lua b/xmake/modules/core/tools/icpx/features.lua new file mode 100644 index 000000000..7628827f1 --- /dev/null +++ b/xmake/modules/core/tools/icpx/features.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +inherit("core.tools.clang.features") + diff --git a/xmake/modules/core/tools/icpx/has_flags.lua b/xmake/modules/core/tools/icpx/has_flags.lua new file mode 100644 index 000000000..284736424 --- /dev/null +++ b/xmake/modules/core/tools/icpx/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.clang.has_flags") + diff --git a/xmake/modules/core/tools/icx/cfeatures.lua b/xmake/modules/core/tools/icx/cfeatures.lua new file mode 100644 index 000000000..9cc3928ce --- /dev/null +++ b/xmake/modules/core/tools/icx/cfeatures.lua @@ -0,0 +1,22 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cfeatures.lua +-- + +-- imports +import("core.tools.clang.cfeatures") diff --git a/xmake/modules/core/tools/icx/cxxfeatures.lua b/xmake/modules/core/tools/icx/cxxfeatures.lua new file mode 100644 index 000000000..4c779fbb8 --- /dev/null +++ b/xmake/modules/core/tools/icx/cxxfeatures.lua @@ -0,0 +1,22 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cxxfeatures.lua +-- + +-- imports +import("core.tools.clang.cxxfeatures") diff --git a/xmake/modules/core/tools/icx/features.lua b/xmake/modules/core/tools/icx/features.lua new file mode 100644 index 000000000..8c04a299c --- /dev/null +++ b/xmake/modules/core/tools/icx/features.lua @@ -0,0 +1,22 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +inherit("core.tools.clang.features") diff --git a/xmake/modules/core/tools/icx/has_flags.lua b/xmake/modules/core/tools/icx/has_flags.lua new file mode 100644 index 000000000..284736424 --- /dev/null +++ b/xmake/modules/core/tools/icx/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.clang.has_flags") + diff --git a/xmake/modules/core/tools/ifort/has_flags.lua b/xmake/modules/core/tools/ifort/has_flags.lua new file mode 100644 index 000000000..df3acfe3e --- /dev/null +++ b/xmake/modules/core/tools/ifort/has_flags.lua @@ -0,0 +1,27 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +if is_host("windows") then + inherit("core.tools.cl.has_flags") +else + inherit("core.tools.gfortran.has_flags") +end + diff --git a/xmake/modules/core/tools/ifx/has_flags.lua b/xmake/modules/core/tools/ifx/has_flags.lua new file mode 100644 index 000000000..d1f745651 --- /dev/null +++ b/xmake/modules/core/tools/ifx/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.ifort.has_flags") + diff --git a/xmake/modules/core/tools/ldc2/has_flags.lua b/xmake/modules/core/tools/ldc2/has_flags.lua new file mode 100644 index 000000000..81dd1e94a --- /dev/null +++ b/xmake/modules/core/tools/ldc2/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.dmd.has_flags") + diff --git a/xmake/modules/core/tools/link/has_flags.lua b/xmake/modules/core/tools/link/has_flags.lua new file mode 100644 index 000000000..1f93b7979 --- /dev/null +++ b/xmake/modules/core/tools/link/has_flags.lua @@ -0,0 +1,121 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.global_detectcache") +import("lib.detect.find_tool") + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + local key = "core.tools.link.has_flags" + local flagskey = opt.program .. "_" .. (opt.programver or "") + local allflags = global_detectcache:get2(key, flagskey) + if not allflags then + allflags = {} + local arglist = nil + try { + function () os.runv(opt.program, {"-?"}, {envs = opt.envs}) end, + catch { + function (errors) arglist = errors end + } + } + if arglist then + for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do + allflags[arg:gsub("/", "-"):lower()] = true + end + end + global_detectcache:set2(key, flagskey, allflags) + global_detectcache:save() + end + local flag = flags[1]:gsub("/", "-"):lower() + return allflags[flag] +end + +-- try running to check flags +function _check_try_running(flags, opt) + + -- make an stub source file + local flags_str = table.concat(flags, " "):lower() + local winmain = flags_str:find("subsystem:windows") + local sourcefile = path.join(os.tmpdir(), "detect", (winmain and "winmain_" or "") .. "link_has_flags.c") + if not os.isfile(sourcefile) then + if winmain then + io.writefile(sourcefile, "int WinMain(void* instance, void* previnst, char** argv, int argc)\n{return 0;}\n") + else + io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}\n") + end + end + + -- compile the source file + local objectfile = os.tmpfile() .. ".obj" + local binaryfile = os.tmpfile() .. ".exe" + local cl = find_tool("cl") + if cl then + os.runv(cl.program, {"-c", "-nologo", "-Fo" .. objectfile, sourcefile}, {envs = opt.envs}) + end + + -- try link it + local ok, errors = _try_running(opt.program, table.join(flags, "-nologo", "-out:" .. binaryfile, objectfile), {envs = opt.envs}) + os.tryrm(objectfile) + os.tryrm(binaryfile) + return ok, errors +end + +-- ignore some flags +function _ignore_flags(flags) + local results = {} + for _, flag in ipairs(flags) do + flag = flag:lower() + if not flag:find("[%-/]def:.+%.def") and not flag:find("[%-/]export:") then + table.insert(results, flag) + end + end + return results +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- ignore some flags + flags = _ignore_flags(flags) + if #flags == 0 then + return true + end + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt) +end + diff --git a/xmake/modules/core/tools/ml/has_flags.lua b/xmake/modules/core/tools/ml/has_flags.lua new file mode 100644 index 000000000..6eeb4e768 --- /dev/null +++ b/xmake/modules/core/tools/ml/has_flags.lua @@ -0,0 +1,105 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.ml.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all allflags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"-?"}, {envs = opt.envs}) + if arglist then + for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do + allflags[arg:gsub("/", "-")] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]:gsub("/", "-")] +end + +-- try running to check flags +function _check_try_running(flags, opt) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "ml_has_flags.asm") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, [[ +ifndef X64 +.686p +.model flat, C +endif +.code +end]]) + end + + -- check it + local errors = nil + return try { function () + if opt.program:find("ml64", 1, true) then + table.insert(flags, "-DX64") + end + local _, errs = os.iorunv(opt.program, table.join("-c", "-nologo", flags, "-Fo" .. os.nuldev(), sourcefile), {envs = opt.envs}) + if errs and #errs:trim() > 0 then + return false, errs + end + return true + end, + catch { function (errs) errors = errs end } + }, errors +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt) +end + diff --git a/xmake/modules/core/tools/ml64/has_flags.lua b/xmake/modules/core/tools/ml64/has_flags.lua new file mode 100644 index 000000000..323fd4d5e --- /dev/null +++ b/xmake/modules/core/tools/ml64/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.ml.has_flags") + diff --git a/xmake/modules/core/tools/nim/has_flags.lua b/xmake/modules/core/tools/nim/has_flags.lua new file mode 100644 index 000000000..84ce412b7 --- /dev/null +++ b/xmake/modules/core/tools/nim/has_flags.lua @@ -0,0 +1,98 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") + +-- try running +function _try_running(...) + + local argv = {...} + local errors = nil + return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.nim.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all allflags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"--help"}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "nim_has_flags.nim") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "echo \"hello\"") + end + + -- check it + local cachedir = os.tmpfile() .. ".dir" + local ok, errors = _try_running(opt.program, table.join("c", "-c", flags, "--nimcache:" .. cachedir, sourcefile)) + os.tryrm(cachedir) + return ok, errors +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt) +end + diff --git a/xmake/modules/core/tools/nvc/features.lua b/xmake/modules/core/tools/nvc/features.lua new file mode 100644 index 000000000..08c822cfd --- /dev/null +++ b/xmake/modules/core/tools/nvc/features.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +inherit("core.tools.gcc.features") + diff --git a/xmake/modules/core/tools/nvc/has_flags.lua b/xmake/modules/core/tools/nvc/has_flags.lua new file mode 100644 index 000000000..76744a133 --- /dev/null +++ b/xmake/modules/core/tools/nvc/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gcc.has_flags") + diff --git a/xmake/modules/core/tools/nvcc/has_flags.lua b/xmake/modules/core/tools/nvcc/has_flags.lua new file mode 100644 index 000000000..347961e70 --- /dev/null +++ b/xmake/modules/core/tools/nvcc/has_flags.lua @@ -0,0 +1,161 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + + -- the flags is "-Wl," or "-Xlinker "? + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then + return true + end + + -- the tool kind is ld or sh? + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("-ld") or toolkind:endswith("-sh") +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + + -- check for the builtin flags + local builtin_flags = {["-code"] = true, + ["--gpu-code"] = true, + ["-gencode"] = true, + ["--generate-code"] = true, + ["-arch"] = true, + ["--gpu-architecture"] = true, + ["-cudart=none"] = true, + ["--cudart=none"] = true} + if builtin_flags[flags[1]] then + return true + end + + -- check for the builtin flag=value + local cudart_flags = {none = true, shared = true, static = true} + local builtin_flags_pair = {["-cudart"] = cudart_flags, + ["--cudart"] = cudart_flags} + if #flags > 1 and builtin_flags_pair[flags[1]] and builtin_flags_pair[flags[1]][flags[2]] then + return true + end + + -- check from the `--help` menu, only for linker + if islinker or #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.nvcc.has_flags" + + -- make flags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all flags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"--help"}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" + local sourcefile = os.tmpfile("nvcc_has_flags:" .. snippet) .. ".cu" + if not os.isfile(sourcefile) then + io.writefile(sourcefile, snippet) + end + + local args = table.join("-o", os.nuldev(), sourcefile) + if not islinker then + table.insert(args, 1, "-c") + end + + -- avoid recursion + if flags[1] ~= "-allow-unsupported-compiler" then + -- add -allow-unsupported-compiler if supported to suppress error of unsupported compiler, + -- which caused all checks failed. + local allow_unsupported_compiler = _has_flags({"-allow-unsupported-compiler"}, opt) + if allow_unsupported_compiler then + table.insert(args, 1, "-allow-unsupported-compiler") + end + end + + -- add architecture flags if cross compiling + if not is_arch(os.arch()) then + if is_arch(".+64.*") then + table.insert(args, 1, "-m64") + else + table.insert(args, 1, "-m32") + end + end + + -- check flags + return _try_running(opt.program, table.join(flags, args), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "cu"} +-- +-- @return true or false +-- +function _has_flags(flags, opt) + + -- is linker? + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt, islinker) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + +function main(...) + return _has_flags(...) +end + diff --git a/xmake/modules/core/tools/nvcxx/features.lua b/xmake/modules/core/tools/nvcxx/features.lua new file mode 100644 index 000000000..08c822cfd --- /dev/null +++ b/xmake/modules/core/tools/nvcxx/features.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +inherit("core.tools.gcc.features") + diff --git a/xmake/modules/core/tools/nvcxx/has_flags.lua b/xmake/modules/core/tools/nvcxx/has_flags.lua new file mode 100644 index 000000000..76744a133 --- /dev/null +++ b/xmake/modules/core/tools/nvcxx/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gcc.has_flags") + diff --git a/xmake/modules/core/tools/nvfortran/has_flags.lua b/xmake/modules/core/tools/nvfortran/has_flags.lua new file mode 100644 index 000000000..d0447806f --- /dev/null +++ b/xmake/modules/core/tools/nvfortran/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gfortran.has_flags") + diff --git a/xmake/modules/core/tools/rc/has_flags.lua b/xmake/modules/core/tools/rc/has_flags.lua new file mode 100644 index 000000000..a635a3f68 --- /dev/null +++ b/xmake/modules/core/tools/rc/has_flags.lua @@ -0,0 +1,68 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.rc.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all allflags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"-?"}, {envs = opt.envs}) + if arglist then + for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do + allflags[arg:gsub("/", "-")] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]:gsub("/", "-")] +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = ""} +-- +-- @return true or false +-- +function main(flags, opt) + return _check_from_arglist(flags, opt) +end + diff --git a/xmake/modules/core/tools/rustc/has_flags.lua b/xmake/modules/core/tools/rustc/has_flags.lua new file mode 100644 index 000000000..9072b1c35 --- /dev/null +++ b/xmake/modules/core/tools/rustc/has_flags.lua @@ -0,0 +1,116 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") + +-- is linker? +function _islinker(flags, opt) + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-C linkarg=") then + return true + end + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") +end + +-- try running +function _try_running(...) + + local argv = {...} + local errors = nil + return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.rustc.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all allflags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"--help"}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "rustc_has_flags.rs") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "fn main() {\n}") + end + + -- check flags for linker + if islinker then + return _try_running(opt.program, table.join("--crate-type=bin", flags, "-o", os.tmpfile(), sourcefile), opt) + end + + -- check flags for compiler + local objectfile = os.tmpfile() .. ".o" + local ok, errors = _try_running(opt.program, table.join("--emit", "obj", flags, "-o", objectfile, sourcefile)) + os.tryrm(objectfile) + return ok, errors +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/xmake/modules/core/tools/sdcc/has_flags.lua b/xmake/modules/core/tools/sdcc/has_flags.lua new file mode 100644 index 000000000..e960fa8e1 --- /dev/null +++ b/xmake/modules/core/tools/sdcc/has_flags.lua @@ -0,0 +1,123 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + + -- the flags is "-Wl,"? + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-Wl,") then + return true + end + + -- the tool kind is ld or sh? + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" +end + +-- try running +function _try_running(...) + + local argv = {...} + local errors = nil + return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + + -- only for compiler + if islinker or #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.sdcc.has_flags" + + -- make flags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all flags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"--help"}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- get extension + -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] + local extension = opt.program:endswith("++") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "sdcc_has_flags" .. extension) + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}\n") + end + + -- check flags for linker + if islinker then + return _try_running(opt.program, table.join(flags, "-o", os.tmpfile(), sourcefile)) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-S", "-o", os.tmpfile(), sourcefile)) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt, islinker) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/xmake/modules/core/tools/swift_frontend/has_flags.lua b/xmake/modules/core/tools/swift_frontend/has_flags.lua new file mode 100644 index 000000000..eecb0ede7 --- /dev/null +++ b/xmake/modules/core/tools/swift_frontend/has_flags.lua @@ -0,0 +1,22 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.swiftc.has_flags") diff --git a/xmake/modules/core/tools/swiftc/has_flags.lua b/xmake/modules/core/tools/swiftc/has_flags.lua new file mode 100644 index 000000000..cf56da7c5 --- /dev/null +++ b/xmake/modules/core/tools/swiftc/has_flags.lua @@ -0,0 +1,101 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") + +-- try running +function _try_running(...) + local argv = {...} + local errors = nil + return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.swiftc.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all allflags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"--help"}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "swiftc_has_flags.swift") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "") + end + + -- check it + local objectfile = os.tmpfile() .. ".o" + local ok, errors = _try_running(opt.program, table.join(flags, "-o", objectfile, sourcefile)) + + -- remove files + os.tryrm(objectfile) + + -- ok? + return ok, errors +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt) +end + diff --git a/xmake/modules/core/tools/tcc/has_flags.lua b/xmake/modules/core/tools/tcc/has_flags.lua new file mode 100644 index 000000000..76744a133 --- /dev/null +++ b/xmake/modules/core/tools/tcc/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gcc.has_flags") + diff --git a/xmake/modules/core/tools/zig/has_flags.lua b/xmake/modules/core/tools/zig/has_flags.lua new file mode 100644 index 000000000..92aeb5c72 --- /dev/null +++ b/xmake/modules/core/tools/zig/has_flags.lua @@ -0,0 +1,114 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") + +-- is linker? +function _islinker(flags, opt) + + -- the tool kind is ld or sh? + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") +end + +-- try running +function _try_running(...) + + local argv = {...} + local errors = nil + return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + + -- only for compiler + if islinker or #flags > 1 then + return + end + + -- make cache key + local key = "core.tools.zig.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all allflags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"build-obj", "--help"}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "zig_has_flags.zig") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "pub fn main() !void {}") + end + + -- init argv + local argv = table.join(flags, "-femit-bin=" .. os.tmpfile(), sourcefile) + if islinker then + table.insert(argv, 1, "build-exe") + else + table.insert(argv, 1, "build-obj") + end + + -- check it + return _try_running(opt.program, argv) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt, islinker) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/xmake/modules/core/tools/zig_cc/features.lua b/xmake/modules/core/tools/zig_cc/features.lua new file mode 100644 index 000000000..08c822cfd --- /dev/null +++ b/xmake/modules/core/tools/zig_cc/features.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +inherit("core.tools.gcc.features") + diff --git a/xmake/modules/core/tools/zig_cc/has_flags.lua b/xmake/modules/core/tools/zig_cc/has_flags.lua new file mode 100644 index 000000000..76744a133 --- /dev/null +++ b/xmake/modules/core/tools/zig_cc/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gcc.has_flags") + diff --git a/xmake/modules/core/tools/zig_cxx/features.lua b/xmake/modules/core/tools/zig_cxx/features.lua new file mode 100644 index 000000000..08c822cfd --- /dev/null +++ b/xmake/modules/core/tools/zig_cxx/features.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +inherit("core.tools.gcc.features") + diff --git a/xmake/modules/core/tools/zig_cxx/has_flags.lua b/xmake/modules/core/tools/zig_cxx/has_flags.lua new file mode 100644 index 000000000..76744a133 --- /dev/null +++ b/xmake/modules/core/tools/zig_cxx/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("core.tools.gcc.has_flags") + diff --git a/xmake/modules/detect/tools/ar/has_flags.lua b/xmake/modules/detect/tools/ar/has_flags.lua deleted file mode 100644 index 914680d69..000000000 --- a/xmake/modules/detect/tools/ar/has_flags.lua +++ /dev/null @@ -1,82 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt) - - -- only one flag? - if #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.ar.has_flags" - - -- make allflags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all allflags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = nil - try - { - function () os.runv(opt.program, {"--help"}) end, - catch - { - function (errors) arglist = errors end - } - } - if arglist then - local found = false - for arg in arglist:gmatch("%-r %[%-(%a+)%]") do - arg:gsub("%a", function (ch) allflags["-" .. ch] = true; allflags["-r" .. ch] = true; allflags["-" .. ch .. "r"] = true end) - found = true - end - if found then - allflags["-r"] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - - -- ok? - return allflags[flags[1]] -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - return _check_from_arglist(flags, opt) -end - diff --git a/xmake/modules/detect/tools/armasm64_msvc/has_flags.lua b/xmake/modules/detect/tools/armasm64_msvc/has_flags.lua deleted file mode 100644 index e05f902c8..000000000 --- a/xmake/modules/detect/tools/armasm64_msvc/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.armasm_msvc.has_flags") - diff --git a/xmake/modules/detect/tools/armasm_msvc/has_flags.lua b/xmake/modules/detect/tools/armasm_msvc/has_flags.lua deleted file mode 100644 index 4f1d4ee97..000000000 --- a/xmake/modules/detect/tools/armasm_msvc/has_flags.lua +++ /dev/null @@ -1,97 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt) - - -- only one flag? - if #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.armasm.has_flags" - - -- make allflags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all allflags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"-?"}, {envs = opt.envs}) - if arglist then - for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do - allflags[arg:gsub("/", "-")] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]:gsub("/", "-")] -end - --- try running to check flags -function _check_try_running(flags, opt) - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "armasm_has_flags.asm") - if not os.isfile(sourcefile) then - io.writefile(sourcefile, [[ -END]]) - end - - -- check it - local errors = nil - return try { function () - local _, errs = os.iorunv(opt.program, table.join(flags, "-o", os.nuldev(), sourcefile), {envs = opt.envs}) - if errs and #errs:trim() > 0 then - return false, errs - end - return true - end, - catch { function (errs) errors = errs end } - }, errors -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt) -end - diff --git a/xmake/modules/detect/tools/armclang/has_flags.lua b/xmake/modules/detect/tools/armclang/has_flags.lua deleted file mode 100644 index d1a2fa752..000000000 --- a/xmake/modules/detect/tools/armclang/has_flags.lua +++ /dev/null @@ -1,128 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- is linker? -function _islinker(flags, opt) - - -- the flags is "-Wl," or "-Xlinker "? - local flags_str = table.concat(flags, " ") - if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then - return true - end - - -- the tool kind is ld or sh? - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") -end - --- try running -function _try_running(program, argv, opt) - local errors = nil - local has_target - for _, v in ipairs(argv) do - if v:startswith("-target=") then - has_target = true - break - end - end - if not has_target then - table.insert(argv, 1, "-mcpu=cortex-m3") - table.insert(argv, 1, "-target=arm-arm-none-eabi") - end - return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - local key = "detect.tools.armclang." .. (islinker and "has_ldflags" or "has_cflags") - local flagskey = opt.program .. "_" .. (opt.programver or "") - local allflags = detectcache:get2(key, flagskey) - if not allflags then - allflags = {} - local arglist = try {function () return os.iorunv(opt.program, {islinker and "-Wl,--help" or "--help"}, {envs = opt.envs}) end} - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - local flag = flags[1] - if islinker and flag then - if flag:startswith("-Wl,") then - flag = flag:match("-Wl,(.-),") or flag:sub(5) - end - end - return allflags[flag] -end - --- get extension -function _get_extension(opt) - -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] - return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "armclang_has_flags" .. _get_extension(opt)) - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}\n") - end - - -- check flags for linker - local tmpfile = os.tmpfile() - if islinker then - return _try_running(opt.program, table.join(flags, "-o", tmpfile, sourcefile), opt) - end - - -- check flags for compiler - -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage - return _try_running(opt.program, table.join(flags, "-c", "-o", tmpfile, sourcefile), opt) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - opt = opt or {} - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if not opt.tryrun and _check_from_arglist(flags, opt, islinker) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - - diff --git a/xmake/modules/detect/tools/circle/has_flags.lua b/xmake/modules/detect/tools/circle/has_flags.lua deleted file mode 100644 index 6464e10b6..000000000 --- a/xmake/modules/detect/tools/circle/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gcc.has_flags") - diff --git a/xmake/modules/detect/tools/cl/cfeatures.lua b/xmake/modules/detect/tools/cl/cfeatures.lua deleted file mode 100644 index 9b043f7e1..000000000 --- a/xmake/modules/detect/tools/cl/cfeatures.lua +++ /dev/null @@ -1,49 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file cfeatures.lua --- - --- set features -function _set(feature, condition) - _g.features = _g.features or {} - _g.features[feature] = condition -end - --- get features -function main() - - -- init conditions - local msvc_minver = "_MSC_VER >= 1200" - local msvc_2005 = "_MSC_VER >= 1400" - local msvc_2010 = "_MSC_VER >= 1600" - local msvc_2019 = "_MSC_VER >= 1920" - - -- set language standard supports - _set("c_std_89", msvc_2005) - _set("c_std_99", msvc_2019) - - -- set features - _set("c_static_assert", msvc_2010) - _set("c_restrict", msvc_2005) - _set("c_variadic_macros", msvc_2005) - _set("c_function_prototypes", msvc_minver) - - -- get features - return _g.features -end - diff --git a/xmake/modules/detect/tools/cl/cxxfeatures.lua b/xmake/modules/detect/tools/cl/cxxfeatures.lua deleted file mode 100644 index c8b683e6f..000000000 --- a/xmake/modules/detect/tools/cl/cxxfeatures.lua +++ /dev/null @@ -1,151 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file cxxfeatures.lua --- - --- set features -function _set(feature, condition) - _g.features = _g.features or {} - _g.features[feature] = condition -end - --- get features --- --- Reference: http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx --- http://blogs.msdn.com/b/vcblog/archive/2013/06/28/c-11-14-stl-features-fixes-and-breaking-changes-in-vs-2013.aspx --- http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx --- http://www.visualstudio.com/en-us/news/vs2015-preview-vs.aspx --- http://blogs.msdn.com/b/vcblog/archive/2015/04/29/c-11-14-17-features-in-vs-2015-rc.aspx --- http://blogs.msdn.com/b/vcblog/archive/2015/06/19/c-11-14-17-features-in-vs-2015-rtm.aspx --- https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-160 --- --- porting from Modules/Compiler/MSVC-CXX-FeatureTests.cmake --- -function main() - - -- init conditions - local msvc_minver = "_MSC_VER >= 1200" - local msvc_60 = "_MSC_VER >= 1200" - local msvc_70 = "_MSC_VER >= 1300" - local msvc_71 = "_MSC_VER >= 1310" - local msvc_2005 = "_MSC_VER >= 1400" - local msvc_2008 = "_MSC_VER >= 1500" - local msvc_2010 = "_MSC_VER >= 1600" - local msvc_2012 = "_MSC_VER >= 1700" - local msvc_2013 = "_MSC_VER >= 1800" - local msvc_2015 = "_MSC_VER >= 1900" - local msvc_2017 = "_MSC_VER >= 1910" - local msvc_2019 = "_MSC_VER >= 1920" - local msvc_2022 = "_MSC_VER >= 1930" - - -- set language standard supports - _set("cxx_std_98", msvc_2005) - _set("cxx_std_11", msvc_2015) - _set("cxx_std_14", msvc_2017) - _set("cxx_std_17", msvc_2019) - _set("cxx_std_20", msvc_2022) - - -- VS version 15 (not 2015) introduces support for aggregate initializers. - _set("cxx_aggregate_default_initializers", "_MSC_FULL_VER >= 190024406") - - -- VS 2015 Update 2 introduces support for variable templates. - -- https://www.visualstudio.com/en-us/news/vs2015-update2-vs.aspx - _set("cxx_variable_templates", "_MSC_FULL_VER >= 190023918") - - _set("cxx_alignas", msvc_2015) - _set("cxx_alignof", msvc_2015) - _set("cxx_attributes", msvc_2015) - _set("cxx_attribute_deprecated", msvc_2015) - _set("cxx_binary_literals", msvc_2015) - _set("cxx_constexpr", msvc_2015) - _set("cxx_decltype_auto", msvc_2015) - _set("cxx_digit_separators", msvc_2015) - _set("cxx_func_identifier", msvc_2015) - _set("cxx_nonstatic_member_init", msvc_2015) - _set("cxx_defaulted_move_initializers", msvc_2015) - _set("cxx_generic_lambdas", msvc_2015) - _set("cxx_inheriting_constructors", msvc_2015) - _set("cxx_inline_namespaces", msvc_2015) - _set("cxx_lambda_init_captures", msvc_2015) - _set("cxx_noexcept", msvc_2015) - _set("cxx_return_type_deduction", msvc_2015) - _set("cxx_sizeof_member", msvc_2015) - _set("cxx_thread_local", msvc_2015) - _set("cxx_unicode_literals", msvc_2015) - _set("cxx_unrestricted_unions", msvc_2015) - _set("cxx_user_literals", msvc_2015) - _set("cxx_reference_qualified_functions", msvc_2015) - - -- "The copies and moves don't interact precisely like the Standard says they - -- should. For example, deletion of moves is specified to also suppress - -- copies, but Visual C++ in Visual Studio 2013 does not." - -- http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx - -- lists this as 'partial' in 2013 - _set("cxx_deleted_functions", msvc_2015) - - -- http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx - -- Note 1. While previous version of VisualStudio said they supported these - -- they silently produced bad code, and are now marked as having partial - -- support in previous versions. The footnote says the support will be complete - -- in msvc 2015, so support the feature for that version, assuming that is true. - -- The blog post also says that VS 2013 Update 3 generates an error in cases - -- that previously produced bad code. - _set("cxx_generalized_initializers", "_MSC_FULL_VER >= 180030723") - - -- Microsoft now states they support contextual conversions in 2013 and above. - -- See footnote 6 at: - -- http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx - _set("cxx_contextual_conversions", msvc_2013) - _set("cxx_default_function_template_args", msvc_2013) - _set("cxx_defaulted_functions", msvc_2013) - _set("cxx_delegating_constructors", msvc_2013) - _set("cxx_explicit_conversions", msvc_2013) - _set("cxx_raw_string_literals", msvc_2013) - _set("cxx_uniform_initialization", msvc_2013) - _set("cxx_alias_templates", msvc_2013) - - -- Support is documented, but possibly partly broken: - -- https://msdn.microsoft.com/en-us/library/hh567368.aspx - -- http://thread.gmane.org/gmane.comp.lib.boost.devel/244986/focus=245333 - _set("cxx_variadic_templates", msvc_2013) - - _set("cxx_enum_forward_declarations", msvc_2012) - _set("cxx_final", msvc_2012) - _set("cxx_range_for", msvc_2012) - _set("cxx_strong_enums", msvc_2012) - - _set("cxx_auto_type", msvc_2010) - _set("cxx_decltype", msvc_2010) - _set("cxx_extended_friend_declarations", msvc_2010) - _set("cxx_extern_templates", msvc_2010) - _set("cxx_lambdas", msvc_2010) - _set("cxx_local_type_template_args", msvc_2010) - _set("cxx_long_long_type", msvc_2010) - _set("cxx_nullptr", msvc_2010) - _set("cxx_override", msvc_2010) - _set("cxx_right_angle_brackets", msvc_2010) - _set("cxx_rvalue_references", msvc_2010) - _set("cxx_static_assert", msvc_2010) - _set("cxx_template_template_parameters", msvc_2010) - _set("cxx_trailing_return_types", msvc_2010) - _set("cxx_variadic_macros", msvc_2010) - - -- get features - return _g.features -end - diff --git a/xmake/modules/detect/tools/cl/features.lua b/xmake/modules/detect/tools/cl/features.lua deleted file mode 100644 index 0957fd7ed..000000000 --- a/xmake/modules/detect/tools/cl/features.lua +++ /dev/null @@ -1,140 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file features.lua --- - --- imports -import("cfeatures") -import("cxxfeatures") - --- get macro defines -function _get_macro_defines(snippets, extension, opt) - - -- make an stub source file - local sourcefile = os.tmpfile() .. extension - local objectfile = sourcefile .. ".obj" - local binaryfile = sourcefile .. ".exe" - io.writefile(sourcefile, "#include \n\nint main(int argc, char** argv)\n{\n" .. table.concat(table.wrap(snippets), "\n") .. "\nreturn 0;\n}\n") - - -- get defines - local results = {} - local defines = try - { - function () - os.runv(opt.program, table.join(opt.flags or {}, {"-nologo", "-Fo" .. objectfile, sourcefile, "-link", "-out:" .. binaryfile}), {envs = opt.envs}) - return os.iorunv(binaryfile, {}, {envs = opt.envs}) - end - } - if defines then - for _, define in ipairs(defines:split("\n")) do - results[define] = true - end - end - - -- remove files - os.tryrm(sourcefile) - os.tryrm(objectfile) - os.tryrm(binaryfile) - return results -end - --- set feature with condition -function _set_feature(feature, condition) - - -- init features - _g.features = _g.features or {} - - -- get feature kind - local kind = feature:match("^(%w-)_") - assert(kind, "unknown kind for the feature: %s", feature) - - -- init language extensions - _g.extensions = _g.extensions or {c = ".c", cxx = ".cpp", objc = ".m", objcxx = ".mm"} - - -- get extension - local extension = _g.extensions[kind] - assert(extension, "not supported kind for the feature: %s", feature) - - -- make snippet - local snippet = format([[ -#if (%s) - printf("%s\n"); -#endif]], condition, feature) - - -- init features with the given extension - local features = _g.features[extension] or {} - _g.features[extension] = features - - -- set feature and snippet - features[feature] = snippet -end - --- set features -function set_features(features) - for feature, condition in pairs(features) do - _set_feature(feature, condition) - end -end - --- check features -function check_features(opt) - - -- check features with all extensions - opt = opt or {} - local results = {} - for extension, features in pairs(_g.features) do - - -- make snippets - local snippets = {} - for _, snippet in pairs(features) do - table.insert(snippets, snippet) - end - - -- get defines - local defines = _get_macro_defines(snippets, extension, opt) - - -- check features - for feature, _ in pairs(features) do - if defines[feature] then - results[feature] = true - end - end - end - - -- ok? - return results -end - --- get features --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", flags = {}} --- --- @return the features --- -function main(opt) - - -- set features for c - set_features(cfeatures()) - - -- set features for c++ - set_features(cxxfeatures()) - - -- check features - return check_features(opt) -end - diff --git a/xmake/modules/detect/tools/cl/has_flags.lua b/xmake/modules/detect/tools/cl/has_flags.lua deleted file mode 100644 index 378c16a5b..000000000 --- a/xmake/modules/detect/tools/cl/has_flags.lua +++ /dev/null @@ -1,119 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.language.language") -import("core.cache.global_detectcache") - --- attempt to check it from known flags -function _check_from_knownargs(flags, opt) - local flag = flags[1]:gsub("/", "-") - if flag:startswith("-D") or - flag:startswith("-U") or - flag:startswith("-I") then - return true - end -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt) - local key = "detect.tools.cl.has_flags" - local flagskey = opt.program .. "_" .. (opt.programver or "") - local allflags = global_detectcache:get2(key, flagskey) - if not allflags then - allflags = {} - local arglist = os.iorunv(opt.program, {"-?"}, {envs = opt.envs}) - if arglist then - for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do - allflags[arg:gsub("/", "-")] = true - end - end - global_detectcache:set2(key, flagskey, allflags) - global_detectcache:save() - end - local flag = flags[1]:gsub("/", "-") - if flag:startswith("-D") or flag:startswith("-I") then - return true - end - return allflags[flag] -end - --- get extension -function _get_extension(opt) - return opt.flagkind == "cxxflags" and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") -end - --- try running to check flags -function _check_try_running(flags, opt) - - -- make an stub source file - local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" - local sourcefile = os.tmpfile("cl_has_flags:" .. snippet) .. _get_extension(opt) - if not os.isfile(sourcefile) then - io.writefile(sourcefile, snippet) - end - - -- check it - local errors = nil - return try { function () - local tmpdir = os.tmpdir() - local nuldev = os.nuldev() - local tmpfile - if not is_host("windows") then - tmpfile = os.tmpfile() - nuldev = tmpfile - end - local _, errs = os.iorunv(opt.program, table.join("-c", "-nologo", flags, "-Fo" .. nuldev, sourcefile), - {envs = opt.envs, curdir = tmpdir}) -- we need to switch to tmpdir to avoid generating some tmp files, e.g. /Zi -> vc140.pdb - if tmpfile then - os.tryrm(tmpfile) - end - if errs and #errs:trim() > 0 then - return false, errs - end - return true - end, - catch { function (errs) errors = errs end } - }, errors -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- attempt to check it from the argument list - opt = opt or {} - if not opt.tryrun then - if _check_from_arglist(flags, opt) then - return true - end - if _check_from_knownargs(flags, opt) then - return true - end - end - - -- try running to check it - return _check_try_running(flags, opt) -end - diff --git a/xmake/modules/detect/tools/cl2000/has_flags.lua b/xmake/modules/detect/tools/cl2000/has_flags.lua deleted file mode 100644 index 4b108a611..000000000 --- a/xmake/modules/detect/tools/cl2000/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.cl6x.has_flags") - diff --git a/xmake/modules/detect/tools/cl6x/has_flags.lua b/xmake/modules/detect/tools/cl6x/has_flags.lua deleted file mode 100644 index d18d9b233..000000000 --- a/xmake/modules/detect/tools/cl6x/has_flags.lua +++ /dev/null @@ -1,121 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- is linker? -function _islinker(flags, opt) - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") -end - --- try running -function _try_running(program, argv, opt) - local errors = nil - return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from known flags -function _check_from_knownargs(flags, opt, islinker) - local flag = flags[1] - if not islinker then - if flag:startswith("-D") or - flag:startswith("-U") or - flag:startswith("-I") then - return true - end - end -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - local key = "detect.tools.cl6x." .. (islinker and "has_ldflags" or "has_cflags") - local flagskey = opt.program .. "_" .. (opt.programver or "") - local allflags = detectcache:get2(key, flagskey) - if not allflags then - allflags = {} - local arglist = try {function () return os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) end} - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - local flag = flags[1] - return allflags[flag] -end - --- get extension -function _get_extension(opt) - -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] - return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" - local sourcefile = os.tmpfile("cl6x_has_flags:" .. snippet) .. _get_extension(opt) - if not os.isfile(sourcefile) then - io.writefile(sourcefile, snippet) - end - - -- check flags for linker - local tmpfile = os.tmpfile() - if islinker then - return _try_running(opt.program, table.join(flags, "-z", "--output_file=" .. tmpfile, sourcefile), opt) - end - - -- check flags for compiler - -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage - return _try_running(opt.program, table.join(flags, "-c", "--output_file=" .. tmpfile, sourcefile), opt) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - opt = opt or {} - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if not opt.tryrun then - if _check_from_arglist(flags, opt, islinker) then - return true - end - if _check_from_knownargs(flags, opt, islinker) then - return true - end - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - diff --git a/xmake/modules/detect/tools/clang/cfeatures.lua b/xmake/modules/detect/tools/clang/cfeatures.lua deleted file mode 100644 index e9a1687a6..000000000 --- a/xmake/modules/detect/tools/clang/cfeatures.lua +++ /dev/null @@ -1,58 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file cfeatures.lua --- - --- imports -import("detect.tools.gcc.cfeatures") - --- set features -function _set(feature, condition) - _g.features[feature] = condition -end - --- get features -function main() - - -- init features - _g.features = cfeatures() - - -- init conditions - -- clang -std=c11 -dM -E - < /dev/null | grep __STDC_VERSION__ - local clang_minver = "((__clang_major__ * 100) + __clang_minor__) >= 304" - local c17 = clang_minver .. " && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L" - local c11 = clang_minver .. " && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L" - local c99 = clang_minver .. " && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L" - local c90 = clang_minver - - -- set language standard supports - _set("c_std_89", c90) - _set("c_std_99", c99) - _set("c_std_11", c11) - _set("c_std_17", c17) - - -- set features - _set("c_static_assert", c11) - _set("c_restrict", c99) - _set("c_variadic_macros", c99) - _set("c_function_prototypes", c90) - - -- get features - return _g.features -end - diff --git a/xmake/modules/detect/tools/clang/cxxfeatures.lua b/xmake/modules/detect/tools/clang/cxxfeatures.lua deleted file mode 100644 index 1fd57c8d6..000000000 --- a/xmake/modules/detect/tools/clang/cxxfeatures.lua +++ /dev/null @@ -1,132 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file cxxfeatures.lua --- - --- imports -import("detect.tools.gcc.cxxfeatures") - --- set features -function _set(feature, condition) - _g.features[feature] = condition -end - --- get features --- --- @see http://clang.llvm.org/cxx_status.html --- --- porting from Modules/Compiler/Clang-CXX-FeatureTests.cmake --- -function main() - - -- init features - _g.features = cxxfeatures() - - -- init conditions - -- clang -x c++ -std=c++20 -dM -E - < /dev/null | grep __cplusplus - local clang_minver = "((__clang_major__ * 100) + __clang_minor__) >= 301" - local clang80_cxx20 = "((__clang_major__ * 100) + __clang_minor__) >= 800 && __cplusplus >= 202002L" - local clang50_cxx17 = "((__clang_major__ * 100) + __clang_minor__) >= 500 && __cplusplus >= 201703L" - local clang34_cxx14 = "((__clang_major__ * 100) + __clang_minor__) >= 304 && __cplusplus > 201103L" - local clang31_cxx11 = clang_minver .. " && __cplusplus >= 201103L" - local clang29_cxx11 = clang_minver .. " && __cplusplus >= 201103L" - local clang_cxx98 = clang_minver .. " && __cplusplus >= 199711L" - - -- set language standard supports - _set("cxx_std_98", clang_cxx98) - _set("cxx_std_11", clang29_cxx11) - _set("cxx_std_14", clang34_cxx14) - _set("cxx_std_17", clang50_cxx17) - _set("cxx_std_20", clang80_cxx20) - - -- set features for __has_feature() - local features_of_has_feature = - { - "cxx_alias_templates" - , "cxx_alignas" - , "cxx_attributes" - , "cxx_auto_type" - , "cxx_binary_literals" - , "cxx_constexpr" - , "cxx_contextual_conversions" - , "cxx_decltype" - , "cxx_default_function_template_args" - , "cxx_defaulted_functions" - , "cxx_delegating_constructors" - , "cxx_deleted_functions" - , "cxx_explicit_conversions" - , "cxx_generalized_initializers" - , "cxx_inheriting_constructors" - , "cxx_lambdas" - , "cxx_local_type_template_args" - , "cxx_noexcept" - , "cxx_nonstatic_member_init" - , "cxx_nullptr" - , "cxx_range_for" - , "cxx_raw_string_literals" - , "cxx_reference_qualified_functions" - , "cxx_relaxed_constexpr" - , "cxx_return_type_deduction" - , "cxx_rvalue_references" - , "cxx_static_assert" - , "cxx_strong_enums" - , "cxx_thread_local" - , "cxx_unicode_literals" - , "cxx_unrestricted_unions" - , "cxx_user_literals" - , "cxx_variable_templates" - , "cxx_variadic_templates" - , {"cxx_aggregate_default_initializers", "cxx_aggregate_nsdmi" } - , {"cxx_trailing_return_types", "cxx_trailing_return" } - , {"cxx_alignof", "cxx_alignas" } - , {"cxx_final", "cxx_override_control" } - , {"cxx_override", "cxx_override_control" } - , {"cxx_uniform_initialization", "cxx_generalized_initializers" } - , {"cxx_defaulted_move_initializers", "cxx_defaulted_functions" } - , {"cxx_lambda_init_captures", "cxx_init_captures" } - } - for _, feature in ipairs(features_of_has_feature) do - local name = feature - local test = feature - if type(feature) == "table" then - name = feature[1] - test = feature[2] - end - _set(name, clang_minver .. " && __has_feature(" .. test .. ")") - end - - -- set features - _set("cxx_attribute_deprecated", clang34_cxx14) -- http://llvm.org/bugs/show_bug.cgi?id=19242 - _set("cxx_decltype_auto", clang34_cxx14) -- http://llvm.org/bugs/show_bug.cgi?id=19698 - _set("cxx_digit_separators", clang34_cxx14) - _set("cxx_generic_lambdas", clang34_cxx14) -- http://llvm.org/bugs/show_bug.cgi?id=19674 - _set("cxx_enum_forward_declarations", clang31_cxx11) - _set("cxx_sizeof_member", clang31_cxx11) - _set("cxx_extended_friend_declarations", clang29_cxx11) - _set("cxx_extern_templates", clang29_cxx11) - _set("cxx_func_identifier", clang29_cxx11) - _set("cxx_inline_namespaces", clang29_cxx11) - _set("cxx_long_long_type", clang29_cxx11) - _set("cxx_right_angle_brackets", clang29_cxx11) - _set("cxx_variadic_macros", clang29_cxx11) - _set("cxx_template_template_parameters", clang_cxx98) - - -- get features - return _g.features -end - diff --git a/xmake/modules/detect/tools/clang/features.lua b/xmake/modules/detect/tools/clang/features.lua deleted file mode 100644 index b7562980f..000000000 --- a/xmake/modules/detect/tools/clang/features.lua +++ /dev/null @@ -1,44 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file features.lua --- - --- imports -inherit("detect.tools.gcc.features") -import("cfeatures") -import("cxxfeatures") - --- get features --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", flags = {}} --- --- @return the features --- -function main(opt) - - -- set features for c - set_features(cfeatures()) - - -- set features for c++ - set_features(cxxfeatures()) - - -- check features - return check_features(opt) -end - - diff --git a/xmake/modules/detect/tools/clang/has_flags.lua b/xmake/modules/detect/tools/clang/has_flags.lua deleted file mode 100644 index 6464e10b6..000000000 --- a/xmake/modules/detect/tools/clang/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gcc.has_flags") - diff --git a/xmake/modules/detect/tools/clang_cl/has_flags.lua b/xmake/modules/detect/tools/clang_cl/has_flags.lua deleted file mode 100644 index 3f173dea4..000000000 --- a/xmake/modules/detect/tools/clang_cl/has_flags.lua +++ /dev/null @@ -1,101 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt) - - -- only one flag? - if #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.clang_cl.has_flags" - - -- make allflags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all allflags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"-?"}) - if arglist then - for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do - allflags[arg:gsub("/", "-")] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]:gsub("/", "-")] -end - --- try running -function _try_running(...) - - local argv = {...} - local errors = nil - return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- try running to check flags -function _check_try_running(flags, opt) - - -- get extension - -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] - local extension = opt.program:endswith("++") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "clang_cl_has_flags" .. extension) - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}\n") - end - - -- check flags for compiler - -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage - return _try_running(opt.program, table.join("-Werror=unused-command-line-argument", flags, "-c", "-o", os.tmpfile(), sourcefile)) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt) -end - diff --git a/xmake/modules/detect/tools/clangxx/features.lua b/xmake/modules/detect/tools/clangxx/features.lua deleted file mode 100644 index b887b9efc..000000000 --- a/xmake/modules/detect/tools/clangxx/features.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file features.lua --- - --- imports -inherit("detect.tools.gcc.features") - diff --git a/xmake/modules/detect/tools/clangxx/has_flags.lua b/xmake/modules/detect/tools/clangxx/has_flags.lua deleted file mode 100644 index 6464e10b6..000000000 --- a/xmake/modules/detect/tools/clangxx/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gcc.has_flags") - diff --git a/xmake/modules/detect/tools/cosmocc/has_flags.lua b/xmake/modules/detect/tools/cosmocc/has_flags.lua deleted file mode 100644 index df8690652..000000000 --- a/xmake/modules/detect/tools/cosmocc/has_flags.lua +++ /dev/null @@ -1,143 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- is linker? -function _islinker(flags, opt) - - -- the flags is "-Wl," or "-Xlinker "? - local flags_str = table.concat(flags, " ") - if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then - return true - end - - -- the tool kind is ld or sh? - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") -end - --- try running -function _try_running(program, argv, opt) - local errors = nil - return try { - function () os.runv(program, argv, table.join(opt or {}, {shell = true})) - return true - end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from known flags -function _check_from_knownargs(flags, opt, islinker) - local flag = flags[1] - if not islinker then - if flag:startswith("-D") or - flag:startswith("-U") or - flag:startswith("-I") then - return true - end - end -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - local key = "detect.tools.cosmocc." .. (islinker and "has_ldflags" or "has_cflags") - local flagskey = opt.program .. "_" .. (opt.programver or "") - local allflags = detectcache:get2(key, flagskey) - if not allflags then - allflags = {} - local arglist = try {function () return os.iorunv(opt.program, {islinker and "-Wl,--help" or "--help"}, {envs = opt.envs, shell = true}) end} - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - local flag = flags[1] - if islinker and flag then - if flag:startswith("-Wl,") then - flag = flag:match("-Wl,(.-),") or flag:sub(5) - end - end - return allflags[flag] -end - --- get extension -function _get_extension(opt) - -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] - return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" - local sourcefile = os.tmpfile("cosmocc_has_flags:" .. snippet) .. _get_extension(opt) - if not os.isfile(sourcefile) then - io.writefile(sourcefile, snippet) - end - if is_host("windows") then - sourcefile = sourcefile:gsub("\\", "/") - end - - -- check flags for linker - local tmpfile = os.tmpfile() - if is_host("windows") then - tmpfile = tmpfile:gsub("\\", "/") - end - if islinker then - return _try_running(opt.program, table.join(flags, "-o", tmpfile, sourcefile), opt) - end - - -- check flags for compiler - -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage - return _try_running(opt.program, table.join(flags, "-o", tmpfile, sourcefile), opt) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - opt = opt or {} - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if not opt.tryrun then - if _check_from_arglist(flags, opt, islinker) then - return true - end - if _check_from_knownargs(flags, opt, islinker) then - return true - end - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - diff --git a/xmake/modules/detect/tools/cosmocxx/has_flags.lua b/xmake/modules/detect/tools/cosmocxx/has_flags.lua deleted file mode 100644 index 3f4e9dfad..000000000 --- a/xmake/modules/detect/tools/cosmocxx/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.cosmocc.has_flags") - diff --git a/xmake/modules/detect/tools/dmd/has_flags.lua b/xmake/modules/detect/tools/dmd/has_flags.lua deleted file mode 100644 index 235e99d4c..000000000 --- a/xmake/modules/detect/tools/dmd/has_flags.lua +++ /dev/null @@ -1,119 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") - --- is linker? -function _islinker(flags, opt) - - -- the flags is "-L=" or "-L"? - local flags_str = table.concat(flags, " ") - if flags_str:startswith("-L=") or flags_str:startswith("-L-") then - return true - end - - -- the tool kind is ld or sh? - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") -end - --- try running -function _try_running(...) - - local argv = {...} - local errors = nil - return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - - -- only for compiler - if islinker or #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.dmd.has_flags" - - -- make allflags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all allflags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"--help"}) - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]] -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "dmd_has_flags.d") - local objectfile = path.join(os.tmpdir(), "detect", "dmd_has_flags.o") - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "void main() {\n}") - end - - -- init argv - local argv = table.join(flags, "-of" .. objectfile, sourcefile) - if not islinker then - table.insert(argv, 1, "-c") - end - - -- check it - return _try_running(opt.program, argv) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt, islinker) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - diff --git a/xmake/modules/detect/tools/dpcpp/cfeatures.lua b/xmake/modules/detect/tools/dpcpp/cfeatures.lua deleted file mode 100644 index 161f91c05..000000000 --- a/xmake/modules/detect/tools/dpcpp/cfeatures.lua +++ /dev/null @@ -1,22 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file cfeatures.lua --- - --- imports -import("detect.tools.clang.cfeatures") diff --git a/xmake/modules/detect/tools/dpcpp/cxxfeatures.lua b/xmake/modules/detect/tools/dpcpp/cxxfeatures.lua deleted file mode 100644 index cf7f8d08e..000000000 --- a/xmake/modules/detect/tools/dpcpp/cxxfeatures.lua +++ /dev/null @@ -1,22 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file cxxfeatures.lua --- - --- imports -import("detect.tools.clang.cxxfeatures") diff --git a/xmake/modules/detect/tools/dpcpp/features.lua b/xmake/modules/detect/tools/dpcpp/features.lua deleted file mode 100644 index e54887f71..000000000 --- a/xmake/modules/detect/tools/dpcpp/features.lua +++ /dev/null @@ -1,22 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file features.lua --- - --- imports -inherit("detect.tools.clang.features") diff --git a/xmake/modules/detect/tools/dpcpp/has_flags.lua b/xmake/modules/detect/tools/dpcpp/has_flags.lua deleted file mode 100644 index d8c6f2792..000000000 --- a/xmake/modules/detect/tools/dpcpp/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.clang.has_flags") - diff --git a/xmake/modules/detect/tools/emcc/has_flags.lua b/xmake/modules/detect/tools/emcc/has_flags.lua deleted file mode 100644 index 6464e10b6..000000000 --- a/xmake/modules/detect/tools/emcc/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gcc.has_flags") - diff --git a/xmake/modules/detect/tools/emxx/has_flags.lua b/xmake/modules/detect/tools/emxx/has_flags.lua deleted file mode 100644 index 27fc6812e..000000000 --- a/xmake/modules/detect/tools/emxx/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.emcc.has_flags") - diff --git a/xmake/modules/detect/tools/fpc/has_flags.lua b/xmake/modules/detect/tools/fpc/has_flags.lua deleted file mode 100644 index 109e1014b..000000000 --- a/xmake/modules/detect/tools/fpc/has_flags.lua +++ /dev/null @@ -1,98 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") - --- try running -function _try_running(...) - - local argv = {...} - local errors = nil - return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt) - - -- only one flag? - if #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.fpc.has_flags" - - -- make allflags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all allflags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"-h"}) - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]] -end - --- try running to check flags -function _check_try_running(flags, opt) - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "fpc_has_flags.pas") - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "program Hello;\nbegin\nend.") - end - - -- check it - local binaryfile = os.tmpfile() - local ok, errors = _try_running(opt.program, table.join(flags, "-o" .. binaryfile, sourcefile)) - os.tryrm(binaryfile) - return ok, errors -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt) -end - diff --git a/xmake/modules/detect/tools/gcc/cfeatures.lua b/xmake/modules/detect/tools/gcc/cfeatures.lua deleted file mode 100644 index b9ebaa036..000000000 --- a/xmake/modules/detect/tools/gcc/cfeatures.lua +++ /dev/null @@ -1,52 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file cfeatures.lua --- - --- set features -function _set(feature, condition) - _g.features = _g.features or {} - _g.features[feature] = condition -end - --- get features -function main() - - -- init conditions - local gcc_minver = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 304" - local gcc10_c17 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 1000 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L" - local gcc46_c11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 406 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201000L" - local gcc34_c99 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 304 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L" - local gcc_c90 = gcc_minver - - -- set language standard supports - _set("c_std_89", gcc46_c90) - _set("c_std_99", gcc34_c99) - _set("c_std_11", gcc46_c11) - _set("c_std_17", gcc46_c17) - - -- set features - _set("c_static_assert", gcc46_c11) -- GNU 4.7 correctly sets __STDC_VERSION__ to 201112L, but GNU 4.6 sets it to 201000L - _set("c_restrict", gcc34_c99) - _set("c_variadic_macros", gcc34_c99) - _set("c_function_prototypes", gcc_c90) - - -- get features - return _g.features -end - diff --git a/xmake/modules/detect/tools/gcc/cxxfeatures.lua b/xmake/modules/detect/tools/gcc/cxxfeatures.lua deleted file mode 100644 index 9d628522c..000000000 --- a/xmake/modules/detect/tools/gcc/cxxfeatures.lua +++ /dev/null @@ -1,222 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file cxxfeatures.lua --- - --- set features -function _set(feature, condition) - _g.features = _g.features or {} - _g.features[feature] = condition -end - --- get features --- --- http://gcc.gnu.org/projects/cxx0x.html --- http://gcc.gnu.org/projects/cxx1y.html --- https://gcc.gnu.org/projects/cxx-status.html --- --- porting from Modules/Compiler/GNU-CXX-FeatureTests.cmake --- -function main() - - -- init conditions - -- gcc -x c++ -std=c++20 -dM -E - < /dev/null | grep __cplusplus - local gcc_minver = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 404" - local gcc90_cxx20 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 900 && __cplusplus >= 202002L" - local gcc70_cxx17 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 700 && __cplusplus >= 201703L" - local gcc50_cxx14 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 500 && __cplusplus >= 201402L" - local gcc49_cxx14 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 409 && __cplusplus > 201103L" - local gcc481_cxx11 = "((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40801) && __cplusplus >= 201103L" - local gcc48_cxx11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 408 && __cplusplus >= 201103L" - local gcc47_cxx11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 407 && __cplusplus >= 201103L" - local gcc_cxx0x_defined = "(__cplusplus >= 201103L || (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__))" - local gcc46_cxx11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 406 && " .. gcc_cxx0x_defined - local gcc45_cxx11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 405 && " .. gcc_cxx0x_defined - local gcc44_cxx11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 404 && " .. gcc_cxx0x_defined - local gcc43_cxx11 = gcc_minver .. " && " .. gcc_cxx0x_defined - - -- set language standard supports - _set("cxx_std_98", gcc_minver) - _set("cxx_std_11", gcc43_cxx11) - _set("cxx_std_14", gcc49_cxx14) - _set("cxx_std_17", gcc70_cxx17) - _set("cxx_std_20", gcc90_cxx20) - - -- set features - _set("cxx_variable_templates", gcc50_cxx14) - _set("cxx_relaxed_constexpr", gcc50_cxx14) - _set("cxx_aggregate_default_initializers", gcc50_cxx14) - - -- GNU 4.9 in c++14 mode sets __cplusplus to 201300L, so don't test for the - -- correct value of it below. - -- https://patchwork.ozlabs.org/patch/382470/ - _set("cxx_contextual_conversions", gcc49_cxx14) - _set("cxx_attribute_deprecated", gcc49_cxx14) - _set("cxx_decltype_auto", gcc49_cxx14) - _set("cxx_digit_separators", gcc49_cxx14) - _set("cxx_generic_lambdas", gcc49_cxx14) - _set("cxx_lambda_init_captures", gcc49_cxx14) - - -- GNU 4.3 supports binary literals as an extension, but may warn about - -- use of extensions prior to GNU 4.9 - -- http://stackoverflow.com/questions/16334024/difference-between-gcc-binary-literals-and-c14-ones - _set("cxx_binary_literals", gcc49_cxx14) - - -- The feature below is documented as available in GNU 4.8 (by implementing an - -- earlier draft of the standard paper), but that version of the compiler - -- does not set __cplusplus to a value greater than 201103L until GNU 4.9: - -- http://gcc.gnu.org/onlinedocs/gcc-4.8.2/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros - -- http://gcc.gnu.org/onlinedocs/gcc-4.9.0/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros - -- So, CMake only reports availability for it with GNU 4.9 or later. - _set("cxx_return_type_deduction", gcc49_cxx14) - - -- Introduced in GCC 4.8.1 - _set("cxx_decltype_incomplete_return_types", gcc481_cxx11) - _set("cxx_reference_qualified_functions", gcc481_cxx11) - - -- The alignof feature works with GNU 4.7 and -std=c++11, but it is documented - -- as available with GNU 4.8, so treat that as true. - _set("cxx_alignas", gcc48_cxx11) - _set("cxx_alignof", gcc48_cxx11) - _set("cxx_attributes", gcc48_cxx11) - _set("cxx_inheriting_constructors", gcc48_cxx11) - _set("cxx_thread_local", gcc48_cxx11) - - _set("cxx_alias_templates", gcc47_cxx11) - _set("cxx_delegating_constructors", gcc47_cxx11) - _set("cxx_extended_friend_declarations", gcc47_cxx11) - _set("cxx_final", gcc47_cxx11) - _set("cxx_nonstatic_member_init", gcc47_cxx11) - _set("cxx_override", gcc47_cxx11) - _set("cxx_user_literals", gcc47_cxx11) - - -- NOTE: C++11 was ratified in September 2011. GNU 4.7 is the first minor - -- release following that (March 2012), and the first minor release to - -- support -std=c++11. Prior to that, support for C++11 features is technically - -- experiemental and possibly incomplete (see for example the note below about - -- cxx_variadic_template_template_parameters) - -- GNU does not define __cplusplus correctly before version 4.7. - -- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773 - -- __GXX_EXPERIMENTAL_CXX0X__ is defined in prior versions, but may not be - -- defined in the future. - _set("cxx_constexpr", gcc46_cxx11) - _set("cxx_defaulted_move_initializers", gcc46_cxx11) - _set("cxx_enum_forward_declarations", gcc46_cxx11) - _set("cxx_noexcept", gcc46_cxx11) - _set("cxx_nullptr", gcc46_cxx11) - _set("cxx_range_for", gcc46_cxx11) - _set("cxx_unrestricted_unions", gcc46_cxx11) - - _set("cxx_explicit_conversions", gcc45_cxx11) - _set("cxx_lambdas", gcc45_cxx11) - _set("cxx_local_type_template_args", gcc45_cxx11) - _set("cxx_raw_string_literals", gcc45_cxx11) - - _set("cxx_auto_type", gcc44_cxx11) - _set("cxx_defaulted_functions", gcc44_cxx11) - _set("cxx_deleted_functions", gcc44_cxx11) - _set("cxx_generalized_initializers", gcc44_cxx11) - _set("cxx_inline_namespaces", gcc44_cxx11) - _set("cxx_sizeof_member", gcc44_cxx11) - _set("cxx_strong_enums", gcc44_cxx11) - _set("cxx_trailing_return_types", gcc44_cxx11) - _set("cxx_unicode_literals", gcc44_cxx11) - _set("cxx_uniform_initialization", gcc44_cxx11) - _set("cxx_variadic_templates", gcc44_cxx11) - - -- TODO: If features are ever recorded for GNU 4.3, there should possibly - -- be a new feature added like cxx_variadic_template_template_parameters, - -- which is implemented by GNU 4.4, but not 4.3. cxx_variadic_templates is - -- actually implemented by GNU 4.3, but variadic template template parameters - -- 'completes' it, so that is the version we record as having the variadic - -- templates capability in CMake. See - -- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2555.pdf - -- TODO: Should be supported by GNU 4.3 - _set("cxx_decltype", gcc43_cxx11) - _set("cxx_default_function_template_args", gcc43_cxx11) - _set("cxx_long_long_type", gcc43_cxx11) - _set("cxx_right_angle_brackets", gcc43_cxx11) - _set("cxx_rvalue_references", gcc43_cxx11) - _set("cxx_static_assert", gcc43_cxx11) - - -- TODO: Should be supported since GNU 3.4? - _set("cxx_extern_templates", gcc_minver .. " && " .. gcc_cxx0x_defined) - - -- TODO: Should be supported forever? - _set("cxx_func_identifier", gcc_minver .. " && " .. gcc_cxx0x_defined) - _set("cxx_variadic_macros", gcc_minver .. " && " .. gcc_cxx0x_defined) - _set("cxx_template_template_parameters", gcc_minver .. " && __cplusplus") - - -- c++17 language features with predefined macros - -- https://en.cppreference.com/w/cpp/feature_test - local features_cxx17 = { - "__cpp_aggregate_bases", - "__cpp_aligned_new", - "__cpp_capture_star_this", - "__cpp_constexpr", - "__cpp_deduction_guides", - "__cpp_enumerator_attributes", - "__cpp_fold_expressions", - "__cpp_guaranteed_copy_elision", - "__cpp_hex_float", - "__cpp_if_constexpr", - "__cpp_inheriting_constructors", - "__cpp_inline_variables", - "__cpp_namespace_attributes", - "__cpp_noexcept_function_type", - "__cpp_nontype_template_args", - "__cpp_nontype_template_parameter_auto", - "__cpp_range_based_for", - "__cpp_static_assert", - "__cpp_structured_bindings", - "__cpp_template_template_args", - "__cpp_variadic_using"} - for _, feature in ipairs(features_cxx17) do - _set((feature:gsub("__cpp", "cxx")), "__cplusplus && defined(" .. feature .. ")") - end - - -- c++20 language features with predefined macros - -- https://en.cppreference.com/w/cpp/feature_test - local features_cxx20 = { - "__cpp_aggregate_paren_init", - "__cpp_char8_t", - "__cpp_concepts", - "__cpp_conditional_explicit", - "__cpp_consteval", - "__cpp_constexpr", - "__cpp_constexpr_dynamic_alloc", - "__cpp_constexpr_in_decltype", - "__cpp_constinit", - "__cpp_deduction_guides", - "__cpp_designated_initializers", - "__cpp_generic_lambdas", - "__cpp_impl_coroutine", - "__cpp_impl_destroying_delete", - "__cpp_impl_three_way_comparison", - "__cpp_init_captures", - "__cpp_modules", - "__cpp_nontype_template_args", - "__cpp_using_enum"} - for _, feature in ipairs(features_cxx20) do - _set((feature:gsub("__cpp", "cxx")), "__cplusplus && defined(" .. feature .. ")") - end - - -- get features - return _g.features -end - diff --git a/xmake/modules/detect/tools/gcc/features.lua b/xmake/modules/detect/tools/gcc/features.lua deleted file mode 100644 index 153cc3fb4..000000000 --- a/xmake/modules/detect/tools/gcc/features.lua +++ /dev/null @@ -1,130 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file features.lua --- - --- imports -import("cfeatures") -import("cxxfeatures") -import("core.language.language") - --- get macro defines -function _get_macro_defines(snippets, extension, opt) - - -- make an stub source file - local sourcefile = os.tmpfile() .. extension - io.writefile(sourcefile, table.concat(table.wrap(snippets), "\n")) - - -- get defines - local results = {} - local defines = try { function () return os.iorunv(opt.program, table.join(opt.flags or {}, {"-dM", "-E", sourcefile}), {envs = opt.envs}) end } - if defines then - for _, define in ipairs(defines:split("\n")) do - local name = define:match("#define%s+(.-)%s+") - if name then - results[name] = true - end - end - end - os.tryrm(sourcefile) - return results -end - --- set feature with condition -function _set_feature(feature, condition) - - -- init features - _g.features = _g.features or {} - - -- get language kind - local langkind = feature:match("^(%w-)_") - assert(langkind, "unknown language kind for the feature: %s", feature) - - -- get source kind from the language kind - local sourcekind = language.langkinds()[langkind] - assert(sourcekind, "unknown language kind: " .. langkind) - - -- get extension - local extension = table.wrap(language.sourcekinds()[sourcekind])[1] - assert(extension, "not supported kind for the feature: %s", feature) - - -- make snippet - local snippet = format([[ -#if (%s) -# define %s 1 -#endif]], condition, feature) - - -- init features with the given extension - local features = _g.features[extension] or {} - _g.features[extension] = features - - -- set feature and snippet - features[feature] = snippet -end - --- set features -function set_features(features) - for feature, condition in pairs(features) do - _set_feature(feature, condition) - end -end - --- check features -function check_features(opt) - - -- check features with all extensions - local results = {} - for extension, features in pairs(_g.features) do - - -- make snippets - local snippets = {} - for _, snippet in pairs(features) do - table.insert(snippets, snippet) - end - - -- get defines - local defines = _get_macro_defines(snippets, extension, opt) - - -- check features - for feature, _ in pairs(features) do - if defines[feature] then - results[feature] = true - end - end - end - return results -end - --- get features --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", flags = {}} --- --- @return the features --- -function main(opt) - - -- set features for c - set_features(cfeatures()) - - -- set features for c++ - set_features(cxxfeatures()) - - -- check features - return check_features(opt) -end - diff --git a/xmake/modules/detect/tools/gcc/has_flags.lua b/xmake/modules/detect/tools/gcc/has_flags.lua deleted file mode 100644 index 181cef04e..000000000 --- a/xmake/modules/detect/tools/gcc/has_flags.lua +++ /dev/null @@ -1,134 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- is linker? -function _islinker(flags, opt) - - -- the flags is "-Wl," or "-Xlinker "? - local flags_str = table.concat(flags, " ") - if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then - return true - end - - -- the tool kind is ld or sh? - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") -end - --- try running -function _try_running(program, argv, opt) - local errors = nil - return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from known flags -function _check_from_knownargs(flags, opt, islinker) - local flag = flags[1] - if not islinker then - if flag:startswith("-D") or - flag:startswith("-U") or - flag:startswith("-I") then - return true - end - end -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - local key = "detect.tools.gcc." .. (islinker and "has_ldflags" or "has_cflags") - local flagskey = opt.program .. "_" .. (opt.programver or "") - local allflags = detectcache:get2(key, flagskey) - if not allflags then - allflags = {} - local arglist = try {function () return os.iorunv(opt.program, {islinker and "-Wl,--help" or "--help"}, {envs = opt.envs}) end} - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - local flag = flags[1] - if islinker and flag then - if flag:startswith("-Wl,") then - flag = flag:match("-Wl,(.-),") or flag:sub(5) - end - end - return allflags[flag] -end - --- get extension -function _get_extension(opt) - -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] - return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" - local sourcefile = os.tmpfile("gcc_has_flags:" .. snippet) .. _get_extension(opt) - if not os.isfile(sourcefile) then - io.writefile(sourcefile, snippet) - end - - -- check flags for linker - local tmpfile = os.tmpfile() - if islinker then - return _try_running(opt.program, table.join(flags, "-o", tmpfile, sourcefile), opt) - end - - -- check flags for compiler - -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage - return _try_running(opt.program, table.join(flags, "-S", "-o", tmpfile, sourcefile), opt) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - opt = opt or {} - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if not opt.tryrun then - if _check_from_arglist(flags, opt, islinker) then - return true - end - if _check_from_knownargs(flags, opt, islinker) then - return true - end - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - diff --git a/xmake/modules/detect/tools/gccgo/has_flags.lua b/xmake/modules/detect/tools/gccgo/has_flags.lua deleted file mode 100644 index 6464e10b6..000000000 --- a/xmake/modules/detect/tools/gccgo/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gcc.has_flags") - diff --git a/xmake/modules/detect/tools/gdc/has_flags.lua b/xmake/modules/detect/tools/gdc/has_flags.lua deleted file mode 100644 index 1ba8c98b0..000000000 --- a/xmake/modules/detect/tools/gdc/has_flags.lua +++ /dev/null @@ -1,118 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- is linker? -function _islinker(flags, opt) - - -- the flags is "-Wl," or "-Xlinker "? - local flags_str = table.concat(flags, " ") - if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then - return true - end - - -- the tool kind is ld or sh? - local toolkind = opt.toolkind or "" - return toolkind == "dcld" or toolkind == "dcsh" -end - --- try running -function _try_running(program, argv, opt) - local errors = nil - return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - - -- only for compiler - if islinker or #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.gdc.has_flags" - - -- make flags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all flags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]] -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "gdc_has_flags.d") - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "void main()\n{}") - end - - -- check flags for linker - if islinker then - return _try_running(opt.program, table.join(flags, "-o", os.tmpfile(), sourcefile), opt) - end - - -- check flags for compiler - -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage - return _try_running(opt.program, table.join(flags, "-S", "-o", os.tmpfile(), sourcefile), opt) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt, islinker) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - - diff --git a/xmake/modules/detect/tools/gfortran/has_flags.lua b/xmake/modules/detect/tools/gfortran/has_flags.lua deleted file mode 100644 index 62a35c653..000000000 --- a/xmake/modules/detect/tools/gfortran/has_flags.lua +++ /dev/null @@ -1,117 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- is linker? -function _islinker(flags, opt) - - -- the flags is "-Wl," or "-Xlinker "? - local flags_str = table.concat(flags, " ") - if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then - return true - end - - -- the tool kind is ld or sh? - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("-ld") or toolkind:endswith("-sh") -end - --- try running -function _try_running(program, argv, opt) - local errors = nil - return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - - -- only for compiler - if islinker or #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.gfortran.has_flags" - - -- make flags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all flags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]] -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "gfortran_has_flags.f90") - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "program hello\n print *, \"Hello World!\"\nend program hello") - end - - -- check flags for linker - if islinker then - return _try_running(opt.program, table.join(flags, "-o", os.tmpfile(), sourcefile), opt) - end - - -- check flags for compiler - -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage - return _try_running(opt.program, table.join(flags, "-S", "-o", os.tmpfile(), sourcefile), opt) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt, islinker) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - diff --git a/xmake/modules/detect/tools/go/has_flags.lua b/xmake/modules/detect/tools/go/has_flags.lua deleted file mode 100644 index e1acf3769..000000000 --- a/xmake/modules/detect/tools/go/has_flags.lua +++ /dev/null @@ -1,130 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- is linker? -function _islinker(flags, opt) - - -- the tool kind is gcld or gcsh? - local toolkind = opt.toolkind or "" - return toolkind:endswith("ld") or toolkind:endswith("sh") -end - --- try running -function _try_running(...) - - local argv = {...} - local errors = nil - return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - - -- only for compiler - if islinker or #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.go.has_flags" - - -- make flags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all flags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- attempt to get argument list from the error info (help menu) - allflags = {} - try - { - function () os.runv(opt.program, {"tool", "compile", "--help"}) end, - catch - { - function (errors) - local arglist = errors - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - end - } - } - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]] -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "go_has_flags.go") - local objectfile = path.join(os.tmpdir(), "detect", "go_has_flags.o") - local targetfile = path.join(os.tmpdir(), "detect", "go_has_flags.bin") - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "package main\nfunc main() {\n}") - end - - -- check flags for linker - if islinker then - - -- compile a object file first - if not os.isfile(objectfile) and not _try_running(opt.program, table.join("tool", "compile", "-o", objectfile, sourcefile)) then - return false - end - - -- check it - return _try_running(opt.program, table.join("tool", "link", flags, "-o", targetfile, objectfile)) - end - - -- check flags for compiler - return _try_running(opt.program, table.join("tool", "compile", flags, "-o", objectfile, sourcefile)) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt, islinker) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - diff --git a/xmake/modules/detect/tools/gxx/features.lua b/xmake/modules/detect/tools/gxx/features.lua deleted file mode 100644 index b887b9efc..000000000 --- a/xmake/modules/detect/tools/gxx/features.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file features.lua --- - --- imports -inherit("detect.tools.gcc.features") - diff --git a/xmake/modules/detect/tools/gxx/has_flags.lua b/xmake/modules/detect/tools/gxx/has_flags.lua deleted file mode 100644 index 6464e10b6..000000000 --- a/xmake/modules/detect/tools/gxx/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gcc.has_flags") - diff --git a/xmake/modules/detect/tools/icc/has_flags.lua b/xmake/modules/detect/tools/icc/has_flags.lua deleted file mode 100644 index 6464e10b6..000000000 --- a/xmake/modules/detect/tools/icc/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gcc.has_flags") - diff --git a/xmake/modules/detect/tools/icl/has_flags.lua b/xmake/modules/detect/tools/icl/has_flags.lua deleted file mode 100644 index eeba3941b..000000000 --- a/xmake/modules/detect/tools/icl/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.cl.has_flags") - diff --git a/xmake/modules/detect/tools/icpc/has_flags.lua b/xmake/modules/detect/tools/icpc/has_flags.lua deleted file mode 100644 index da83182b5..000000000 --- a/xmake/modules/detect/tools/icpc/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gxx.has_flags") - diff --git a/xmake/modules/detect/tools/icpx/features.lua b/xmake/modules/detect/tools/icpx/features.lua deleted file mode 100644 index e9dc9ae44..000000000 --- a/xmake/modules/detect/tools/icpx/features.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file features.lua --- - --- imports -inherit("detect.tools.clang.features") - diff --git a/xmake/modules/detect/tools/icpx/has_flags.lua b/xmake/modules/detect/tools/icpx/has_flags.lua deleted file mode 100644 index d8c6f2792..000000000 --- a/xmake/modules/detect/tools/icpx/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.clang.has_flags") - diff --git a/xmake/modules/detect/tools/icx/cfeatures.lua b/xmake/modules/detect/tools/icx/cfeatures.lua deleted file mode 100644 index 161f91c05..000000000 --- a/xmake/modules/detect/tools/icx/cfeatures.lua +++ /dev/null @@ -1,22 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file cfeatures.lua --- - --- imports -import("detect.tools.clang.cfeatures") diff --git a/xmake/modules/detect/tools/icx/cxxfeatures.lua b/xmake/modules/detect/tools/icx/cxxfeatures.lua deleted file mode 100644 index cf7f8d08e..000000000 --- a/xmake/modules/detect/tools/icx/cxxfeatures.lua +++ /dev/null @@ -1,22 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file cxxfeatures.lua --- - --- imports -import("detect.tools.clang.cxxfeatures") diff --git a/xmake/modules/detect/tools/icx/features.lua b/xmake/modules/detect/tools/icx/features.lua deleted file mode 100644 index e54887f71..000000000 --- a/xmake/modules/detect/tools/icx/features.lua +++ /dev/null @@ -1,22 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file features.lua --- - --- imports -inherit("detect.tools.clang.features") diff --git a/xmake/modules/detect/tools/icx/has_flags.lua b/xmake/modules/detect/tools/icx/has_flags.lua deleted file mode 100644 index d8c6f2792..000000000 --- a/xmake/modules/detect/tools/icx/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.clang.has_flags") - diff --git a/xmake/modules/detect/tools/ifort/has_flags.lua b/xmake/modules/detect/tools/ifort/has_flags.lua deleted file mode 100644 index 86a504867..000000000 --- a/xmake/modules/detect/tools/ifort/has_flags.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -if is_host("windows") then - inherit("detect.tools.cl.has_flags") -else - inherit("detect.tools.gfortran.has_flags") -end - diff --git a/xmake/modules/detect/tools/ifx/has_flags.lua b/xmake/modules/detect/tools/ifx/has_flags.lua deleted file mode 100644 index 161e337e9..000000000 --- a/xmake/modules/detect/tools/ifx/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.ifort.has_flags") - diff --git a/xmake/modules/detect/tools/ldc2/has_flags.lua b/xmake/modules/detect/tools/ldc2/has_flags.lua deleted file mode 100644 index 107ec49b9..000000000 --- a/xmake/modules/detect/tools/ldc2/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.dmd.has_flags") - diff --git a/xmake/modules/detect/tools/link/has_flags.lua b/xmake/modules/detect/tools/link/has_flags.lua deleted file mode 100644 index 6b0cf48f8..000000000 --- a/xmake/modules/detect/tools/link/has_flags.lua +++ /dev/null @@ -1,121 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.global_detectcache") -import("lib.detect.find_tool") - --- try running -function _try_running(program, argv, opt) - local errors = nil - return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt) - local key = "detect.tools.link.has_flags" - local flagskey = opt.program .. "_" .. (opt.programver or "") - local allflags = global_detectcache:get2(key, flagskey) - if not allflags then - allflags = {} - local arglist = nil - try { - function () os.runv(opt.program, {"-?"}, {envs = opt.envs}) end, - catch { - function (errors) arglist = errors end - } - } - if arglist then - for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do - allflags[arg:gsub("/", "-"):lower()] = true - end - end - global_detectcache:set2(key, flagskey, allflags) - global_detectcache:save() - end - local flag = flags[1]:gsub("/", "-"):lower() - return allflags[flag] -end - --- try running to check flags -function _check_try_running(flags, opt) - - -- make an stub source file - local flags_str = table.concat(flags, " "):lower() - local winmain = flags_str:find("subsystem:windows") - local sourcefile = path.join(os.tmpdir(), "detect", (winmain and "winmain_" or "") .. "link_has_flags.c") - if not os.isfile(sourcefile) then - if winmain then - io.writefile(sourcefile, "int WinMain(void* instance, void* previnst, char** argv, int argc)\n{return 0;}\n") - else - io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}\n") - end - end - - -- compile the source file - local objectfile = os.tmpfile() .. ".obj" - local binaryfile = os.tmpfile() .. ".exe" - local cl = find_tool("cl") - if cl then - os.runv(cl.program, {"-c", "-nologo", "-Fo" .. objectfile, sourcefile}, {envs = opt.envs}) - end - - -- try link it - local ok, errors = _try_running(opt.program, table.join(flags, "-nologo", "-out:" .. binaryfile, objectfile), {envs = opt.envs}) - os.tryrm(objectfile) - os.tryrm(binaryfile) - return ok, errors -end - --- ignore some flags -function _ignore_flags(flags) - local results = {} - for _, flag in ipairs(flags) do - flag = flag:lower() - if not flag:find("[%-/]def:.+%.def") and not flag:find("[%-/]export:") then - table.insert(results, flag) - end - end - return results -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- ignore some flags - flags = _ignore_flags(flags) - if #flags == 0 then - return true - end - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt) -end - diff --git a/xmake/modules/detect/tools/ml/has_flags.lua b/xmake/modules/detect/tools/ml/has_flags.lua deleted file mode 100644 index 0dbda2134..000000000 --- a/xmake/modules/detect/tools/ml/has_flags.lua +++ /dev/null @@ -1,105 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt) - - -- only one flag? - if #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.ml.has_flags" - - -- make allflags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all allflags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"-?"}, {envs = opt.envs}) - if arglist then - for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do - allflags[arg:gsub("/", "-")] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]:gsub("/", "-")] -end - --- try running to check flags -function _check_try_running(flags, opt) - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "ml_has_flags.asm") - if not os.isfile(sourcefile) then - io.writefile(sourcefile, [[ -ifndef X64 -.686p -.model flat, C -endif -.code -end]]) - end - - -- check it - local errors = nil - return try { function () - if opt.program:find("ml64", 1, true) then - table.insert(flags, "-DX64") - end - local _, errs = os.iorunv(opt.program, table.join("-c", "-nologo", flags, "-Fo" .. os.nuldev(), sourcefile), {envs = opt.envs}) - if errs and #errs:trim() > 0 then - return false, errs - end - return true - end, - catch { function (errs) errors = errs end } - }, errors -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt) -end - diff --git a/xmake/modules/detect/tools/ml64/has_flags.lua b/xmake/modules/detect/tools/ml64/has_flags.lua deleted file mode 100644 index 259ac1e1d..000000000 --- a/xmake/modules/detect/tools/ml64/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.ml.has_flags") - diff --git a/xmake/modules/detect/tools/nim/has_flags.lua b/xmake/modules/detect/tools/nim/has_flags.lua deleted file mode 100644 index 5538257fb..000000000 --- a/xmake/modules/detect/tools/nim/has_flags.lua +++ /dev/null @@ -1,98 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") - --- try running -function _try_running(...) - - local argv = {...} - local errors = nil - return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt) - - -- only one flag? - if #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.nim.has_flags" - - -- make allflags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all allflags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"--help"}) - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]] -end - --- try running to check flags -function _check_try_running(flags, opt) - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "nim_has_flags.nim") - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "echo \"hello\"") - end - - -- check it - local cachedir = os.tmpfile() .. ".dir" - local ok, errors = _try_running(opt.program, table.join("c", "-c", flags, "--nimcache:" .. cachedir, sourcefile)) - os.tryrm(cachedir) - return ok, errors -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt) -end - diff --git a/xmake/modules/detect/tools/nvc/features.lua b/xmake/modules/detect/tools/nvc/features.lua deleted file mode 100644 index b887b9efc..000000000 --- a/xmake/modules/detect/tools/nvc/features.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file features.lua --- - --- imports -inherit("detect.tools.gcc.features") - diff --git a/xmake/modules/detect/tools/nvc/has_flags.lua b/xmake/modules/detect/tools/nvc/has_flags.lua deleted file mode 100644 index 6464e10b6..000000000 --- a/xmake/modules/detect/tools/nvc/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gcc.has_flags") - diff --git a/xmake/modules/detect/tools/nvcc/has_flags.lua b/xmake/modules/detect/tools/nvcc/has_flags.lua deleted file mode 100644 index ff1c47b42..000000000 --- a/xmake/modules/detect/tools/nvcc/has_flags.lua +++ /dev/null @@ -1,161 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- is linker? -function _islinker(flags, opt) - - -- the flags is "-Wl," or "-Xlinker "? - local flags_str = table.concat(flags, " ") - if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then - return true - end - - -- the tool kind is ld or sh? - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("-ld") or toolkind:endswith("-sh") -end - --- try running -function _try_running(program, argv, opt) - local errors = nil - return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - - -- check for the builtin flags - local builtin_flags = {["-code"] = true, - ["--gpu-code"] = true, - ["-gencode"] = true, - ["--generate-code"] = true, - ["-arch"] = true, - ["--gpu-architecture"] = true, - ["-cudart=none"] = true, - ["--cudart=none"] = true} - if builtin_flags[flags[1]] then - return true - end - - -- check for the builtin flag=value - local cudart_flags = {none = true, shared = true, static = true} - local builtin_flags_pair = {["-cudart"] = cudart_flags, - ["--cudart"] = cudart_flags} - if #flags > 1 and builtin_flags_pair[flags[1]] and builtin_flags_pair[flags[1]][flags[2]] then - return true - end - - -- check from the `--help` menu, only for linker - if islinker or #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.nvcc.has_flags" - - -- make flags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all flags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"--help"}) - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]] -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" - local sourcefile = os.tmpfile("nvcc_has_flags:" .. snippet) .. ".cu" - if not os.isfile(sourcefile) then - io.writefile(sourcefile, snippet) - end - - local args = table.join("-o", os.nuldev(), sourcefile) - if not islinker then - table.insert(args, 1, "-c") - end - - -- avoid recursion - if flags[1] ~= "-allow-unsupported-compiler" then - -- add -allow-unsupported-compiler if supported to suppress error of unsupported compiler, - -- which caused all checks failed. - local allow_unsupported_compiler = _has_flags({"-allow-unsupported-compiler"}, opt) - if allow_unsupported_compiler then - table.insert(args, 1, "-allow-unsupported-compiler") - end - end - - -- add architecture flags if cross compiling - if not is_arch(os.arch()) then - if is_arch(".+64.*") then - table.insert(args, 1, "-m64") - else - table.insert(args, 1, "-m32") - end - end - - -- check flags - return _try_running(opt.program, table.join(flags, args), opt) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "cu"} --- --- @return true or false --- -function _has_flags(flags, opt) - - -- is linker? - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt, islinker) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - -function main(...) - return _has_flags(...) -end - diff --git a/xmake/modules/detect/tools/nvcxx/features.lua b/xmake/modules/detect/tools/nvcxx/features.lua deleted file mode 100644 index b887b9efc..000000000 --- a/xmake/modules/detect/tools/nvcxx/features.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file features.lua --- - --- imports -inherit("detect.tools.gcc.features") - diff --git a/xmake/modules/detect/tools/nvcxx/has_flags.lua b/xmake/modules/detect/tools/nvcxx/has_flags.lua deleted file mode 100644 index 6464e10b6..000000000 --- a/xmake/modules/detect/tools/nvcxx/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gcc.has_flags") - diff --git a/xmake/modules/detect/tools/nvfortran/has_flags.lua b/xmake/modules/detect/tools/nvfortran/has_flags.lua deleted file mode 100644 index c0ee706cd..000000000 --- a/xmake/modules/detect/tools/nvfortran/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gfortran.has_flags") - diff --git a/xmake/modules/detect/tools/rc/has_flags.lua b/xmake/modules/detect/tools/rc/has_flags.lua deleted file mode 100644 index ac023c466..000000000 --- a/xmake/modules/detect/tools/rc/has_flags.lua +++ /dev/null @@ -1,68 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt) - - -- only one flag? - if #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.rc.has_flags" - - -- make allflags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all allflags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"-?"}, {envs = opt.envs}) - if arglist then - for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do - allflags[arg:gsub("/", "-")] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]:gsub("/", "-")] -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = ""} --- --- @return true or false --- -function main(flags, opt) - return _check_from_arglist(flags, opt) -end - diff --git a/xmake/modules/detect/tools/rustc/has_flags.lua b/xmake/modules/detect/tools/rustc/has_flags.lua deleted file mode 100644 index e1696e454..000000000 --- a/xmake/modules/detect/tools/rustc/has_flags.lua +++ /dev/null @@ -1,116 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") - --- is linker? -function _islinker(flags, opt) - local flags_str = table.concat(flags, " ") - if flags_str:startswith("-C linkarg=") then - return true - end - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") -end - --- try running -function _try_running(...) - - local argv = {...} - local errors = nil - return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt) - - -- only one flag? - if #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.rustc.has_flags" - - -- make allflags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all allflags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"--help"}) - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]] -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "rustc_has_flags.rs") - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "fn main() {\n}") - end - - -- check flags for linker - if islinker then - return _try_running(opt.program, table.join("--crate-type=bin", flags, "-o", os.tmpfile(), sourcefile), opt) - end - - -- check flags for compiler - local objectfile = os.tmpfile() .. ".o" - local ok, errors = _try_running(opt.program, table.join("--emit", "obj", flags, "-o", objectfile, sourcefile)) - os.tryrm(objectfile) - return ok, errors -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - diff --git a/xmake/modules/detect/tools/sdcc/has_flags.lua b/xmake/modules/detect/tools/sdcc/has_flags.lua deleted file mode 100644 index 18c0eb3ae..000000000 --- a/xmake/modules/detect/tools/sdcc/has_flags.lua +++ /dev/null @@ -1,123 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- is linker? -function _islinker(flags, opt) - - -- the flags is "-Wl,"? - local flags_str = table.concat(flags, " ") - if flags_str:startswith("-Wl,") then - return true - end - - -- the tool kind is ld or sh? - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" -end - --- try running -function _try_running(...) - - local argv = {...} - local errors = nil - return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - - -- only for compiler - if islinker or #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.sdcc.has_flags" - - -- make flags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all flags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"--help"}) - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]] -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- get extension - -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] - local extension = opt.program:endswith("++") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "sdcc_has_flags" .. extension) - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}\n") - end - - -- check flags for linker - if islinker then - return _try_running(opt.program, table.join(flags, "-o", os.tmpfile(), sourcefile)) - end - - -- check flags for compiler - -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage - return _try_running(opt.program, table.join(flags, "-S", "-o", os.tmpfile(), sourcefile)) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt, islinker) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - diff --git a/xmake/modules/detect/tools/swift_frontend/has_flags.lua b/xmake/modules/detect/tools/swift_frontend/has_flags.lua deleted file mode 100644 index 4af0d592f..000000000 --- a/xmake/modules/detect/tools/swift_frontend/has_flags.lua +++ /dev/null @@ -1,22 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.swiftc.has_flags") diff --git a/xmake/modules/detect/tools/swiftc/has_flags.lua b/xmake/modules/detect/tools/swiftc/has_flags.lua deleted file mode 100644 index 99b36de75..000000000 --- a/xmake/modules/detect/tools/swiftc/has_flags.lua +++ /dev/null @@ -1,101 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") - --- try running -function _try_running(...) - local argv = {...} - local errors = nil - return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt) - - -- only one flag? - if #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.swiftc.has_flags" - - -- make allflags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all allflags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"--help"}) - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]] -end - --- try running to check flags -function _check_try_running(flags, opt) - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "swiftc_has_flags.swift") - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "") - end - - -- check it - local objectfile = os.tmpfile() .. ".o" - local ok, errors = _try_running(opt.program, table.join(flags, "-o", objectfile, sourcefile)) - - -- remove files - os.tryrm(objectfile) - - -- ok? - return ok, errors -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt) -end - diff --git a/xmake/modules/detect/tools/tcc/has_flags.lua b/xmake/modules/detect/tools/tcc/has_flags.lua deleted file mode 100644 index 6464e10b6..000000000 --- a/xmake/modules/detect/tools/tcc/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gcc.has_flags") - diff --git a/xmake/modules/detect/tools/zig/has_flags.lua b/xmake/modules/detect/tools/zig/has_flags.lua deleted file mode 100644 index 1dea91cfe..000000000 --- a/xmake/modules/detect/tools/zig/has_flags.lua +++ /dev/null @@ -1,114 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") - --- is linker? -function _islinker(flags, opt) - - -- the tool kind is ld or sh? - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") -end - --- try running -function _try_running(...) - - local argv = {...} - local errors = nil - return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - - -- only for compiler - if islinker or #flags > 1 then - return - end - - -- make cache key - local key = "detect.tools.zig.has_flags" - - -- make allflags key - local flagskey = opt.program .. "_" .. (opt.programver or "") - - -- get all allflags from argument list - local allflags = detectcache:get2(key, flagskey) - if not allflags then - - -- get argument list - allflags = {} - local arglist = os.iorunv(opt.program, {"build-obj", "--help"}) - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - - -- save cache - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - return allflags[flags[1]] -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "zig_has_flags.zig") - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "pub fn main() !void {}") - end - - -- init argv - local argv = table.join(flags, "-femit-bin=" .. os.tmpfile(), sourcefile) - if islinker then - table.insert(argv, 1, "build-exe") - else - table.insert(argv, 1, "build-obj") - end - - -- check it - return _try_running(opt.program, argv) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if _check_from_arglist(flags, opt, islinker) then - return true - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - diff --git a/xmake/modules/detect/tools/zig_cc/features.lua b/xmake/modules/detect/tools/zig_cc/features.lua deleted file mode 100644 index b887b9efc..000000000 --- a/xmake/modules/detect/tools/zig_cc/features.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file features.lua --- - --- imports -inherit("detect.tools.gcc.features") - diff --git a/xmake/modules/detect/tools/zig_cc/has_flags.lua b/xmake/modules/detect/tools/zig_cc/has_flags.lua deleted file mode 100644 index 6464e10b6..000000000 --- a/xmake/modules/detect/tools/zig_cc/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gcc.has_flags") - diff --git a/xmake/modules/detect/tools/zig_cxx/features.lua b/xmake/modules/detect/tools/zig_cxx/features.lua deleted file mode 100644 index b887b9efc..000000000 --- a/xmake/modules/detect/tools/zig_cxx/features.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file features.lua --- - --- imports -inherit("detect.tools.gcc.features") - diff --git a/xmake/modules/detect/tools/zig_cxx/has_flags.lua b/xmake/modules/detect/tools/zig_cxx/has_flags.lua deleted file mode 100644 index 6464e10b6..000000000 --- a/xmake/modules/detect/tools/zig_cxx/has_flags.lua +++ /dev/null @@ -1,23 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -inherit("detect.tools.gcc.has_flags") - diff --git a/xmake/modules/lib/detect/features.lua b/xmake/modules/lib/detect/features.lua index 7a00b04b4..ac72d288d 100644 --- a/xmake/modules/lib/detect/features.lua +++ b/xmake/modules/lib/detect/features.lua @@ -68,8 +68,8 @@ function main(name, opt) return result end - -- detect.tools.xxx.features(opt)? - local features = import("detect.tools." .. tool.name .. ".features", {try = true}) + -- core.tools.xxx.features(opt)? + local features = import("core.tools." .. tool.name .. ".features", {try = true}) if features then result = features(opt) end diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua index abfae3a57..7f915fe21 100644 --- a/xmake/modules/lib/detect/has_flags.lua +++ b/xmake/modules/lib/detect/has_flags.lua @@ -118,8 +118,8 @@ function main(name, flags, opt) -- start profile profiler.enter("has_flags", tool.name, checkflags[1]) - -- detect.tools.xxx.has_flags(flags, opt)? - local hasflags = import("detect.tools." .. tool.name .. ".has_flags", {try = true}) + -- core.tools.xxx.has_flags(flags, opt)? + local hasflags = import("core.tools." .. tool.name .. ".has_flags", {try = true}) local errors = nil if hasflags then result, errors = hasflags(checkflags, opt) -- cgit v1.3.1 From aeb4adecfe44aa0e73eb7d5860a89c47ba3bed95 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:59:33 +0800 Subject: move modules --- tests/apis/custom_toolchain/3 | Bin 4606 -> 0 bytes .../custom_toolchain/modules/core/tools/ar6x.lua | 27 +++ .../custom_toolchain/modules/core/tools/cl6x.lua | 207 +++++++++++++++++++++ .../modules/core/tools/cl6x/has_flags.lua | 121 ++++++++++++ .../modules/core/tools/cl6x/parse_deps.lua | 77 ++++++++ .../modules/detect/tools/find_ar6x.lua | 58 ++++++ .../modules/detect/tools/find_cl6x.lua | 48 +++++ .../toolchains/modules/core/tools/ar6x.lua | 27 --- .../toolchains/modules/core/tools/cl6x.lua | 207 --------------------- .../modules/core/tools/cl6x/has_flags.lua | 121 ------------ .../modules/core/tools/cl6x/parse_deps.lua | 77 -------- .../toolchains/modules/detect/tools/find_ar6x.lua | 58 ------ .../toolchains/modules/detect/tools/find_cl6x.lua | 48 ----- tests/apis/custom_toolchain/xmake.lua | 2 +- 14 files changed, 539 insertions(+), 539 deletions(-) delete mode 100644 tests/apis/custom_toolchain/3 create mode 100644 tests/apis/custom_toolchain/modules/core/tools/ar6x.lua create mode 100644 tests/apis/custom_toolchain/modules/core/tools/cl6x.lua create mode 100644 tests/apis/custom_toolchain/modules/core/tools/cl6x/has_flags.lua create mode 100644 tests/apis/custom_toolchain/modules/core/tools/cl6x/parse_deps.lua create mode 100644 tests/apis/custom_toolchain/modules/detect/tools/find_ar6x.lua create mode 100644 tests/apis/custom_toolchain/modules/detect/tools/find_cl6x.lua delete mode 100644 tests/apis/custom_toolchain/toolchains/modules/core/tools/ar6x.lua delete mode 100644 tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x.lua delete mode 100644 tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/has_flags.lua delete mode 100644 tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/parse_deps.lua delete mode 100644 tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_ar6x.lua delete mode 100644 tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_cl6x.lua diff --git a/tests/apis/custom_toolchain/3 b/tests/apis/custom_toolchain/3 deleted file mode 100644 index 51405a6f1..000000000 Binary files a/tests/apis/custom_toolchain/3 and /dev/null differ diff --git a/tests/apis/custom_toolchain/modules/core/tools/ar6x.lua b/tests/apis/custom_toolchain/modules/core/tools/ar6x.lua new file mode 100644 index 000000000..821b955e3 --- /dev/null +++ b/tests/apis/custom_toolchain/modules/core/tools/ar6x.lua @@ -0,0 +1,27 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file ar6x.lua +-- + +inherit("core.tools.ar") + +-- init it +function init(self) + self:set("arflags", "-r") +end + diff --git a/tests/apis/custom_toolchain/modules/core/tools/cl6x.lua b/tests/apis/custom_toolchain/modules/core/tools/cl6x.lua new file mode 100644 index 000000000..f350808da --- /dev/null +++ b/tests/apis/custom_toolchain/modules/core/tools/cl6x.lua @@ -0,0 +1,207 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cl6x.lua +-- + +-- imports +import("core.base.option") +import("core.base.global") +import("core.project.policy") +import("core.language.language") +import("utils.progress") + +-- init it +function init(self) +end + +-- make the symbol flag +function nf_symbol(self, level) + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = _g.symbol_maps + if not maps then + maps = + { + debug = "-g" + } + _g.symbol_maps = maps + end + return maps[level .. '_' .. kind] or maps[level] + end +end + +-- make the optimize flag +function nf_optimize(self, level) + local maps = + { + none = "-O0" + , fast = "-O1" + , faster = "-O2" + , fastest = "-O3" + , smallest = "-m3" + , aggressive = "-O3" + } + return maps[level] +end + +-- make the define flag +function nf_define(self, macro) + return "-D" .. macro +end + +-- make the undefine flag +function nf_undefine(self, macro) + return "-U" .. macro +end + +-- make the includedir flag +function nf_includedir(self, dir) + return {"-I" .. dir} +end + +-- make the sysincludedir flag +function nf_sysincludedir(self, dir) + return nf_includedir(self, dir) +end + +-- make the link flag +function nf_link(self, lib) + if not lib:endswith(".a") and not lib:endswith(".so") then + lib = "lib" .. lib .. ".a" + end + return "-l" .. lib +end + +-- make the syslink flag +function nf_syslink(self, lib) + return nf_link(self, lib) +end + +-- make the linkdir flag +function nf_linkdir(self, dir) + return {"-i" .. path.translate(dir)} +end + +-- make the rpathdir flag +function nf_rpathdir(self, dir, opt) + opt = opt or {} + local extra = opt.extra + if extra and extra.installonly then + return + end + dir = path.translate(dir) + return {"-rpath=" .. dir} +end + +-- make the link arguments list +function linkargv(self, objectfiles, targetkind, targetfile, flags, opt) + local argv = table.join("-z", "--output_file=" .. targetfile, objectfiles, flags) + return self:program(), argv +end + +-- link the target file +-- +-- maybe we need to use os.vrunv() to show link output when enable verbose information +-- @see https://github.com/xmake-io/xmake/discussions/2916 +-- +function link(self, objectfiles, targetkind, targetfile, flags, opt) + opt = opt or {} + os.mkdir(path.directory(targetfile)) + local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags) + if option.get("verbose") then + os.execv(program, argv, {envs = self:runenvs(), shell = opt.shell}) + else + os.vrunv(program, argv, {envs = self:runenvs(), shell = opt.shell}) + end +end + +-- make the compile arguments list +function compargv(self, sourcefile, objectfile, flags) + return self:program(), table.join("-c", "--preproc_with_compile", flags, "--output_file=" .. objectfile, sourcefile) +end + +-- compile the source file +function compile(self, sourcefile, objectfile, dependinfo, flags, opt) + os.mkdir(path.directory(objectfile)) + local depfile = dependinfo and os.tmpfile() or nil + try + { + function () + local compflags = flags + if depfile then + compflags = table.join(compflags, "-ppd=" .. depfile) + end + local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, compflags)) + return (outdata or "") .. (errdata or "") + end, + catch + { + function (errors) + + -- try removing the old object file for forcing to rebuild this source file + os.tryrm(objectfile) + + -- find the start line of error + local lines = tostring(errors):split("\n") + local start = 0 + for index, line in ipairs(lines) do + if line:find("error:", 1, true) or line:find("错误:", 1, true) then + start = index + break + end + end + + -- get 16 lines of errors + if start > 0 or not option.get("verbose") then + if start == 0 then start = 1 end + errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n") + end + + -- raise compiling errors + raise(errors) + end + }, + finally + { + function (ok, warnings) + + -- print some warnings + if warnings and #warnings > 0 and policy.build_warnings(opt) then + if progress.showing_without_scroll() then + print("") + end + cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n')) + end + + -- generate the dependent includes + if depfile and os.isfile(depfile) then + if dependinfo then + dependinfo.depfiles_format = "cl6x" + dependinfo.depfiles = io.readfile(depfile, {continuation = "\\"}) + end + + -- remove the temporary dependent file + os.tryrm(depfile) + end + end + } + } +end + + diff --git a/tests/apis/custom_toolchain/modules/core/tools/cl6x/has_flags.lua b/tests/apis/custom_toolchain/modules/core/tools/cl6x/has_flags.lua new file mode 100644 index 000000000..a5f3f4b87 --- /dev/null +++ b/tests/apis/custom_toolchain/modules/core/tools/cl6x/has_flags.lua @@ -0,0 +1,121 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from known flags +function _check_from_knownargs(flags, opt, islinker) + local flag = flags[1] + if not islinker then + if flag:startswith("-D") or + flag:startswith("-U") or + flag:startswith("-I") then + return true + end + end +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + local key = "core.tools.cl6x." .. (islinker and "has_ldflags" or "has_cflags") + local flagskey = opt.program .. "_" .. (opt.programver or "") + local allflags = detectcache:get2(key, flagskey) + if not allflags then + allflags = {} + local arglist = try {function () return os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) end} + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + local flag = flags[1] + return allflags[flag] +end + +-- get extension +function _get_extension(opt) + -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] + return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" + local sourcefile = os.tmpfile("cl6x_has_flags:" .. snippet) .. _get_extension(opt) + if not os.isfile(sourcefile) then + io.writefile(sourcefile, snippet) + end + + -- check flags for linker + local tmpfile = os.tmpfile() + if islinker then + return _try_running(opt.program, table.join(flags, "-z", "--output_file=" .. tmpfile, sourcefile), opt) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-c", "--output_file=" .. tmpfile, sourcefile), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + opt = opt or {} + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if not opt.tryrun then + if _check_from_arglist(flags, opt, islinker) then + return true + end + if _check_from_knownargs(flags, opt, islinker) then + return true + end + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/tests/apis/custom_toolchain/modules/core/tools/cl6x/parse_deps.lua b/tests/apis/custom_toolchain/modules/core/tools/cl6x/parse_deps.lua new file mode 100644 index 000000000..a5d5ecd40 --- /dev/null +++ b/tests/apis/custom_toolchain/modules/core/tools/cl6x/parse_deps.lua @@ -0,0 +1,77 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps.lua +-- + +-- imports +import("core.project.config") +import("core.project.project") +import("core.base.hashset") + +-- normailize path of a dependecy +function _normailize_dep(dep, projectdir) + -- escape characters, e.g. \#Qt.Widget_pch.h -> #Qt.Widget_pch.h + -- @see https://github.com/xmake-io/xmake/issues/4134 + -- https://github.com/xmake-io/xmake/issues/4273 + if not is_host("windows") then + dep = dep:gsub("\\(.)", "%1") + end + if path.is_absolute(dep) then + dep = path.translate(dep) + else + dep = path.absolute(dep, projectdir) + end + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) + else + -- we also need to check header files outside project + -- https://github.com/xmake-io/xmake/issues/1154 + return dep + end +end + +-- parse depsfiles from string +-- +-- parse_deps(io.readfile(depfile, {continuation = "\\"})) +-- +-- eg. +-- +-- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.c +-- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.h +-- +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/main.c +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/foo.h +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/bar.h +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/zoo.h +-- +function main(depsdata, opt) + local results = hashset.new() + local projectdir = os.projectdir() + local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first + local plain = {plain = true} + for _, includefile in ipairs(line:split('\n', plain)) do -- it will trim all internal spaces without `{strict = true}` + includefile = includefile:split(": ", plain)[2] + if includefile and #includefile > 0 then + includefile = _normailize_dep(includefile, projectdir) + if includefile then + results:insert(includefile) + end + end + end + return results:to_array() +end diff --git a/tests/apis/custom_toolchain/modules/detect/tools/find_ar6x.lua b/tests/apis/custom_toolchain/modules/detect/tools/find_ar6x.lua new file mode 100644 index 000000000..823a1f220 --- /dev/null +++ b/tests/apis/custom_toolchain/modules/detect/tools/find_ar6x.lua @@ -0,0 +1,58 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_ar6x.lua +-- + +-- imports +import("lib.detect.find_program") + +-- check +function _check(program) + + -- make a stub object file + local libraryfile = os.tmpfile() .. ".a" + local objectfile = os.tmpfile() .. ".o" + io.writefile(objectfile, "") + + -- archive it + os.execv(program, {"-r", libraryfile, objectfile}) + + -- remove files + os.rm(objectfile) + os.rm(libraryfile) +end + +-- find ar +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local ar = find_ar6x() +-- local ar, version = find_ar6x({program = "xcrun -sdk macosx g++", version = true}) +-- +-- @endcode +-- +function main(opt) + opt = opt or {} + opt.check = opt.check or _check + return find_program(opt.program or "ar6x", opt) +end + diff --git a/tests/apis/custom_toolchain/modules/detect/tools/find_cl6x.lua b/tests/apis/custom_toolchain/modules/detect/tools/find_cl6x.lua new file mode 100644 index 000000000..c961326ad --- /dev/null +++ b/tests/apis/custom_toolchain/modules/detect/tools/find_cl6x.lua @@ -0,0 +1,48 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_cl6x.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find cl6x +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local cl6x = find_cl6x() +-- local cl6x, version = find_cl6x({program = "cl6x", version = true}) +-- +-- @endcode +-- +function main(opt) + opt = opt or {} + opt.check = "--help" + opt.command = "--help" + local program = find_program(opt.program or "cl6x", opt) + local version = nil + if program and opt.version then + version = find_programver(program, opt) + end + return program, version +end diff --git a/tests/apis/custom_toolchain/toolchains/modules/core/tools/ar6x.lua b/tests/apis/custom_toolchain/toolchains/modules/core/tools/ar6x.lua deleted file mode 100644 index 821b955e3..000000000 --- a/tests/apis/custom_toolchain/toolchains/modules/core/tools/ar6x.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file ar6x.lua --- - -inherit("core.tools.ar") - --- init it -function init(self) - self:set("arflags", "-r") -end - diff --git a/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x.lua b/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x.lua deleted file mode 100644 index f350808da..000000000 --- a/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x.lua +++ /dev/null @@ -1,207 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file cl6x.lua --- - --- imports -import("core.base.option") -import("core.base.global") -import("core.project.policy") -import("core.language.language") -import("utils.progress") - --- init it -function init(self) -end - --- make the symbol flag -function nf_symbol(self, level) - -- only for source kind - local kind = self:kind() - if language.sourcekinds()[kind] then - local maps = _g.symbol_maps - if not maps then - maps = - { - debug = "-g" - } - _g.symbol_maps = maps - end - return maps[level .. '_' .. kind] or maps[level] - end -end - --- make the optimize flag -function nf_optimize(self, level) - local maps = - { - none = "-O0" - , fast = "-O1" - , faster = "-O2" - , fastest = "-O3" - , smallest = "-m3" - , aggressive = "-O3" - } - return maps[level] -end - --- make the define flag -function nf_define(self, macro) - return "-D" .. macro -end - --- make the undefine flag -function nf_undefine(self, macro) - return "-U" .. macro -end - --- make the includedir flag -function nf_includedir(self, dir) - return {"-I" .. dir} -end - --- make the sysincludedir flag -function nf_sysincludedir(self, dir) - return nf_includedir(self, dir) -end - --- make the link flag -function nf_link(self, lib) - if not lib:endswith(".a") and not lib:endswith(".so") then - lib = "lib" .. lib .. ".a" - end - return "-l" .. lib -end - --- make the syslink flag -function nf_syslink(self, lib) - return nf_link(self, lib) -end - --- make the linkdir flag -function nf_linkdir(self, dir) - return {"-i" .. path.translate(dir)} -end - --- make the rpathdir flag -function nf_rpathdir(self, dir, opt) - opt = opt or {} - local extra = opt.extra - if extra and extra.installonly then - return - end - dir = path.translate(dir) - return {"-rpath=" .. dir} -end - --- make the link arguments list -function linkargv(self, objectfiles, targetkind, targetfile, flags, opt) - local argv = table.join("-z", "--output_file=" .. targetfile, objectfiles, flags) - return self:program(), argv -end - --- link the target file --- --- maybe we need to use os.vrunv() to show link output when enable verbose information --- @see https://github.com/xmake-io/xmake/discussions/2916 --- -function link(self, objectfiles, targetkind, targetfile, flags, opt) - opt = opt or {} - os.mkdir(path.directory(targetfile)) - local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags) - if option.get("verbose") then - os.execv(program, argv, {envs = self:runenvs(), shell = opt.shell}) - else - os.vrunv(program, argv, {envs = self:runenvs(), shell = opt.shell}) - end -end - --- make the compile arguments list -function compargv(self, sourcefile, objectfile, flags) - return self:program(), table.join("-c", "--preproc_with_compile", flags, "--output_file=" .. objectfile, sourcefile) -end - --- compile the source file -function compile(self, sourcefile, objectfile, dependinfo, flags, opt) - os.mkdir(path.directory(objectfile)) - local depfile = dependinfo and os.tmpfile() or nil - try - { - function () - local compflags = flags - if depfile then - compflags = table.join(compflags, "-ppd=" .. depfile) - end - local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, compflags)) - return (outdata or "") .. (errdata or "") - end, - catch - { - function (errors) - - -- try removing the old object file for forcing to rebuild this source file - os.tryrm(objectfile) - - -- find the start line of error - local lines = tostring(errors):split("\n") - local start = 0 - for index, line in ipairs(lines) do - if line:find("error:", 1, true) or line:find("错误:", 1, true) then - start = index - break - end - end - - -- get 16 lines of errors - if start > 0 or not option.get("verbose") then - if start == 0 then start = 1 end - errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n") - end - - -- raise compiling errors - raise(errors) - end - }, - finally - { - function (ok, warnings) - - -- print some warnings - if warnings and #warnings > 0 and policy.build_warnings(opt) then - if progress.showing_without_scroll() then - print("") - end - cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n')) - end - - -- generate the dependent includes - if depfile and os.isfile(depfile) then - if dependinfo then - dependinfo.depfiles_format = "cl6x" - dependinfo.depfiles = io.readfile(depfile, {continuation = "\\"}) - end - - -- remove the temporary dependent file - os.tryrm(depfile) - end - end - } - } -end - - diff --git a/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/has_flags.lua b/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/has_flags.lua deleted file mode 100644 index a5f3f4b87..000000000 --- a/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/has_flags.lua +++ /dev/null @@ -1,121 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- is linker? -function _islinker(flags, opt) - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") -end - --- try running -function _try_running(program, argv, opt) - local errors = nil - return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from known flags -function _check_from_knownargs(flags, opt, islinker) - local flag = flags[1] - if not islinker then - if flag:startswith("-D") or - flag:startswith("-U") or - flag:startswith("-I") then - return true - end - end -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - local key = "core.tools.cl6x." .. (islinker and "has_ldflags" or "has_cflags") - local flagskey = opt.program .. "_" .. (opt.programver or "") - local allflags = detectcache:get2(key, flagskey) - if not allflags then - allflags = {} - local arglist = try {function () return os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) end} - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - local flag = flags[1] - return allflags[flag] -end - --- get extension -function _get_extension(opt) - -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] - return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" - local sourcefile = os.tmpfile("cl6x_has_flags:" .. snippet) .. _get_extension(opt) - if not os.isfile(sourcefile) then - io.writefile(sourcefile, snippet) - end - - -- check flags for linker - local tmpfile = os.tmpfile() - if islinker then - return _try_running(opt.program, table.join(flags, "-z", "--output_file=" .. tmpfile, sourcefile), opt) - end - - -- check flags for compiler - -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage - return _try_running(opt.program, table.join(flags, "-c", "--output_file=" .. tmpfile, sourcefile), opt) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - opt = opt or {} - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if not opt.tryrun then - if _check_from_arglist(flags, opt, islinker) then - return true - end - if _check_from_knownargs(flags, opt, islinker) then - return true - end - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - diff --git a/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/parse_deps.lua b/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/parse_deps.lua deleted file mode 100644 index a5d5ecd40..000000000 --- a/tests/apis/custom_toolchain/toolchains/modules/core/tools/cl6x/parse_deps.lua +++ /dev/null @@ -1,77 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file parse_deps.lua --- - --- imports -import("core.project.config") -import("core.project.project") -import("core.base.hashset") - --- normailize path of a dependecy -function _normailize_dep(dep, projectdir) - -- escape characters, e.g. \#Qt.Widget_pch.h -> #Qt.Widget_pch.h - -- @see https://github.com/xmake-io/xmake/issues/4134 - -- https://github.com/xmake-io/xmake/issues/4273 - if not is_host("windows") then - dep = dep:gsub("\\(.)", "%1") - end - if path.is_absolute(dep) then - dep = path.translate(dep) - else - dep = path.absolute(dep, projectdir) - end - if dep:startswith(projectdir) then - return path.relative(dep, projectdir) - else - -- we also need to check header files outside project - -- https://github.com/xmake-io/xmake/issues/1154 - return dep - end -end - --- parse depsfiles from string --- --- parse_deps(io.readfile(depfile, {continuation = "\\"})) --- --- eg. --- --- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.c --- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.h --- --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/main.c --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/foo.h --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/bar.h --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/zoo.h --- -function main(depsdata, opt) - local results = hashset.new() - local projectdir = os.projectdir() - local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first - local plain = {plain = true} - for _, includefile in ipairs(line:split('\n', plain)) do -- it will trim all internal spaces without `{strict = true}` - includefile = includefile:split(": ", plain)[2] - if includefile and #includefile > 0 then - includefile = _normailize_dep(includefile, projectdir) - if includefile then - results:insert(includefile) - end - end - end - return results:to_array() -end diff --git a/tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_ar6x.lua b/tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_ar6x.lua deleted file mode 100644 index 823a1f220..000000000 --- a/tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_ar6x.lua +++ /dev/null @@ -1,58 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file find_ar6x.lua --- - --- imports -import("lib.detect.find_program") - --- check -function _check(program) - - -- make a stub object file - local libraryfile = os.tmpfile() .. ".a" - local objectfile = os.tmpfile() .. ".o" - io.writefile(objectfile, "") - - -- archive it - os.execv(program, {"-r", libraryfile, objectfile}) - - -- remove files - os.rm(objectfile) - os.rm(libraryfile) -end - --- find ar --- --- @param opt the argument options, e.g. {version = true} --- --- @return program, version --- --- @code --- --- local ar = find_ar6x() --- local ar, version = find_ar6x({program = "xcrun -sdk macosx g++", version = true}) --- --- @endcode --- -function main(opt) - opt = opt or {} - opt.check = opt.check or _check - return find_program(opt.program or "ar6x", opt) -end - diff --git a/tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_cl6x.lua b/tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_cl6x.lua deleted file mode 100644 index c961326ad..000000000 --- a/tests/apis/custom_toolchain/toolchains/modules/detect/tools/find_cl6x.lua +++ /dev/null @@ -1,48 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file find_cl6x.lua --- - --- imports -import("lib.detect.find_program") -import("lib.detect.find_programver") - --- find cl6x --- --- @param opt the argument options, e.g. {version = true} --- --- @return program, version --- --- @code --- --- local cl6x = find_cl6x() --- local cl6x, version = find_cl6x({program = "cl6x", version = true}) --- --- @endcode --- -function main(opt) - opt = opt or {} - opt.check = "--help" - opt.command = "--help" - local program = find_program(opt.program or "cl6x", opt) - local version = nil - if program and opt.version then - version = find_programver(program, opt) - end - return program, version -end diff --git a/tests/apis/custom_toolchain/xmake.lua b/tests/apis/custom_toolchain/xmake.lua index 729f9fd81..0f11b9a61 100644 --- a/tests/apis/custom_toolchain/xmake.lua +++ b/tests/apis/custom_toolchain/xmake.lua @@ -1,7 +1,7 @@ add_rules("mode.debug", "mode.release") includes("toolchains/my-c6000") -add_moduledirs("toolchains/modules") +add_moduledirs("modules") set_toolchains("my-c6000") -- cgit v1.3.1 From 493ece8e6cc9373187692109d3a9ffb0b7a9e866 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:59:43 +0800 Subject: move modules --- .../custom_toolchain/modules/core/tools/ar6x.lua | 27 --- .../custom_toolchain/modules/core/tools/cl6x.lua | 207 --------------------- .../modules/core/tools/cl6x/has_flags.lua | 121 ------------ .../modules/core/tools/cl6x/parse_deps.lua | 77 -------- .../modules/detect/tools/find_ar6x.lua | 58 ------ .../modules/detect/tools/find_cl6x.lua | 48 ----- .../custom_toolchain/toolchains/my-c6000/xmake.lua | 20 -- tests/apis/custom_toolchain/xmake.lua | 4 +- .../xmake/modules/core/tools/ar6x.lua | 27 +++ .../xmake/modules/core/tools/cl6x.lua | 207 +++++++++++++++++++++ .../xmake/modules/core/tools/cl6x/has_flags.lua | 121 ++++++++++++ .../xmake/modules/core/tools/cl6x/parse_deps.lua | 77 ++++++++ .../xmake/modules/detect/tools/find_ar6x.lua | 58 ++++++ .../xmake/modules/detect/tools/find_cl6x.lua | 48 +++++ .../xmake/toolchains/my-c6000/xmake.lua | 20 ++ 15 files changed, 560 insertions(+), 560 deletions(-) delete mode 100644 tests/apis/custom_toolchain/modules/core/tools/ar6x.lua delete mode 100644 tests/apis/custom_toolchain/modules/core/tools/cl6x.lua delete mode 100644 tests/apis/custom_toolchain/modules/core/tools/cl6x/has_flags.lua delete mode 100644 tests/apis/custom_toolchain/modules/core/tools/cl6x/parse_deps.lua delete mode 100644 tests/apis/custom_toolchain/modules/detect/tools/find_ar6x.lua delete mode 100644 tests/apis/custom_toolchain/modules/detect/tools/find_cl6x.lua delete mode 100644 tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua create mode 100644 tests/apis/custom_toolchain/xmake/modules/core/tools/ar6x.lua create mode 100644 tests/apis/custom_toolchain/xmake/modules/core/tools/cl6x.lua create mode 100644 tests/apis/custom_toolchain/xmake/modules/core/tools/cl6x/has_flags.lua create mode 100644 tests/apis/custom_toolchain/xmake/modules/core/tools/cl6x/parse_deps.lua create mode 100644 tests/apis/custom_toolchain/xmake/modules/detect/tools/find_ar6x.lua create mode 100644 tests/apis/custom_toolchain/xmake/modules/detect/tools/find_cl6x.lua create mode 100644 tests/apis/custom_toolchain/xmake/toolchains/my-c6000/xmake.lua diff --git a/tests/apis/custom_toolchain/modules/core/tools/ar6x.lua b/tests/apis/custom_toolchain/modules/core/tools/ar6x.lua deleted file mode 100644 index 821b955e3..000000000 --- a/tests/apis/custom_toolchain/modules/core/tools/ar6x.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file ar6x.lua --- - -inherit("core.tools.ar") - --- init it -function init(self) - self:set("arflags", "-r") -end - diff --git a/tests/apis/custom_toolchain/modules/core/tools/cl6x.lua b/tests/apis/custom_toolchain/modules/core/tools/cl6x.lua deleted file mode 100644 index f350808da..000000000 --- a/tests/apis/custom_toolchain/modules/core/tools/cl6x.lua +++ /dev/null @@ -1,207 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file cl6x.lua --- - --- imports -import("core.base.option") -import("core.base.global") -import("core.project.policy") -import("core.language.language") -import("utils.progress") - --- init it -function init(self) -end - --- make the symbol flag -function nf_symbol(self, level) - -- only for source kind - local kind = self:kind() - if language.sourcekinds()[kind] then - local maps = _g.symbol_maps - if not maps then - maps = - { - debug = "-g" - } - _g.symbol_maps = maps - end - return maps[level .. '_' .. kind] or maps[level] - end -end - --- make the optimize flag -function nf_optimize(self, level) - local maps = - { - none = "-O0" - , fast = "-O1" - , faster = "-O2" - , fastest = "-O3" - , smallest = "-m3" - , aggressive = "-O3" - } - return maps[level] -end - --- make the define flag -function nf_define(self, macro) - return "-D" .. macro -end - --- make the undefine flag -function nf_undefine(self, macro) - return "-U" .. macro -end - --- make the includedir flag -function nf_includedir(self, dir) - return {"-I" .. dir} -end - --- make the sysincludedir flag -function nf_sysincludedir(self, dir) - return nf_includedir(self, dir) -end - --- make the link flag -function nf_link(self, lib) - if not lib:endswith(".a") and not lib:endswith(".so") then - lib = "lib" .. lib .. ".a" - end - return "-l" .. lib -end - --- make the syslink flag -function nf_syslink(self, lib) - return nf_link(self, lib) -end - --- make the linkdir flag -function nf_linkdir(self, dir) - return {"-i" .. path.translate(dir)} -end - --- make the rpathdir flag -function nf_rpathdir(self, dir, opt) - opt = opt or {} - local extra = opt.extra - if extra and extra.installonly then - return - end - dir = path.translate(dir) - return {"-rpath=" .. dir} -end - --- make the link arguments list -function linkargv(self, objectfiles, targetkind, targetfile, flags, opt) - local argv = table.join("-z", "--output_file=" .. targetfile, objectfiles, flags) - return self:program(), argv -end - --- link the target file --- --- maybe we need to use os.vrunv() to show link output when enable verbose information --- @see https://github.com/xmake-io/xmake/discussions/2916 --- -function link(self, objectfiles, targetkind, targetfile, flags, opt) - opt = opt or {} - os.mkdir(path.directory(targetfile)) - local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags) - if option.get("verbose") then - os.execv(program, argv, {envs = self:runenvs(), shell = opt.shell}) - else - os.vrunv(program, argv, {envs = self:runenvs(), shell = opt.shell}) - end -end - --- make the compile arguments list -function compargv(self, sourcefile, objectfile, flags) - return self:program(), table.join("-c", "--preproc_with_compile", flags, "--output_file=" .. objectfile, sourcefile) -end - --- compile the source file -function compile(self, sourcefile, objectfile, dependinfo, flags, opt) - os.mkdir(path.directory(objectfile)) - local depfile = dependinfo and os.tmpfile() or nil - try - { - function () - local compflags = flags - if depfile then - compflags = table.join(compflags, "-ppd=" .. depfile) - end - local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, compflags)) - return (outdata or "") .. (errdata or "") - end, - catch - { - function (errors) - - -- try removing the old object file for forcing to rebuild this source file - os.tryrm(objectfile) - - -- find the start line of error - local lines = tostring(errors):split("\n") - local start = 0 - for index, line in ipairs(lines) do - if line:find("error:", 1, true) or line:find("错误:", 1, true) then - start = index - break - end - end - - -- get 16 lines of errors - if start > 0 or not option.get("verbose") then - if start == 0 then start = 1 end - errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n") - end - - -- raise compiling errors - raise(errors) - end - }, - finally - { - function (ok, warnings) - - -- print some warnings - if warnings and #warnings > 0 and policy.build_warnings(opt) then - if progress.showing_without_scroll() then - print("") - end - cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n')) - end - - -- generate the dependent includes - if depfile and os.isfile(depfile) then - if dependinfo then - dependinfo.depfiles_format = "cl6x" - dependinfo.depfiles = io.readfile(depfile, {continuation = "\\"}) - end - - -- remove the temporary dependent file - os.tryrm(depfile) - end - end - } - } -end - - diff --git a/tests/apis/custom_toolchain/modules/core/tools/cl6x/has_flags.lua b/tests/apis/custom_toolchain/modules/core/tools/cl6x/has_flags.lua deleted file mode 100644 index a5f3f4b87..000000000 --- a/tests/apis/custom_toolchain/modules/core/tools/cl6x/has_flags.lua +++ /dev/null @@ -1,121 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file has_flags.lua --- - --- imports -import("core.cache.detectcache") -import("core.language.language") - --- is linker? -function _islinker(flags, opt) - local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") -end - --- try running -function _try_running(program, argv, opt) - local errors = nil - return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors -end - --- attempt to check it from known flags -function _check_from_knownargs(flags, opt, islinker) - local flag = flags[1] - if not islinker then - if flag:startswith("-D") or - flag:startswith("-U") or - flag:startswith("-I") then - return true - end - end -end - --- attempt to check it from the argument list -function _check_from_arglist(flags, opt, islinker) - local key = "core.tools.cl6x." .. (islinker and "has_ldflags" or "has_cflags") - local flagskey = opt.program .. "_" .. (opt.programver or "") - local allflags = detectcache:get2(key, flagskey) - if not allflags then - allflags = {} - local arglist = try {function () return os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) end} - if arglist then - for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - allflags[arg] = true - end - end - detectcache:set2(key, flagskey, allflags) - detectcache:save() - end - local flag = flags[1] - return allflags[flag] -end - --- get extension -function _get_extension(opt) - -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] - return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") -end - --- try running to check flags -function _check_try_running(flags, opt, islinker) - - -- make an stub source file - local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" - local sourcefile = os.tmpfile("cl6x_has_flags:" .. snippet) .. _get_extension(opt) - if not os.isfile(sourcefile) then - io.writefile(sourcefile, snippet) - end - - -- check flags for linker - local tmpfile = os.tmpfile() - if islinker then - return _try_running(opt.program, table.join(flags, "-z", "--output_file=" .. tmpfile, sourcefile), opt) - end - - -- check flags for compiler - -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage - return _try_running(opt.program, table.join(flags, "-c", "--output_file=" .. tmpfile, sourcefile), opt) -end - --- has_flags(flags)? --- --- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} --- --- @return true or false --- -function main(flags, opt) - - -- is linker? - opt = opt or {} - local islinker = _islinker(flags, opt) - - -- attempt to check it from the argument list - if not opt.tryrun then - if _check_from_arglist(flags, opt, islinker) then - return true - end - if _check_from_knownargs(flags, opt, islinker) then - return true - end - end - - -- try running to check it - return _check_try_running(flags, opt, islinker) -end - diff --git a/tests/apis/custom_toolchain/modules/core/tools/cl6x/parse_deps.lua b/tests/apis/custom_toolchain/modules/core/tools/cl6x/parse_deps.lua deleted file mode 100644 index a5d5ecd40..000000000 --- a/tests/apis/custom_toolchain/modules/core/tools/cl6x/parse_deps.lua +++ /dev/null @@ -1,77 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file parse_deps.lua --- - --- imports -import("core.project.config") -import("core.project.project") -import("core.base.hashset") - --- normailize path of a dependecy -function _normailize_dep(dep, projectdir) - -- escape characters, e.g. \#Qt.Widget_pch.h -> #Qt.Widget_pch.h - -- @see https://github.com/xmake-io/xmake/issues/4134 - -- https://github.com/xmake-io/xmake/issues/4273 - if not is_host("windows") then - dep = dep:gsub("\\(.)", "%1") - end - if path.is_absolute(dep) then - dep = path.translate(dep) - else - dep = path.absolute(dep, projectdir) - end - if dep:startswith(projectdir) then - return path.relative(dep, projectdir) - else - -- we also need to check header files outside project - -- https://github.com/xmake-io/xmake/issues/1154 - return dep - end -end - --- parse depsfiles from string --- --- parse_deps(io.readfile(depfile, {continuation = "\\"})) --- --- eg. --- --- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.c --- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.h --- --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/main.c --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/foo.h --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/bar.h --- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/zoo.h --- -function main(depsdata, opt) - local results = hashset.new() - local projectdir = os.projectdir() - local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first - local plain = {plain = true} - for _, includefile in ipairs(line:split('\n', plain)) do -- it will trim all internal spaces without `{strict = true}` - includefile = includefile:split(": ", plain)[2] - if includefile and #includefile > 0 then - includefile = _normailize_dep(includefile, projectdir) - if includefile then - results:insert(includefile) - end - end - end - return results:to_array() -end diff --git a/tests/apis/custom_toolchain/modules/detect/tools/find_ar6x.lua b/tests/apis/custom_toolchain/modules/detect/tools/find_ar6x.lua deleted file mode 100644 index 823a1f220..000000000 --- a/tests/apis/custom_toolchain/modules/detect/tools/find_ar6x.lua +++ /dev/null @@ -1,58 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file find_ar6x.lua --- - --- imports -import("lib.detect.find_program") - --- check -function _check(program) - - -- make a stub object file - local libraryfile = os.tmpfile() .. ".a" - local objectfile = os.tmpfile() .. ".o" - io.writefile(objectfile, "") - - -- archive it - os.execv(program, {"-r", libraryfile, objectfile}) - - -- remove files - os.rm(objectfile) - os.rm(libraryfile) -end - --- find ar --- --- @param opt the argument options, e.g. {version = true} --- --- @return program, version --- --- @code --- --- local ar = find_ar6x() --- local ar, version = find_ar6x({program = "xcrun -sdk macosx g++", version = true}) --- --- @endcode --- -function main(opt) - opt = opt or {} - opt.check = opt.check or _check - return find_program(opt.program or "ar6x", opt) -end - diff --git a/tests/apis/custom_toolchain/modules/detect/tools/find_cl6x.lua b/tests/apis/custom_toolchain/modules/detect/tools/find_cl6x.lua deleted file mode 100644 index c961326ad..000000000 --- a/tests/apis/custom_toolchain/modules/detect/tools/find_cl6x.lua +++ /dev/null @@ -1,48 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file find_cl6x.lua --- - --- imports -import("lib.detect.find_program") -import("lib.detect.find_programver") - --- find cl6x --- --- @param opt the argument options, e.g. {version = true} --- --- @return program, version --- --- @code --- --- local cl6x = find_cl6x() --- local cl6x, version = find_cl6x({program = "cl6x", version = true}) --- --- @endcode --- -function main(opt) - opt = opt or {} - opt.check = "--help" - opt.command = "--help" - local program = find_program(opt.program or "cl6x", opt) - local version = nil - if program and opt.version then - version = find_programver(program, opt) - end - return program, version -end diff --git a/tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua b/tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua deleted file mode 100644 index 2de2275a7..000000000 --- a/tests/apis/custom_toolchain/toolchains/my-c6000/xmake.lua +++ /dev/null @@ -1,20 +0,0 @@ -toolchain("my-c6000") - set_kind("standalone") - set_homepage("https://www.ti.com") - set_description("TI-CGT C6000 compiler") - - set_toolset("cc", "cl6x") - set_toolset("cxx", "cl6x") - set_toolset("ld", "cl6x") - set_toolset("sh", "cl6x") - set_toolset("ar", "ar6x") - set_toolset("strip", "strip6x") - set_toolset("as", "cl6x") - - on_check(function (toolchain) - return import("lib.detect.find_tool")("cl6x") - end) - - on_load(function (toolchain) - toolchain:add("cxflags", "-Dxxx") - end) diff --git a/tests/apis/custom_toolchain/xmake.lua b/tests/apis/custom_toolchain/xmake.lua index 0f11b9a61..e67603129 100644 --- a/tests/apis/custom_toolchain/xmake.lua +++ b/tests/apis/custom_toolchain/xmake.lua @@ -1,7 +1,7 @@ add_rules("mode.debug", "mode.release") -includes("toolchains/my-c6000") -add_moduledirs("modules") +includes("xmake/toolchains/my-c6000") +add_moduledirs("xmake/modules") set_toolchains("my-c6000") diff --git a/tests/apis/custom_toolchain/xmake/modules/core/tools/ar6x.lua b/tests/apis/custom_toolchain/xmake/modules/core/tools/ar6x.lua new file mode 100644 index 000000000..821b955e3 --- /dev/null +++ b/tests/apis/custom_toolchain/xmake/modules/core/tools/ar6x.lua @@ -0,0 +1,27 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file ar6x.lua +-- + +inherit("core.tools.ar") + +-- init it +function init(self) + self:set("arflags", "-r") +end + diff --git a/tests/apis/custom_toolchain/xmake/modules/core/tools/cl6x.lua b/tests/apis/custom_toolchain/xmake/modules/core/tools/cl6x.lua new file mode 100644 index 000000000..f350808da --- /dev/null +++ b/tests/apis/custom_toolchain/xmake/modules/core/tools/cl6x.lua @@ -0,0 +1,207 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cl6x.lua +-- + +-- imports +import("core.base.option") +import("core.base.global") +import("core.project.policy") +import("core.language.language") +import("utils.progress") + +-- init it +function init(self) +end + +-- make the symbol flag +function nf_symbol(self, level) + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = _g.symbol_maps + if not maps then + maps = + { + debug = "-g" + } + _g.symbol_maps = maps + end + return maps[level .. '_' .. kind] or maps[level] + end +end + +-- make the optimize flag +function nf_optimize(self, level) + local maps = + { + none = "-O0" + , fast = "-O1" + , faster = "-O2" + , fastest = "-O3" + , smallest = "-m3" + , aggressive = "-O3" + } + return maps[level] +end + +-- make the define flag +function nf_define(self, macro) + return "-D" .. macro +end + +-- make the undefine flag +function nf_undefine(self, macro) + return "-U" .. macro +end + +-- make the includedir flag +function nf_includedir(self, dir) + return {"-I" .. dir} +end + +-- make the sysincludedir flag +function nf_sysincludedir(self, dir) + return nf_includedir(self, dir) +end + +-- make the link flag +function nf_link(self, lib) + if not lib:endswith(".a") and not lib:endswith(".so") then + lib = "lib" .. lib .. ".a" + end + return "-l" .. lib +end + +-- make the syslink flag +function nf_syslink(self, lib) + return nf_link(self, lib) +end + +-- make the linkdir flag +function nf_linkdir(self, dir) + return {"-i" .. path.translate(dir)} +end + +-- make the rpathdir flag +function nf_rpathdir(self, dir, opt) + opt = opt or {} + local extra = opt.extra + if extra and extra.installonly then + return + end + dir = path.translate(dir) + return {"-rpath=" .. dir} +end + +-- make the link arguments list +function linkargv(self, objectfiles, targetkind, targetfile, flags, opt) + local argv = table.join("-z", "--output_file=" .. targetfile, objectfiles, flags) + return self:program(), argv +end + +-- link the target file +-- +-- maybe we need to use os.vrunv() to show link output when enable verbose information +-- @see https://github.com/xmake-io/xmake/discussions/2916 +-- +function link(self, objectfiles, targetkind, targetfile, flags, opt) + opt = opt or {} + os.mkdir(path.directory(targetfile)) + local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags) + if option.get("verbose") then + os.execv(program, argv, {envs = self:runenvs(), shell = opt.shell}) + else + os.vrunv(program, argv, {envs = self:runenvs(), shell = opt.shell}) + end +end + +-- make the compile arguments list +function compargv(self, sourcefile, objectfile, flags) + return self:program(), table.join("-c", "--preproc_with_compile", flags, "--output_file=" .. objectfile, sourcefile) +end + +-- compile the source file +function compile(self, sourcefile, objectfile, dependinfo, flags, opt) + os.mkdir(path.directory(objectfile)) + local depfile = dependinfo and os.tmpfile() or nil + try + { + function () + local compflags = flags + if depfile then + compflags = table.join(compflags, "-ppd=" .. depfile) + end + local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, compflags)) + return (outdata or "") .. (errdata or "") + end, + catch + { + function (errors) + + -- try removing the old object file for forcing to rebuild this source file + os.tryrm(objectfile) + + -- find the start line of error + local lines = tostring(errors):split("\n") + local start = 0 + for index, line in ipairs(lines) do + if line:find("error:", 1, true) or line:find("错误:", 1, true) then + start = index + break + end + end + + -- get 16 lines of errors + if start > 0 or not option.get("verbose") then + if start == 0 then start = 1 end + errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n") + end + + -- raise compiling errors + raise(errors) + end + }, + finally + { + function (ok, warnings) + + -- print some warnings + if warnings and #warnings > 0 and policy.build_warnings(opt) then + if progress.showing_without_scroll() then + print("") + end + cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n')) + end + + -- generate the dependent includes + if depfile and os.isfile(depfile) then + if dependinfo then + dependinfo.depfiles_format = "cl6x" + dependinfo.depfiles = io.readfile(depfile, {continuation = "\\"}) + end + + -- remove the temporary dependent file + os.tryrm(depfile) + end + end + } + } +end + + diff --git a/tests/apis/custom_toolchain/xmake/modules/core/tools/cl6x/has_flags.lua b/tests/apis/custom_toolchain/xmake/modules/core/tools/cl6x/has_flags.lua new file mode 100644 index 000000000..a5f3f4b87 --- /dev/null +++ b/tests/apis/custom_toolchain/xmake/modules/core/tools/cl6x/has_flags.lua @@ -0,0 +1,121 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +import("core.cache.detectcache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from known flags +function _check_from_knownargs(flags, opt, islinker) + local flag = flags[1] + if not islinker then + if flag:startswith("-D") or + flag:startswith("-U") or + flag:startswith("-I") then + return true + end + end +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + local key = "core.tools.cl6x." .. (islinker and "has_ldflags" or "has_cflags") + local flagskey = opt.program .. "_" .. (opt.programver or "") + local allflags = detectcache:get2(key, flagskey) + if not allflags then + allflags = {} + local arglist = try {function () return os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) end} + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + local flag = flags[1] + return allflags[flag] +end + +-- get extension +function _get_extension(opt) + -- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] + return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n" + local sourcefile = os.tmpfile("cl6x_has_flags:" .. snippet) .. _get_extension(opt) + if not os.isfile(sourcefile) then + io.writefile(sourcefile, snippet) + end + + -- check flags for linker + local tmpfile = os.tmpfile() + if islinker then + return _try_running(opt.program, table.join(flags, "-z", "--output_file=" .. tmpfile, sourcefile), opt) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-c", "--output_file=" .. tmpfile, sourcefile), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + opt = opt or {} + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if not opt.tryrun then + if _check_from_arglist(flags, opt, islinker) then + return true + end + if _check_from_knownargs(flags, opt, islinker) then + return true + end + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/tests/apis/custom_toolchain/xmake/modules/core/tools/cl6x/parse_deps.lua b/tests/apis/custom_toolchain/xmake/modules/core/tools/cl6x/parse_deps.lua new file mode 100644 index 000000000..a5d5ecd40 --- /dev/null +++ b/tests/apis/custom_toolchain/xmake/modules/core/tools/cl6x/parse_deps.lua @@ -0,0 +1,77 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps.lua +-- + +-- imports +import("core.project.config") +import("core.project.project") +import("core.base.hashset") + +-- normailize path of a dependecy +function _normailize_dep(dep, projectdir) + -- escape characters, e.g. \#Qt.Widget_pch.h -> #Qt.Widget_pch.h + -- @see https://github.com/xmake-io/xmake/issues/4134 + -- https://github.com/xmake-io/xmake/issues/4273 + if not is_host("windows") then + dep = dep:gsub("\\(.)", "%1") + end + if path.is_absolute(dep) then + dep = path.translate(dep) + else + dep = path.absolute(dep, projectdir) + end + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) + else + -- we also need to check header files outside project + -- https://github.com/xmake-io/xmake/issues/1154 + return dep + end +end + +-- parse depsfiles from string +-- +-- parse_deps(io.readfile(depfile, {continuation = "\\"})) +-- +-- eg. +-- +-- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.c +-- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.h +-- +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/main.c +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/foo.h +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/bar.h +-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/zoo.h +-- +function main(depsdata, opt) + local results = hashset.new() + local projectdir = os.projectdir() + local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first + local plain = {plain = true} + for _, includefile in ipairs(line:split('\n', plain)) do -- it will trim all internal spaces without `{strict = true}` + includefile = includefile:split(": ", plain)[2] + if includefile and #includefile > 0 then + includefile = _normailize_dep(includefile, projectdir) + if includefile then + results:insert(includefile) + end + end + end + return results:to_array() +end diff --git a/tests/apis/custom_toolchain/xmake/modules/detect/tools/find_ar6x.lua b/tests/apis/custom_toolchain/xmake/modules/detect/tools/find_ar6x.lua new file mode 100644 index 000000000..823a1f220 --- /dev/null +++ b/tests/apis/custom_toolchain/xmake/modules/detect/tools/find_ar6x.lua @@ -0,0 +1,58 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_ar6x.lua +-- + +-- imports +import("lib.detect.find_program") + +-- check +function _check(program) + + -- make a stub object file + local libraryfile = os.tmpfile() .. ".a" + local objectfile = os.tmpfile() .. ".o" + io.writefile(objectfile, "") + + -- archive it + os.execv(program, {"-r", libraryfile, objectfile}) + + -- remove files + os.rm(objectfile) + os.rm(libraryfile) +end + +-- find ar +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local ar = find_ar6x() +-- local ar, version = find_ar6x({program = "xcrun -sdk macosx g++", version = true}) +-- +-- @endcode +-- +function main(opt) + opt = opt or {} + opt.check = opt.check or _check + return find_program(opt.program or "ar6x", opt) +end + diff --git a/tests/apis/custom_toolchain/xmake/modules/detect/tools/find_cl6x.lua b/tests/apis/custom_toolchain/xmake/modules/detect/tools/find_cl6x.lua new file mode 100644 index 000000000..c961326ad --- /dev/null +++ b/tests/apis/custom_toolchain/xmake/modules/detect/tools/find_cl6x.lua @@ -0,0 +1,48 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_cl6x.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find cl6x +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local cl6x = find_cl6x() +-- local cl6x, version = find_cl6x({program = "cl6x", version = true}) +-- +-- @endcode +-- +function main(opt) + opt = opt or {} + opt.check = "--help" + opt.command = "--help" + local program = find_program(opt.program or "cl6x", opt) + local version = nil + if program and opt.version then + version = find_programver(program, opt) + end + return program, version +end diff --git a/tests/apis/custom_toolchain/xmake/toolchains/my-c6000/xmake.lua b/tests/apis/custom_toolchain/xmake/toolchains/my-c6000/xmake.lua new file mode 100644 index 000000000..2de2275a7 --- /dev/null +++ b/tests/apis/custom_toolchain/xmake/toolchains/my-c6000/xmake.lua @@ -0,0 +1,20 @@ +toolchain("my-c6000") + set_kind("standalone") + set_homepage("https://www.ti.com") + set_description("TI-CGT C6000 compiler") + + set_toolset("cc", "cl6x") + set_toolset("cxx", "cl6x") + set_toolset("ld", "cl6x") + set_toolset("sh", "cl6x") + set_toolset("ar", "ar6x") + set_toolset("strip", "strip6x") + set_toolset("as", "cl6x") + + on_check(function (toolchain) + return import("lib.detect.find_tool")("cl6x") + end) + + on_load(function (toolchain) + toolchain:add("cxflags", "-Dxxx") + end) -- cgit v1.3.1 From 7f01ecf6da7e040d4b0e27efaa035a8f27533e5e Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:00:55 +0800 Subject: add toolchain dirs --- tests/apis/custom_toolchain/xmake.lua | 2 +- xmake/core/project/project.lua | 12 ++++++++++++ xmake/core/sandbox/modules/import/core/tool/toolchain.lua | 3 ++- xmake/core/tool/toolchain.lua | 9 +++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/apis/custom_toolchain/xmake.lua b/tests/apis/custom_toolchain/xmake.lua index e67603129..03d2b5344 100644 --- a/tests/apis/custom_toolchain/xmake.lua +++ b/tests/apis/custom_toolchain/xmake.lua @@ -1,7 +1,7 @@ add_rules("mode.debug", "mode.release") -includes("xmake/toolchains/my-c6000") add_moduledirs("xmake/modules") +add_toolchaindirs("xmake/toolchains") set_toolchains("my-c6000") diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 20b0a171b..7b42d47ea 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -202,6 +202,17 @@ function project._api_add_platformdirs(interp, ...) end end +-- add toolchain directories +function project._api_add_toolchaindirs(interp, ...) + local scriptdir = project.interpreter():scriptdir() + for _, dir in ipairs({...}) do + if not path.is_absolute(dir) then + dir = path.absolute(dir, scriptdir) + end + toolchain.add_directories(dir) + end +end + -- load the project file function project._load(force, disable_filter) @@ -658,6 +669,7 @@ function project.apis() , {"add_moduledirs", project._api_add_moduledirs } , {"add_plugindirs", project._api_add_plugindirs } , {"add_platformdirs", project._api_add_platformdirs } + , {"add_toolchaindirs", project._api_add_toolchaindirs } } } end diff --git a/xmake/core/sandbox/modules/import/core/tool/toolchain.lua b/xmake/core/sandbox/modules/import/core/tool/toolchain.lua index 46bd9fb1d..48867300e 100644 --- a/xmake/core/sandbox/modules/import/core/tool/toolchain.lua +++ b/xmake/core/sandbox/modules/import/core/tool/toolchain.lua @@ -28,7 +28,8 @@ local project = require("project/project") local raise = require("sandbox/modules/raise") -- inherit some builtin interfaces -sandbox_core_tool_toolchain.apis = toolchain.apis +sandbox_core_tool_toolchain.apis = toolchain.apis +sandbox_core_tool_toolchain.directories = toolchain.directories -- get all toolchains list function sandbox_core_tool_toolchain.list() diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index a19413d34..1085df198 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -640,6 +640,15 @@ function toolchain.directories() return dirs end +-- add toolchain directories +function toolchain.add_directories(...) + local dirs = toolchain.directories() + for _, dir in ipairs({...}) do + table.insert(dirs, 1, dir) + end + toolchain._DIRS = table.unique(dirs) +end + -- load toolchain function toolchain.load(name, opt) -- cgit v1.3.1 From 8729cdf3afc01932f67ba826ceda14b0319d3f7f Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:05:31 +0800 Subject: fix import --- xmake/modules/core/tools/cl.lua | 4 ++-- xmake/modules/core/tools/cl/parse_include.lua | 2 +- xmake/modules/core/tools/cl2000/parse_deps.lua | 2 +- xmake/modules/core/tools/ifort.lua | 2 +- xmake/modules/core/tools/link.lua | 2 +- xmake/modules/core/tools/ml.lua | 2 +- xmake/modules/core/tools/rc.lua | 2 +- xmake/plugins/project/ninja/build_ninja.lua | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 8a2971328..3b73719e7 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -25,8 +25,8 @@ import("core.base.hashset") import("core.project.project") import("core.project.policy") import("core.language.language") -import("private.tools.vstool") -import("private.tools.cl.parse_include") +import("core.tools.vstool") +import("core.tools.cl.parse_include") import("private.cache.build_cache") import("private.service.distcc_build.client", {alias = "distcc_build_client"}) import("utils.progress") diff --git a/xmake/modules/core/tools/cl/parse_include.lua b/xmake/modules/core/tools/cl/parse_include.lua index 700f9823f..009d6d1f5 100644 --- a/xmake/modules/core/tools/cl/parse_include.lua +++ b/xmake/modules/core/tools/cl/parse_include.lua @@ -24,7 +24,7 @@ import("core.base.hashset") import("core.tool.toolchain") import("core.cache.detectcache") import("lib.detect.find_tool") -import("private.tools.vstool") +import("core.tools.vstool") -- probe include note prefix from cl function probe_include_note_from_cl() diff --git a/xmake/modules/core/tools/cl2000/parse_deps.lua b/xmake/modules/core/tools/cl2000/parse_deps.lua index e02cf0501..c5d6e29c6 100644 --- a/xmake/modules/core/tools/cl2000/parse_deps.lua +++ b/xmake/modules/core/tools/cl2000/parse_deps.lua @@ -19,5 +19,5 @@ -- -- imports -inherit("private.tools.cl6x.parse_deps") +inherit("core.tools.cl6x.parse_deps") diff --git a/xmake/modules/core/tools/ifort.lua b/xmake/modules/core/tools/ifort.lua index 2d48f34c7..6235c50ff 100644 --- a/xmake/modules/core/tools/ifort.lua +++ b/xmake/modules/core/tools/ifort.lua @@ -23,7 +23,7 @@ if is_host("windows") then -- imports inherit("cl") inherit("link") - import("private.tools.vstool") + import("core.tools.vstool") -- init it function init(self) diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua index 3e51ad40a..62f794bdd 100644 --- a/xmake/modules/core/tools/link.lua +++ b/xmake/modules/core/tools/link.lua @@ -20,7 +20,7 @@ -- imports import("core.project.config") -import("private.tools.vstool") +import("core.tools.vstool") -- init it function init(self) diff --git a/xmake/modules/core/tools/ml.lua b/xmake/modules/core/tools/ml.lua index 5bb1fb884..4af30e7e7 100644 --- a/xmake/modules/core/tools/ml.lua +++ b/xmake/modules/core/tools/ml.lua @@ -19,7 +19,7 @@ -- -- imports -import("private.tools.vstool") +import("core.tools.vstool") import("core.base.hashset") -- init it diff --git a/xmake/modules/core/tools/rc.lua b/xmake/modules/core/tools/rc.lua index 91c1984ca..423652b49 100644 --- a/xmake/modules/core/tools/rc.lua +++ b/xmake/modules/core/tools/rc.lua @@ -22,7 +22,7 @@ import("core.base.option") import("core.base.hashset") import("core.project.project") -import("private.tools.vstool") +import("core.tools.vstool") -- normailize path of a dependecy function _normailize_dep(dep, projectdir) diff --git a/xmake/plugins/project/ninja/build_ninja.lua b/xmake/plugins/project/ninja/build_ninja.lua index 7a9ce3998..819758447 100644 --- a/xmake/plugins/project/ninja/build_ninja.lua +++ b/xmake/plugins/project/ninja/build_ninja.lua @@ -27,7 +27,7 @@ import("core.tool.linker") import("core.tool.compiler") import("lib.detect.find_tool") import("lib.detect.find_toolname") -import("private.tools.cl.parse_include") +import("core.tools.cl.parse_include") -- this sourcebatch is built? function _sourcebatch_is_built(sourcebatch) -- cgit v1.3.1 From beff9a0f84ce1ebdd1eeb85caee55500320595a3 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jan 2025 00:10:13 +0800 Subject: fix imports --- xmake/modules/core/tools/cl.lua | 2 +- xmake/modules/core/tools/cl/parse_include.lua | 2 +- xmake/modules/core/tools/ifort.lua | 2 +- xmake/modules/core/tools/link.lua | 2 +- xmake/modules/core/tools/ml.lua | 2 +- xmake/modules/core/tools/rc.lua | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 3b73719e7..06e6759b9 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -25,7 +25,7 @@ import("core.base.hashset") import("core.project.project") import("core.project.policy") import("core.language.language") -import("core.tools.vstool") +import("private.tools.vstool") import("core.tools.cl.parse_include") import("private.cache.build_cache") import("private.service.distcc_build.client", {alias = "distcc_build_client"}) diff --git a/xmake/modules/core/tools/cl/parse_include.lua b/xmake/modules/core/tools/cl/parse_include.lua index 009d6d1f5..700f9823f 100644 --- a/xmake/modules/core/tools/cl/parse_include.lua +++ b/xmake/modules/core/tools/cl/parse_include.lua @@ -24,7 +24,7 @@ import("core.base.hashset") import("core.tool.toolchain") import("core.cache.detectcache") import("lib.detect.find_tool") -import("core.tools.vstool") +import("private.tools.vstool") -- probe include note prefix from cl function probe_include_note_from_cl() diff --git a/xmake/modules/core/tools/ifort.lua b/xmake/modules/core/tools/ifort.lua index 6235c50ff..2d48f34c7 100644 --- a/xmake/modules/core/tools/ifort.lua +++ b/xmake/modules/core/tools/ifort.lua @@ -23,7 +23,7 @@ if is_host("windows") then -- imports inherit("cl") inherit("link") - import("core.tools.vstool") + import("private.tools.vstool") -- init it function init(self) diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua index 62f794bdd..3e51ad40a 100644 --- a/xmake/modules/core/tools/link.lua +++ b/xmake/modules/core/tools/link.lua @@ -20,7 +20,7 @@ -- imports import("core.project.config") -import("core.tools.vstool") +import("private.tools.vstool") -- init it function init(self) diff --git a/xmake/modules/core/tools/ml.lua b/xmake/modules/core/tools/ml.lua index 4af30e7e7..5bb1fb884 100644 --- a/xmake/modules/core/tools/ml.lua +++ b/xmake/modules/core/tools/ml.lua @@ -19,7 +19,7 @@ -- -- imports -import("core.tools.vstool") +import("private.tools.vstool") import("core.base.hashset") -- init it diff --git a/xmake/modules/core/tools/rc.lua b/xmake/modules/core/tools/rc.lua index 423652b49..91c1984ca 100644 --- a/xmake/modules/core/tools/rc.lua +++ b/xmake/modules/core/tools/rc.lua @@ -22,7 +22,7 @@ import("core.base.option") import("core.base.hashset") import("core.project.project") -import("core.tools.vstool") +import("private.tools.vstool") -- normailize path of a dependecy function _normailize_dep(dep, projectdir) -- cgit v1.3.1