diff options
| author | ruki <[email protected]> | 2023-02-18 00:43:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-02-18 00:43:06 +0800 |
| commit | 008d4d6b28b0475b4fc1cf0f88fcff7fd0f3c71b (patch) | |
| tree | 8502c84f39dc8baee83078aa13ac0c624db5d535 | |
| parent | 1e09fd1f030bc9f0deb4b7f2c6c406ebc2622639 (diff) | |
add executable_path
| -rw-r--r-- | xmake/modules/package/tools/meson.lua | 20 | ||||
| -rw-r--r-- | xmake/modules/private/utils/executable_path.lua | 58 | ||||
| -rw-r--r-- | xmake/modules/private/utils/trim_trailing_spaces.lua | 20 | ||||
| -rw-r--r-- | xmake/plugins/project/clang/compile_commands.lua | 20 |
4 files changed, 91 insertions, 27 deletions
diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua index cdfbc7fb1..0df12b796 100644 --- a/xmake/modules/package/tools/meson.lua +++ b/xmake/modules/package/tools/meson.lua @@ -25,6 +25,7 @@ import("core.tool.toolchain") import("core.tool.linker") import("core.tool.compiler") import("lib.detect.find_tool") +import("private.utils.executable_path") -- get build directory function _get_buildir(package, opt) @@ -70,42 +71,41 @@ function _get_cross_file(package, opt) file:print("[binaries]") local cc = package:build_getenv("cc") if cc then - -- we need split it, maybe is `xcrun -sdk iphoneos clang` - file:print("c=['%s']", table.concat(os.argv(cc), "', '")) + file:print("c='%s'", executable_path(cc)) end local cxx = package:build_getenv("cxx") if cxx then - file:print("cpp=['%s']", table.concat(os.argv(cxx), "', '")) + file:print("cpp='%s'", executable_path(cxx)) end local ld = package:build_getenv("ld") if ld then - file:print("ld=['%s']", table.concat(os.argv(ld), "', '")) + file:print("ld='%s'", executable_path(ld)) end local ar = package:build_getenv("ar") if ar then - file:print("ar=['%s']", table.concat(os.argv(ar), "', '")) + file:print("ar='%s'", executable_path(ar)) end local strip = package:build_getenv("strip") if strip then - file:print("strip='%s'", strip) + file:print("strip='%s'", executable_path(strip)) end local ranlib = package:build_getenv("ranlib") if ranlib then - file:print("ranlib='%s'", ranlib) + file:print("ranlib='%s'", executable_path(ranlib)) end if package:is_plat("mingw") then local mrc = package:build_getenv("mrc") if mrc then - file:print("windres='%s'", mrc) + file:print("windres='%s'", executable_path(mrc)) end end local cmake = find_tool("cmake") if cmake then - file:print("cmake='%s'", cmake.program) + file:print("cmake='%s'", executable_path(cmake.program)) end local pkgconfig = _get_pkgconfig(package) if pkgconfig then - file:print("pkgconfig='%s'", pkgconfig) + file:print("pkgconfig='%s'", executable_path(pkgconfig)) end file:print("") diff --git a/xmake/modules/private/utils/executable_path.lua b/xmake/modules/private/utils/executable_path.lua new file mode 100644 index 000000000..f410d9a00 --- /dev/null +++ b/xmake/modules/private/utils/executable_path.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 executable_path.lua +-- + +-- get executable file path +-- +-- e.g. +-- "/usr/bin/xcrun -sdk macosx clang" -> "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" +-- +-- @see +-- https://github.com/xmake-io/xmake/issues/3159 +-- https://github.com/xmake-io/xmake/issues/3286 +-- https://github.com/xmake-io/xmake-repo/pull/1840#issuecomment-1434096993 +function main(program) + local program_map = _g.program_map + if program_map == nil then + program_map = {} + _g.program_map = program_map + end + local filepath = program_map[program] + if filepath then + return filepath + end + if is_host("macosx") and program:find("xcrun -sdk", 1, true) then + local cmd = program:gsub("xcrun %-sdk (%S+) (%S+)", function (plat, cc) + return "xcrun -sdk " .. plat .. " -f " .. cc + end) + local splitinfo = cmd:split("%s") + local result = try {function() return os.iorunv(splitinfo[1], table.slice(splitinfo, 2) or {}) end} + if result then + result = result:trim() + if #result > 0 then + filepath = result + end + end + end + if not filepath then + filepath = program + end + program_map[program] = filepath + return filepath +end diff --git a/xmake/modules/private/utils/trim_trailing_spaces.lua b/xmake/modules/private/utils/trim_trailing_spaces.lua index b40371c39..df8089b41 100644 --- a/xmake/modules/private/utils/trim_trailing_spaces.lua +++ b/xmake/modules/private/utils/trim_trailing_spaces.lua @@ -1,3 +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 trim_trailing_spaces.lua +-- + function main(pattern) for _, filepath in ipairs(os.files(pattern)) do local filedata = io.readfile(filepath) diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index e82bfb4f7..24a580d34 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -25,6 +25,7 @@ import("core.project.rule") import("core.project.project") import("core.language.language") import("private.utils.batchcmds") +import("private.utils.executable_path") -- escape path function _escape_path(p) @@ -58,7 +59,6 @@ function _translate_arguments(arguments) local cc = path.basename(arguments[1]):lower() local is_include = false local lsp = _get_lsp() - local program_map = {} for idx, arg in ipairs(arguments) do -- convert path to string, maybe we need convert path, but not supported now. arg = tostring(arg) @@ -108,22 +108,8 @@ function _translate_arguments(arguments) -- @see -- https://github.com/xmake-io/xmake/issues/3159 -- https://github.com/xmake-io/xmake/issues/3286 - if idx == 1 and is_host("macosx") and arg:find("xcrun -sdk", 1, true) then - local cmd = program_map[arg] - if cmd == nil then - cmd = arg:gsub("xcrun %-sdk (%S+) (%S+)", function (plat, cc) - return "xcrun -sdk " .. plat .. " -f " .. cc - end) - local splitinfo = cmd:split("%s") - local binpath = try {function() return os.iorunv(splitinfo[1], table.slice(splitinfo, 2) or {}) end} - if binpath then - binpath = binpath:trim() - if #binpath > 0 then - arg = binpath - end - end - program_map[arg] = cmd - end + if idx == 1 then + arg = executable_path(arg) end table.insert(args, arg) end |
