Unnamed: 0
int64
0
0
repo_id
stringlengths
5
186
file_path
stringlengths
15
223
content
stringlengths
1
32.8M
0
repos/xmake/xmake/modules/detect
repos/xmake/xmake/modules/detect/tools/find_cc.lua
--!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_cc.lua -- -- imports import("lib.detect.find_program") import("lib.detect.find_programver") -- find c++ -- -- @param opt the argument options, e.g. {version = true} -- -- @return program, version -- -- @code -- -- local cc = find_cc() -- -- @endcode -- function main(opt) -- init options opt = opt or {} -- find program local program = find_program(opt.program or "cc", opt) -- find program version local version = nil if program and opt and opt.version then version = find_programver(program, opt) end -- is clang++ or c++ local is_clang = false if program then local versioninfo = os.iorunv(program, {"--version"}) if versioninfo and versioninfo:find("clang", 1, true) then is_clang = true end end return program, version, (is_clang and "clang" or "cc") end
0
repos/xmake/xmake/modules/detect
repos/xmake/xmake/modules/detect/tools/find_bison.lua
--!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_bison.lua -- -- imports import("lib.detect.find_program") import("lib.detect.find_programver") -- find bison -- -- @param opt the argument options, e.g. {version = true} -- -- @return program, version -- -- @code -- -- local bison = find_bison() -- local bison, version = find_bison({version = true}) -- -- @endcode -- function main(opt) opt = opt or {} local program = find_program(opt.program or "bison", opt) if not program and not opt.program and is_host("windows") then program = find_program("win_bison", opt) end local version = nil if program and opt and opt.version then version = find_programver(program, opt) end return program, version end
0
repos/xmake/xmake/modules/detect
repos/xmake/xmake/modules/detect/tools/find_wasm_ld.lua
--!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_wasm_ld.lua -- -- imports import("core.tool.compiler") import("lib.detect.find_program") -- find ar -- -- @param opt the argument options, e.g. {version = true} -- -- @return program, version -- -- @code -- -- local ar = find_wasm_ld() -- local ar, version = find_wasm_ld({program = "wasm.ld", version = true}) -- -- @endcode -- function main(opt) opt = opt or {} local program = find_program(opt.program or "wasm.ld", opt) local version = nil if program and opt and opt.version then version = find_programver(program, opt) end return program, version end
0
repos/xmake/xmake/modules/detect
repos/xmake/xmake/modules/detect/tools/find_cudagdb.lua
--!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 OpportunityLiu -- @file find_cudagdb.lua -- -- imports import("private.detect.find_cudatool") -- find cudagdb -- -- @param opt the argument options, e.g. {version = true} -- -- @return program, version -- -- @code -- -- local cudagdb = find_cudagdb() -- local cudagdb, version = find_cudagdb({program = "cuda-gdb", version = true}) -- -- @endcode -- function main(opt) return find_cudatool("cuda-gdb", "(%d+%.?%d*%.?%d*.-)%s+release", opt) end
0
repos/xmake/xmake/modules/detect
repos/xmake/xmake/modules/detect/tools/find_lib.lua
--!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_lib.lua -- -- imports import("lib.detect.find_program") import("lib.detect.find_programver") import("lib.detect.find_tool") -- find lib -- -- @param opt the argument options, e.g. {version = true} -- -- @return program, version -- -- @code -- -- local lib = find_lib() -- -- @endcode -- function main(opt) -- init version info first local verinfo = nil -- init options opt = opt or {} opt.check = opt.check or function (program) -- make an stub source file local libraryfile = os.tmpfile() .. ".lib" local objectfile = os.tmpfile() .. ".obj" local sourcefile = os.tmpfile() .. ".c" io.writefile(sourcefile, "int test(void)\n{return 0;}") -- check it local cl = assert(find_tool("cl", {envs = opt.envs})) local link = assert(find_tool("link", {envs = opt.envs})) os.runv(cl.program, {"-c", "-Fo" .. objectfile, sourcefile}, {envs = opt.envs}) os.runv(link.program, {"-lib", "-out:" .. libraryfile, objectfile}, {envs = opt.envs}) verinfo = os.iorunv(program, {"-list", libraryfile}, {envs = opt.envs}) -- remove files os.rm(objectfile) os.rm(sourcefile) os.rm(libraryfile) end opt.command = opt.command or function () return verinfo end opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end -- find program local program = find_program(opt.program or "lib.exe", opt) -- find program version local version = nil if program and opt and opt.version then version = find_programver(program, opt) end -- ok? return program, version end
0
repos/xmake/xmake/modules/detect
repos/xmake/xmake/modules/detect/tools/find_gcc_ar.lua
--!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_gcc_ar.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.runv(program, {"-cr", 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_gcc_ar() -- local ar, version = find_ar({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 "gcc-ar", opt) end
0
repos/xmake/xmake/modules/detect
repos/xmake/xmake/modules/detect/tools/find_nasm.lua
--!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_nasm.lua -- -- imports import("lib.detect.find_program") import("lib.detect.find_programver") -- find nasm -- -- @param opt the argument options, e.g. {version = true} -- -- @return program, version -- -- @code -- -- local nasm = find_nasm() -- local nasm, version = find_nasm({program = "nasm", version = true}) -- -- @endcode -- function main(opt) -- init options opt = opt or {} opt.check = "-v" -- find program local program = find_program(opt.program or "nasm", opt) -- find program version local version = nil if program and opt and opt.version then version = find_programver(program, opt) end -- ok? return program, version end
0
repos/xmake/xmake/modules/detect
repos/xmake/xmake/modules/detect/tools/find_llvm_as.lua
--!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 xq114 -- @file find_llvm_as.lua -- -- imports import("lib.detect.find_program") import("lib.detect.find_programver") -- find llvm-ar -- -- @param opt the argument options, e.g. {version = true, program = "c:\xxx\llvm-as.exe"} -- -- @return program, version -- -- @code -- -- local llvm_as = find_llvm_as() -- local llvm_as, version = find_llvm_as({version = true}) -- local llvm_as, version = find_llvm_as({version = true, program = "c:\xxx\llvm-as.exe"}) -- -- @endcode -- function main(opt) -- init options opt = opt or {} opt.check = opt.check or "-version" opt.command = opt.command or "-version" -- find program local program = find_program(opt.program or "llvm-as", opt) -- find program version local version = nil if program and opt.version then version = find_programver(program, opt) end -- ok? return program, version end
0
repos/xmake/xmake/modules/detect
repos/xmake/xmake/modules/detect/tools/find_x64dbg.lua
--!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_x64dbg.lua -- -- imports import("lib.detect.find_program") import("lib.detect.find_programver") -- find x64dbg -- -- @param opt the argument options, e.g. {version = true, program = "c:\xxx\x64dbg.exe"} -- -- @return program, version -- -- @code -- -- local x64dbg = find_x64dbg() -- local x64dbg, version = find_x64dbg({version = true}) -- local x64dbg, version = find_x64dbg({version = true, program = "c:\xxx\x64dbg.exe"}) -- -- @endcode -- function main(opt) -- not on windows? if os.host() ~= "windows" then return end -- init options opt = opt or {} opt.paths = opt.paths or function () for _, reg in ipairs({"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger"}) do return (val("reg " .. reg) or ""):match("\"(.-)\"") end end opt.check = opt.check or function (program) if not os.isfile(program) then raise() end end -- find program return find_program(opt.program or "x64dbg", opt) end
0
repos/xmake/xmake/modules/detect
repos/xmake/xmake/modules/detect/tools/find_metal.lua
--!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_metal.lua -- -- imports import("lib.detect.find_program") import("lib.detect.find_programver") -- find metal -- -- @param opt the argument options, e.g. {version = true} -- -- @return program, version -- -- @code -- -- local metal = find_metal() -- local metal, version = find_metal({program = "xcrun -sdk macosx metal", version = true}) -- -- @endcode -- function main(opt) -- find program opt = opt or {} local program = find_program(opt.program or "xcrun -sdk macosx metal", opt) -- find program version local version = nil if program and opt and opt.version then version = find_programver(program, opt) end return program, version end
0
repos/xmake/xmake/modules/detect
repos/xmake/xmake/modules/detect/tools/find_sdcc.lua
--!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_sdcc.lua -- -- imports import("lib.detect.find_program") import("lib.detect.find_programver") -- find sdcc -- -- @param opt the argument options, e.g. {version = true} -- -- @return program, version -- -- @code -- -- local sdcc = find_sdcc() -- -- @endcode -- function main(opt) -- init options opt = opt or {} opt.command = opt.command or "--version" -- add search paths local paths = {} local bindir = get_config("bin") if bindir and os.isdir(bindir) then table.insert(paths, bindir) end if is_host("windows") then table.insert(paths, "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\SDCC)\\bin") end if #paths > 0 then opt.paths = paths end -- find program local program = find_program(opt.program or "sdcc", opt) -- find program version local version = nil if program and opt and opt.version then version = find_programver(program, opt) end return program, version end
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/ml64/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/nvfortran/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/dpcpp/features.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/dpcpp/cxxfeatures.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/dpcpp/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/dpcpp/cfeatures.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/nim/has_flags.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/icc/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/dmd/has_flags.lua
--!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=<arg>" or "-L<arg>"? 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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/cosmocxx/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/cl/features.lua
--!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 <stdio.h>\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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/cl/cxxfeatures.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/cl/has_flags.lua
--!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;}" 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 _, errs = os.iorunv(opt.program, table.join("-c", "-nologo", flags, "-Fo" .. os.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 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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/cl/cfeatures.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/gfortran/has_flags.lua
--!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,<arg>" or "-Xlinker <arg>"? 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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/ldc2/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/swiftc/has_flags.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/ifort/has_flags.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/swift_frontend/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/armasm_msvc/has_flags.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/gcc/features.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/gcc/cxxfeatures.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/gcc/has_flags.lua
--!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,<arg>" or "-Xlinker <arg>"? 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;}" 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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/gcc/cfeatures.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/circle/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/gxx/features.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/gxx/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/icx/features.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/icx/cxxfeatures.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/icx/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/icx/cfeatures.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/zig_cxx/features.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/zig_cxx/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/icpc/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/icpx/features.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/icpx/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/nvcc/has_flags.lua
--!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,<arg>" or "-Xlinker <arg>"? 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;}" 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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/link/has_flags.lua
--!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;}") else io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") 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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/nvc/features.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/nvc/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/tcc/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/cosmocc/has_flags.lua
--!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,<arg>" or "-Xlinker <arg>"? 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;}" 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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/clang_cl/has_flags.lua
--!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;}") 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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/ml/has_flags.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/clangxx/features.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/clangxx/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/zig/has_flags.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/rustc/has_flags.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/fpc/has_flags.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/armasm64_msvc/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/zig_cc/features.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/zig_cc/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/go/has_flags.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/emcc/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/icl/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/emxx/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/rc/has_flags.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/ar/has_flags.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/clang/features.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/clang/cxxfeatures.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/clang/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/clang/cfeatures.lua
--!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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/armclang/has_flags.lua
--!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,<arg>" or "-Xlinker <arg>"? 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;}") 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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/gccgo/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/ifx/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/nvcxx/features.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/nvcxx/has_flags.lua
--!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")
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/gdc/has_flags.lua
--!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,<arg>" or "-Xlinker <arg>"? 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
0
repos/xmake/xmake/modules/detect/tools
repos/xmake/xmake/modules/detect/tools/sdcc/has_flags.lua
--!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,<arg>"? 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;}") 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
0
repos/xmake/xmake/plugins
repos/xmake/xmake/plugins/pack/batchcmds.lua
--!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 batchcmds.lua -- -- imports import("core.base.option") import("core.base.hashset") import("utils.archive") import("utils.binary.deplibs", {alias = "get_depend_libraries"}) import("private.utils.batchcmds") function _get_target_bindir(package, target) local bindir = package:bindir() local prefixdir = target:prefixdir() if prefixdir then bindir = path.join(package:installdir(), prefixdir, target:extraconf("prefixdir", prefixdir, "bindir") or "bin") end return path.normalize(bindir) end function _get_target_libdir(package, target) local libdir = package:libdir() local prefixdir = target:prefixdir() if prefixdir then libdir = path.join(package:installdir(), prefixdir, target:extraconf("prefixdir", prefixdir, "libdir") or "lib") end return path.normalize(libdir) end function _get_target_includedir(package, target) local includedir = package:includedir() local prefixdir = target:prefixdir() if prefixdir then includedir = path.join(package:installdir(), prefixdir, target:extraconf("prefixdir", prefixdir, "includedir") or "include") end return path.normalize(includedir) end function _get_target_installdir(package, target) local installdir = package:installdir() local prefixdir = target:prefixdir() if prefixdir then installdir = path.join(package:installdir(), prefixdir) end return path.normalize(installdir) end -- we need to get all deplibs, e.g. app -> libfoo.so -> libbar.so ... -- @see https://github.com/xmake-io/xmake/issues/5325#issuecomment-2242597732 function _get_target_package_deplibs(target, depends, libfiles, binaryfile) local deplibs = get_depend_libraries(binaryfile, {plat = target:plat(), arch = target:arch()}) local depends_new = hashset.new() for _, deplib in ipairs(deplibs) do local libname = path.filename(deplib) if not depends:has(libname) then depends:insert(libname) depends_new:insert(libname) end end for _, libfile in ipairs(libfiles) do local libname = path.filename(libfile) if depends_new:has(libname) then _get_target_package_deplibs(target, depends, libfiles, libfile) end end end function _get_target_package_libfiles(target, opt) local libfiles = {} for _, pkg in ipairs(target:orderpkgs(opt)) do if pkg:enabled() and pkg:get("libfiles") then for _, libfile in ipairs(table.wrap(pkg:get("libfiles"))) do local filename = path.filename(libfile) if filename:endswith(".dll") or filename:endswith(".so") or filename:find("%.so%.%d+$") or filename:endswith(".dylib") then table.insert(libfiles, libfile) end end end end -- we can only reserve used libraries if target:is_binary() or target:is_shared() then local depends = hashset.new() _get_target_package_deplibs(target, depends, libfiles, target:targetfile()) table.remove_if(libfiles, function (_, libfile) return not depends:has(path.filename(libfile)) end) end return libfiles end -- copy file with symlinks function _copy_file_with_symlinks(batchcmds_, srcfile, outputdir) if os.islink(srcfile) then local srcfile_symlink = os.readlink(srcfile) if not path.is_absolute(srcfile_symlink) then srcfile_symlink = path.join(path.directory(srcfile), srcfile_symlink) end _copy_file_with_symlinks(batchcmds_, srcfile_symlink, outputdir) batchcmds_:cp(srcfile, path.join(outputdir, path.filename(srcfile)), {symlink = true, force = true}) else batchcmds_:cp(srcfile, path.join(outputdir, path.filename(srcfile))) end end -- update install rpath, we can only get and update rpathdirs with `{installonly = true}` -- e.g. add_rpathdirs("@loader_path/../lib", {installonly = true}) function _update_target_install_rpath(target, batchcmds_, opt) if target:is_plat("windows", "mingw") then return end local package = opt.package local bindir = _get_target_bindir(package, target) local targetfile = path.join(bindir, target:filename()) if target:policy("install.rpath") then batchcmds_:clean_rpath(targetfile, {plat = target:plat(), arch = target:arch()}) local result, sources = target:get_from("rpathdirs", "*") if result and sources then for idx, rpathdirs in ipairs(result) do local source = sources[idx] local extraconf = target:extraconf_from("rpathdirs", source) if extraconf then for _, rpathdir in ipairs(rpathdirs) do local extra = extraconf[rpathdir] if extra and extra.installonly then batchcmds_:insert_rpath(targetfile, rpathdir, {plat = target:plat(), arch = target:arch()}) end end end end end end end -- install target files function _install_target_files(target, batchcmds_, opt) local package = opt.package local srcfiles, dstfiles = target:installfiles(_get_target_installdir(package, target)) if srcfiles and dstfiles then for idx, srcfile in ipairs(srcfiles) do batchcmds_:cp(srcfile, dstfiles[idx]) end end for _, dep in ipairs(target:orderdeps()) do local srcfiles, dstfiles = dep:installfiles(_get_target_installdir(package, dep), {interface = true}) if srcfiles and dstfiles then for idx, srcfile in ipairs(srcfiles) do batchcmds_:cp(srcfile, dstfiles[idx]) end end end end -- install target headers function _install_target_headers(target, batchcmds_, opt) local package = opt.package local srcheaders, dstheaders = target:headerfiles(_get_target_includedir(package, target), {installonly = true}) if srcheaders and dstheaders then for idx, srcheader in ipairs(srcheaders) do batchcmds_:cp(srcheader, dstheaders[idx]) end end for _, dep in ipairs(target:orderdeps()) do local srcheaders, dstheaders = dep:headerfiles(_get_target_includedir(package, dep), {installonly = true, interface = true}) if srcheaders and dstheaders then for idx, srcheader in ipairs(srcheaders) do batchcmds_:cp(srcheader, dstheaders[idx]) end end end end -- install target shared libraries function _install_target_shared_libraries(target, batchcmds_, opt) local package = opt.package local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(package, target) or _get_target_libdir(package, target) -- get all dependent shared libraries local libfiles = {} for _, dep in ipairs(target:orderdeps()) do if dep:kind() == "shared" then local depfile = dep:targetfile() if os.isfile(depfile) then table.insert(libfiles, depfile) end end table.join2(libfiles, _get_target_package_libfiles(dep, {interface = true})) end table.join2(libfiles, _get_target_package_libfiles(target)) -- deduplicate libfiles, prevent packages using the same libfiles from overwriting each other libfiles = table.unique(libfiles) -- do install for _, libfile in ipairs(libfiles) do local filename = path.filename(libfile) _copy_file_with_symlinks(batchcmds_, libfile, bindir) end end -- uninstall target files function _uninstall_target_files(target, batchcmds_, opt) local package = opt.package local _, dstfiles = target:installfiles(_get_target_installdir(package, target)) for _, dstfile in ipairs(dstfiles) do batchcmds_:rm(dstfile, {emptydirs = true}) end for _, dep in ipairs(target:orderdeps()) do local _, dstfiles = dep:installfiles(_get_target_installdir(package, dep), {interface = true}) for _, dstfile in ipairs(dstfiles) do batchcmds_:rm(dstfile, {emptydirs = true}) end end end -- uninstall target headers function _uninstall_target_headers(target, batchcmds_, opt) local package = opt.package local _, dstheaders = target:headerfiles(_get_target_includedir(package, target), {installonly = true}) for _, dstheader in ipairs(dstheaders) do batchcmds_:rm(dstheader, {emptydirs = true}) end for _, dep in ipairs(target:orderdeps()) do local _, dstheaders = dep:headerfiles(_get_target_includedir(package, dep), {installonly = true, interface = true}) for _, dstheader in ipairs(dstheaders) do batchcmds_:rm(dstheader, {emptydirs = true}) end end end -- uninstall target shared libraries function _uninstall_target_shared_libraries(target, batchcmds_, opt) local package = opt.package local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(package, target) or _get_target_libdir(package, target) -- get all dependent shared libraries local libfiles = {} for _, dep in ipairs(target:orderdeps()) do if dep:kind() == "shared" then local depfile = dep:targetfile() if os.isfile(depfile) then table.insert(libfiles, depfile) end end table.join2(libfiles, _get_target_package_libfiles(dep, {interface = true})) end table.join2(libfiles, _get_target_package_libfiles(target)) -- deduplicate libfiles, prevent packages using the same libfiles from overwriting each other libfiles = table.unique(libfiles) -- do uninstall for _, libfile in ipairs(libfiles) do local filename = path.filename(libfile) batchcmds_:rm(libfile, path.join(bindir, filename), {emptydirs = true}) end end -- on install binary target command function _on_target_installcmd_binary(target, batchcmds_, opt) local package = opt.package local bindir = _get_target_bindir(package, target) batchcmds_:cp(target:targetfile(), path.join(bindir, target:filename())) if os.isfile(target:symbolfile()) then batchcmds_:cp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) end _install_target_shared_libraries(target, batchcmds_, opt) _update_target_install_rpath(target, batchcmds_, opt) end -- on install shared target command function _on_target_installcmd_shared(target, batchcmds_, opt) local package = opt.package local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(package, target) or _get_target_libdir(package, target) local libdir = _get_target_libdir(package, target) _copy_file_with_symlinks(batchcmds_, target:targetfile(), bindir) if os.isfile(target:symbolfile()) then batchcmds_:cp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) end -- install *.lib for shared/windows (*.dll) target -- @see https://github.com/xmake-io/xmake/issues/714 local targetfile = target:targetfile() local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. (target:is_plat("mingw") and ".dll.a" or ".lib")) if os.isfile(targetfile_lib) then batchcmds_:mkdir(libdir) batchcmds_:cp(targetfile_lib, path.join(libdir, path.filename(targetfile_lib))) end _install_target_headers(target, batchcmds_, opt) _install_target_shared_libraries(target, batchcmds_, opt) end -- on install static target command function _on_target_installcmd_static(target, batchcmds_, opt) local package = opt.package local libdir = _get_target_libdir(package, target) batchcmds_:cp(target:targetfile(), path.join(libdir, target:filename())) if os.isfile(target:symbolfile()) then batchcmds_:cp(target:symbolfile(), path.join(libdir, path.filename(target:symbolfile()))) end _install_target_headers(target, batchcmds_, opt) end -- on install headeronly target command function _on_target_installcmd_headeronly(target, batchcmds_, opt) _install_target_headers(target, batchcmds_, opt) end -- on install source target command function _on_target_installcmd_source(target, batchcmds_, opt) local package = opt.package batchcmds_:vrunv("xmake", {"install", "-P", ".", "-y", "-o", path(package:install_rootdir()), target:name()}) end -- on build target command function _on_target_buildcmd(target, batchcmds_, opt) local package = opt.package batchcmds_:vrunv("xmake", {"build", "-P", ".", "-y", target:name()}) end -- on install target command function _on_target_installcmd(target, batchcmds_, opt) local package = opt.package if package:from_source() then _on_target_installcmd_source(target, batchcmds_, opt) return end -- install target binaries local scripts = { binary = _on_target_installcmd_binary, shared = _on_target_installcmd_shared, static = _on_target_installcmd_static, headeronly = _on_target_installcmd_headeronly } local script = scripts[target:kind()] if script then script(target, batchcmds_, opt) end -- install target files _install_target_files(target, batchcmds_, opt) end -- on uninstall binary target command function _on_target_uninstallcmd_binary(target, batchcmds_, opt) local package = opt.package local bindir = _get_target_bindir(package, target) -- uninstall target file batchcmds_:rm(path.join(bindir, target:filename()), {emptydirs = true}) batchcmds_:rm(path.join(bindir, path.filename(target:symbolfile())), {emptydirs = true}) -- uninstall target shared libraries _uninstall_target_shared_libraries(target, batchcmds_, opt) end -- on uninstall shared target command function _on_target_uninstallcmd_shared(target, batchcmds_, opt) local package = opt.package local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(package, target) or _get_target_libdir(package, target) local libdir = _get_target_libdir(package, target) -- uninstall target file batchcmds_:rm(path.join(bindir, target:filename()), {emptydirs = true}) batchcmds_:rm(path.join(bindir, path.filename(target:symbolfile())), {emptydirs = true}) -- uninstall *.lib for shared/windows (*.dll) target -- @see https://github.com/xmake-io/xmake/issues/714 local targetfile = target:targetfile() batchcmds_:rm(path.join(libdir, path.basename(targetfile) .. (target:is_plat("mingw") and ".dll.a" or ".lib")), {emptydirs = true}) -- uninstall target headers _uninstall_target_headers(target, batchcmds_, opt) -- uninstall target shared libraries _uninstall_target_shared_libraries(target, batchcmds_, opt) end -- on uninstall static target command function _on_target_uninstallcmd_static(target, batchcmds_, opt) local package = opt.package local libdir = _get_target_libdir(package, target) -- uninstall target file batchcmds_:rm(path.join(libdir, target:filename()), {emptydirs = true}) batchcmds_:rm(path.join(libdir, path.filename(target:symbolfile())), {emptydirs = true}) -- remove headers from the include directory _uninstall_target_headers(target, batchcmds_, opt) end -- on uninstall headeronly target command function _on_target_uninstallcmd_headeronly(target, batchcmds_, opt) _uninstall_target_headers(target, batchcmds_, opt) end -- on uninstall source target command function _on_target_uninstallcmd_source(target, batchcmds_, opt) -- TODO end -- on uninstall target command function _on_target_uninstallcmd(target, batchcmds_, opt) local package = opt.package if package:from_source() then _on_target_uninstallcmd_source(target, batchcmds_, opt) return end -- uninstall target binaries local scripts = { binary = _on_target_uninstallcmd_binary, shared = _on_target_uninstallcmd_shared, static = _on_target_uninstallcmd_static, headeronly = _on_target_uninstallcmd_headeronly } local script = scripts[target:kind()] if script then script(target, batchcmds_, opt) end -- uninstall target files _uninstall_target_files(target, batchcmds_, opt) end -- get build commands from targets function _get_target_buildcmds(target, batchcmds_, opt) -- call script to get build commands local scripts = { target:script("buildcmd_before"), -- TODO unused function (target) for _, r in ipairs(target:orderules()) do local before_buildcmd = r:script("buildcmd_before") if before_buildcmd then before_buildcmd(target, batchcmds_, opt) end end end, target:script("buildcmd", _on_target_buildcmd), -- TODO unused function (target) for _, r in ipairs(target:orderules()) do local after_buildcmd = r:script("buildcmd_after") if after_buildcmd then after_buildcmd(target, batchcmds_, opt) end end end, target:script("buildcmd_after") -- TODO unused } for i = 1, 5 do local script = scripts[i] if script ~= nil then script(target, batchcmds_, opt) end end end -- get install commands from targets function _get_target_installcmds(target, batchcmds_, opt) -- call script to get install commands local scripts = { target:script("installcmd_before"), function (target) for _, r in ipairs(target:orderules()) do local before_installcmd = r:script("installcmd_before") if before_installcmd then before_installcmd(target, batchcmds_, opt) end end end, target:script("installcmd", _on_target_installcmd), function (target) for _, r in ipairs(target:orderules()) do local after_installcmd = r:script("installcmd_after") if after_installcmd then after_installcmd(target, batchcmds_, opt) end end end, target:script("installcmd_after") } for i = 1, 5 do local script = scripts[i] if script ~= nil then script(target, batchcmds_, opt) end end end -- get uninstall commands from targets function _get_target_uninstallcmds(target, batchcmds_, opt) -- call script to get uninstall commands local scripts = { target:script("uninstallcmd_before"), function (target) for _, r in ipairs(target:orderules()) do local before_uninstallcmd = r:script("uninstallcmd_before") if before_uninstallcmd then before_uninstallcmd(target, batchcmds_, opt) end end end, target:script("uninstallcmd", _on_target_uninstallcmd), function (target) for _, r in ipairs(target:orderules()) do local after_uninstallcmd = r:script("uninstallcmd_after") if after_uninstallcmd then after_uninstallcmd(target, batchcmds_, opt) end end end, target:script("uninstallcmd_after") } for i = 1, 5 do local script = scripts[i] if script ~= nil then script(target, batchcmds_, opt) end end end -- on build command function _on_buildcmd(package, batchcmds_) if not package:from_source() then return end for _, target in ipairs(package:targets()) do _get_target_buildcmds(target, batchcmds_, {package = package}) end end -- on install command function _on_installcmd(package, batchcmds_) local srcfiles, dstfiles = package:installfiles() for idx, srcfile in ipairs(srcfiles) do batchcmds_:cp(srcfile, dstfiles[idx]) end for _, target in ipairs(package:targets()) do _get_target_installcmds(target, batchcmds_, {package = package}) end end -- on uninstall command function _on_uninstallcmd(package, batchcmds_) local _, dstfiles = package:installfiles() for _, dstfile in ipairs(dstfiles) do batchcmds_:rm(dstfile, {emptydirs = true}) end for _, target in ipairs(package:targets()) do _get_target_uninstallcmds(target, batchcmds_, {package = package}) end end -- get build commands function get_buildcmds(package) local batchcmds_ = batchcmds.new() -- call script to get build commands local scripts = { package:script("buildcmd_before"), package:script("buildcmd", _on_buildcmd), package:script("buildcmd_after") } for i = 1, 3 do local script = scripts[i] if script ~= nil then script(package, batchcmds_) end end return batchcmds_ end -- get install commands function get_installcmds(package) local batchcmds_ = batchcmds.new() -- call script to get install commands local scripts = { package:script("installcmd_before"), package:script("installcmd", _on_installcmd), package:script("installcmd_after") } for i = 1, 3 do local script = scripts[i] if script ~= nil then script(package, batchcmds_) end end return batchcmds_ end -- get uninstall commands function get_uninstallcmds(package) local batchcmds_ = batchcmds.new() -- call script to get uninstall commands local scripts = { package:script("uninstallcmd_before"), package:script("uninstallcmd", _on_uninstallcmd), package:script("uninstallcmd_after") } for i = 1, 3 do local script = scripts[i] if script ~= nil then script(package, batchcmds_) end end return batchcmds_ end
0
repos/xmake/xmake/plugins
repos/xmake/xmake/plugins/pack/main.lua
--!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 main.lua -- -- imports import("core.base.task") import("core.base.option") import("core.project.config") import("core.project.project") import("private.service.remote_build.action", {alias = "remote_build_action"}) import("actions.build.main", {rootdir = os.programdir(), alias = "build_action"}) import("xpack") -- get packages function _get_packages() -- get need formats local formats_need = option.get("formats") if formats_need then formats_need = formats_need:split(",") if formats_need[1] == "all" then formats_need = nil end end local packages = {} for _, package in ipairs(xpack.packages()) do if not formats_need or table.contains(formats_need, package:format()) then table.insert(packages, package) end end return packages end -- load package function _load_package(package) -- ensure build and output directories os.tryrm(package:buildir()) os.mkdir(package:outputdir()) -- load it local script = package:script("load") if script then script(package) end end -- pack the given package function _on_package(package) import(package:format())(package) end function _pack_package(package) -- do pack local scripts = { package:script("package_before"), package:script("package", _on_package), package:script("package_after") } _load_package(package) for i = 1, 3 do local script = scripts[i] if script ~= nil then script(package) end end end function _pack_packages() for _, package in ipairs(_get_packages()) do _pack_package(package) end end function _build_targets() local targetnames = {} for _, package in ipairs(_get_packages()) do if package:from_binary() then local targets = package:get("targets") if targets then table.join2(targetnames, targets) end end end if #targetnames > 0 then build_action.build_targets(targetnames) end end function main() -- do action for remote? if remote_build_action.enabled() then return remote_build_action() end -- load config first task.run("config", {}, {disable_dump = true}) -- lock the whole project project.lock() -- enter project directory local oldir = os.cd(project.directory()) -- build targets first if option.get("autobuild") then _build_targets() end -- do pack _pack_packages() -- leave project directory os.cd(oldir) -- unlock the whole project project.unlock() cprint("${color.success}pack ok") end
0
repos/xmake/xmake/plugins
repos/xmake/xmake/plugins/pack/xpack_component.lua
--!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 xpack_component.lua -- -- imports import("core.base.object") import("core.base.option") import("core.project.config") import("core.project.project") import("private.core.base.select_script") import("private.core.base.match_copyfiles") -- define module local xpack_component = xpack_component or object {_init = {"_name", "_info", "_package"}} -- get name function xpack_component:name() return self._name end -- get values function xpack_component:get(name) if self._info then return self._info:get(name) end end -- set values function xpack_component:set(name, ...) if self._info then self._info:apival_set(name, ...) end end -- add values function xpack_component:add(name, ...) if self._info then self._info:apival_add(name, ...) end end -- get the extra configuration function xpack_component:extraconf(name, item, key) if self._info then return self._info:extraconf(name, item, key) end end -- get the component title function xpack_component:title() return self:get("title") or self:name() end -- get the component description function xpack_component:description() return self:get("description") end -- get xxx_script function xpack_component:script(name, generic) local script = self:get(name) local result = select_script(script, {plat = self:package():plat(), arch = self:package():arch()}) or generic return result end -- get targets function xpack_component:targets() local targets = self._targets if not targets then targets = {} local targetnames = self:get("targets") if targetnames then for _, name in ipairs(targetnames) do local target = project.target(name) if target then table.insert(targets, target) else raise("xpack_component(%s): target(%s) not found!", self:name(), name) end end end self._targets = targets end return targets end -- get the given target function xpack_component:target(name) local targetnames = self:get("targets") if targetnames and table.contains(table.wrap(targetnames), name) then return project.target(name) end end -- get the package function xpack_component:package() return self._package end -- get the install files function xpack_component:installfiles() return match_copyfiles(self, "installfiles", self:package():installdir()) end -- get the installed root directory, this is just a temporary sandbox installation path, -- we may replace it with the actual installation path in the specfile function xpack_component:install_rootdir() return self:package():install_rootdir() end -- get the installed directory function xpack_component:installdir(...) return self:package():installdir(...) end -- get the source files function xpack_component:sourcefiles() return match_copyfiles(self, "sourcefiles", self:package():sourcedir()) end -- get the source root directory function xpack_component:source_rootdir() return self:package():souece_rootdir() end -- get the source directory function xpack_component:sourcedir(...) return self:package():sourcedir(...) end -- get the binary directory function xpack_component:bindir() return self:package():bindir() end -- get the library directory function xpack_component:libdir() return self:package():libdir() end -- get the include directory function xpack_component:includedir() return self:package():includedir() end -- pack from source files? function xpack_component:from_source() return self:package():from_source() end -- pack from binary files? function xpack_component:from_binary() return self:package():from_binary() end -- new a xpack_component function new(name, info, package) return xpack_component {name, info:clone(), package} end
0
repos/xmake/xmake/plugins
repos/xmake/xmake/plugins/pack/archive.lua
--!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 archive.lua -- -- imports import("core.base.option") import("utils.archive") import("batchcmds") -- pack archive package function _pack_archive(package) -- archive source files if package:from_source() then local srcfiles, dstfiles = package:sourcefiles() for idx, srcfile in ipairs(srcfiles) do os.vcp(srcfile, dstfiles[idx]) end for _, component in table.orderpairs(package:components()) do if component:get("default") ~= false then local srcfiles, dstfiles = component:sourcefiles() for idx, srcfile in ipairs(srcfiles) do os.vcp(srcfile, dstfiles[idx]) end end end else -- archive binary files batchcmds.get_installcmds(package):runcmds() for _, component in table.orderpairs(package:components()) do if component:get("default") ~= false then batchcmds.get_installcmds(component):runcmds() end end end -- archive install files local rootdir = package:from_source() and package:source_rootdir() or package:install_rootdir() local oldir = os.cd(rootdir) local archivefiles = os.files("**") os.cd(oldir) os.tryrm(package:outputfile()) archive.archive(path.absolute(package:outputfile()), archivefiles, {curdir = rootdir, compress = "best"}) end function main(package) cprint("packing %s .. ", package:outputfile()) _pack_archive(package) end
0
repos/xmake/xmake/plugins
repos/xmake/xmake/plugins/pack/filter.lua
--!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 filter.lua -- -- imports import("core.base.filter") import("core.base.option") import("core.base.global") import("core.project.config") import("core.project.project") import("core.sandbox.sandbox") -- get filter function _filter() if _g.filter == nil then _g.filter = filter.new() _g.filter:register("common", function (variable) -- attempt to get it directly from the configure local result = config.get(variable) if result == nil then -- init maps _g.common_maps = _g.common_maps or { host = os.host() , subhost = os.subhost() , tmpdir = function () return os.tmpdir() end , curdir = function () return os.curdir() end , scriptdir = function () return os.scriptdir() end , globaldir = global.directory() , configdir = config.directory() , projectdir = project.directory() , programdir = os.programdir() } -- map it result = _g.common_maps[variable] end -- is script? call it if type(result) == "function" then result = result() end return result end) end return _g.filter end -- the package handler function _handler(package, strval) -- @note cannot cache it, because the package instance will be changed return function (variable) local maps = { arch = package:arch(), plat = package:plat(), version = package:version() } -- get value local result = maps[variable] if type(result) == "function" then result = result() end return result end end -- attach filter to the given script and call it function call(script, package, opt) -- get sandbox filter and handlers of the given script local sandbox_filter = sandbox.filter(script) local sandbox_handlers = sandbox_filter:handlers() -- switch to the handlers of the current filter sandbox_filter:set_handlers(_filter():handlers()) -- register package handler sandbox_filter:register("package", _handler(package)) -- call it script(package, opt) -- restore handlers sandbox_filter:set_handlers(sandbox_handlers) end -- handle the string value of package function handle(strval, package) -- register filter handler _filter():register("package", _handler(package, strval)) -- handle string value strval = _filter():handle(strval) -- register filter handler _filter():register("package", nil) return strval end
0
repos/xmake/xmake/plugins
repos/xmake/xmake/plugins/pack/xpack.lua
--!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 xpack.lua -- -- imports import("core.base.object") import("core.base.option") import("core.base.semver") import("core.base.hashset") import("core.project.config") import("core.project.project") import("private.core.base.select_script") import("private.core.base.match_copyfiles") import("lib.detect.find_tool") import("filter") import("xpack_component") -- define module local xpack = xpack or object {_init = {"_name", "_info"}} -- get name function xpack:name() return self._name end -- get values function xpack:get(name) if self._info then return self._info:get(name) end end -- set values function xpack:set(name, ...) if self._info then self._info:apival_set(name, ...) end end -- add values function xpack:add(name, ...) if self._info then self._info:apival_add(name, ...) end end -- get the extra configuration function xpack:extraconf(name, item, key) if self._info then return self._info:extraconf(name, item, key) end end -- get the package license function xpack:license() return self:get("license") end -- get the package title function xpack:title() local title = self:get("title") if title == nil then title = self:name() end return filter.handle(title, self) end -- get the package description function xpack:description() return self:get("description") end -- get the platform of package function xpack:plat() return config.get("plat") or os.subhost() end -- get the architecture of package function xpack:arch() return config.get("arch") or os.subarch() end -- the current platform is belong to the given platforms? function xpack:is_plat(...) local plat = self:plat() for _, v in ipairs(table.pack(...)) do if v and plat == v then return true end end end -- the current architecture is belong to the given architectures? function xpack:is_arch(...) local arch = self:arch() for _, v in ipairs(table.pack(...)) do if v and arch:find("^" .. v:gsub("%-", "%%-") .. "$") then return true end end end -- get xxx_script function xpack:script(name, generic) local script = self:get(name) local result = select_script(script, {plat = self:plat(), arch = self:arch()}) or generic return result end -- get targets function xpack:targets() local targets = self._targets if not targets then targets = {} local targetnames = self:get("targets") if targetnames then for _, name in ipairs(targetnames) do local target = project.target(name) if target then table.insert(targets, target) else raise("xpack(%s): target(%s) not found!", self:name(), name) end end end self._targets = targets end return targets end -- get the given target function xpack:target(name) local targetnames = self:get("targets") if targetnames and table.contains(table.wrap(targetnames), name) then return project.target(name) end end -- get formats function xpack:formats() local formats = self._formats if not formats then formats = hashset.new() for _, format in ipairs(self:get("formats")) do formats:insert(format) end self._formats = formats end return formats end -- has the given format? function xpack:format_has(...) local formats = self:formats() for _, v in ipairs(table.pack(...)) do if v and formats:has(v) then return true end end end -- set the current format function xpack:format_set(format) self._FORMAT = format end -- get the current format function xpack:format() return self._FORMAT end -- get the input kind function xpack:inputkind() local inputkind = self:get("inputkind") if inputkind == nil then local inputkinds = { wix = "binary", nsis = "binary", zip = "binary", targz = "binary", srczip = "source", srctargz = "source", runself = "source", deb = "source", srpm = "source", rpm = "source" } inputkind = inputkinds[self:format()] or "binary" end return inputkind end -- get the output kind function xpack:outputkind() local outputkinds = { wix = "binary", nsis = "binary", zip = "binary", targz = "binary", srczip = "source", srctargz = "source", runself = "source", deb = "binary", srpm = "source", rpm = "binary" } local outputkind = outputkinds[self:format()] or "binary" return outputkind end -- pack from source files? function xpack:from_source() return self:inputkind() == "source" end -- pack from binary files? function xpack:from_binary() return self:inputkind() == "binary" end -- pack with source files? function xpack:with_source() return self:outputkind() == "source" end -- pack with binary files? function xpack:with_binary() return self:outputkind() == "binary" end -- get the build directory function xpack:buildir() return path.join(config.buildir(), ".xpack", self:name()) end -- get the output directory function xpack:outputdir() local outputdir = option.get("outputdir") if outputdir == nil then outputdir = path.join(config.buildir(), "xpack", self:name()) end return outputdir end -- get the basename function xpack:basename() local basename = option.get("basename") or self:get("basename") if basename == nil then basename = self:name() if self:with_source() then basename = basename .. "-src" end local version = self:version() if version then basename = basename .. "-" .. version end end -- we need filter builtin variables, e.g. $(plat), $(arch), $(version) ... return filter.handle(basename, self) end -- get the spec variables function xpack:specvars() local specvars = self._specvars if specvars == nil then specvars = { PACKAGE_ARCH = self:arch(), PACKAGE_PLAT = self:plat(), PACKAGE_NAME = self:name(), PACKAGE_TITLE = self:title() or "", PACKAGE_DESCRIPTION = self:description() or "", PACKAGE_FILENAME = self:filename(), PACKAGE_AUTHOR = self:get("author") or "", PACKAGE_MAINTAINER = self:get("maintainer") or self:get("author") or "", PACKAGE_HOMEPAGE = self:get("homepage") or "", PACKAGE_COPYRIGHT = self:get("copyright") or "", PACKAGE_COMPANY = self:get("company") or "", PACKAGE_ICONFILE = self:get("iconfile") or "", PACKAGE_LICENSE = self:license() or "", PACKAGE_LICENSEFILE = self:get("licensefile") or "" } -- get version local version, version_build = self:version() if version then specvars.PACKAGE_VERSION = version or "0.0.0" try {function () local v = semver.new(version) if v then specvars.PACKAGE_VERSION_MAJOR = v:major() or "0" specvars.PACKAGE_VERSION_MINOR = v:minor() or "0" specvars.PACKAGE_VERSION_ALTER = v:patch() or "0" end end} specvars.PACKAGE_VERSION_BUILD = version_build or "" end -- get git information local cmds = { GIT_TAG = {"describe", "--tags"}, GIT_TAG_LONG = {"describe", "--tags", "--long"}, GIT_BRANCH = {"rev-parse", "--abbrev-ref", "HEAD"}, GIT_COMMIT = {"rev-parse", "--short", "HEAD"}, GIT_COMMIT_LONG = {"rev-parse", "HEAD"}, GIT_COMMIT_DATE = {"log", "-1", "--date=format:%Y%m%d%H%M%S", "--format=%ad"} } for name, argv in pairs(cmds) do specvars[name] = function () local result local git = find_tool("git") if git then result = try {function () return os.iorunv(git.program, argv) end} end if not result then result = "none" end return result:trim() end end -- get user variables local vars = self:get("specvar") if vars then table.join2(specvars, vars) end self._specvars = specvars end return specvars end -- get the extension function xpack:extension() local extension = self:get("extension") if extension == nil then local extensions = { wix = ".msi", nsis = ".exe", zip = ".zip", targz = ".tar.gz", srczip = ".zip", srctargz = ".tar.gz", runself = ".gz.run", deb = ".deb", srpm = ".src.rpm", rpm = ".rpm" } extension = extensions[self:format()] or "" end return extension end -- get the output filename function xpack:filename() return self:basename() .. self:extension() end -- get the output file function xpack:outputfile() return path.join(self:outputdir(), self:filename()) end -- get the package version function xpack:version() local version = self:get("version") local version_build if version == nil then for _, target in ipairs(self:targets()) do version, version_build = target:version() if version then break end end if version == nil then version, version_build = project.version() end else version_build = self:extraconf("version", version, "build") if type(version_build) == "string" then version_build = os.date(version_build, os.time()) end end return version, version_build end -- get the install files function xpack:installfiles() return match_copyfiles(self, "installfiles", self:installdir()) end -- get the installed root directory, this is just a temporary sandbox installation path, -- we may replace it with the actual installation path in the specfile function xpack:install_rootdir() return path.join(self:buildir(), "installed", self:format()) end -- get the installed directory function xpack:installdir(...) local installdir = self:install_rootdir() local prefixdir = self:prefixdir() if prefixdir then installdir = path.join(installdir, prefixdir) end return path.normalize(path.join(installdir, ...)) end -- get the source files function xpack:sourcefiles() return match_copyfiles(self, "sourcefiles", self:sourcedir()) end -- get the source root directory function xpack:source_rootdir() return path.join(self:buildir(), "source", self:format()) end -- get the source directory function xpack:sourcedir(...) local sourcedir = self:source_rootdir() local prefixdir = self:prefixdir() if prefixdir then sourcedir = path.join(sourcedir, prefixdir) end return path.normalize(path.join(sourcedir, ...)) end -- get the prefixdir function xpack:prefixdir() local prefixdir = self:get("prefixdir") if prefixdir then return filter.handle(prefixdir, self) end return prefixdir end -- get the binary directory function xpack:bindir() local bindir = self:get("bindir") or self:extraconf("prefixdir", self:prefixdir(), "bindir") if bindir == nil then bindir = "bin" end return self:installdir(bindir) end -- get the library directory function xpack:libdir() local libdir = self:get("libdir") or self:extraconf("prefixdir", self:prefixdir(), "libdir") if libdir == nil then libdir = "lib" end return self:installdir(libdir) end -- get the include directory function xpack:includedir() local includedir = self:get("includedir") or self:extraconf("prefixdir", self:prefixdir(), "includedir") if includedir == nil then includedir = "include" end return self:installdir(includedir) end -- get the components function xpack:components() local components = _g.components if components == nil then components = {} local xpack_component_scope = project.scope("xpack_component") for _, component_name in ipairs(self:get("components")) do local scope = xpack_component_scope[component_name] if scope then local instance = xpack_component.new(component_name, scope, self) components[component_name] = instance else raise("unknown xpack component(%s) in xpack(%s)", component_name, self:name()) end end _g.components = components end return components end -- get the given component function xpack:component(name) return self:components()[name] end -- new a xpack, and we need to clone scope info, -- because two different format packages maybe have same scope function _new(name, info) return xpack {name, info:clone()} end -- get xpack packages function packages() local packages = _g.packages if not packages then packages = {} local packages_need = option.get("packages") if packages_need then packages_need = hashset.from(packages_need) end local xpack_scope = project.scope("xpack") for name, scope in pairs(xpack_scope) do local need = false if packages_need then if packages_need:has(name) then need = true end else need = true end if need then local formats = scope:get("formats") if formats then for _, format in ipairs(formats) do local instance = _new(name, scope) instance:format_set(format) table.insert(packages, instance) end else raise("xpack(%s): formats not found, please use `set_formats()` to set it.", scope:get("name")) end end end _g.packages = packages end return packages end
0
repos/xmake/xmake/plugins
repos/xmake/xmake/plugins/pack/xmake.lua
--!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 pack.lua -- task("pack") set_category("plugin") on_run("main") set_menu { usage = "xmake pack [options] [names]", description = "Pack binary installation packages.", options = { {'o', "outputdir", "kv", nil, "Set the output directory. (default: build/xpack)"}, {nil, "basename", "kv", nil, "Set the basename of the output file."}, {nil, "autobuild", "kv", true, "Build targets automatically."}, {'j', "jobs", "kv", tostring(os.default_njob()), "Set the number of parallel compilation jobs." }, {'f', "formats", "kv", "all", "Pack the given package formats.", "e.g.", " - xmake pack -f nsis,deb,rpm", "values:", values = {"nsis", "wix", "deb", "srpm", "rpm", "runself", "targz", "zip", "srctargz", "srczip"}}, {}, {nil, "packages", "vs", nil, "The package names."} } }
0
repos/xmake/xmake/plugins/pack
repos/xmake/xmake/plugins/pack/zip/main.lua
--!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 main.lua -- -- imports import(".archive") function main(package) archive(package) end
0
repos/xmake/xmake/plugins/pack
repos/xmake/xmake/plugins/pack/runself/main.lua
--!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 main.lua -- -- imports import("core.base.option") import("core.base.semver") import("lib.detect.find_tool") import("private.action.require.impl.packagenv") import("private.action.require.impl.install_packages") import(".batchcmds") -- get the makeself function _get_makeself() -- enter the environments of makeself local oldenvs = packagenv.enter("makeself") -- find makeself local packages = {} local makeself = find_tool("makeself.sh") if not makeself then table.join2(packages, install_packages("makeself")) end -- enter the environments of installed packages for _, instance in ipairs(packages) do instance:envs_enter() end -- we need to force detect and flush detect cache after loading all environments if not makeself then makeself = find_tool("makeself.sh", {force = true}) end assert(makeself, "makeself not found!") return makeself, oldenvs end -- get specvars function _get_specvars(package) local specvars = table.clone(package:specvars()) return specvars end -- write install command function _write_installcmd(package, scriptfile, cmd) local opt = cmd.opt or {} local kind = cmd.kind if kind == "cp" then local srcfiles = os.files(cmd.srcpath) for _, srcfile in ipairs(srcfiles) do -- the destination is directory? append the filename local dstfile = cmd.dstpath if #srcfiles > 1 or path.islastsep(dstfile) then if opt.rootdir then dstfile = path.join(dstfile, path.relative(srcfile, opt.rootdir)) else dstfile = path.join(dstfile, path.filename(srcfile)) end end scriptfile:print("cp -p \"%s\" \"%s\"", srcfile, dstfile) end elseif kind == "rm" then local filepath = cmd.filepath scriptfile:print("rm -f \"%s\"", filepath) elseif kind == "rmdir" then local dir = cmd.dir scriptfile:print("rm -rf \"%s\"", dir) elseif kind == "mv" then local srcpath = cmd.srcpath local dstpath = cmd.dstpath scriptfile:print("mv \"%s\" \"%s\"", srcfile, dstfile) elseif kind == "cd" then local dir = cmd.dir scriptfile:print("cd \"%s\"", dir) elseif kind == "mkdir" then local dir = cmd.dir scriptfile:print("mkdir -p \"%s\"", dir) elseif cmd.program then scriptfile:print("%s", os.args(table.join(cmd.program, cmd.argv))) end end -- write install commands function _write_installcmds(package, scriptfile, cmds) for _, cmd in ipairs(cmds) do _write_installcmd(package, scriptfile, cmd) end end -- pack runself package function _pack_runself(makeself, package) -- install the initial specfile local specfile = path.join(package:buildir(), package:basename() .. ".lsm") if not os.isfile(specfile) then local specfile_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "runself", "makeself.lsm") os.cp(specfile_template, specfile, {writeable = true}) end -- replace variables in specfile local specvars = _get_specvars(package) local pattern = package:extraconf("specfile", "pattern") or "%${([^\n]-)}" local specvars_names = {} local specvars_values = {} io.gsub(specfile, "(" .. pattern .. ")", function(_, name) table.insert(specvars_names, name) end) for _, name in ipairs(specvars_names) do name = name:trim() if specvars_values[name] == nil then local value = specvars[name] if type(value) == "function" then value = value() end if value ~= nil then dprint(" > replace %s -> %s", name, value) end if type(value) == "table" then dprint("invalid variable value", value) end specvars_values[name] = value end end io.gsub(specfile, "(" .. pattern .. ")", function(_, name) name = name:trim() return specvars_values[name] end) -- archive source files local srcfiles, dstfiles = package:sourcefiles() for idx, srcfile in ipairs(srcfiles) do os.vcp(srcfile, dstfiles[idx]) end for _, component in table.orderpairs(package:components()) do if component:get("default") ~= false then local srcfiles, dstfiles = component:sourcefiles() for idx, srcfile in ipairs(srcfiles) do os.vcp(srcfile, dstfiles[idx]) end end end -- generate the setup.sh script local sourcedir = package:sourcedir() local setupfile = path.join(sourcedir, "__setup__.sh") os.cp(path.join(os.programdir(), "scripts", "xpack", "runself", "setup.sh"), setupfile) local scriptfile = io.open(setupfile, "a+") if scriptfile then _write_installcmds(package, scriptfile, batchcmds.get_installcmds(package):cmds()) for _, component in table.orderpairs(package:components()) do if component:get("default") ~= false then _write_installcmds(package, scriptfile, batchcmds.get_installcmds(component):cmds()) end end scriptfile:close() end -- make package os.vrunv(makeself, {"--gzip", "--sha256", "--lsm", specfile, sourcedir, package:outputfile(), package:basename(), "./__setup__.sh"}) end function main(package) if is_subhost("windows") then return end cprint("packing %s", package:outputfile()) -- get makeself local makeself, oldenvs = _get_makeself() -- pack runself package _pack_runself(makeself.program, package) -- done os.setenvs(oldenvs) end
0
repos/xmake/xmake/plugins/pack
repos/xmake/xmake/plugins/pack/srczip/main.lua
--!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 main.lua -- -- imports import(".archive") function main(package) archive(package) end
0
repos/xmake/xmake/plugins/pack
repos/xmake/xmake/plugins/pack/rpm/main.lua
--!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 main.lua -- -- imports import(".srpm") function main(package) srpm(package) end
0
repos/xmake/xmake/plugins/pack
repos/xmake/xmake/plugins/pack/nsis/main.lua
--!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 main.lua -- -- imports import("core.base.option") import("core.base.semver") import("lib.detect.find_tool") import("private.action.require.impl.packagenv") import("private.action.require.impl.install_packages") import(".filter") import(".batchcmds") -- check makensis, we need check some plugins function _check_makensis(program) local tmpdir = os.tmpfile() .. ".dir" io.writefile(path.join(tmpdir, "test.nsis"), [[ !include "MUI2.nsh" !include "WordFunc.nsh" !include "WinMessages.nsh" !include "FileFunc.nsh" !include "UAC.nsh" Name "test" OutFile "test.exe" Function .onInit FunctionEnd Section "test" InstallExeutable SectionEnd Function un.onInit FunctionEnd Section "Uninstall" SectionEnd]]) os.runv(program, {"test.nsis"}, {curdir = tmpdir}) os.tryrm(tmpdir) end -- get the makensis function _get_makensis() -- enter the environments of nsis local oldenvs = packagenv.enter("nsis") -- find makensis local packages = {} local makensis = find_tool("makensis", {check = _check_makensis}) if not makensis then table.join2(packages, install_packages("nsis")) end -- enter the environments of installed packages for _, instance in ipairs(packages) do instance:envs_enter() end -- we need to force detect and flush detect cache after loading all environments if not makensis then makensis = find_tool("makensis", {check = _check_makensis, force = true}) end assert(makensis, "makensis not found!") return makensis, oldenvs end -- get unique tag function _get_unique_tag(content) return hash.uuid(content):split("-", {plain = true})[1]:lower() end -- translate the file path function _translate_filepath(package, filepath) return filepath:replace(package:install_rootdir(), "$InstDir", {plain = true}) end -- get command string function _get_command_strings(package, cmd, opt) opt = table.join(cmd.opt or {}, opt) local result = {} local kind = cmd.kind if kind == "cp" then -- https://nsis.sourceforge.io/Reference/File local srcfiles = os.files(cmd.srcpath) for _, srcfile in ipairs(srcfiles) do -- the destination is directory? append the filename local dstfile = _translate_filepath(package, cmd.dstpath) if #srcfiles > 1 or path.islastsep(dstfile) then if opt.rootdir then dstfile = path.join(dstfile, path.relative(srcfile, opt.rootdir)) else dstfile = path.join(dstfile, path.filename(srcfile)) end end srcfile = path.normalize(srcfile) local dstname = path.filename(dstfile) local dstdir = path.normalize(path.directory(dstfile)) table.insert(result, string.format("SetOutPath \"%s\"", dstdir)) table.insert(result, string.format("File \"/oname=%s\" \"%s\"", dstname, srcfile)) end elseif kind == "rm" then local filepath = _translate_filepath(package, cmd.filepath) table.insert(result, string.format("${%s} \"%s\"", opt.install and "RMFileIfExists" or "unRMFileIfExists", filepath)) if opt.emptydirs then table.insert(result, string.format("${%s} \"%s\"", opt.install and "RMEmptyParentDirs" or "unRMEmptyParentDirs", filepath)) end elseif kind == "rmdir" then local dir = _translate_filepath(package, cmd.dir) table.insert(result, string.format("${%s} \"%s\"", opt.install and "RMDirIfExists" or "unRMDirIfExists", dir)) if opt.emptydirs then table.insert(result, string.format("${%s} \"%s\"", opt.install and "RMEmptyParentDirs" or "unRMEmptyParentDirs", dir)) end elseif kind == "mv" then local srcpath = _translate_filepath(package, cmd.srcpath) local dstpath = _translate_filepath(package, cmd.dstpath) table.insert(result, string.format("Rename \"%s\" \"%s\"", srcpath, dstpath)) elseif kind == "cd" then local dir = _translate_filepath(package, cmd.dir) table.insert(result, string.format("SetOutPath \"%s\"", dir)) elseif kind == "mkdir" then local dir = _translate_filepath(package, cmd.dir) table.insert(result, string.format("CreateDirectory \"%s\"", dir)) elseif kind == "nsis" then table.insert(result, cmd.rawstr) end return result end -- get commands string function _get_commands_string(package, cmds, opt) local cmdstrs = {} for _, cmd in ipairs(cmds) do table.join2(cmdstrs, _get_command_strings(package, cmd, opt)) end return table.concat(cmdstrs, "\n ") end -- get install commands of component function _get_component_installcmds(component) return _get_commands_string(component, batchcmds.get_installcmds(component):cmds(), {install = true}) end -- get uninstall commands of component function _get_component_uninstallcmds(component) return _get_commands_string(component, batchcmds.get_uninstallcmds(component):cmds(), {install = false}) end -- get install commands function _get_installcmds(package) return _get_commands_string(package, batchcmds.get_installcmds(package):cmds(), {install = true}) end -- get uninstall commands function _get_uninstallcmds(package) return _get_commands_string(package, batchcmds.get_uninstallcmds(package):cmds(), {install = false}) end -- get value and filter it function _get_filter_value(package, name) local value = package:get(name) if type(value) == "string" then value = filter.handle(value, package) end return value end -- get target file path function _get_target_filepath(package) local targetfile for _, target in ipairs(package:targets()) do if target:is_binary() then targetfile = target:targetfile() break end end if targetfile then return _translate_filepath(package, path.join(package:bindir(), path.filename(targetfile))) end end -- get specvars function _get_specvars(package) local specvars = table.clone(package:specvars()) specvars.PACKAGE_WORKDIR = path.absolute(os.projectdir()) specvars.PACKAGE_BINDIR = _translate_filepath(package, package:bindir()) specvars.PACKAGE_OUTPUTFILE = path.absolute(package:outputfile()) if specvars.PACKAGE_VERSION_BUILD then -- @see https://github.com/xmake-io/xmake/issues/5306 specvars.PACKAGE_VERSION_BUILD = specvars.PACKAGE_VERSION_BUILD:gsub(" ", "_") end specvars.PACKAGE_INSTALLCMDS = function () return _get_installcmds(package) end specvars.PACKAGE_UNINSTALLCMDS = function () return _get_uninstallcmds(package) end specvars.PACKAGE_NSIS_DISPLAY_ICON = function () local iconpath = _get_filter_value(package, "nsis_displayicon") if iconpath then iconpath = path.join(package:installdir(), iconpath) end if not iconpath then iconpath = _get_target_filepath(package) or "" end return _translate_filepath(package, iconpath) end -- install sections local install_sections = {} local install_descs = {} local install_description_texts = {} for name, component in table.orderpairs(package:components()) do local installcmds = _get_component_installcmds(component) if installcmds and #installcmds > 0 then local tag = "Install" .. name table.insert(install_sections, string.format('Section%s "%s" %s', component:get("default") == false and " /o" or "", component:title(), tag)) table.insert(install_sections, installcmds) table.insert(install_sections, "SectionEnd") table.insert(install_descs, string.format('LangString DESC_%s ${LANG_ENGLISH} "%s"', tag, component:description() or "")) table.insert(install_description_texts, string.format('!insertmacro MUI_DESCRIPTION_TEXT ${%s} $(DESC_%s)', tag, tag)) end local uninstallcmds = _get_component_uninstallcmds(component) if uninstallcmds and #uninstallcmds > 0 then local tag = "Uninstall" .. name table.insert(install_sections, string.format('Section "un.%s" %s', component:title(), tag)) table.insert(install_sections, uninstallcmds) table.insert(install_sections, "SectionEnd") end end specvars.PACKAGE_NSIS_INSTALL_SECTIONS = table.concat(install_sections, "\n ") specvars.PACKAGE_NSIS_INSTALL_DESCS = table.concat(install_descs, "\n ") specvars.PACKAGE_NSIS_INSTALL_DESCRIPTION_TEXTS = table.concat(install_description_texts, "\n ") return specvars end -- pack nsis package function _pack_nsis(makensis, package) -- install the initial specfile local specfile = path.join(package:buildir(), package:basename() .. ".nsi") if not os.isfile(specfile) then local specfile_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "nsis", "makensis.nsi") os.cp(specfile_template, specfile) end -- replace variables in specfile, -- and we need to avoid `attempt to yield across a C-call boundary` in io.gsub local specvars = _get_specvars(package) local pattern = package:extraconf("specfile", "pattern") or "%${([^\n]-)}" local specvars_names = {} local specvars_values = {} io.gsub(specfile, "(" .. pattern .. ")", function(_, name) table.insert(specvars_names, name) end, {encoding = "ansi"}) for _, name in ipairs(specvars_names) do name = name:trim() if specvars_values[name] == nil then local value = specvars[name] if type(value) == "function" then value = value() end if value ~= nil then dprint(" > replace %s -> %s", name, value) end if type(value) == "table" then dprint("invalid variable value", value) end specvars_values[name] = value end end io.gsub(specfile, "(" .. pattern .. ")", function(_, name) name = name:trim() return specvars_values[name] end, {encoding = "ansi"}) -- make package os.vrunv(makensis, {specfile}) end function main(package) -- only for windows if not is_host("windows") then return end cprint("packing %s", package:outputfile()) -- get makensis local makensis, oldenvs = _get_makensis() -- pack nsis package _pack_nsis(makensis.program, package) -- done os.setenvs(oldenvs) end
0
repos/xmake/xmake/plugins/pack
repos/xmake/xmake/plugins/pack/wix/main.lua
--!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 A2va -- @file main.lua -- import("lib.detect.find_tool") import("private.action.require.impl.packagenv") import("private.action.require.impl.install_packages") import(".batchcmds") -- get the wixtoolset function _get_wix() -- enter the environments of wix local oldenvs = packagenv.enter("wixtoolset") -- find makensis local packages = {} local wix = find_tool("wix") if not wix then table.join2(packages, install_packages("wixtoolset")) end -- enter the environments of installed packages for _, instance in ipairs(packages) do instance:envs_enter() end -- we need to force detect and flush detect cache after loading all environments if not wix then wix = find_tool("wix", {force = true}) end assert(wix, "wix not found (ensure that wix is up to date)!") return wix, oldenvs end -- translate the file path function _translate_filepath(package, filepath) return path.relative(filepath, package:install_rootdir()) end function _to_rtf_string(str) if str == "" then return str end local escape_text = str:gsub("\\", "\\\\") escape_text = escape_text:gsub("{", "\\{") escape_text = escape_text:gsub("}", "\\}") local rtf = "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard "; rtf = rtf .. escape_text:gsub("\r\n", " \\par ") .. "}" return rtf end -- get a table where the key is a directory and the value a list of files -- used to regroup all files that are placed in the same directory under the same component. function _get_cp_kind_table(package, cmds, opt) local result = {} for _, cmd in ipairs(cmds) do if cmd.kind ~= "cp" then goto continue end local option = table.join(cmd.opt or {}, opt) local srcfiles = os.files(cmd.srcpath) for _, srcfile in ipairs(srcfiles) do -- the destination is directory? append the filename local dstfile = cmd.dstpath if #srcfiles > 1 or path.islastsep(dstfile) then if option.rootdir then dstfile = path.join(dstfile, path.relative(srcfile, option.rootdir)) else dstfile = path.join(dstfile, path.filename(srcfile)) end end srcfile = path.normalize(srcfile) local dstname = path.filename(dstfile) local dstdir = path.normalize(path.directory(dstfile)) dstdir = _translate_filepath(package, dstdir) if result[dstdir] then table.insert(result[dstdir], {srcfile, dstname}) else result[dstdir] = {{srcfile, dstname}} end end ::continue:: end return result end -- get id function _get_id(name) return "A" .. hash.uuid(name):gsub("-", ".") end -- for each id/guid in the file wix want them to be unique -- so compute a hash for each directory based on the file that are inside function _get_dir_id(cp_table) local hashes = {} for dir, files in pairs(cp_table) do local s = "" for _, file in ipairs(files) do s = s .. table.concat(file, "") end -- wix required id to start with a letter and without any hyphen hashes[dir] = _get_id(s) end return hashes end -- get custom commands function _get_other_commands(package, cmd, opt) opt = table.join(cmd.opt or {}, opt) local result = "" local kind = cmd.kind local id = _get_id() if kind == "rm" then local subdirectory = _translate_filepath(package, path.directory(cmd.filepath)) subdirectory = subdirectory ~= "." and string.format([[Subdirectory="%s"]], subdirectory) or "" local on = opt.install and [[On="install"]] or [[On="uninstall"]] local filename = path.filename(cmd.filepath) result = string.format([[<RemoveFile Id="%s" Directory="INSTALLFOLDER" Name="%s" %s %s/>]], id, filename, subdirectory, on) elseif kind == "rmdir" then local dir = _translate_filepath(package, cmd.dir) local subdirectory = dir ~= "." and string.format([[Subdirectory="%s"]], dir) or "" local on = opt.install and [[On="install"]] or [[On="uninstall"]] result = string.format([[<RemoveFolder Id="%s" Directory="INSTALLFOLDER" %s %s/>]], id, subdirectory, on) elseif kind == "mkdir" then local dir = _translate_filepath(package, cmd.dir) local subdirectory = dir ~= "." and string.format([[Subdirectory="%s"]], dir) or "" result = string.format([[<CreateFolder Id="%s" Directory="INSTALLFOLDER" %s/>]], id, subdirectory) elseif kind == "wix" then result = cmd.rawstr end return result end -- get the string of a wix feature function _get_feature_string(name, title, opt) local level = opt.default and 1 or 2 local description = opt.description or "" local allow_absent = opt.force and "false" or "true" local allow_advertise = opt.force and "false" or "true" local typical_default = [[TypicalDefault="install"]] local directory = opt.config_dir and [[ConfigurableDirectory="INSTALLFOLDER"]] or "" local feature = string.format([[<Feature Id="%s" Title="%s" Description="%s" Level="%d" AllowAdvertise="%s" AllowAbsent="%s" %s %s>]], name:gsub("[ ()]", ""), title, description, level, allow_advertise, allow_absent, typical_default, directory) return feature end function _get_component_string(id, subdirectory) local subdirectory = (subdirectory ~= "." and subdirectory ~= nil) and string.format([[Subdirectory="%s"]], subdirectory) or "" return string.format([[<Component Id="%s" Guid="%s" Directory="INSTALLFOLDER" %s>]], id:gsub("[ ()]", ""), hash.uuid(id), subdirectory) end -- build a feature from batchcmds function _build_feature(package, opt) opt = opt or {} local default = opt.default or package:get("default") local result = {} local name = opt.name or package:title() table.insert(result, _get_feature_string(name, package:title(), table.join(opt, {default = default, description = package:description()}))) local installcmds = batchcmds.get_installcmds(package):cmds() local uninstallcmds = batchcmds.get_uninstallcmds(package):cmds() local cp_table = _get_cp_kind_table(package, installcmds, opt) table.remove_if(installcmds, function (_, cmd) return cmd.kind == "cp" end) local dir_id = _get_dir_id(cp_table) for dir, files in pairs(cp_table) do table.insert(result, _get_component_string(dir_id[dir], dir)) for _, file in ipairs(files) do local srcfile = file[1] local dstname = file[2] table.insert(result, string.format([[<File Source="%s" Name="%s" Id="%s"/>]], srcfile, dstname, _get_id())) end table.insert(result, "</Component>") end table.insert(result, _get_component_string(name .. "Cmds")) for _, cmd in ipairs(installcmds) do table.insert(result, _get_other_commands(package, cmd, {install = true})) end for _, cmd in ipairs(uninstallcmds) do table.insert(result, _get_other_commands(package, cmd, {install = false})) end table.insert(result, "</Component>") table.insert(result, "</Feature>") return result end -- add to path feature function _add_to_path(package) local result = {} table.insert(result, _get_feature_string("PATH", "Add to PATH", {default = false, force = false, description = "Add to PATH"})) table.insert(result, _get_component_string("PATH")) table.insert(result, [[<Environment Id="PATH" Name="PATH" Value="[INSTALLFOLDER]bin" Permanent="false" Part="last" Action="set" System="true" />]]) table.insert(result, "</Component>") table.insert(result, "</Feature>") return result end -- get specvars function _get_specvars(package) local installcmds = batchcmds.get_installcmds(package):cmds() local specvars = table.clone(package:specvars()) local features = {} table.join2(features, _build_feature(package, {default = true, force = true, config_dir = true})) table.join2(features, _add_to_path(package)) for name, component in table.orderpairs(package:components()) do table.join2(features, _build_feature(component, {name = "Install " .. name})) end specvars.PACKAGE_LICENSEFILE = function () local rtf_string = "" local licensefile = package:get("licensefile") if licensefile then rtf_string = _to_rtf_string(io.readfile(licensefile)) end local rtf_file = path.join(package:buildir(), "license.rtf") io.writefile(rtf_file, rtf_string) return rtf_file end specvars.PACKAGE_WIX_CMDS = table.concat(features, "\n ") specvars.PACKAGE_WIX_UPGRADECODE = hash.uuid(package:name()) -- company cannot be empty with wix if package:get("company") == nil or package:get("company") == "" then specvars.PACKAGE_COMPANY = package:name() end return specvars end function _pack_wix(wix, package) -- install the initial specfile local specfile = path.join(package:buildir(), package:basename() .. ".wxs") if not os.isfile(specfile) then local specfile_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "wix", "msi.wxs") os.cp(specfile_template, specfile) end -- replace variables in specfile -- and we need to avoid `attempt to yield across a C-call boundary` in io.gsub local specvars = _get_specvars(package) local pattern = package:extraconf("specfile", "pattern") or "%${([^\n]-)}" local specvars_names = {} local specvars_values = {} io.gsub(specfile, "(" .. pattern .. ")", function(_, name) table.insert(specvars_names, name) end) for _, name in ipairs(specvars_names) do name = name:trim() if specvars_values[name] == nil then local value = specvars[name] if type(value) == "function" then value = value() end if value ~= nil then dprint(" > replace %s -> %s", name, value) end if type(value) == "table" then dprint("invalid variable value", value) end specvars_values[name] = value end end io.gsub(specfile, "(" .. pattern .. ")", function(_, name) name = name:trim() return specvars_values[name] end) local argv = {"build", specfile} table.join2(argv, {"-ext", "WixToolset.UI.wixext"}) table.join2(argv, {"-o", package:outputfile()}) if package:arch() == "x64" then table.join2(argv, {"-arch", "x64"}) elseif package:arch() == "x86" then table.join2(argv, {"-arch", "x86"}) end -- make package os.vrunv(wix, argv) end function main(package) -- only for windows if not is_host("windows") then return end cprint("packing %s", package:outputfile()) -- get wix local wix, oldenvs = _get_wix() -- pack nsis package _pack_wix(wix.program, package) -- done os.setenvs(oldenvs) end
0
repos/xmake/xmake/plugins/pack
repos/xmake/xmake/plugins/pack/srctargz/main.lua
--!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 main.lua -- -- imports import(".archive") function main(package) archive(package) end
0
repos/xmake/xmake/plugins/pack
repos/xmake/xmake/plugins/pack/srpm/main.lua
--!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 main.lua -- -- imports import("core.base.option") import("core.base.semver") import("core.base.hashset") import("lib.detect.find_tool") import("lib.detect.find_file") import("utils.archive") import("private.action.require.impl.packagenv") import("private.action.require.impl.install_packages") import(".batchcmds") -- get the rpmbuild function _get_rpmbuild() -- enter the environments of rpmbuild local oldenvs = packagenv.enter("rpm") -- find rpmbuild local packages = {} local rpmbuild = find_tool("rpmbuild") if not rpmbuild then table.join2(packages, install_packages("rpm")) end -- enter the environments of installed packages for _, instance in ipairs(packages) do instance:envs_enter() end -- we need to force detect and flush detect cache after loading all environments if not rpmbuild then rpmbuild = find_tool("rpmbuild", {force = true}) end assert(rpmbuild, "rpmbuild not found!") return rpmbuild, oldenvs end -- get archive file function _get_archivefile(package) return path.absolute(path.join(package:buildir(), package:basename() .. ".tar.gz")) end -- translate the file path function _translate_filepath(package, filepath) return filepath:replace(package:install_rootdir(), "%{buildroot}/%{_exec_prefix}", {plain = true}) end -- get install command function _get_customcmd(package, installcmds, cmd) local opt = cmd.opt or {} local kind = cmd.kind if kind == "cp" then local srcfiles = os.files(cmd.srcpath) for _, srcfile in ipairs(srcfiles) do -- the destination is directory? append the filename local dstfile = _translate_filepath(package, cmd.dstpath) if #srcfiles > 1 or path.islastsep(dstfile) then if opt.rootdir then dstfile = path.join(dstfile, path.relative(srcfile, opt.rootdir)) else dstfile = path.join(dstfile, path.filename(srcfile)) end end table.insert(installcmds, string.format("install -Dpm0644 \"%s\" \"%s\"", srcfile, dstfile)) end elseif kind == "rm" then local filepath = _translate_filepath(package, cmd.filepath) table.insert(installcmds, string.format("rm -f \"%s\"", filepath)) elseif kind == "rmdir" then local dir = _translate_filepath(package, cmd.dir) table.insert(installcmds, string.format("rm -rf \"%s\"", dir)) elseif kind == "mv" then local srcpath = _translate_filepath(package, cmd.srcpath) local dstpath = _translate_filepath(package, cmd.dstpath) table.insert(installcmds, string.format("mv \"%s\" \"%s\"", srcfile, dstfile)) elseif kind == "cd" then local dir = _translate_filepath(package, cmd.dir) table.insert(installcmds, string.format("cd \"%s\"", dir)) elseif kind == "mkdir" then local dir = _translate_filepath(package, cmd.dir) table.insert(installcmds, string.format("mkdir -p \"%s\"", dir)) elseif cmd.program then local argv = {} for _, arg in ipairs(cmd.argv) do if path.instance_of(arg) then arg = arg:clone():set(_translate_filepath(package, arg:rawstr())):str() elseif path.is_absolute(arg) then arg = _translate_filepath(package, arg) end table.insert(argv, arg) end table.insert(installcmds, string.format("%s", os.args(table.join(cmd.program, argv)))) end end -- get build commands function _get_buildcmds(package, buildcmds, cmds) for _, cmd in ipairs(cmds) do _get_customcmd(package, buildcmds, cmd) end end -- get install commands function _get_installcmds(package, installcmds, cmds) for _, cmd in ipairs(cmds) do _get_customcmd(package, installcmds, cmd) end end -- get specvars function _get_specvars(package) local specvars = table.clone(package:specvars()) specvars.PACKAGE_ARCHIVEFILE = path.filename(_get_archivefile(package)) local datestr = os.iorunv("date", {"+%a %b %d %Y"}, {envs = {LC_TIME = "en_US"}}) if datestr then datestr = datestr:trim() end specvars.PACKAGE_PREFIXDIR = package:prefixdir() or "" specvars.PACKAGE_DATE = datestr or "" specvars.PACKAGE_INSTALLCMDS = function () local prefixdir = package:get("prefixdir") package:set("prefixdir", nil) local installcmds = {} _get_installcmds(package, installcmds, batchcmds.get_installcmds(package):cmds()) for _, component in table.orderpairs(package:components()) do if component:get("default") ~= false then _get_installcmds(package, installcmds, batchcmds.get_installcmds(component):cmds()) end end package:set("prefixdir", prefixdir) return table.concat(installcmds, "\n") end specvars.PACKAGE_BUILDCMDS = function () local buildcmds = {} _get_buildcmds(package, buildcmds, batchcmds.get_buildcmds(package):cmds()) return table.concat(buildcmds, "\n") end specvars.PACKAGE_BUILDREQUIRES = function () local requires = {} local buildrequires = package:get("buildrequires") if buildrequires then for _, buildrequire in ipairs(buildrequires) do table.insert(requires, "BuildRequires: " .. buildrequire) end else local programs = hashset.new() for _, cmd in ipairs(batchcmds.get_buildcmds(package):cmds()) do local program = cmd.program if program then programs:insert(program) end end local map = { xmake = "xmake", cmake = "cmake", make = "make" } for _, program in programs:keys() do local requirename = map[program] if requirename then table.insert(requires, "BuildRequires: " .. requirename) end end if #requires > 0 then table.insert(requires, "BuildRequires: gcc") table.insert(requires, "BuildRequires: gcc-c++") end end return table.concat(requires, "\n") end return specvars end -- pack srpm package function _pack_srpm(rpmbuild, package) -- ensure prefixdir local prefixdir = package:get("prefixdir") if not prefixdir then prefixdir = package:name() .. "-" .. package:version() package:set("prefixdir", prefixdir) end -- install the initial specfile local specfile = path.join(package:buildir(), package:basename() .. ".spec") if not os.isfile(specfile) then local specfile_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "srpm", "srpm.spec") os.cp(specfile_template, specfile, {writeable = true}) end -- replace variables in specfile -- and we need to avoid `attempt to yield across a C-call boundary` in io.gsub local specvars = _get_specvars(package) local pattern = package:extraconf("specfile", "pattern") or "%${([^\n]-)}" local specvars_names = {} local specvars_values = {} io.gsub(specfile, "(" .. pattern .. ")", function(_, name) table.insert(specvars_names, name) end) for _, name in ipairs(specvars_names) do name = name:trim() if specvars_values[name] == nil then local value = specvars[name] if type(value) == "function" then value = value() end if value ~= nil then dprint(" > replace %s -> %s", name, value) end if type(value) == "table" then dprint("invalid variable value", value) end specvars_values[name] = value end end io.gsub(specfile, "(" .. pattern .. ")", function(_, name) name = name:trim() return specvars_values[name] end) -- archive source files local srcfiles, dstfiles = package:sourcefiles() for idx, srcfile in ipairs(srcfiles) do os.vcp(srcfile, dstfiles[idx]) end for _, component in table.orderpairs(package:components()) do if component:get("default") ~= false then local srcfiles, dstfiles = component:sourcefiles() for idx, srcfile in ipairs(srcfiles) do os.vcp(srcfile, dstfiles[idx]) end end end -- archive install files local rootdir = package:source_rootdir() local oldir = os.cd(rootdir) local archivefiles = os.files("**") os.cd(oldir) local archivefile = _get_archivefile(package) os.tryrm(archivefile) archive.archive(archivefile, archivefiles, {curdir = rootdir, compress = "best"}) -- pack srpm package os.vrunv(rpmbuild, {"-bs", specfile, "--define", "_topdir " .. package:buildir(), "--define", "_sourcedir " .. package:buildir(), "--define", "_srcrpmdir " .. package:outputdir()}) -- pack rpm package if package:format() == "rpm" then local srpmfile = find_file("*.src.rpm", package:outputdir()) if srpmfile then os.vrunv(rpmbuild, {"--rebuild", srpmfile, "--define", "_rpmdir " .. package:outputdir()}) end end end function main(package) if not is_host("linux") then return end cprint("packing %s", package:outputfile()) -- get rpmbuild local rpmbuild, oldenvs = _get_rpmbuild() -- pack srpm package _pack_srpm(rpmbuild.program, package) -- done os.setenvs(oldenvs) end
0
repos/xmake/xmake/plugins/pack
repos/xmake/xmake/plugins/pack/targz/main.lua
--!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 main.lua -- -- imports import(".archive") function main(package) archive(package) end
0
repos/xmake/xmake/plugins/pack
repos/xmake/xmake/plugins/pack/deb/main.lua
--!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 main.lua -- -- imports import("core.base.option") import("core.base.semver") import("core.base.hashset") import("lib.detect.find_tool") import("lib.detect.find_file") import("utils.archive") import(".batchcmds") -- get the debuild function _get_debuild() local debuild = find_tool("debuild", {force = true}) assert(debuild, "debuild not found, please run `sudo apt install devscripts` to install it!") return debuild end -- get archive file function _get_archivefile(package) return path.absolute(path.join(path.directory(package:sourcedir()), package:name() .. "_" .. package:version() .. ".orig.tar.gz")) end -- translate the file path function _translate_filepath(package, filepath) return filepath:replace(package:install_rootdir(), "$(PREFIX)", {plain = true}) end -- get install command function _get_customcmd(package, installcmds, cmd) local opt = cmd.opt or {} local kind = cmd.kind if kind == "cp" then local srcfiles = os.files(cmd.srcpath) for _, srcfile in ipairs(srcfiles) do -- the destination is directory? append the filename local dstfile = _translate_filepath(package, cmd.dstpath) if #srcfiles > 1 or path.islastsep(dstfile) then if opt.rootdir then dstfile = path.join(dstfile, path.relative(srcfile, opt.rootdir)) else dstfile = path.join(dstfile, path.filename(srcfile)) end end table.insert(installcmds, string.format("install -Dpm0644 \"%s\" \"%s\"", srcfile, dstfile)) end elseif kind == "rm" then local filepath = _translate_filepath(package, cmd.filepath) table.insert(installcmds, string.format("rm -f \"%s\"", filepath)) elseif kind == "rmdir" then local dir = _translate_filepath(package, cmd.dir) table.insert(installcmds, string.format("rm -rf \"%s\"", dir)) elseif kind == "mv" then local srcpath = _translate_filepath(package, cmd.srcpath) local dstpath = _translate_filepath(package, cmd.dstpath) table.insert(installcmds, string.format("mv \"%s\" \"%s\"", srcfile, dstfile)) elseif kind == "cd" then local dir = _translate_filepath(package, cmd.dir) table.insert(installcmds, string.format("cd \"%s\"", dir)) elseif kind == "mkdir" then local dir = _translate_filepath(package, cmd.dir) table.insert(installcmds, string.format("mkdir -p \"%s\"", dir)) elseif cmd.program then local argv = {} for _, arg in ipairs(cmd.argv) do if path.instance_of(arg) then arg = arg:clone():set(_translate_filepath(package, arg:rawstr())):str() elseif path.is_absolute(arg) then arg = _translate_filepath(package, arg) end table.insert(argv, arg) end table.insert(installcmds, string.format("%s", os.args(table.join(cmd.program, argv)))) end end -- get build commands function _get_buildcmds(package, buildcmds, cmds) for _, cmd in ipairs(cmds) do _get_customcmd(package, buildcmds, cmd) end end -- get install commands function _get_installcmds(package, installcmds, cmds) for _, cmd in ipairs(cmds) do _get_customcmd(package, installcmds, cmd) end end -- get uninstall commands function _get_uninstallcmds(package, uninstallcmds, cmds) for _, cmd in ipairs(cmds) do _get_customcmd(package, uninstallcmds, cmd) end end -- get specvars function _get_specvars(package) local specvars = table.clone(package:specvars()) local datestr = os.iorunv("date", {"-u", "+%a, %d %b %Y %H:%M:%S +0000"}, {envs = {LC_TIME = "en_US"}}) if datestr then datestr = datestr:trim() end specvars.PACKAGE_DATE = datestr or "" local author = package:get("author") or "unknown <[email protected]>" specvars.PACKAGE_COPYRIGHT = os.date("%Y") .. " " .. author specvars.PACKAGE_INSTALLCMDS = function () local prefixdir = package:get("prefixdir") package:set("prefixdir", nil) local installcmds = {} _get_installcmds(package, installcmds, batchcmds.get_installcmds(package):cmds()) for _, component in table.orderpairs(package:components()) do if component:get("default") ~= false then _get_installcmds(package, installcmds, batchcmds.get_installcmds(component):cmds()) end end package:set("prefixdir", prefixdir) return table.concat(installcmds, "\n\t") end specvars.PACKAGE_UNINSTALLCMDS = function () local uninstallcmds = {} _get_uninstallcmds(package, uninstallcmds, batchcmds.get_uninstallcmds(package):cmds()) for _, component in table.orderpairs(package:components()) do if component:get("default") ~= false then _get_uninstallcmds(package, uninstallcmds, batchcmds.get_uninstallcmds(component):cmds()) end end return table.concat(uninstallcmds, "\n\t") end specvars.PACKAGE_BUILDCMDS = function () local buildcmds = {} _get_buildcmds(package, buildcmds, batchcmds.get_buildcmds(package):cmds()) return table.concat(buildcmds, "\n\t") end specvars.PACKAGE_BUILDREQUIRES = function () local requires = {} local buildrequires = package:get("buildrequires") if buildrequires then for _, buildrequire in ipairs(buildrequires) do table.insert(requires, buildrequire) end else local programs = hashset.new() for _, cmd in ipairs(batchcmds.get_buildcmds(package):cmds()) do local program = cmd.program if program then programs:insert(program) end end local map = { xmake = "xmake", cmake = "cmake", make = "make" } for _, program in programs:keys() do local requirename = map[program] if requirename then table.insert(requires, requirename) end end end return table.concat(requires, ", ") end return specvars end -- pack deb package function _pack_deb(debuild, package) -- install the initial debian directory local sourcedir = package:sourcedir() local debiandir = path.join(sourcedir, "debian") if not os.isdir(debiandir) then local debiandir_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "deb", "debian") os.cp(debiandir_template, debiandir, {writeable = true}) end -- replace variables in specfile -- and we need to avoid `attempt to yield across a C-call boundary` in io.gsub local specvars = _get_specvars(package) local pattern = package:extraconf("specfile", "pattern") or "%${([^\n]-)}" local specvars_names = {} local specvars_values = {} for _, specfile in ipairs(os.files(path.join(debiandir, "**"))) do io.gsub(specfile, "(" .. pattern .. ")", function(_, name) table.insert(specvars_names, name) end) end for _, name in ipairs(specvars_names) do name = name:trim() if specvars_values[name] == nil then local value = specvars[name] if type(value) == "function" then value = value() end if value ~= nil then dprint("[%s]: > replace %s -> %s", path.filename(specfile), name, value) end if type(value) == "table" then dprint("invalid variable value", value) end specvars_values[name] = value end end for _, specfile in ipairs(os.files(path.join(debiandir, "**"))) do io.gsub(specfile, "(" .. pattern .. ")", function(_, name) name = name:trim() return specvars_values[name] end) end -- archive source files local srcfiles, dstfiles = package:sourcefiles() for idx, srcfile in ipairs(srcfiles) do os.vcp(srcfile, dstfiles[idx]) end for _, component in table.orderpairs(package:components()) do if component:get("default") ~= false then local srcfiles, dstfiles = component:sourcefiles() for idx, srcfile in ipairs(srcfiles) do os.vcp(srcfile, dstfiles[idx]) end end end -- archive install files local rootdir = package:source_rootdir() local oldir = os.cd(rootdir) local archivefiles = os.files("**") os.cd(oldir) local archivefile = _get_archivefile(package) os.tryrm(archivefile) archive.archive(archivefile, archivefiles, {curdir = rootdir, compress = "best"}) -- build package os.vrunv(debuild, {"-us", "-uc"}, {curdir = sourcedir}) -- copy deb file os.vcp(path.join(path.directory(sourcedir), "*.deb"), package:outputfile()) end function main(package) if not is_host("linux") then return end cprint("packing %s", package:outputfile()) -- get debuild local debuild = _get_debuild() -- pack deb package _pack_deb(debuild.program, package) end
0
repos/xmake/xmake/plugins
repos/xmake/xmake/plugins/plugin/main.lua
--!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 main.lua -- -- imports import("core.base.option") import("core.base.global") import("devel.git") import("net.fasturl") import("private.action.require.impl.environment") -- get plugin urls function _plugin_urls() local urls = option.get("plugins") if not urls then urls = { "https://github.com/xmake-io/xmake-plugins.git", "https://gitlab.com/tboox/xmake-plugins.git", "https://gitee.com/tboox/xmake-plugins.git"} urls = fasturl.add(urls) urls = fasturl.sort(urls) end return urls end -- get manifest path function _manifest_path() return path.join(global.directory(), "plugins", "manifest.txt") end -- load manifest function _load_manifest() local manifest_path = _manifest_path() if os.isfile(manifest_path) then return io.load(manifest_path) end end -- save manifest function _save_manifest(manifest) io.save(_manifest_path(), manifest) end -- install plugins function _install() -- enter environment environment.enter() try { function () -- do install local urls = _plugin_urls() local tmpdir = os.tmpfile() .. ".dir" local plugindir = path.join(global.directory(), "plugins") local installed_url for _, url in ipairs(urls) do cprint("installing plugins from %s ..", url) git.clone(url, {verbose = option.get("verbose"), outputdir = tmpdir}) installed_url = url break end for _, filepath in ipairs(os.files(path.join(tmpdir, "*", "xmake.lua"))) do local srcdir = path.directory(filepath) local name = path.filename(srcdir) local dstdir = path.join(plugindir, name) assert(not os.isdir(dstdir), "plugin(%s) already exists!", name) os.vcp(srcdir, dstdir) cprint(" ${yellow}->${clear} %s", name) end os.tryrm(tmpdir) -- save manifest if installed_url then local manifest = _load_manifest() or {} manifest.urls = manifest.urls or {} table.join2(manifest.urls, installed_url) _save_manifest(manifest) end cprint("${bright}all plugins have been installed in %s!", plugindir) end, catch { function (errors) raise(errors) end } } -- leave environment environment.leave() end -- update plugins function _update() -- enter environment environment.enter() try { function () -- do update local manifest = _load_manifest() assert(manifest and manifest.urls, "3rd plugins not found!") local urls = manifest.urls local plugindir = path.join(global.directory(), "plugins") for _, url in ipairs(urls) do cprint("updating plugins from %s ..", url) local tmpdir = os.tmpfile() .. ".dir" git.clone(url, {verbose = option.get("verbose"), outputdir = tmpdir}) for _, filepath in ipairs(os.files(path.join(tmpdir, "*", "xmake.lua"))) do local srcdir = path.directory(filepath) local name = path.filename(srcdir) local dstdir = path.join(plugindir, name) os.tryrm(dstdir) os.vcp(srcdir, dstdir) cprint(" ${yellow}->${clear} %s", name) end os.tryrm(tmpdir) end cprint("${bright}all plugins have been updated in %s!", plugindir) end, catch { function (errors) raise(errors) end } } -- leave environment environment.leave() end -- clear all installed plugins function _clear() local plugindir = path.join(global.directory(), "plugins") if os.isdir(plugindir) then os.rmdir(plugindir) end cprint("${color.success}clear all installed plugins ok!") end function main() if option.get("install") then _install() elseif option.get("update") then _update() elseif option.get("clear") then _clear() end end
0
repos/xmake/xmake/plugins
repos/xmake/xmake/plugins/plugin/xmake.lua
--!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 plugin.lua -- task("plugin") set_category("plugin") on_run("main") set_menu { usage = "xmake plugin [options]", description = "Manage plugins of xmake.", options = { {'i', "install", "k", nil, "Install plugins." }, {'u', "update", "k", nil, "Update plugins." }, {'c', "clear", "k", nil, "Clear all installed plugins." }, {nil, "plugins", "v", nil, "The plugins path or url.", "e.g.", " $ xmake plugin --install https://github.com/xmake-io/xmake-plugins", " $ xmake plugin --update"} } }
0
repos/xmake/xmake/plugins
repos/xmake/xmake/plugins/doxygen/main.lua
--!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 main.lua -- -- imports import("core.base.option") import("core.project.config") import("core.project.project") import("lib.detect.find_tool") import("private.action.require.impl.packagenv") import("private.action.require.impl.install_packages") -- generate doxyfile function _generate_doxyfile(doxygen) -- generate the default doxyfile local doxyfile = path.join(project.directory(), "doxyfile") os.vrunv(doxygen.program, {"-g", doxyfile}) -- enable recursive -- -- RECURSIVE = YES -- io.gsub(doxyfile, "RECURSIVE%s-=%s-NO", "RECURSIVE = YES") -- set the source directory -- -- INPUT = xxx -- local srcdir = option.get("srcdir") if srcdir and os.isdir(srcdir) then io.gsub(doxyfile, "INPUT%s-=.-\n", format("INPUT = %s\n", srcdir)) end -- set the output directory -- -- OUTPUT_DIRECTORY = -- local outputdir = option.get("outputdir") or config.buildir() if outputdir then io.gsub(doxyfile, "OUTPUT_DIRECTORY%s-=.-\n", format("OUTPUT_DIRECTORY = %s\n", outputdir)) os.mkdir(outputdir) end -- set the project name -- -- PROJECT_NAME = -- local name = project.name() if name then io.gsub(doxyfile, "PROJECT_NAME%s-=.-\n", format("PROJECT_NAME = %s\n", name)) end return doxyfile end function main() -- load configuration config.load() -- enter the environments of doxygen local oldenvs = packagenv.enter("doxygen") -- find doxygen local packages = {} local doxygen = find_tool("doxygen") if not doxygen then table.join2(packages, install_packages("doxygen")) end -- enter the environments of installed packages for _, instance in ipairs(packages) do instance:envs_enter() end -- we need to force detect and flush detect cache after loading all environments if not doxygen then doxygen = find_tool("doxygen", {force = true}) end assert(doxygen, "doxygen not found!") -- get doxyfile first local doxyfile = "doxyfile" if not os.isfile(doxyfile) then doxyfile = _generate_doxyfile(doxygen) end assert(os.isfile(doxyfile), "%s not found!", doxyfile) -- set the project version -- -- PROJECT_NUMBER = -- local version = project.version() if version then io.gsub(doxyfile, "PROJECT_NUMBER%s-=.-\n", format("PROJECT_NUMBER = %s\n", version)) end -- generate document cprint("generating ..") os.vrunv(doxygen.program, {doxyfile}, {curdir = project.directory()}) -- done local outputdir = option.get("outputdir") or config.buildir() cprint("${bright green}result: ${default green}%s/html/index.html", outputdir) cprint("${color.success}doxygen ok!") os.setenvs(oldenvs) end