Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 | repos/xmake/xmake/templates/c | repos/xmake/xmake/templates/c/tbox.static/template.lua | template("tbox.static")
add_configfiles("xmake.lua")
add_configfiles("src/_demo/main.c")
add_configfiles("src/_demo/xmake.lua")
add_configfiles("src/_library/xmake.lua")
after_create(function (template, opt)
os.mv("src/_library", path.join("src", opt.targetname))
os.mv("src/_demo", path.join("src", opt.targetname .. "_demo"))
end)
|
0 | repos/xmake/xmake/templates/c/tbox.static | repos/xmake/xmake/templates/c/tbox.static/project/xmake.lua | set_xmakever("2.3.6")
set_warnings("all", "error")
set_languages("c99", "cxx11")
add_cxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing")
add_mxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing")
add_rules("mode.release", "mode.debug")
add_requires("tbox", {debug = is_mode("debug")})
if is_plat("windows") then
if is_mode("release") then
add_cxflags("-MT")
elseif is_mode("debug") then
add_cxflags("-MTd")
end
add_ldflags("-nodefaultlib:msvcrt.lib")
end
includes("src/${TARGETNAME}", "src/${TARGETNAME}_demo")
${FAQ}
|
0 | repos/xmake/xmake/templates/c/tbox.static/project/src | repos/xmake/xmake/templates/c/tbox.static/project/src/_library/interface.c | /* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "interface.h"
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
tb_int_t add(tb_int_t a, tb_int_t b)
{
return a + b;
}
|
0 | repos/xmake/xmake/templates/c/tbox.static/project/src | repos/xmake/xmake/templates/c/tbox.static/project/src/_library/interface.h | #ifndef INTERFACE_H
#define INTERFACE_H
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "tbox/tbox.h"
/* //////////////////////////////////////////////////////////////////////////////////////
* extern
*/
__tb_extern_c_enter__
/*! calculate add(a, b)
*
* @param a the first argument
* @param b the second argument
*
* @return the result
*/
tb_int_t add(tb_int_t a, tb_int_t b);
/* //////////////////////////////////////////////////////////////////////////////////////
* extern
*/
__tb_extern_c_leave__
#endif
|
0 | repos/xmake/xmake/templates/c/tbox.static/project/src | repos/xmake/xmake/templates/c/tbox.static/project/src/_library/xmake.lua | -- add target
target("${TARGETNAME}")
-- set kind
set_kind("static")
-- add definitions
add_defines("__tb_prefix__=\"${TARGETNAME}\"")
-- add the header files for installing
add_headerfiles("../(${TARGETNAME}/**.h)")
-- add includes directory
add_includedirs("..", {interface = true})
-- add packages
add_packages("tbox")
-- add files
add_files("*.c")
|
0 | repos/xmake/xmake/templates/c/tbox.static/project/src | repos/xmake/xmake/templates/c/tbox.static/project/src/_demo/main.c | /* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "${TARGETNAME}/interface.h"
/* //////////////////////////////////////////////////////////////////////////////////////
* main
*/
tb_int_t main(tb_int_t argc, tb_char_t** argv) {
if (tb_init(tb_null, tb_null)) {
tb_trace_i("hello tbox!");
tb_trace_i("add(1 + 1) = %d", add(1, 1));
tb_exit();
}
return 0;
}
|
0 | repos/xmake/xmake/templates/c/tbox.static/project/src | repos/xmake/xmake/templates/c/tbox.static/project/src/_demo/xmake.lua | target("demo")
set_kind("binary")
add_deps("${TARGETNAME}")
add_defines("__tb_prefix__=\"demo\"")
add_files("*.c")
add_packages("tbox")
|
0 | repos/xmake/xmake/templates/c | repos/xmake/xmake/templates/c/tbox.console/template.lua | template("tbox.console")
add_configfiles("xmake.lua")
add_configfiles("src/xmake.lua")
|
0 | repos/xmake/xmake/templates/c/tbox.console | repos/xmake/xmake/templates/c/tbox.console/project/xmake.lua | set_xmakever("2.3.6")
set_warnings("all", "error")
set_languages("c99", "cxx11")
add_cxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing")
add_mxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing")
add_rules("mode.release", "mode.debug")
add_requires("tbox", {debug = is_mode("debug")})
if is_plat("windows") then
if is_mode("release") then
add_cxflags("-MT")
elseif is_mode("debug") then
add_cxflags("-MTd")
end
add_ldflags("-nodefaultlib:msvcrt.lib")
end
includes("src")
|
0 | repos/xmake/xmake/templates/c/tbox.console/project | repos/xmake/xmake/templates/c/tbox.console/project/src/main.c | /* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "tbox/tbox.h"
/* //////////////////////////////////////////////////////////////////////////////////////
* main
*/
tb_int_t main(tb_int_t argc, tb_char_t** argv) {
if (tb_init(tb_null, tb_null)) {
tb_trace_i("hello tbox!");
tb_exit();
}
return 0;
}
|
0 | repos/xmake/xmake/templates/c/tbox.console/project | repos/xmake/xmake/templates/c/tbox.console/project/src/xmake.lua | -- add target
target("${TARGETNAME}")
-- set kind
set_kind("binary")
-- add definitions
add_defines("__tb_prefix__=\"${TARGETNAME}\"")
-- add packages
add_packages("tbox")
-- add files
add_files("*.c")
|
0 | repos/xmake/xmake/templates/c | repos/xmake/xmake/templates/c/module.shared/template.lua | template("module.shared")
add_configfiles("xmake.lua")
|
0 | repos/xmake/xmake/templates/c/module.shared | repos/xmake/xmake/templates/c/module.shared/project/xmake.lua | add_rules("mode.debug", "mode.release")
add_moduledirs("modules")
target("${TARGETNAME}")
set_kind("binary")
add_files("src/*.c")
on_config(function (target)
import("shared.foo")
print("shared: 1 + 1 = %s", foo.add(1, 1))
print("shared: 1 - 1 = %s", foo.sub(1, 1))
end)
${FAQ}
|
0 | repos/xmake/xmake/templates/c/module.shared/project/modules/shared | repos/xmake/xmake/templates/c/module.shared/project/modules/shared/foo/xmake.lua | add_rules("mode.debug", "mode.release")
target("foo")
add_rules("module.shared")
add_files("src/foo.c")
|
0 | repos/xmake/xmake/templates/c/module.shared/project/modules/shared/foo | repos/xmake/xmake/templates/c/module.shared/project/modules/shared/foo/src/foo.c | #include <xmi.h>
static int add(lua_State* lua) {
int a = lua_tointeger(lua, 1);
int b = lua_tointeger(lua, 2);
lua_pushinteger(lua, a + b);
return 1;
}
static int sub(lua_State* lua) {
int a = lua_tointeger(lua, 1);
int b = lua_tointeger(lua, 2);
lua_pushinteger(lua, a - b);
return 1;
}
int luaopen(foo, lua_State* lua) {
static const luaL_Reg funcs[] = {
{"add", add},
{"sub", sub},
{NULL, NULL}
};
lua_newtable(lua);
luaL_setfuncs(lua, funcs, 0);
return 1;
}
|
0 | repos/xmake/xmake/templates/c/module.shared/project | repos/xmake/xmake/templates/c/module.shared/project/src/main.c | #include <stdio.h>
int main(int argc, char** argv) {
printf("hello world!\n");
return 0;
}
|
0 | repos/xmake/xmake/templates/c | repos/xmake/xmake/templates/c/xmake.cli/template.lua | template("xmake.cli")
add_configfiles("src/lni/main.c")
add_configfiles("xmake.lua")
|
0 | repos/xmake/xmake/templates/c/xmake.cli | repos/xmake/xmake/templates/c/xmake.cli/project/xmake.lua | add_rules("mode.debug", "mode.release")
add_requires("libxmake", {debug = is_mode("debug")})
target("${TARGETNAME}")
add_rules("xmake.cli")
add_files("src/lni/*.c")
add_packages("libxmake")
${FAQ} |
0 | repos/xmake/xmake/templates/c/xmake.cli/project/src | repos/xmake/xmake/templates/c/xmake.cli/project/src/lni/main.c | #include <xmake/xmake.h>
static tb_int_t lni_test_hello(lua_State* lua) {
lua_pushliteral(lua, "hello xmake!");
return 1;
}
static tb_void_t lni_initalizer(xm_engine_ref_t engine, lua_State* lua) {
static luaL_Reg const lni_test_funcs[] = {
{"hello", lni_test_hello}
, {tb_null, tb_null}
};
xm_engine_register(engine, "test", lni_test_funcs);
}
tb_int_t main(tb_int_t argc, tb_char_t** argv) {
tb_char_t* taskargv[] = {"lua", "-D", "lua.main", tb_null};
return xm_engine_run("${TARGETNAME}", argc, argv, taskargv, lni_initalizer);
}
|
0 | repos/xmake/xmake/templates/c/xmake.cli/project/src | repos/xmake/xmake/templates/c/xmake.cli/project/src/lua/main.lua | import("core.base.option")
import("lib.lni.test")
function main ()
print(test.hello())
local argv = option.get("arguments")
if argv then
print(argv)
end
end
|
0 | repos/xmake/xmake/templates/c | repos/xmake/xmake/templates/c/tbox.shared/template.lua | template("tbox.shared")
add_configfiles("xmake.lua")
add_configfiles("src/_demo/main.c")
add_configfiles("src/_demo/xmake.lua")
add_configfiles("src/_library/xmake.lua")
after_create(function (template, opt)
os.mv("src/_library", path.join("src", opt.targetname))
os.mv("src/_demo", path.join("src", opt.targetname .. "_demo"))
end)
|
0 | repos/xmake/xmake/templates/c/tbox.shared | repos/xmake/xmake/templates/c/tbox.shared/project/xmake.lua | set_xmakever("2.3.6")
set_warnings("all", "error")
set_languages("c99", "cxx11")
add_cxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing")
add_mxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing")
add_rules("mode.release", "mode.debug")
add_requires("tbox", {debug = is_mode("debug")})
if is_plat("windows") then
if is_mode("release") then
add_cxflags("-MT")
elseif is_mode("debug") then
add_cxflags("-MTd")
end
add_ldflags("-nodefaultlib:msvcrt.lib")
end
includes("src/${TARGETNAME}", "src/${TARGETNAME}_demo")
${FAQ}
|
0 | repos/xmake/xmake/templates/c/tbox.shared/project/src | repos/xmake/xmake/templates/c/tbox.shared/project/src/_library/interface.c | /* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "interface.h"
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
tb_int_t add(tb_int_t a, tb_int_t b) {
return a + b;
}
|
0 | repos/xmake/xmake/templates/c/tbox.shared/project/src | repos/xmake/xmake/templates/c/tbox.shared/project/src/_library/interface.h | #ifndef INTERFACE_H
#define INTERFACE_H
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "tbox/tbox.h"
/* //////////////////////////////////////////////////////////////////////////////////////
* extern
*/
__tb_extern_c_enter__
/*! calculate add(a, b)
*
* @param a the first argument
* @param b the second argument
*
* @return the result
*/
__tb_export__ tb_int_t add(tb_int_t a, tb_int_t b);
/* //////////////////////////////////////////////////////////////////////////////////////
* extern
*/
__tb_extern_c_leave__
#endif
|
0 | repos/xmake/xmake/templates/c/tbox.shared/project/src | repos/xmake/xmake/templates/c/tbox.shared/project/src/_library/xmake.lua | -- add target
target("${TARGETNAME}")
-- set kind
set_kind("shared")
-- add definitions
add_defines("__tb_prefix__=\"${TARGETNAME}\"")
-- add the header files for installing
add_headerfiles("../(${TARGETNAME}/**.h)")
-- add includes directory
add_includedirs("..", {interface = true})
-- add packages
add_packages("tbox")
-- add files
add_files("*.c")
|
0 | repos/xmake/xmake/templates/c/tbox.shared/project/src | repos/xmake/xmake/templates/c/tbox.shared/project/src/_demo/main.c | /* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "${TARGETNAME}/interface.h"
/* //////////////////////////////////////////////////////////////////////////////////////
* main
*/
tb_int_t main(tb_int_t argc, tb_char_t** argv) {
if (tb_init(tb_null, tb_null)) {
tb_trace_i("hello tbox!");
tb_trace_i("add(1 + 1) = %d", add(1, 1));
tb_exit();
}
return 0;
}
|
0 | repos/xmake/xmake/templates/c/tbox.shared/project/src | repos/xmake/xmake/templates/c/tbox.shared/project/src/_demo/xmake.lua | target("demo")
set_kind("binary")
add_deps("${TARGETNAME}")
add_defines("__tb_prefix__=\"demo\"")
add_files("*.c")
add_packages("tbox")
|
0 | repos/xmake/xmake/templates/go | repos/xmake/xmake/templates/go/static/template.lua | template("static")
add_configfiles("xmake.lua")
|
0 | repos/xmake/xmake/templates/go/static | repos/xmake/xmake/templates/go/static/project/xmake.lua | add_rules("mode.debug", "mode.release")
target("module")
set_kind("static")
add_files("src/test/*.go")
target("${TARGETNAME}_demo")
set_kind("binary")
add_deps("module")
add_files("src/*.go")
${FAQ}
|
0 | repos/xmake/xmake/templates/go/static/project | repos/xmake/xmake/templates/go/static/project/src/main.go | package main
func main() {
Run()
}
|
0 | repos/xmake/xmake/templates/go/static/project | repos/xmake/xmake/templates/go/static/project/src/test.go | package main
import (
"fmt"
"module"
)
func Run() {
fmt.Printf("add: %d\n", module.Add(1, 2));
fmt.Printf("sub: %d\n", module.Sub(1, 2));
}
|
0 | repos/xmake/xmake/templates/go/static/project/src | repos/xmake/xmake/templates/go/static/project/src/test/add.go | package module
func Add(a int, b int) int {
return a + b;
}
|
0 | repos/xmake/xmake/templates/go/static/project/src | repos/xmake/xmake/templates/go/static/project/src/test/sub.go | package module
func Sub(a int, b int) int {
return a - b;
}
|
0 | repos/xmake/xmake/templates/go | repos/xmake/xmake/templates/go/console/template.lua | template("console")
add_configfiles("xmake.lua")
|
0 | repos/xmake/xmake/templates/go/console | repos/xmake/xmake/templates/go/console/project/xmake.lua | add_rules("mode.debug", "mode.release")
target("${TARGETNAME}")
set_kind("binary")
add_files("src/*.go")
${FAQ}
|
0 | repos/xmake/xmake/templates/go/console/project | repos/xmake/xmake/templates/go/console/project/src/main.go | package main
import "fmt"
func main() {
fmt.Println("hello xmake!")
}
|
0 | repos/xmake/xmake/templates/fortran | repos/xmake/xmake/templates/fortran/shared/template.lua | template("shared")
add_configfiles("xmake.lua")
|
0 | repos/xmake/xmake/templates/fortran/shared | repos/xmake/xmake/templates/fortran/shared/project/xmake.lua | add_rules("mode.debug", "mode.release")
target("${TARGETNAME}_lib")
set_kind("shared")
add_files("src/test.f90")
target("${TARGETNAME}")
set_kind("binary")
add_deps("${TARGETNAME}_lib")
add_files("src/main.f90")
|
0 | repos/xmake/xmake/templates/fortran | repos/xmake/xmake/templates/fortran/static/template.lua | template("static")
add_configfiles("xmake.lua")
|
0 | repos/xmake/xmake/templates/fortran/static | repos/xmake/xmake/templates/fortran/static/project/xmake.lua | add_rules("mode.debug", "mode.release")
target("${TARGETNAME}_lib")
set_kind("static")
add_files("src/test.f90")
target("${TARGETNAME}")
set_kind("binary")
add_deps("${TARGETNAME}_lib")
add_files("src/main.f90")
|
0 | repos/xmake/xmake/templates/fortran | repos/xmake/xmake/templates/fortran/console/template.lua | template("console")
add_configfiles("xmake.lua")
|
0 | repos/xmake/xmake/templates/fortran/console | repos/xmake/xmake/templates/fortran/console/project/xmake.lua | add_rules("mode.debug", "mode.release")
target("${TARGETNAME}")
set_kind("binary")
add_files("src/*.f90")
|
0 | repos/xmake/xmake/repository/packages/7 | repos/xmake/xmake/repository/packages/7/7z/xmake.lua | package("7z")
set_kind("binary")
set_homepage("https://www.7-zip.org/")
set_description("A file archiver with a high compression ratio.")
if is_host("windows") then
if is_arch("x64", "x86_64") then
set_urls("https://github.com/xmake-mirror/7zip/releases/download/$(version)/7z$(version)-x64.zip",
"https://gitlab.com/xmake-mirror/7zip-releases/raw/master/7z$(version)-x64.zip")
add_versions("19.00", "fc21cf510d70a69bfa8e5b0449fe0a054fb76e2f8bd568364821f319c8b1d86d")
add_versions("18.05", "e6e2d21e2c482f1b1c5a6d21ed80800ce1273b902cf4b9afa68621545540ee2f")
else
set_urls("https://github.com/xmake-mirror/7zip/releases/download/$(version)/7z$(version)-x86.zip",
"https://gitlab.com/xmake-mirror/7zip-releases/raw/master/7z$(version)-x86.zip")
add_versions("19.00", "f84fab081a2d8a6b5868a2eaf01cd56017363fb24560259cea80567f8062334f")
add_versions("18.05", "544c37bebee30437aba405071484e0ac6310332b4bdabe4ca7420a800d4b4b5e")
end
else
set_urls("https://github.com/xmake-mirror/7zip/archive/refs/tags/$(version).tar.gz",
"https://github.com/xmake-mirror/7zip.git")
add_versions("21.02", "b2a4c5bec8207508b26f94507f62f5a79c57ae9ab77dbf393f3b2fc8eef2e382")
add_patches("21.02", path.join(os.scriptdir(), "patches", "21.02", "backport-21.03-fix-for-GCC-10.patch"), "f1d8fa0bbb25123b28e9b2842da07604238b77e51b918260a369f97c2f694c89")
end
on_install("macosx", "linux", function (package)
-- Clang has some indentation warnings that fails compilation using -Werror, remove it
io.replace("CPP/7zip/7zip_gcc.mak", "CFLAGS_WARN_WALL = -Wall -Werror -Wextra", "CFLAGS_WARN_WALL = -Wall -Wextra", {plain = true})
os.cd("CPP/7zip/Bundles/Alone2")
os.vrun("make -j -f makefile.gcc")
local bin = package:installdir("bin")
os.cp("_o/7zz", bin)
os.ln(bin .. "/7zz", bin .. "/7z")
end)
on_install("windows", function (package)
os.cp("*", package:installdir("bin"))
--[[
Build code for windows
local archdir = package:is_arch("x64", "x86_64") and "x64" or "x86"
os.cd("CPP/7zip/Bundles/Alone2")
local configs = {"-f", "makefile"}
table.insert(configs, "PLATFORM=" .. archdir)
import("package.tools.nmake").build(package, configs)
local bin = package:installdir("bin")
os.cp(archdir .. "/7zz.exe", bin .. "/7z.exe")
]]
end)
on_test(function (package)
os.vrun("7z --help")
end)
|
0 | repos/xmake/xmake/repository/packages/7/7z/patches | repos/xmake/xmake/repository/packages/7/7z/patches/21.02/backport-21.03-fix-for-GCC-10.patch | diff --git a/CPP/7zip/Common/OffsetStream.cpp b/CPP/7zip/Common/OffsetStream.cpp
index b3e710f..b16124c 100644
--- a/CPP/7zip/Common/OffsetStream.cpp
+++ b/CPP/7zip/Common/OffsetStream.cpp
@@ -20,13 +20,13 @@ STDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *proc
STDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
{
- UInt64 absoluteNewPosition;
if (seekOrigin == STREAM_SEEK_SET)
{
if (offset < 0)
return HRESULT_WIN32_ERROR_NEGATIVE_SEEK;
offset += _offset;
}
+ UInt64 absoluteNewPosition = 0; // =0 for gcc-10
HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);
if (newPosition)
*newPosition = absoluteNewPosition - _offset;
|
0 | repos/xmake/xmake/repository/packages/g | repos/xmake/xmake/repository/packages/g/git/xmake.lua | package("git")
set_kind("binary")
set_homepage("https://git-scm.com/")
set_description("A free and open source distributed version control system")
if is_host("windows") then
if os.arch() == "x64" then
add_urls("https://github.com/git-for-windows/git/releases/download/v$(version).windows.1/MinGit-$(version)-64-bit.zip",
"https://gitlab.com/xmake-mirror/git-for-windows-releases/raw/master/MinGit-$(version)-64-bit.zip")
if winos.version():gt("winxp") then
add_versions("2.20.0", "f577f81c401535858761fc4857a105337cc12880b79e72f89d0740167083d287")
else
add_versions("2.10.0", "2e1101ec57da526728704c04792293613f3c5aa18e65f13a4129d00b54de2087")
end
else
add_urls("https://github.com/git-for-windows/git/releases/download/v$(version).windows.1/MinGit-$(version)-32-bit.zip",
"https://gitlab.com/xmake-mirror/git-for-windows-releases/raw/master/MinGit-$(version)-32-bit.zip")
if winos.version():gt("winxp") then
add_versions("2.20.0", "39d3dce9f67d7ae884edf0416d28f6dd8e24b6326de8e509613a2b12fb4f0820")
else
add_versions("2.10.0", "36f890870126dcf840d87eaec7e55b8a483bc336ebf8970de2f9d549a3cfc195")
end
end
end
on_load("windows", function (package)
package:addenv("PATH", path.join("share", "MinGit", package:is_arch("x86_64", "x64") and "mingw64" or "mingw32", "bin"))
package:addenv("PATH", path.join("share", "MinGit", "cmd"))
end)
on_install("macosx", "linux", "bsd", function (package)
import("package.manager.install_package")("git")
end)
on_install("windows", function (package)
os.cp("*", package:installdir("share/MinGit"))
end)
on_test(function (package)
os.vrun("git --version")
end)
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_cincludes.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 check_cincludes.lua
--
-- check include c files and add macro definition
--
-- e.g.
--
-- check_cincludes("HAS_STRING_H", "string.h")
-- check_cincludes("HAS_STRING_AND_STDIO_H", {"string.h", "stdio.h"})
--
function check_cincludes(definition, includes, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_cincludes(includes)
if opt.includedirs then
add_includedirs(opt.includedirs)
end
add_defines(definition)
option_end()
interp_restore_scope()
add_options(optname)
end
-- check include c files and add macro definition to the configuration files
--
-- e.g.
--
-- configvar_check_cincludes("HAS_STRING_H", "string.h")
-- configvar_check_cincludes("HAS_STRING_H", "string.h", {default = 0})
-- configvar_check_cincludes("HAS_STRING_AND_STDIO_H", {"string.h", "stdio.h"})
--
function configvar_check_cincludes(definition, includes, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_cincludes(includes)
if opt.includedirs then
add_includedirs(opt.includedirs)
end
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_cflags.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 check_cflags.lua
--
-- check c flags and add macro definition
--
-- e.g.
--
-- check_cflags("HAS_SSE2", "-msse2")
-- check_cflags("HAS_SSE2", {"-msse", "-msse2"})
--
function check_cflags(definition, flags, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_defines(definition)
on_check(function (option)
import("core.tool.compiler")
if compiler.has_flags("c", flags, opt) then
option:enable(true)
end
end)
option_end()
interp_restore_scope()
add_options(optname)
end
-- check c flags and add macro definition to the configuration flags
--
-- e.g.
--
-- configvar_check_cflags("HAS_SSE2", "-msse2")
-- configvar_check_cflags("HAS_SSE2", {"-msse", "-msse2"})
-- configvar_check_cflags("HAS_SSE2", "-msse2", {default = 0})
-- configvar_check_cflags("SSE_STR=2", "-msse2")
-- configvar_check_cflags("SSE=2", "-msse2", {quote = false})
--
function configvar_check_cflags(definition, flags, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
on_check(function (option)
import("core.tool.compiler")
if compiler.has_flags("c", flags, opt) then
option:enable(true)
end
end)
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_macros.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 check_macros.lua
--
-- check macros and add macro definition
--
-- e.g.
--
-- check_macros("HAS_GCC", "__GNUC__")
-- check_macros("NO_GCC", "__GNUC__", {defined = false})
-- check_macros("HAS_CXX20", "__cplusplus >= 202002L", {languages = "c++20"})
--
function check_macros(definition, macros, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local snippets = {}
interp_save_scope()
option(optname)
set_showmenu(false)
for _, macro in ipairs(macros) do
if macro:find(' ', 1, true) then
table.insert(snippets, ([[
#if %s
#else
# #error %s is not satisfied!
#endif
]]):format(macro, macro))
else
table.insert(snippets, ([[
#if%s %s
#else
# #error %s is not defined!
#endif
]]):format(opt.defined ~= false and "def" or "ndef", macro, macro))
end
end
if opt.languages and opt.languages:startswith("c++") then
add_cxxsnippets(definition, table.concat(snippets, "\n"))
else
add_csnippets(definition, table.concat(snippets, "\n"))
end
add_defines(definition)
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.cxxflags then
add_cxxflags(opt.cxxflags)
end
option_end()
interp_restore_scope()
add_options(optname)
end
-- check macros and add macro definition to the configuration files
--
-- e.g.
-- configvar_check_macros("HAS_GCC", "__GNUC__")
-- configvar_check_macros("NO_GCC", "__GNUC__", {defined = false})
-- configvar_check_macros("HAS_CXX20", "__cplusplus >= 202002L", {languages = "c++20"})
function configvar_check_macros(definition, macros, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
local snippets = {}
interp_save_scope()
option(optname)
set_showmenu(false)
for _, macro in ipairs(macros) do
if macro:find(' ', 1, true) then
table.insert(snippets, ([[
#if %s
#else
# #error %s is not satisfied!
#endif
]]):format(macro, macro))
else
table.insert(snippets, ([[
#if%s %s
#else
# #error %s is not defined!
#endif
]]):format(opt.defined ~= false and "def" or "ndef", macro, macro))
end
end
if opt.languages and opt.languages:startswith("c++") then
add_cxxsnippets(definition, table.concat(snippets, "\n"))
else
add_csnippets(definition, table.concat(snippets, "\n"))
end
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.cxxflags then
add_cxxflags(opt.cxxflags)
end
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_cxxfuncs.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 check_cxxfuncs.lua
--
-- check c++ funcs and add macro definition
--
-- the function syntax
-- - sigsetjmp
-- - sigsetjmp((void*)0, 0)
-- - sigsetjmp{sigsetjmp((void*)0, 0);}
-- - sigsetjmp{int a = 0; sigsetjmp((void*)a, a);}
--
-- e.g.
--
-- check_cxxfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}, links = {}})
-- check_cxxfuncs("HAS_SETJMP", {"setjmp", "sigsetjmp{sigsetjmp((void*)0, 0);}"})
--
function check_cxxfuncs(definition, funcs, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_cxxfuncs(funcs)
add_defines(definition)
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cxxincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.cxxflags then
add_cxxflags(opt.cxxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.warnings then
set_warnings(opt.warnings)
end
option_end()
interp_restore_scope()
add_options(optname)
end
-- check c++ funcs and add macro definition to the configuration files
--
-- e.g.
--
-- configvar_check_cxxfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}, links = {}})
-- configvar_check_cxxfuncs("HAS_SETJMP", {"setjmp", "sigsetjmp{sigsetjmp((void*)0, 0);}"})
-- configvar_check_cxxfuncs("HAS_SETJMP", "setjmp", {includes = {"setjmp.h"}, default = 0})
-- configvar_check_cxxfuncs("CUSTOM_SETJMP=setjmp", "setjmp", {includes = {"setjmp.h"}, default = "", quote = false})
--
function configvar_check_cxxfuncs(definition, funcs, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_cxxfuncs(funcs)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cxxincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.cxxflags then
add_cxxflags(opt.cxxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.warnings then
set_warnings(opt.warnings)
end
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_syslinks.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 check_syslinks.lua
--
-- check links and add macro definition
--
-- e.g.
--
-- check_syslinks("HAS_PTHREAD", "pthread")
-- check_syslinks("HAS_PTHREAD", {"pthread", "m", "dl"})
--
function check_syslinks(definition, links, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_syslinks(links)
add_defines(definition)
option_end()
interp_restore_scope()
add_options(optname)
end
-- check links and add macro definition to the configuration files
--
-- e.g.
--
-- configvar_check_syslinks("HAS_PTHREAD", "pthread")
-- configvar_check_syslinks("HAS_PTHREAD", "pthread", {default = 0})
-- configvar_check_syslinks("HAS_PTHREAD", {"pthread", "m", "dl"})
--
function configvar_check_syslinks(definition, links, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_syslinks(links)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_cfuncs.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 check_cfuncs.lua
--
-- check c funcs and add macro definition
--
-- the function syntax
-- - sigsetjmp
-- - sigsetjmp((void*)0, 0)
-- - sigsetjmp{sigsetjmp((void*)0, 0);}
-- - sigsetjmp{int a = 0; sigsetjmp((void*)a, a);}
--
-- e.g.
--
-- check_cfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}, links = {}})
-- check_cfuncs("HAS_SETJMP", {"setjmp", "sigsetjmp{sigsetjmp((void*)0, 0);}"})
--
function check_cfuncs(definition, funcs, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_cfuncs(funcs)
add_defines(definition)
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.warnings then
set_warnings(opt.warnings)
end
option_end()
interp_restore_scope()
add_options(optname)
end
-- check c funcs and add macro definition to the configuration files
--
-- e.g.
--
-- configvar_check_cfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}, links = {}})
-- configvar_check_cfuncs("HAS_SETJMP", {"setjmp", "sigsetjmp{sigsetjmp((void*)0, 0);}"})
-- configvar_check_cfuncs("HAS_SETJMP", "setjmp", {includes = {"setjmp.h"}, default = 0})
-- configvar_check_cfuncs("CUSTOM_SETJMP=setjmp", "setjmp", {includes = {"setjmp.h"}, default = "", quote = false})
--
function configvar_check_cfuncs(definition, funcs, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_cfuncs(funcs)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.warnings then
set_warnings(opt.warnings)
end
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_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 check_features.lua
--
-- check features and add macro definition
--
-- e.g.
--
-- check_features("HAS_CONSTEXPR", "cxx_constexpr")
-- check_features("HAS_CONSEXPR_AND_STATIC_ASSERT", {"cxx_constexpr", "c_static_assert"}, {cxflags = "", languages = "c++11"})
--
function check_features(definition, features, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_features(features)
add_defines(definition)
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.cxxflags then
add_cxxflags(opt.cxxflags)
end
option_end()
interp_restore_scope()
add_options(optname)
end
-- check features and add macro definition to the configuration files
--
-- e.g.
--
-- configvar_check_features("HAS_CONSTEXPR", "cxx_constexpr")
-- configvar_check_features("HAS_CONSTEXPR", "cxx_constexpr", {default = 0})
-- configvar_check_features("HAS_CONSEXPR_AND_STATIC_ASSERT", {"cxx_constexpr", "c_static_assert"}, {languages = "c++11"})
--
function configvar_check_features(definition, features, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_features(features)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.cxxflags then
add_cxxflags(opt.cxxflags)
end
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_cxxflags.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 check_cxxflags.lua
--
-- check c++ flags and add macro definition
--
-- e.g.
--
-- check_cxxflags("HAS_SSE2", "-msse2")
-- check_cxxflags("HAS_SSE2", {"-msse", "-msse2"})
--
function check_cxxflags(definition, flags, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_defines(definition)
on_check(function (option)
import("core.tool.compiler")
if compiler.has_flags("cxx", flags, opt) then
option:enable(true)
end
end)
option_end()
interp_restore_scope()
add_options(optname)
end
-- check c++ flags and add macro definition to the configuration flags
--
-- e.g.
--
-- configvar_check_cxxflags("HAS_SSE2", "-msse2")
-- configvar_check_cxxflags("HAS_SSE2", {"-msse", "-msse2"})
-- configvar_check_cxxflags("HAS_SSE2", "-msse2", {default = 0})
-- configvar_check_cxxflags("SSE_STR=2", "-msse2")
-- configvar_check_cxxflags("SSE=2", "-msse2", {quote = false})
--
function configvar_check_cxxflags(definition, flags, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
on_check(function (option)
import("core.tool.compiler")
if compiler.has_flags("cxx", flags, opt) then
option:enable(true)
end
end)
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_cxxsnippets.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 check_cxxsnippets.lua
--
-- check c++ snippets and add macro definition
--
-- e.g.
--
-- check_cxxsnippets("HAS_STATIC_ASSERT", "static_assert(1, \"\");")
-- check_csnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true})
-- check_csnippets("PTR_SIZE", 'printf("%d", sizeof(void*)); return 0;', {output = true, number = true})
--
function check_cxxsnippets(definition, snippets, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_cxxsnippets(definition, snippets, {tryrun = opt.tryrun, output = opt.output})
if not opt.output then
add_defines(definition)
end
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cxxincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.cxxflags then
add_cxxflags(opt.cxxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.warnings then
set_warnings(opt.warnings)
end
if opt.output then
after_check(function (option)
if option:value() then
if opt.number then
option:add("defines", definition .. "=" .. tonumber(option:value()))
elseif opt.quote == false then
option:add("defines", definition .. "=" .. option:value())
else
option:add("defines", definition .. "=\"" .. option:value() .. "\"")
end
end
end)
end
option_end()
interp_restore_scope()
add_options(optname)
end
-- check c++ snippets and add macro definition to the configuration snippets
--
-- e.g.
--
-- configvar_check_cxxsnippets("HAS_STATIC_ASSERT", "static_assert(1, \"\");")
-- configvar_check_cxxsnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true})
-- configvar_check_cxxsnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true, default = 0})
-- configvar_check_cxxsnippets("LONG_SIZE=8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true, quote = false})
-- configvar_check_cxxsnippets("PTR_SIZE", 'printf("%d", sizeof(void*)); return 0;', {output = true, number = true})
--
function configvar_check_cxxsnippets(definition, snippets, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_cxxsnippets(definition, snippets, {tryrun = opt.tryrun, output = opt.output})
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cxxincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.cxxflags then
add_cxxflags(opt.cxxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.warnings then
set_warnings(opt.warnings)
end
if opt.output then
after_check(function (option)
if option:value() then
option:set("configvar", defname, opt.number and tonumber(option:value()) or option:value(), {quote = opt.quote})
end
end)
end
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_links.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 check_links.lua
--
-- check links and add macro definition
--
-- e.g.
--
-- check_links("HAS_PTHREAD", "pthread")
-- check_links("HAS_PTHREAD", {"pthread", "m", "dl"})
--
function check_links(definition, links, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_links(links)
add_defines(definition)
option_end()
interp_restore_scope()
add_options(optname)
end
-- check links and add macro definition to the configuration files
--
-- e.g.
--
-- configvar_check_links("HAS_PTHREAD", "pthread")
-- configvar_check_links("HAS_PTHREAD", "pthread", {default = 0})
-- configvar_check_links("HAS_PTHREAD", {"pthread", "m", "dl"})
--
function configvar_check_links(definition, links, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_links(links)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_csnippets.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 check_csnippets.lua
--
-- check c snippets and add macro definition
--
-- e.g.
--
-- check_csnippets("HAS_STATIC_ASSERT", "_Static_assert(1, \"\");", {includes = "stdio.h"})
-- check_csnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true})
-- check_csnippets("PTR_SIZE", 'printf("%d", sizeof(void*)); return 0;', {output = true, number = true})
--
function check_csnippets(definition, snippets, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_csnippets(definition, snippets, {tryrun = opt.tryrun, output = opt.output})
if not opt.output then
add_defines(definition)
end
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.warnings then
set_warnings(opt.warnings)
end
if opt.output then
after_check(function (option)
if option:value() then
if opt.number then
option:add("defines", definition .. "=" .. tonumber(option:value()))
elseif opt.quote == false then
option:add("defines", definition .. "=" .. option:value())
else
option:add("defines", definition .. "=\"" .. option:value() .. "\"")
end
end
end)
end
option_end()
interp_restore_scope()
add_options(optname)
end
-- check c snippets and add macro definition to the configuration snippets
--
-- e.g.
--
-- configvar_check_csnippets("HAS_STATIC_ASSERT", "_Static_assert(1, \"\");", {includes = "stdio.h"})
-- configvar_check_csnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true})
-- configvar_check_csnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true, default = 0})
-- configvar_check_csnippets("LONG_SIZE=8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true, quote = false})
-- configvar_check_csnippets("PTR_SIZE", 'printf("%d", sizeof(void*)); return 0;', {output = true, number = true})
--
function configvar_check_csnippets(definition, snippets, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_csnippets(definition, snippets, {tryrun = opt.tryrun, output = opt.output})
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.warnings then
set_warnings(opt.warnings)
end
if opt.output then
after_check(function (option)
if option:value() then
option:set("configvar", defname, opt.number and tonumber(option:value()) or option:value(), {quote = opt.quote})
end
end)
end
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_cxxincludes.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 check_cxxincludes.lua
--
-- check include c++ files and add macro definition
--
-- e.g.
--
-- check_cxxincludes("HAS_STRING_H", "string.h")
-- check_cxxincludes("HAS_STRING_AND_STDIO_H", {"string.h", "stdio.h"})
--
function check_cxxincludes(definition, includes, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_cxxincludes(includes)
add_defines(definition)
option_end()
interp_restore_scope()
add_options(optname)
end
-- check include c++ files and add macro definition to the configuration files
--
-- e.g.
--
-- configvar_check_cxxincludes("HAS_STRING_H", "string.h")
-- configvar_check_cxxincludes("HAS_STRING_H", "string.h", {default = 0})
-- configvar_check_cxxincludes("HAS_STRING_AND_STDIO_H", {"string.h", "stdio.h"})
--
function configvar_check_cxxincludes(definition, includes, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_cxxincludes(includes)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_bigendian.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) 2024, TBOOX Open Source Group.
--
-- @author CarbeneHu
-- @file check_bigendian.lua
--
-- check compiler byteorder(big-endian/little-endian) add to macro definition
--
-- from https://github.com/xmake-io/xmake/issues/4843
--
-- e.g.
--
-- check_bigendian("IS_BIG_ENDIAN") => IS_BIG_ENDIAN=0
--
-- configvar_check_bigendian("IS_BIG_ENDIAN") => #define IS_BIG_ENDIAN 0
--
local check_bigendian_template = [[
#include <inttypes.h>
/* A 16 bit integer is required. */
typedef uint16_t byteorder_int16_t;
/* On a little endian machine, these 16bit ints will give "THIS IS LITTLE ENDIAN."
On a big endian machine the characters will be exchanged pairwise. */
const byteorder_int16_t info_little[] = {0x4854, 0x5349, 0x4920, 0x2053, 0x494c, 0x5454, 0x454c, 0x4520, 0x444e, 0x4149, 0x2e4e, 0x0000};
/* on a big endian machine, these 16bit ints will give "THIS IS BIG ENDIAN."
On a little endian machine the characters will be exchanged pairwise. */
const byteorder_int16_t info_big[] = {0x5448, 0x4953, 0x2049, 0x5320, 0x4249, 0x4720, 0x454e, 0x4449, 0x414e, 0x2e2e, 0x0000};
int main(int argc, char *argv[])
{
int require = 0;
require += info_little[argc];
require += info_big[argc];
(void)argv;
return require;
}]]
local function _byteorder_binary_match(content)
local match = content:match("THIS IS BIG ENDIAN")
return match and true or false
end
function check_bigendian(definition, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_cxxsnippets(definition, check_bigendian_template, {binary_match = _byteorder_binary_match})
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cxxincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.warnings then
set_warnings(opt.warnings)
end
after_check(function(option)
option:add("defines", definition .. "=" .. (option:value() and 1 or 0))
end)
option_end()
interp_restore_scope()
add_options(optname)
end
function configvar_check_bigendian(definition, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_cxxsnippets(definition, check_bigendian_template, {binary_match = _byteorder_binary_match})
if opt.default == nil then
set_configvar(defname, defval or 1, { quote = false })
end
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cxxincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.warnings then
set_warnings(opt.warnings)
end
after_check(function(option)
option:set("configvar", defname, option:value() and 1 or 0, { quote = false })
end)
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, { quote = false })
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_ctypes.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 check_ctypes.lua
--
-- check c types and add macro definition
--
-- e.g.
--
-- check_ctypes("HAS_WCHAR", "wchar_t")
-- check_ctypes("HAS_WCHAR_AND_FLOAT", {"wchar_t", "float"})
--
function check_ctypes(definition, types, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_ctypes(types)
add_defines(definition)
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.includes then
add_cincludes(opt.includes)
end
option_end()
interp_restore_scope()
add_options(optname)
end
-- check c types and add macro definition to the configuration types
--
-- e.g.
--
-- configvar_check_ctypes("HAS_WCHAR", "wchar_t")
-- configvar_check_ctypes("HAS_WCHAR", "wchar_t", {default = 0})
-- configvar_check_ctypes("CUSTOM_WCHAR=wchar_t", "wchar_t", {default = "", quote = false})
-- configvar_check_ctypes("HAS_WCHAR_AND_FLOAT", {"wchar_t", "float"})
--
function configvar_check_ctypes(definition, types, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_ctypes(types)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.includes then
add_cincludes(opt.includes)
end
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_cxxtypes.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 check_cxxtypes.lua
--
-- check c++ types and add macro definition
--
-- e.g.
--
-- check_cxxtypes("HAS_WCHAR", "wchar_t")
-- check_cxxtypes("HAS_WCHAR_AND_FLOAT", {"wchar_t", "float"})
--
function check_cxxtypes(definition, types, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
interp_save_scope()
option(optname)
set_showmenu(false)
add_cxxtypes(types)
add_defines(definition)
if opt.languages then
set_languages(opt.languages)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.cxxflags then
add_cxxflags(opt.cxxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.includes then
add_cxxincludes(opt.includes)
end
option_end()
interp_restore_scope()
add_options(optname)
end
-- check c++ types and add macro definition to the configuration types
--
-- e.g.
--
-- configvar_check_cxxtypes("HAS_WCHAR", "wchar_t")
-- configvar_check_cxxtypes("HAS_WCHAR", "wchar_t", {default = 0})
-- configvar_check_cxxtypes("CUSTOM_WCHAR=wchar_t", "wchar_t", {default = "", quote = false})
-- configvar_check_cxxtypes("HAS_WCHAR_AND_FLOAT", {"wchar_t", "float"})
--
function configvar_check_cxxtypes(definition, types, opt)
opt = opt or {}
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_cxxtypes(types)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.cxxflags then
add_cxxflags(opt.cxxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.includes then
add_cxxincludes(opt.includes)
end
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/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 xmake.lua
--
includes("@builtin/check/check_cflags.lua")
includes("@builtin/check/check_cfuncs.lua")
includes("@builtin/check/check_cincludes.lua")
includes("@builtin/check/check_csnippets.lua")
includes("@builtin/check/check_ctypes.lua")
includes("@builtin/check/check_cxxflags.lua")
includes("@builtin/check/check_cxxfuncs.lua")
includes("@builtin/check/check_cxxincludes.lua")
includes("@builtin/check/check_cxxsnippets.lua")
includes("@builtin/check/check_cxxtypes.lua")
includes("@builtin/check/check_features.lua")
includes("@builtin/check/check_links.lua")
includes("@builtin/check/check_macros.lua")
includes("@builtin/check/check_syslinks.lua")
includes("@builtin/check/check_sizeof.lua")
includes("@builtin/check/check_bigendian.lua")
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/check/check_sizeof.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) 2023, TBOOX Open Source Group.
--
-- @author zeromake
-- @file check_sizeof.lua
--
-- check c sizeof(type) add to macro definition support cross compile
--
-- from https://github.com/xmake-io/xmake/issues/4345
--
-- e.g.
--
-- check_sizeof("SIZEOF_LONG", "long") => SIZEOF_LONG=4
--
-- configvar_check_sizeof("SIZEOF_LONG", "long") => #define SIZEOF_LONG 4
--
local binary_match_pattern = 'INFO:size%[(%d+)%]'
local check_sizeof_template = [[
#define SIZE (sizeof(${TYPE}))
static char info_size[] = {'I', 'N', 'F', 'O', ':', 's','i','z','e','[',
('0' + ((SIZE / 10000)%10)),
('0' + ((SIZE / 1000)%10)),
('0' + ((SIZE / 100)%10)),
('0' + ((SIZE / 10)%10)),
('0' + (SIZE % 10)),
']',
'\0'};
int main(int argc, char *argv[]) {
int require = 0;
require += info_size[argc];
(void)argv;
return require;
}]]
function _binary_match(content)
local match = content:match(binary_match_pattern)
if match then
return match:ltrim("0")
end
end
function check_sizeof(definition, typename, opt)
opt = opt or {}
if opt.number == nil then
opt.number = true
end
local optname = opt.name or ("__" .. definition)
local snippet = opt.snippet or ""
interp_save_scope()
option(optname)
set_showmenu(false)
add_cxxsnippets(definition, check_sizeof_template:gsub('${TYPE}', typename), {binary_match = _binary_match})
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cxxincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.warnings then
set_warnings(opt.warnings)
end
after_check(function (option)
if option:value() then
if opt.number then
option:add("defines", definition .. "=" .. tonumber(option:value()))
elseif opt.quote == false then
option:add("defines", definition .. "=" .. option:value())
else
option:add("defines", definition .. "=\"" .. option:value() .. "\"")
end
end
end)
option_end()
interp_restore_scope()
add_options(optname)
end
function configvar_check_sizeof(definition, typename, opt)
opt = opt or {}
if opt.number == nil then
opt.number = true
end
local optname = opt.name or ("__" .. definition)
local defname, defval = table.unpack(definition:split('='))
interp_save_scope()
option(optname)
set_showmenu(false)
add_cxxsnippets(definition, check_sizeof_template:gsub('${TYPE}', typename), {binary_match = _binary_match})
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cxxincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
if opt.defines then
add_defines(opt.defines)
end
if opt.warnings then
set_warnings(opt.warnings)
end
after_check(function (option)
if option:value() then
option:set("configvar", defname, opt.number and tonumber(option:value()) or option:value(), {quote = opt.quote})
end
end)
option_end()
interp_restore_scope()
if opt.default == nil then
add_options(optname)
else
set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = true})
end
end
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/xpack/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 xmake.lua
--
-- Define xpack interfaces to generate installation package. e.g. nsis, deb, rpm, ...
--
-- And we can call `xmake pack` plugin to pack them.
--
-- @see https://github.com/xmake-io/xmake/issues/1433
--
-- define apis
local apis = {
values = {
-- set package version, we will also get it from project/target
"xpack.set_version",
-- set package homepage url
"xpack.set_homepage",
-- set package title
"xpack.set_title",
-- set author
"xpack.set_author",
-- set maintainer,
"xpack.set_maintainer",
-- set package description
"xpack.set_description",
-- set input kind, e.g. binary, source
"xpack.set_inputkind",
-- set package copyright
"xpack.set_copyright",
-- set company name
"xpack.set_company",
-- set package formats, e.g. nsis, deb, srpm, rpm, targz, zip, srctargz, srczip, runself, ...
-- we can also add custom formats
"xpack.set_formats",
-- set the base name of the output file
"xpack.set_basename",
-- set the extension of the output file
"xpack.set_extension",
-- add targets to be packaged
"xpack.add_targets",
-- add package components
"xpack.add_components",
-- set installed binary directory, e.g. bin
"xpack.set_bindir",
-- set installed library directory, e.g. lib
"xpack.set_libdir",
-- set installed include directory, e.g. include
"xpack.set_includedir",
-- set prefix directory, e.g. prefixdir/bin, prefixdir/lib ..
"xpack.set_prefixdir",
-- add build requires for source inputkind
"xpack.add_buildrequires",
-- set nsis display icon
"xpack.set_nsis_displayicon",
-- set package component title
"xpack_component.set_title",
-- set package component description
"xpack_component.set_description",
-- enable/disable this component by default
"xpack_component.set_default"
},
paths = {
-- set the spec file path, support the custom variable pattern, e.g. set_specfile("", {pattern = "%${([^\n]-)}"})
"xpack.set_specfile",
-- set icon file path, e.g foo.ico
"xpack.set_iconfile",
-- set package license
"xpack.set_license",
-- set package license file, we will also get them from target
"xpack.set_licensefile",
-- add source files
"xpack.add_sourcefiles",
-- add install files, we will also get them from target
"xpack.add_installfiles",
-- add source files for component
"xpack_component.add_sourcefiles",
-- add install files for component
"xpack_component.add_installfiles"
},
script = {
-- add custom load script
"xpack.on_load",
-- add custom package script before packing package
"xpack.before_package",
-- rewrite custom package script
"xpack.on_package",
-- add custom package script after packing package
"xpack.after_package",
-- add custom build commands script before building, it's only for source inputkind
"xpack.before_buildcmd",
-- add custom build commands script, it's only for source inputkind
"xpack.on_buildcmd",
-- add custom build commands script after building, it's only for source inputkind
"xpack.after_buildcmd",
-- add custom commands script before installing
"xpack.before_installcmd",
-- add custom commands script before uninstalling
"xpack.before_uninstallcmd",
-- rewrite custom install commands script, we will also get it from target/rules
"xpack.on_installcmd",
-- rewrite custom uninstall commands script, we will also get it from target/rules
"xpack.on_uninstallcmd",
-- add custom commands script after installing
"xpack.after_installcmd",
-- add custom commands script after uninstalling
"xpack.after_uninstallcmd",
-- add custom load script in component
"xpack_component.on_load",
-- add custom commands script before installing in component
"xpack_component.before_installcmd",
-- add custom commands script before uninstalling in component
"xpack_component.before_uninstallcmd",
-- rewrite custom install commands script in component, we will also get it from target/rules
"xpack_component.on_installcmd",
-- rewrite custom uninstall commands script in component, we will also get it from target/rules
"xpack_component.on_uninstallcmd",
-- add custom commands script after installing in component
"xpack_component.after_installcmd",
-- add custom commands script after uninstalling in component
"xpack_component.after_uninstallcmd"
},
keyvalues = {
-- set the spec variable
"xpack.set_specvar"
}
}
interp_add_scopeapis(apis)
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/qt/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 xmake.lua
--
includes("@builtin/qt/qt_add_static_plugins.lua")
|
0 | repos/xmake/xmake/includes | repos/xmake/xmake/includes/qt/qt_add_static_plugins.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 qt_add_static_plugins.lua
--
-- add static plugins for qt rules
--
-- e.g.
--
-- @code
-- includes("qt_add_static_plugins.lua")
-- target("test")
-- add_rules("qt.quickapp")
-- add_files("src/*.c")
-- qt_add_static_plugins("QSvgPlugin", {linkdirs = "plugins/imageformats", links = {"qsvg"}})
-- @endcode
--
function qt_add_static_plugins(plugin, opt)
opt = opt or {}
add_values("qt.plugins", plugin)
if opt.links then
add_values("qt.links", table.unpack(table.wrap(opt.links)))
end
if opt.linkdirs then
add_values("qt.linkdirs", table.unpack(table.wrap(opt.linkdirs)))
end
end
|
0 | repos/xmake/xmake/themes | repos/xmake/xmake/themes/ninja/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 xmake.lua
--
-- define theme
theme("ninja")
-- the success status
set_text("success", "$ok")
set_color("success", "green bright")
-- the failure status
set_text("failure", "$failed")
set_color("failure", "red bright")
-- the nothing status
set_text("nothing", "$no")
set_color("nothing", "red bright")
-- the error info
set_text("error", "$error")
set_color("error", "red bright")
-- the warning info
set_text("warning", "$warning")
set_color("warning", "yellow bright")
-- the building progress
set_text("build.progress_format", "[%3d%%]")
set_text("build.progress_style", "noscroll")
set_color("build.progress", "green bright")
-- the building object file
set_color("build.object", "")
-- the building target file
set_color("build.target", "magenta bright")
-- the spinner chars
if (is_subhost("windows") and winos.version():lt("win10")) or is_subhost("msys", "cygwin") then
set_text("spinner.chars", '\\', '-', '/', '|')
else
set_text("spinner.chars", '⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏')
end
-- color dump
set_text("dump.default_format", "%s")
set_text("dump.udata_format", "%s")
set_text("dump.table_format", "%s")
set_text("dump.anchor", "&%s")
set_text("dump.reference", "*%s")
set_color("dump.anchor", "yellow")
set_color("dump.reference", "yellow")
set_color("dump.default", "red")
set_color("dump.udata", "yellow")
set_color("dump.table", "bright")
set_color("dump.string", "magenta bright")
set_color("dump.string_quote", "magenta")
set_color("dump.keyword", "blue")
set_color("dump.number", "green bright")
set_color("dump.function", "cyan")
-- menu
set_color("menu.main.task.name", "magenta")
set_color("menu.option.name", "green")
set_color("menu.usage", "cyan")
-- interactive mode
set_text("interactive.prompt", "xmake>")
set_text("interactive.prompt2", "xmake>>")
set_color("interactive.prompt", "green")
set_color("interactive.prompt2", "green")
|
0 | repos/xmake/xmake/themes | repos/xmake/xmake/themes/powershell/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 xmake.lua
--
-- define theme
theme("powershell")
-- the success status
set_text("success", "$ok")
set_color("success", "green bright")
-- the failure status
set_text("failure", "$failed")
set_color("failure", "red bright")
-- the nothing status
set_text("nothing", "$no")
set_color("nothing", "red bright")
-- the error info
set_text("error", "$error")
set_color("error", "red bright")
-- the warning info
set_text("warning", "$warning")
set_color("warning", "yellow")
-- the building progress
set_text("build.progress_format", "[%3d%%]")
set_text("build.progress_style", "scroll")
set_color("build.progress", "green bright")
-- the building object file
set_color("build.object", "")
-- the building target file
set_color("build.target", "cyan bright")
-- the spinner chars
if (is_subhost("windows") and winos.version():lt("win10")) or is_subhost("msys", "cygwin") then
set_text("spinner.chars", '\\', '-', '/', '|')
else
set_text("spinner.chars", '⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏')
end
-- color dump
set_text("dump.default_format", "%s")
set_text("dump.udata_format", "%s")
set_text("dump.table_format", "%s")
set_text("dump.anchor", "&%s")
set_text("dump.reference", "*%s")
set_color("dump.anchor", "yellow")
set_color("dump.reference", "yellow")
set_color("dump.default", "red")
set_color("dump.udata", "yellow")
set_color("dump.table", "bright")
set_color("dump.string", "red bright")
set_color("dump.string_quote", "red")
set_color("dump.keyword", "blue")
set_color("dump.number", "green bright")
set_color("dump.function", "cyan")
-- menu
set_color("menu.main.task.name", "cyan bright")
set_color("menu.option.name", "green bright")
set_color("menu.usage", "cyan")
-- interactive mode
set_text("interactive.prompt", "xmake>")
set_text("interactive.prompt2", "xmake>>")
set_color("interactive.prompt", "green")
set_color("interactive.prompt2", "green dim")
|
0 | repos/xmake/xmake/themes | repos/xmake/xmake/themes/emoji/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 xmake.lua
--
-- define theme
theme("emoji")
-- the success status
set_text("success", "heavy_check_mark")
set_color("success", "")
-- the failure status
set_text("failure", "x")
set_color("failure", "")
-- the nothing status
set_text("nothing", "o")
set_color("nothing", "")
-- the error info
set_text("error", "exclamation error")
set_color("error", "red bright")
-- the warning info
set_text("warning", "warning $warning")
set_color("warning", "yellow bright")
-- the building progress
set_text("build.progress_format", "[%3d%%]")
set_text("build.progress_style", "scroll")
set_color("build.progress", "green bright")
-- the building object file
set_color("build.object", "")
-- the building target file
set_color("build.target", "magenta bright")
-- the spinner chars
set_text("spinner.chars", '⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏')
-- color dump
set_text("dump.default_format", "%s")
set_text("dump.udata_format", "%s")
set_text("dump.table_format", "%s")
set_text("dump.anchor", "${anchor} %s")
set_text("dump.reference", "${sailboat} %s")
set_color("dump.anchor", "yellow")
set_color("dump.reference", "yellow")
set_color("dump.default", "red")
set_color("dump.udata", "yellow")
set_color("dump.table", "bright")
set_color("dump.string", "magenta bright")
set_color("dump.string_quote", "magenta")
set_color("dump.keyword", "blue")
set_color("dump.number", "green")
set_color("dump.function", "cyan")
-- menu
set_color("menu.main.task.name", "magenta")
set_color("menu.option.name", "green")
set_color("menu.usage", "cyan")
-- interactive mode
set_text("interactive.prompt", "xmake>")
set_text("interactive.prompt2", "xmake>>")
set_color("interactive.prompt", "green")
set_color("interactive.prompt2", "green")
|
0 | repos/xmake/xmake/themes | repos/xmake/xmake/themes/light/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 xmake.lua
--
-- define theme
theme("light")
-- the success status
set_text("success", "$ok")
set_color("success", "green bright")
-- the failure status
set_text("failure", "$failed")
set_color("failure", "red bright")
-- the nothing status
set_text("nothing", "$no")
set_color("nothing", "red bright")
-- the error info
set_text("error", "$error")
set_color("error", "red bright")
-- the warning info
set_text("warning", "$warning")
set_color("warning", "yellow bright")
-- the building progress
set_text("build.progress_format", "[%3d%%]")
set_text("build.progress_style", "scroll")
set_color("build.progress", "green bright")
-- the building object file
set_color("build.object", "")
-- the building target file
set_color("build.target", "cyan bright")
-- the spinner chars
if (is_subhost("windows") and winos.version():lt("win10")) or is_subhost("msys", "cygwin") then
set_text("spinner.chars", '\\', '-', '/', '|')
else
set_text("spinner.chars", '⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏')
end
-- color dump
set_text("dump.default_format", "%s")
set_text("dump.udata_format", "%s")
set_text("dump.table_format", "%s")
set_text("dump.anchor", "&%s")
set_text("dump.reference", "*%s")
set_color("dump.anchor", "yellow")
set_color("dump.reference", "yellow")
set_color("dump.default", "red")
set_color("dump.udata", "yellow")
set_color("dump.table", "bright")
set_color("dump.string", "red bright")
set_color("dump.string_quote", "red")
set_color("dump.keyword", "blue")
set_color("dump.number", "green bright")
set_color("dump.function", "cyan")
-- menu
set_color("menu.main.task.name", "cyan bright")
set_color("menu.option.name", "green bright")
set_color("menu.usage", "cyan")
-- interactive mode
set_text("interactive.prompt", "xmake>")
set_text("interactive.prompt2", "xmake>>")
set_color("interactive.prompt", "green")
set_color("interactive.prompt2", "green")
|
0 | repos/xmake/xmake/themes | repos/xmake/xmake/themes/dark/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 xmake.lua
--
-- define theme
theme("dark")
-- the success status
set_text("success", "$ok")
set_color("success", "green")
-- the failure status
set_text("failure", "$failed")
set_color("failure", "red")
-- the nothing status
set_text("nothing", "$no")
set_color("nothing", "red")
-- the error info
set_text("error", "$error")
set_color("error", "red")
-- the warning info
set_text("warning", "$warning")
set_color("warning", "cyan")
-- the building progress
set_text("build.progress_format", "[%3d%%]")
set_text("build.progress_style", "scroll")
set_color("build.progress", "green")
-- the building object file
set_color("build.object", "")
-- the building target file
set_color("build.target", "magenta")
-- the spinner chars
if (is_subhost("windows") and winos.version():lt("win10")) or is_subhost("msys", "cygwin") then
set_text("spinner.chars", '\\', '-', '/', '|')
else
set_text("spinner.chars", '⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏')
end
-- color dump
set_text("dump.default_format", "%s")
set_text("dump.udata_format", "%s")
set_text("dump.table_format", "%s")
set_text("dump.anchor", "&%s")
set_text("dump.reference", "*%s")
set_color("dump.anchor", "olive")
set_color("dump.reference", "olive")
set_color("dump.default", "red")
set_color("dump.udata", "olive")
set_color("dump.table", "bright")
set_color("dump.string", "magenta bright")
set_color("dump.string_quote", "magenta")
set_color("dump.keyword", "cyan")
set_color("dump.number", "green")
set_color("dump.function", "cyan")
-- menu
set_color("menu.main.task.name", "magenta")
set_color("menu.option.name", "green")
set_color("menu.usage", "cyan")
-- interactive mode
set_text("interactive.prompt", "xmake>")
set_text("interactive.prompt2", "xmake>>")
set_color("interactive.prompt", "green")
set_color("interactive.prompt2", "green")
|
0 | repos/xmake/xmake/themes | repos/xmake/xmake/themes/default/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 xmake.lua
--
-- define theme
theme("default")
-- the success status
set_text("success", "$ok")
set_color("success", "green bright")
-- the failure status
set_text("failure", "$failed")
set_color("failure", "red bright")
-- the nothing status
set_text("nothing", "$no")
set_color("nothing", "red bright")
-- the error info
set_text("error", "$error")
set_color("error", "red bright")
-- the warning info
set_text("warning", "$warning")
set_color("warning", "yellow bright")
-- the building progress
set_text("build.progress_format", "[%3d%%]")
set_text("build.progress_style", "scroll")
set_color("build.progress", "green bright")
-- the building object file
set_color("build.object", "")
-- the building target file
if is_subhost("windows") and (os.term() == "powershell" or os.term() == "pwsh") then
set_color("build.target", "cyan bright")
else
set_color("build.target", "magenta bright")
end
-- the spinner chars
if (is_subhost("windows") and winos.version():lt("win10")) or is_subhost("msys", "cygwin") then
set_text("spinner.chars", '\\', '-', '/', '|')
else
set_text("spinner.chars", '⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏')
end
-- color dump
set_text("dump.default_format", "%s")
set_text("dump.udata_format", "%s")
set_text("dump.table_format", "%s")
set_text("dump.anchor", "&%s")
set_text("dump.reference", "*%s")
set_color("dump.anchor", "yellow")
set_color("dump.reference", "yellow")
set_color("dump.default", "red")
set_color("dump.udata", "yellow")
set_color("dump.table", "bright")
if is_subhost("windows") and (os.term() == "powershell" or os.term() == "pwsh") then
set_color("dump.string", "red bright")
set_color("dump.string_quote", "red")
else
set_color("dump.string", "magenta bright")
set_color("dump.string_quote", "magenta")
end
set_color("dump.keyword", "blue")
set_color("dump.number", "green bright")
set_color("dump.function", "cyan")
-- menu
if is_subhost("windows") and (os.term() == "powershell" or os.term() == "pwsh") then
set_color("menu.main.task.name", "cyan bright")
set_color("menu.option.name", "green bright")
else
set_color("menu.main.task.name", "magenta")
set_color("menu.option.name", "green")
end
set_color("menu.usage", "cyan")
-- interactive mode
set_text("interactive.prompt", "xmake>")
set_text("interactive.prompt2", "xmake>>")
set_color("interactive.prompt", "green")
set_color("interactive.prompt2", "green")
|
0 | repos/xmake/xmake/themes | repos/xmake/xmake/themes/plain/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 xmake.lua
--
-- define theme
theme("plain")
-- the success status
set_text("success", "$ok")
set_color("success", "")
-- the failure status
set_text("failure", "$failed")
set_color("failure", "")
-- the nothing status
set_text("nothing", "$no")
set_color("nothing", "")
-- the error info
set_text("error", "$error")
set_color("error", "")
-- the warning info
set_text("warning", "$warning")
set_color("warning", "")
-- the building progress
set_text("build.progress_format", "[%3d%%]")
set_text("build.progress_style", "scroll")
set_color("build.progress", "")
-- the building object file
set_color("build.object", "")
-- the building target file
set_color("build.target", "")
-- the spinner chars
set_text("spinner.chars", '\\', '-', '/', '|')
-- color dump
set_text("dump.default_format", "%s")
set_text("dump.udata_format", "%s")
set_text("dump.table_format", "%s")
set_text("dump.anchor", "&%s")
set_text("dump.reference", "*%s")
set_color("dump.anchor", "")
set_color("dump.reference", "")
set_color("dump.default", "")
set_color("dump.udata", "")
set_color("dump.table", "")
set_color("dump.string", "")
set_color("dump.string_quote", "")
set_color("dump.keyword", "")
set_color("dump.number", "")
set_color("dump.function", "")
-- menu
set_color("menu.main.task.name", "")
set_color("menu.option.name", "")
set_color("menu.usage", "")
-- interactive mode
set_text("interactive.prompt", "xmake>")
set_text("interactive.prompt2", "xmake>>")
set_color("interactive.prompt", "")
set_color("interactive.prompt2", "")
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/require/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.task")
import("core.project.config")
import("core.project.project")
import("core.platform.platform")
import("private.action.require.list")
import("private.action.require.scan")
import("private.action.require.info")
import("private.action.require.fetch")
import("private.action.require.clean")
import("private.action.require.search")
import("private.action.require.export")
import("private.action.require.import", {alias = "import_packages"})
import("private.action.require.install")
import("private.action.require.uninstall")
import("private.action.require.download")
import("private.action.require.check")
import("private.service.remote_build.action", {alias = "remote_build_action"})
--
-- the default repositories:
-- xmake-repo https://github.com/xmake-io/xmake-repo.git
--
-- add other repositories:
-- xmake repo --add other-repo https://github.com/other/other-repo.git
-- or
-- add_repositories("other-repo https://github.com/other/other-repo.git")
--
-- add requires:
--
-- add_requires("tboox.tbox >=1.5.1", "zlib >=1.2.11")
-- add_requires("zlib master")
-- add_requires("[email protected] >=1.5.1")
-- add_requires("https://github.com/tboox/[email protected] >=1.5.1")
--
-- add package dependencies:
--
-- target("test")
-- add_packages("tboox.tbox", "zlib")
--
-- load project
function _load_project()
-- config it first
task.run("config", {require = false}, {disable_dump = true})
-- enter project directory
os.cd(project.directory())
end
-- main
function main()
-- do action for remote?
if remote_build_action.enabled() then
return remote_build_action()
end
-- load project first
_load_project()
-- clean all installed packages cache
if option.get("clean") then
clean(option.get("requires"))
-- search for the given packages from repositories
elseif option.get("search") then
search(option.get("requires"))
-- uninstall the installed packages
elseif option.get("uninstall") then
uninstall(option.get("requires"))
-- export the installed packages
elseif option.get("export") then
export(option.get("requires"))
-- import the installed packages
elseif option.get("import") then
import_packages(option.get("requires"))
-- show the given package info
elseif option.get("info") then
info(option.get("requires"))
-- fetch the library info of the given packages
elseif option.get("fetch") then
fetch(option.get("requires"))
-- download the given package source archive files
elseif option.get("download") then
download(option.get("requires"))
-- check the given packages
elseif option.get("check") then
check(option.get("requires"))
-- list all package dependencies in project
elseif option.get("list") then
list()
-- scan the given or all packages
elseif option.get("scan") then
scan(option.get("requires"))
-- install and upgrade all outdated package dependencies by default if no arguments
else
install(option.get("requires"))
end
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/require/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 require.lua
--
-- define task
task("require")
-- set category
set_category("action")
-- on run
on_run("main")
-- set menu
set_menu {
-- usage
usage = "xmake require [options] [packages]"
-- description
, description = "Install and update required packages."
-- xmake q
, shortname = 'q'
-- options
, options =
{
{'c', "clean", "k", nil, "Clear all package caches and uninstall all not-referenced packages.",
"e.g.",
" $ xmake require --clean",
" $ xmake require --clean zlib tbox pcr*" }
, {nil, "clean_modes","kv", nil, "Set the modes of cleaning packages.",
"e.g.",
" $ xmake require --clean --clean_modes=cache,package" }
, {'f', "force", "k", nil, "Force to reinstall all package dependencies." }
, {'j', "jobs", "kv", tostring(os.default_njob()),
"Set the number of parallel compilation jobs." }
, {nil, "linkjobs", "kv", nil, "Set the number of parallel link jobs." }
, {nil, "shallow", "k", nil, "Does not install dependent packages." }
, {nil, "build", "k", nil, "Always build and install packages from source." }
, {'l', "list", "k", nil, "List all package dependencies in project.",
"e.g.",
" $ xmake require --list" }
, {nil, "scan", "k", nil, "Scan the given or all installed packages.",
"e.g.",
" $ xmake require --scan",
" $ xmake require --scan zlib tbox pcr*" }
, { }
, {nil, "info", "k", nil, "Show the given package info.",
"e.g.",
" $ xmake require --info tbox" }
, {nil, "check", "k", nil, "Check whether the given package is supported",
"e.g.",
" $ xmake require --check tbox" }
, {nil, "fetch", "k", nil, "Fetch the library info of given package.",
"e.g.",
" $ xmake require --fetch tbox" }
, {nil, "fetch_modes","kv", nil, "Set the modes of fetching packages.",
"e.g.",
" $ xmake require --fetch --fetch_modes=cflags,external tbox",
" $ xmake require --fetch --fetch_modes=deps,cflags,ldflags tbox" }
, {'s', "search", "k", nil, "Search for the given packages from repositories.",
"e.g.",
" $ xmake require --search tbox" }
, {nil, "upgrade", "k", nil, "Upgrade the installed packages." }
, {nil, "download", "k", nil, "Only download the given package source archive files." }
, {nil, "uninstall", "k", nil, "Uninstall the installed packages.",
"e.g.",
" $ xmake require --uninstall",
" $ xmake require --uninstall tbox",
" $ xmake require --uninstall --extra=\"{debug=true}\" tbox" }
, {nil, "export", "k", nil, "Export the installed packages and their dependencies.",
"e.g.",
" $ xmake require --export",
" $ xmake require --export tbox zlib",
" $ xmake require --export --packagedir=packagesdir zlib",
" $ xmake require --export --extra=\"{debug=true}\" tbox" }
, {nil, "import", "k", nil, "Import the installed packages and their dependencies.",
"e.g.",
" $ xmake require --import",
" $ xmake require --import tbox zlib",
" $ xmake require --import --packagedir=packagesdir zlib",
" $ xmake require --import --extra=\"{debug=true}\" tbox" }
, {nil, "packagedir", "kv", "packages","Set the packages directory for exporting, importing and downloading."}
, {nil, "debugdir", "kv", nil, "Set the source directory of the current package for debugging." }
, {nil, "extra", "kv", nil, "Set the extra info of packages." }
, { }
, {nil, "requires", "vs", nil, "The package requires.",
"e.g.",
" $ xmake require zlib tbox",
" $ xmake require \"zlib >=1.2.11\" \"tbox master\"",
" $ xmake require --extra=\"{debug=true,configs={xxx=true}}\" tbox"}
}
}
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/global/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("core.theme.theme")
import("core.cache.global_detectcache")
import("menuconf", {alias = "menuconf_show"})
-- main
function main()
-- enter menu config
if option.get("menu") then
menuconf_show()
end
-- load the global configure
--
-- priority: option > option_default > config_check > global_cache
--
if option.get("clean") then
global.clear()
end
-- override the option configure
local changed = false
for name, value in pairs(option.options()) do
if name ~= "verbose" then
-- the config value is changed by argument options?
changed = changed or global.get(name) ~= value
-- @note override it and mark as readonly
global.set(name, value, {readonly = true})
end
end
-- merge the default options
for name, value in pairs(option.defaults()) do
if name ~= "verbose" and global.get(name) == nil then
global.set(name, value)
end
end
-- load and check theme
local themename = option.get("theme")
if themename then
theme.load(themename)
end
-- save it
global.save()
-- clear detect cache
if option.get("clean") or option.get("check") then
global_detectcache:clear()
global_detectcache:save()
end
-- dump it
global.dump()
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/global/menuconf.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 menuconf.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.ui.log")
import("core.ui.rect")
import("core.ui.view")
import("core.ui.label")
import("core.ui.event")
import("core.ui.action")
import("core.ui.menuconf")
import("core.ui.mconfdialog")
import("core.ui.application")
-- the app application
local app = application()
-- init app
function app:init()
-- init name
application.init(self, "app.config")
-- init background
self:background_set("blue")
-- insert menu config dialog
self:insert(self:mconfdialog())
-- load configs
self:load()
end
-- get menu config dialog
function app:mconfdialog()
if not self._MCONFDIALOG then
local mconfdialog = mconfdialog:new("app.config.mconfdialog", rect {1, 1, self:width() - 1, self:height() - 1}, "menu config")
mconfdialog:action_set(action.ac_on_exit, function (v)
self:quit()
os.exit()
end)
mconfdialog:action_set(action.ac_on_save, function (v)
self:save()
self:quit()
end)
self._MCONFDIALOG = mconfdialog
end
return self._MCONFDIALOG
end
-- on resize
function app:on_resize()
self:mconfdialog():bounds_set(rect{1, 1, self:width() - 1, self:height() - 1})
application.on_resize(self)
end
-- filter option
function app:_filter_option(name)
local options =
{
file = true
, root = true
, yes = true
, quiet = true
, confirm = true
, project = true
, verbose = true
, diagnosis = true
, version = true
, help = true
, clean = true
, menu = true
, check = true
}
return not options[name]
end
-- get or make menu by category
function app:_menu_by_category(root, configs, menus, category)
-- is root?
if category == "." or category == "" then
return
end
-- attempt to get menu first
local menu = menus[category]
if not menu then
-- get config path
local parentdir = path.directory(category)
local config_path = path.join(root, parentdir == "." and "" or parentdir)
-- make a new menu
menu = menuconf.menu {name = category, path = config_path, description = path.basename(category), configs = {}}
menus[category] = menu
-- insert to the parent or root configs
local parent = self:_menu_by_category(root, configs, menus, parentdir)
table.insert(parent and parent.configs or configs, menu)
end
return menu
end
-- make configs by category
function app:_make_configs_by_category(root, options_by_category, cache, get_option_info)
-- make configs category
--
-- root category: "."
-- category path: "a", "a/b", "a/b/c" ...
--
local menus = {}
local configs = {}
for category, options in pairs(options_by_category) do
-- get or make menu by category
local menu = self:_menu_by_category(root, configs, menus, category)
-- get sub-configs
local subconfigs = menu and menu.configs or configs
-- insert options to sub-configs
for _, opt in ipairs(options) do
-- get option info
local info = get_option_info(opt)
-- new value?
local newvalue = true
-- load value
local value = nil
if cache then
value = global.get(info.name)
if value ~= nil and info.kind == "choice" and info.values then
for idx, val in ipairs(info.values) do
if value == val then
value = idx
break
end
end
end
if value ~= nil then
newvalue = false
end
end
-- find the menu index in subconfigs
local menu_index = #subconfigs + 1
for idx, subconfig in ipairs(subconfigs) do
if subconfig.kind == "menu" then
menu_index = idx
break
end
end
-- get config path
local config_path = path.join(root, category == "." and "" or category)
-- insert config before all sub-menus
if info.kind == "string" then
table.insert(subconfigs, menu_index, menuconf.string {name = info.name, value = value, new = newvalue, default = info.default, path = config_path, description = info.description, sourceinfo = info.sourceinfo})
elseif info.kind == "boolean" then
table.insert(subconfigs, menu_index, menuconf.boolean {name = info.name, value = value, new = newvalue, default = info.default, path = config_path, description = info.description, sourceinfo = info.sourceinfo})
elseif info.kind == "choice" then
table.insert(subconfigs, menu_index, menuconf.choice {name = info.name, value = value, new = newvalue, default = info.default, path = config_path, values = info.values, description = info.description, sourceinfo = info.sourceinfo})
end
end
end
-- done
return configs
end
-- get global configs
function app:_global_configs(cache)
-- get configs from the cache first
local configs = self._GLOBAL_CONFIGS
if configs then
return configs
end
-- get config menu
local menu = option.taskmenu("global")
-- merge options by category
local category = "."
local options = menu and menu.options or {}
local options_by_category = {}
for _, opt in pairs(options) do
local name = opt[2] or opt[1]
if name and self:_filter_option(name) then
options_by_category[category] = options_by_category[category] or {}
table.insert(options_by_category[category], opt)
elseif opt.category then
category = opt.category
end
end
-- make configs by category
self._GLOBAL_CONFIGS = self:_make_configs_by_category("Global Configuration", options_by_category, cache, function (opt)
-- get default
local default = opt[4]
-- get kind
local kind = (opt[3] == "k" or type(default) == "boolean") and "boolean" or "string"
-- choice option?
local values = opt.values
if values then
if type(values) == "function" then
values = values()
end
values = table.wrap(values)
for idx, value in ipairs(values) do
if default == value then
default = idx
break
end
end
end
if values then
kind = "choice"
end
-- get description
local description = {}
for i = 5, 64 do
local desc = opt[i]
if type(desc) == "function" then
desc = desc()
end
if type(desc) == "string" then
table.insert(description, desc)
elseif type(desc) == "table" then
table.join2(description, desc)
else
break
end
end
-- make option info
return {name = opt[2] or opt[1], kind = kind, default = default, values = values, description = description}
end)
return self._GLOBAL_CONFIGS
end
-- save the given configs
function app:_save_configs(configs)
local options = option.options()
for _, conf in pairs(configs) do
if conf.kind == "menu" then
self:_save_configs(conf.configs)
elseif not conf.new and (conf.kind == "boolean" or conf.kind == "string") then
options[conf.name] = conf.value
elseif not conf.new and (conf.kind == "choice") then
options[conf.name] = conf.values[conf.value]
end
end
end
-- load configs from options
function app:load()
-- clean the global configuration
if option.get("clean") then
global.clear()
end
-- clear configs first
self._GLOBAL_CONFIGS = nil
-- load configs
local configs = {}
table.insert(configs, menuconf.menu {description = "Global Configuration", configs = self:_global_configs(cache)})
self:mconfdialog():load(configs)
-- the previous config is only for loading menuconf, so clear config now
if option.get("clean") then
global.clear()
end
end
-- save configs to options
function app:save()
self:_save_configs(self:_global_configs())
end
-- main entry
function main(...)
app:run(...)
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/global/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 xmake.lua
--
task("global")
set_category("action")
on_run("main")
set_menu {
usage = "xmake global|g [options] [target]",
description = "Configure the global options for xmake.",
shortname = 'g',
options = {
{'c', "clean", "k", nil , "Clean the cached user configs and detection cache."},
{nil, "check", "k", nil , "Just ignore detection cache and force to check all, it will reserve the cached user configs."},
{nil, "menu", "k" , nil , "Configure with a menu-driven user interface." },
{category = "."},
{nil, "theme", "kv", "default" , "The theme name."
, values = function ()
return import("core.theme.theme.names")()
end},
{nil, "debugger", "kv", "auto" , "The debugger program path." },
{nil, "ccache", "kv", nil , "Enable or disable the c/c++ compiler cache." },
{category = "Build Configuration"},
{nil, "cachedir", "kv", nil , "The global cache directory." },
{nil, "policies", "kv", nil , "Set the global project policies.",
" e.g.",
" - xmake g --policies=run.autobuild",
" - xmake g --policies=build.warning:n" },
-- network configuration
{category = "Network Configuration"},
{nil, "network", "kv", "public" , "Set the network mode."
, values = {"public", "private"} },
{nil, "insecure-ssl", "kv", nil , "Disable to check ssl certificates for downloading." },
{'x', "proxy", "kv", nil , "Use proxy on given port. [protocol://]host[:port]"
, " e.g."
, " - xmake g --proxy='http://host:port'"
, " - xmake g --proxy='https://host:port'"
, " - xmake g --proxy='socks5://host:port'" },
{nil, "proxy_hosts", "kv", nil , "Only enable proxy for the given hosts list, it will enable all if be unset,"
, "and we can pass match pattern to list:"
, " e.g."
, " - xmake g --proxy_hosts='github.com,gitlab.*,*.xmake.io'"},
{nil, "proxy_pac", "kv", "pac.lua" , "Set the auto proxy configuration file."
, " e.g."
, " - xmake g --proxy_pac=pac.lua (in $(globaldir) or absolute path)"
, " - function main(url, host)"
, " if host == 'github.com' then"
, " return true"
, " end"
, " end"
, ""
, "Builtin pac files:"
, function ()
local description = {}
local pacfiles = os.files(path.join(os.programdir(), "scripts", "pac", "*.lua"))
for _, pacfile in ipairs(pacfiles) do
table.insert(description, " - " .. path.filename(pacfile))
end
return description
end},
-- package configuration
{category = "Package Configuration"},
{nil, "pkg_searchdirs", "kv", nil , "The search directories of the remote package."
, " e.g."
, " - xmake g --pkg_searchdirs=/dir1" .. path.envsep() .. "/dir2"},
{nil, "pkg_cachedir", "kv", nil , "The cache root directory of the remote package."},
{nil, "pkg_installdir", "kv", nil , "The install root directory of the remote package."},
-- show platform menu options
{category = "Platform Configuration"},
function ()
import("core.platform.menu")
return menu.options("global")
end
}
}
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/uninstall/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.task")
import("core.platform.platform")
import("core.base.privilege")
import("privilege.sudo")
import("uninstall")
function main()
-- load config first
task.run("config", {require = false}, {disable_dump = true})
-- attempt to uninstall directly
local targetname = option.get("target")
try
{
function ()
uninstall(targetname)
cprint("${color.success}uninstall ok!")
end,
catch
{
-- failed or not permission? request administrator permission and uninstall it again
function (errors)
-- try get privilege
if privilege.get() then
local ok = try
{
function ()
uninstall(targetname)
cprint("${color.success}uninstall ok!")
return true
end
}
-- release privilege
privilege.store()
if ok then
return
end
end
-- continue to uninstall with administrator permission?
local ok = false
if sudo.has() and option.get("admin") then
-- uninstall target with administrator permission
sudo.execl(path.join(os.scriptdir(), "uninstall_admin.lua"), {
targetname or "__all",
option.get("installdir") or "",
option.get("prefix")})
-- trace
cprint("${color.success}uninstall ok!")
ok = true
end
if not ok then
local syserror = os.syserror()
if syserror == os.SYSERR_NOT_PERM or syserror == os.SYSERR_NOT_ACCESS then
wprint("please pass the --admin parameter to `xmake uninstall` to request administrator permissions!")
end
end
assert(ok, "uninstall failed, %s", errors or "unknown reason")
end
}
}
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/uninstall/uninstall.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 uninstall.lua
--
-- imports
import("core.base.task")
import("core.project.rule")
import("core.project.project")
import("target.action.uninstall", {alias = "_do_uninstall_target"})
-- on uninstall target
function _on_uninstall_target(target)
-- trace
print("uninstalling %s ..", target:name())
-- build target with rules
local done = false
for _, r in ipairs(target:orderules()) do
local on_uninstall = r:script("uninstall")
if on_uninstall then
on_uninstall(target)
done = true
end
end
if done then return end
-- do uninstall
_do_uninstall_target(target)
end
-- uninstall the given target
function _uninstall_target(target)
-- has been disabled?
if not target:is_enabled() then
return
end
-- enter project directory
local oldir = os.cd(project.directory())
-- enter the environments of the target packages
local oldenvs = os.addenvs(target:pkgenvs())
-- the target scripts
local scripts =
{
target:script("uninstall_before")
, function (target)
for _, r in ipairs(target:orderules()) do
local before_uninstall = r:script("uninstall_before")
if before_uninstall then
before_uninstall(target)
end
end
end
, target:script("uninstall", _on_uninstall_target)
, function (target)
for _, r in ipairs(target:orderules()) do
local after_uninstall = r:script("uninstall_after")
if after_uninstall then
after_uninstall(target)
end
end
end
, target:script("uninstall_after")
}
-- uninstall the target scripts
for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target)
end
end
-- leave the environments of the target packages
os.setenvs(oldenvs)
-- leave project directory
os.cd(oldir)
end
-- uninstall the given targets
function _uninstall_targets(targets)
for _, target in ipairs(targets) do
_uninstall_target(target)
end
end
-- uninstall
function main(targetname)
local targets = {}
if targetname and not targetname:startswith("__") then
local target = project.target(targetname)
table.insert(targets, target)
else
for _, target in ipairs(project.ordertargets()) do
local group = target:get("group")
if (target:is_default() and not group_pattern) or targetname == "__all" or (group_pattern and group and group:match(group_pattern)) then
table.insert(targets, target)
end
end
end
if #targets > 0 then
_uninstall_targets(table.unique(targets))
end
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/uninstall/uninstall_admin.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 uninstall_admin.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.platform.platform")
import("uninstall")
function main(targetname, installdir, prefix)
local verbose = option.get("verbose")
if installdir and #installdir == 0 then
installdir = nil
end
os.cd(project.directory())
config.load()
platform.load(config.plat())
-- save the current option and push a new option context
option.save()
option.set("verbose", verbose)
if installdir then
option.set("installdir", installdir)
end
if prefix then
option.set("prefix", prefix)
end
-- uninstall target
uninstall(targetname ~= "__all" and targetname or nil)
option.restore()
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/uninstall/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 xmake.lua
--
task("uninstall")
set_category("action")
on_run("main")
set_menu {
usage = "xmake uninstall|u [options] [target]",
description = "Uninstall the project binary files.",
shortname = 'u',
options = {
{nil, "installdir", "kv", nil , "Set the install directory.",
"e.g.",
" $ xmake uninstall -o /usr/local",
"or $ DESTDIR=/usr/local xmake uninstall",
"or $ INSTALLDIR=/usr/local xmake uninstall" },
{'g', "group", "kv", nil , "Uninstall all targets of the given group. It support path pattern matching.",
"e.g.",
" xmake uninstall -g test",
" xmake uninstall -g test_*",
" xmake uninstall --group=benchmark/*" },
{'p', "prefix", "kv", nil , "Set the prefix directory.",
"e.g.",
" $ xmake uninstall --prefix=local",
"or $ PREFIX=local xmake uninstall" },
{nil, "admin", "k", nil , "Try to request administrator permission to uninstall"},
{ },
{nil, "target", "v", nil , "The target name. It will uninstall all default targets if this parameter is not specified.",
values = function (complete, opt)
return import("private.utils.complete_helper.targets")(complete, opt)
end}
}
}
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/build/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("core.base.task")
import("core.project.rule")
import("core.project.config")
import("core.project.project")
import("core.platform.platform")
import("core.theme.theme")
import("utils.progress")
import("build")
import("build_files")
import("cleaner")
import("check", {alias = "check_targets"})
import("private.cache.build_cache")
import("private.service.remote_build.action", {alias = "remote_build_action"})
import("private.utils.statistics")
-- try building it
function _do_try_build(configfile, tool, trybuild, trybuild_detected, targetname)
if configfile and tool and (trybuild or utils.confirm({default = true,
description = "${bright}" .. path.filename(configfile) .. "${clear} found, try building it or you can run `${bright}xmake f --trybuild=${clear}` to set buildsystem"})) then
if not trybuild then
task.run("config", {trybuild = trybuild_detected})
end
tool.build()
return true
end
end
-- do build for the third-party buildsystem
function _try_build()
-- load config
config.load()
-- rebuild it? do clean first
local targetname = option.get("target")
if option.get("rebuild") then
task.run("clean", {target = targetname})
end
-- get the buildsystem tool
local configfile = nil
local tool = nil
local trybuild = config.get("trybuild")
local trybuild_detected = nil
if trybuild then
tool = import("private.action.trybuild." .. trybuild, {try = true, anonymous = true})
if tool then
configfile = tool.detect()
else
raise("unknown build tool: %s", trybuild)
end
return _do_try_build(configfile, tool, trybuild, trybuild_detected, targetname)
else
for _, name in ipairs({"xrepo", "autoconf", "cmake", "meson", "scons", "bazel", "msbuild", "xcodebuild", "make", "ninja", "ndkbuild"}) do
tool = import("private.action.trybuild." .. name, {anonymous = true})
configfile = tool.detect()
if configfile then
trybuild_detected = name
if _do_try_build(configfile, tool, trybuild, trybuild_detected, targetname) then
return true
end
end
end
end
end
-- do global project rules
function _do_project_rules(scriptname, opt)
for _, rulename in ipairs(project.get("target.rules")) do
local r = project.rule(rulename) or rule.rule(rulename)
if r and r:kind() == "project" then
local buildscript = r:script(scriptname)
if buildscript then
buildscript(opt)
end
end
end
end
-- do build
function _do_build(targetname, group_pattern)
local sourcefiles = option.get("files")
if sourcefiles then
build_files(targetname, group_pattern, sourcefiles)
else
build(targetname, group_pattern)
end
end
-- build targets
function build_targets(targetnames, opt)
opt = opt or {}
local group_pattern = opt.group_pattern
try
{
function ()
-- do rules before building
_do_project_rules("build_before")
-- do build
_do_build(targetnames, group_pattern)
-- do check
check_targets(targetnames, {build = true})
-- dump cache stats
if option.get("diagnosis") then
build_cache.dump_stats()
end
end,
catch
{
function (errors)
-- @see https://github.com/xmake-io/xmake/issues/3401
check_targets(targetnames, {build_failure = true})
-- do rules after building
_do_project_rules("build_after", {errors = errors})
-- raise
if errors then
raise(errors)
elseif group_pattern then
raise("build targets with group(%s) failed!", group_pattern)
elseif targetnames then
targetnames = table.wrap(targetnames)
raise("build target: %s failed!", table.concat(targetnames, ", "))
else
raise("build target failed!")
end
end
}
}
-- do rules after building
_do_project_rules("build_after")
end
function main()
-- try building it using third-party buildsystem if xmake.lua not exists
if not os.isfile(project.rootfile()) and _try_build() then
return
end
-- post statistics before locking project
statistics.post()
-- do action for remote?
if remote_build_action.enabled() then
return remote_build_action()
end
-- lock the whole project
project.lock()
-- config it first
local targetname
local group_pattern = option.get("group")
if group_pattern then
group_pattern = "^" .. path.pattern(group_pattern) .. "$"
else
targetname = option.get("target")
end
task.run("config", {}, {disable_dump = true})
-- enter project directory
local oldir = os.cd(project.directory())
-- clean up temporary files once a day
cleaner.cleanup()
-- build targets
local build_time = os.mclock()
build_targets(targetname, {group_pattern = group_pattern})
build_time = os.mclock() - build_time
-- leave project directory
os.cd(oldir)
-- unlock the whole project
project.unlock()
-- trace
local str = ""
if build_time then
str = string.format(", spent %ss", build_time / 1000)
end
progress.show(100, "${color.success}build ok%s", str)
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/build/build_files.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 build_files.lua
--
-- imports
import("core.base.option")
import("core.base.hashset")
import("core.project.config")
import("core.project.project")
import("private.async.jobpool")
import("async.runjobs")
import("kinds.object")
-- match source files
function _match_sourcefiles(sourcefile, filepatterns)
for _, filepattern in ipairs(filepatterns) do
if sourcefile:match(filepattern.pattern) == sourcefile then
if filepattern.excludes then
if filepattern.rootdir and sourcefile:startswith(filepattern.rootdir) then
sourcefile = sourcefile:sub(#filepattern.rootdir + 2)
end
for _, exclude in ipairs(filepattern.excludes) do
if sourcefile:match(exclude) == sourcefile then
return false
end
end
end
return true
end
end
end
-- add batch jobs
function _add_batchjobs(batchjobs, rootjob, target, filepatterns)
local newbatches = {}
local sourcecount = 0
for rulename, sourcebatch in pairs(target:sourcebatches()) do
local objectfiles = sourcebatch.objectfiles
local dependfiles = sourcebatch.dependfiles
local sourcekind = sourcebatch.sourcekind
for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do
if _match_sourcefiles(sourcefile, filepatterns) then
local newbatch = newbatches[rulename]
if not newbatch then
newbatch = {}
newbatch.sourcekind = sourcekind
newbatch.rulename = rulename
newbatch.sourcefiles = {}
end
table.insert(newbatch.sourcefiles, sourcefile)
if objectfiles then
newbatch.objectfiles = newbatch.objectfiles or {}
table.insert(newbatch.objectfiles, objectfiles[idx])
end
if dependfiles then
newbatch.dependfiles = newbatch.dependfiles or {}
table.insert(newbatch.dependfiles, dependfiles[idx])
end
newbatches[rulename] = newbatch
sourcecount = sourcecount + 1
end
end
end
if sourcecount > 0 then
return object.add_batchjobs_for_sourcefiles(batchjobs, rootjob, target, newbatches)
else
return rootjob, rootjob
end
end
-- add batch jobs for the given target
function _add_batchjobs_for_target(batchjobs, rootjob, target, filepatterns)
-- has been disabled?
if not target:is_enabled() then
return
end
-- add batch jobs for target
return _add_batchjobs(batchjobs, rootjob, target, filepatterns)
end
-- add batch jobs for the given target and deps
function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, jobrefs, target, filepatterns)
local targetjob_ref = jobrefs[target:name()]
if targetjob_ref then
batchjobs:add(targetjob_ref, rootjob)
else
local targetjob, targetjob_root = _add_batchjobs_for_target(batchjobs, rootjob, target, filepatterns)
if targetjob and targetjob_root then
jobrefs[target:name()] = targetjob_root
for _, depname in ipairs(target:get("deps")) do
_add_batchjobs_for_target_and_deps(batchjobs, targetjob, jobrefs, project.target(depname), filepatterns)
end
end
end
end
-- get batch jobs
function _get_batchjobs(targetname, group_pattern, filepatterns)
-- get root targets
local targets_root = {}
if targetname then
table.insert(targets_root, project.target(targetname))
else
local depset = hashset.new()
local targets = {}
for _, target in pairs(project.targets()) do
local group = target:get("group")
if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then
for _, depname in ipairs(target:get("deps")) do
depset:insert(depname)
end
table.insert(targets, target)
end
end
for _, target in pairs(targets) do
if not depset:has(target:name()) then
table.insert(targets_root, target)
end
end
end
-- generate batch jobs for default or all targets
local jobrefs = {}
local batchjobs = jobpool.new()
for _, target in pairs(targets_root) do
_add_batchjobs_for_target_and_deps(batchjobs, batchjobs:rootjob(), jobrefs, target, filepatterns)
end
return batchjobs
end
-- convert all sourcefiles to lua pattern
function _get_file_patterns(sourcefiles)
local patterns = {}
for _, sourcefile in ipairs(path.splitenv(sourcefiles)) do
-- get the excludes
local pattern = sourcefile:trim()
local excludes = pattern:match("|.*$")
if excludes then excludes = excludes:split("|", {plain = true}) end
-- translate excludes
if excludes then
local _excludes = {}
for _, exclude in ipairs(excludes) do
exclude = path.translate(exclude)
exclude = path.pattern(exclude)
table.insert(_excludes, exclude)
end
excludes = _excludes
end
-- translate path and remove some repeat separators
pattern = path.translate(pattern:gsub("|.*$", ""))
-- remove "./" or '.\\' prefix
if pattern:sub(1, 2):find('%.[/\\]') then
pattern = pattern:sub(3)
end
-- get the root directory
local rootdir = pattern
local startpos = pattern:find("*", 1, true)
if startpos then
rootdir = rootdir:sub(1, startpos - 1)
end
rootdir = path.directory(rootdir)
-- convert to lua path pattern
pattern = path.pattern(pattern)
table.insert(patterns, {pattern = pattern, excludes = excludes, rootdir = rootdir})
end
return patterns
end
-- the main entry
function main(targetname, group_pattern, sourcefiles)
-- convert all sourcefiles to lua pattern
local filepatterns = _get_file_patterns(sourcefiles)
-- build all jobs
local batchjobs = _get_batchjobs(targetname, group_pattern, filepatterns)
if batchjobs and batchjobs:size() > 0 then
local curdir = os.curdir()
runjobs("build_files", batchjobs, {comax = option.get("jobs") or 1, curdir = curdir})
os.cd(curdir)
else
wprint("%s not found!", sourcefiles)
end
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/build/build.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 build.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("core.project.project")
import("private.async.jobpool")
import("async.runjobs")
import("private.utils.batchcmds")
import("core.base.hashset")
import("private.service.remote_cache.client", {alias = "remote_cache_client"})
import("private.service.distcc_build.client", {alias = "distcc_build_client"})
-- clean target for rebuilding
function _clean_target(target)
if target:targetfile() then
os.tryrm(target:symbolfile())
os.tryrm(target:targetfile())
end
end
-- add builtin batch jobs
function _add_batchjobs_builtin(batchjobs, rootjob, target)
-- uses the rules script?
local job, job_leaf
for _, r in irpairs(target:orderules()) do -- reverse rules order for batchjobs:addjob()
local script = r:script("build")
if script then
if r:extraconf("build", "batch") then
job, job_leaf = assert(script(target, batchjobs, {rootjob = job or rootjob}), "rule(%s):on_build(): no returned job!", r:name())
else
job = batchjobs:addjob("rule/" .. r:name() .. "/build", function (index, total, opt)
script(target, {progress = opt.progress})
end, {rootjob = job or rootjob})
end
else
local buildcmd = r:script("buildcmd")
if buildcmd then
job = batchjobs:addjob("rule/" .. r:name() .. "/build", function (index, total, opt)
local batchcmds_ = batchcmds.new({target = target})
buildcmd(target, batchcmds_, {progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end, {rootjob = job or rootjob})
end
end
end
-- uses the builtin target script
if not job and (target:is_static() or target:is_binary() or target:is_shared() or target:is_object() or target:is_moduleonly()) then
job, job_leaf = import("kinds." .. target:kind(), {anonymous = true})(batchjobs, rootjob, target)
end
job = job or rootjob
return job, job_leaf or job
end
-- add batch jobs
function _add_batchjobs(batchjobs, rootjob, target)
local job, job_leaf
local script = target:script("build")
if not script then
-- do builtin batch jobs
job, job_leaf = _add_batchjobs_builtin(batchjobs, rootjob, target)
elseif target:extraconf("build", "batch") then
-- do custom batch script
-- e.g.
-- target("test")
-- on_build(function (target, batchjobs, opt)
-- return batchjobs:addjob("test", function (idx, total)
-- print("build it")
-- end, {rootjob = opt.rootjob})
-- end, {batch = true})
--
job, job_leaf = assert(script(target, batchjobs, {rootjob = rootjob}), "target(%s):on_build(): no returned job!", target:name())
else
-- do custom script directly
-- e.g.
--
-- target("test")
-- on_build(function (target, opt)
-- print("build it")
-- end)
--
job = batchjobs:addjob(target:name() .. "/build", function (index, total, opt)
script(target, {progress = opt.progress})
end, {rootjob = rootjob})
end
return job, job_leaf or job
end
-- add batch jobs for the given target
function _add_batchjobs_for_target(batchjobs, rootjob, target)
-- has been disabled?
if not target:is_enabled() then
return
end
-- add after_build job for target
local pkgenvs = _g.pkgenvs or {}
_g.pkgenvs = pkgenvs
local job_build_after = batchjobs:addjob(target:name() .. "/after_build", function (index, total, opt)
-- do after_build
local progress = opt.progress
local after_build = target:script("build_after")
if after_build then
after_build(target, {progress = progress})
end
for _, r in ipairs(target:orderules()) do
local after_build = r:script("build_after")
if after_build then
after_build(target, {progress = progress})
else
local after_buildcmd = r:script("buildcmd_after")
if after_buildcmd then
local batchcmds_ = batchcmds.new({target = target})
after_buildcmd(target, batchcmds_, {progress = progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end
end
end
-- restore environments
if target:pkgenvs() then
pkgenvs.oldenvs = pkgenvs.oldenvs or os.getenvs()
pkgenvs.newenvs = pkgenvs.newenvs or {}
pkgenvs.newenvs[target] = nil
local newenvs = pkgenvs.oldenvs
for _, envs in pairs(pkgenvs.newenvs) do
newenvs = os.joinenvs(envs, newenvs)
end
os.setenvs(newenvs)
end
end, {rootjob = rootjob})
-- add batch jobs for target, @note only on_build script support batch jobs
local job_build, job_build_leaf = _add_batchjobs(batchjobs, job_build_after, target)
-- add before_build job for target
local job_build_before = batchjobs:addjob(target:name() .. "/before_build", function (index, total, opt)
-- enter package environments
-- https://github.com/xmake-io/xmake/issues/4033
--
-- maybe mixing envs isn't a great solution,
-- but it's the most efficient compromise compared to setting envs in every on_build_file.
--
if target:pkgenvs() then
pkgenvs.oldenvs = pkgenvs.oldenvs or os.getenvs()
pkgenvs.newenvs = pkgenvs.newenvs or {}
pkgenvs.newenvs[target] = target:pkgenvs()
local newenvs = pkgenvs.oldenvs
for _, envs in pairs(pkgenvs.newenvs) do
newenvs = os.joinenvs(envs, newenvs)
end
os.setenvs(newenvs)
end
-- clean target if rebuild
if target:is_rebuilt() and not option.get("dry-run") then
_clean_target(target)
end
-- do before_build
-- we cannot add batchjobs for this rule scripts, @see https://github.com/xmake-io/xmake/issues/2684
local progress = opt.progress
local before_build = target:script("build_before")
if before_build then
before_build(target, {progress = progress})
end
for _, r in ipairs(target:orderules()) do
local before_build = r:script("build_before")
if before_build then
before_build(target, {progress = progress})
else
local before_buildcmd = r:script("buildcmd_before")
if before_buildcmd then
local batchcmds_ = batchcmds.new({target = target})
before_buildcmd(target, batchcmds_, {progress = progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end
end
end
end, {rootjob = job_build_leaf})
return job_build_before, job_build, job_build_after
end
-- add batch jobs for the given target and deps
function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, target, jobrefs, jobrefs_before)
local targetjob_ref = jobrefs[target:name()]
if targetjob_ref then
batchjobs:add(targetjob_ref, rootjob)
else
local job_build_before, job_build, job_build_after = _add_batchjobs_for_target(batchjobs, rootjob, target)
if job_build_before and job_build and job_build_after then
jobrefs[target:name()] = job_build_after
jobrefs_before[target:name()] = job_build_before
for _, depname in ipairs(target:get("deps")) do
local dep = project.target(depname)
local targetjob = job_build
-- @see https://github.com/xmake-io/xmake/discussions/2500
if dep:policy("build.across_targets_in_parallel") == false then
targetjob = job_build_before
end
_add_batchjobs_for_target_and_deps(batchjobs, targetjob, dep, jobrefs, jobrefs_before)
end
end
end
end
-- get batch jobs, @note we need to export it for private.diagnosis.dump_buildjobs
function get_batchjobs(targetnames, group_pattern)
-- get root targets
local targets_root = {}
if targetnames then
for _, targetname in ipairs(table.wrap(targetnames)) do
local target = project.target(targetname)
if target then
table.insert(targets_root, target)
if option.get("rebuild") then
target:data_set("rebuilt", true)
if not option.get("shallow") then
for _, dep in ipairs(target:orderdeps()) do
dep:data_set("rebuilt", true)
end
end
end
end
end
else
local depset = hashset.new()
local targets = {}
for _, target in ipairs(project.ordertargets()) do
if target:is_enabled() then
local group = target:get("group")
if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then
for _, depname in ipairs(target:get("deps")) do
depset:insert(depname)
end
table.insert(targets, target)
end
end
end
for _, target in ipairs(targets) do
if not depset:has(target:name()) then
table.insert(targets_root, target)
end
if option.get("rebuild") then
target:data_set("rebuilt", true)
end
end
end
-- generate batch jobs for default or all targets
local jobrefs = {}
local jobrefs_before = {}
local batchjobs = jobpool.new()
for _, target in ipairs(targets_root) do
_add_batchjobs_for_target_and_deps(batchjobs, batchjobs:rootjob(), target, jobrefs, jobrefs_before)
end
-- add fence jobs, @see https://github.com/xmake-io/xmake/issues/5003
for _, target in ipairs(project.ordertargets()) do
local target_job_before = jobrefs_before[target:name()]
if target_job_before then
for _, dep in ipairs(target:orderdeps()) do
if dep:policy("build.fence") then
local fence_job = jobrefs[dep:name()]
if fence_job then
batchjobs:add(fence_job, target_job_before)
end
end
end
end
end
return batchjobs
end
-- the main entry
function main(targetnames, group_pattern)
-- enable distcc?
local distcc
if distcc_build_client.is_connected() then
distcc = distcc_build_client.singleton()
end
-- build all jobs
local batchjobs = get_batchjobs(targetnames, group_pattern)
if batchjobs and batchjobs:size() > 0 then
local curdir = os.curdir()
runjobs("build", batchjobs, {on_exit = function (errors)
import("utils.progress")
if errors and progress.showing_without_scroll() then
print("")
end
end, comax = option.get("jobs") or 1, curdir = curdir, distcc = distcc})
os.cd(curdir)
end
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/build/cleaner.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 cleaner.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.base.process")
import("core.project.config")
import("core.project.project")
import("core.package.package")
import("core.platform.platform")
-- clean up temporary files once a day
function cleanup()
-- has been cleaned up today?
local markfile = path.join(os.tmpdir(), "cleanup", os.date("%y%m%d") .. ".mark")
if os.isfile(markfile) then
return
end
-- mark as posted first, avoid posting it repeatly
io.writefile(markfile, "ok")
-- init argument list
local argv = {"lua", path.join(os.scriptdir(), "cleaner.lua")}
for _, name in ipairs({"root", "file", "project", "diagnosis", "verbose", "quiet", "yes", "confirm"}) do
local value = option.get(name)
if type(value) == "string" then
table.insert(argv, "--" .. name .. "=" .. value)
elseif value then
table.insert(argv, "--" .. name)
end
end
-- try to post it in background
try
{
function ()
process.openv(os.programfile(), argv, {stdout = path.join(os.tmpdir(), "cleaner.log"), detach = true}):close()
end
}
end
-- the main function
function main()
-- clean up the temporary files at last 30 days, @see os.tmpdir()
local parentdir = path.directory(os.tmpdir())
for day = 1, 30 do
local tmpdir = path.join(parentdir, os.date("%y%m%d", os.time() - day * 24 * 3600))
if os.isdir(tmpdir) then
print("cleanup %s ..", tmpdir)
os.tryrm(tmpdir)
end
end
-- clean up the temporary files of project at last 30 days, @see project.tmpdir()
if os.isfile(os.projectfile()) then
local parentdir = path.directory(project.tmpdir())
for day = 1, 30 do
local tmpdir = path.join(parentdir, os.date("%y%m%d", os.time() - day * 24 * 3600))
if os.isdir(tmpdir) then
print("cleanup %s ..", tmpdir)
os.tryrm(tmpdir)
end
end
end
-- clean up the previous month package cache files, @see package.cachedir()
local cachedir = path.join(package.cachedir({rootonly = true}), os.date("%y%m", os.time() - 31 * 24 * 3600))
if os.isdir(cachedir) and cachedir ~= package.cachedir() then
print("cleanup %s ..", cachedir)
os.tryrm(cachedir)
end
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/build/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 xmake.lua
--
task("build")
set_category("main")
on_run("main")
set_menu {
usage = "xmake [task] [options] [target]"
, description = "Build targets if no given tasks."
, shortname = 'b'
, options =
{
{nil, "version", "k", nil , "Print the version number and exit." }
, {'b', "build", "k", nil , "Build target. This is default building mode and optional." }
, {'r', "rebuild", "k", nil , "Rebuild the target." }
, {'a', "all", "k", nil , "Build all targets." }
, {nil, "shallow", "k", nil , "Only re-build the given targets without dependencies." }
, {'g', "group", "kv", nil , "Build all targets of the given group. It support path pattern matching.",
"e.g.",
" xmake -g test",
" xmake -g test_*",
" xmake --group=benchmark/*" }
, {nil, "dry-run", "k", nil , "Dry run to build target." }
, {}
, {'j', "jobs", "kv", tostring(os.default_njob()),
"Set the number of parallel compilation jobs." }
, {nil, "linkjobs", "kv", nil, "Set the number of parallel link jobs." }
, {'w', "warning", "k", false , "Enable the warnings output. (deprecated)" }
, {nil, "files", "kv", nil , "Build the given source files.",
"e.g. ",
" - xmake --files=src/main.c",
" - xmake --files='src/*.c' [target]",
" - xmake --files='src/**.c|excluded_file.c'",
" - xmake --files='src/main.c" .. path.envsep() .. "src/test.c'" }
, {}
, {nil, "target", "v", nil , "The target name. It will build all default targets if this parameter is not specified."
, values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end }
}
}
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/build/check.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 check_targets.lua
--
-- imports
import("core.base.option")
import("core.project.project")
import("private.check.checker")
function _show(str, opt)
opt = opt or {}
_g.showed = _g.showed or {}
local showed = _g.showed
local infostr
if str and opt.sourcetips then
infostr = string.format("%s${clear}: %s", opt.sourcetips, str)
elseif opt.sourcetips and opt.apiname and opt.value ~= nil then
infostr = string.format("%s${clear}: unknown %s value '%s'", opt.sourcetips, opt.apiname, opt.value)
elseif str then
infostr = string.format("${clear}: %s", str)
end
if opt.probable_value then
infostr = string.format("%s, it may be '%s'", infostr, opt.probable_value)
end
if not showed[infostr] then
wprint(infostr)
showed[infostr] = true
end
end
function main(targetnames, opt)
opt = opt or {}
-- get targets
local targets = {}
if targetnames then
for _, targetname in ipairs(table.wrap(targetnames)) do
table.insert(targets, project.target(targetname))
end
else
for _, target in pairs(project.targets()) do
if target:is_enabled() then
local group = target:get("group")
if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then
table.insert(targets, target)
end
end
end
end
-- do check
local checkers = checker.checkers()
for name, info in table.orderpairs(checkers) do
if (info.build and opt.build) or (info.build_failure and opt.build_failure) then
local check = import("private.check.checkers." .. name, {anonymous = true})
for _, target in ipairs(targets) do
check({target = target, show = _show})
end
end
end
end
|
0 | repos/xmake/xmake/actions/build | repos/xmake/xmake/actions/build/kinds/static.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 static.lua
--
-- imports
import("core.base.option")
import("core.theme.theme")
import("core.tool.linker")
import("core.tool.compiler")
import("core.project.depend")
import("utils.progress")
import("private.utils.batchcmds")
import("object", {alias = "add_batchjobs_for_object"})
import("linkdepfiles", {alias = "get_linkdepfiles"})
-- do link target
function _do_link_target(target, opt)
local linkinst = linker.load(target:kind(), target:sourcekinds(), {target = target})
local linkflags = linkinst:linkflags({target = target})
-- need build this target?
local depfiles = get_linkdepfiles(target)
local dryrun = option.get("dry-run")
local depvalues = {linkinst:program(), linkflags}
depend.on_changed(function ()
local targetfile = target:targetfile()
progress.show(opt.progress, "${color.build.target}archiving.$(mode) %s", path.filename(targetfile))
local objectfiles = target:objectfiles()
local verbose = option.get("verbose")
if verbose then
-- show the full link command with raw arguments, it will expand @xxx.args for msvc/link on windows
print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags, rawargs = true}))
end
if not dryrun then
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
end
end, {dependfile = target:dependfile(),
lastmtime = os.mtime(target:targetfile()),
changed = target:is_rebuilt(),
values = depvalues, files = depfiles, dryrun = dryrun})
end
-- on link the given target
function _on_link_target(target, opt)
-- link target with rules
local done = false
for _, r in ipairs(target:orderules()) do
local on_link = r:script("link")
if on_link then
on_link(target, opt)
done = true
end
local on_linkcmd = r:script("linkcmd")
if on_linkcmd then
local batchcmds_ = batchcmds.new({target = target})
on_linkcmd(target, batchcmds_, {progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
done = true
end
end
if done then return end
-- do link
_do_link_target(target, opt)
end
-- link target
function _link_target(target, opt)
-- do before link for target
local before_link = target:script("link_before")
if before_link then
before_link(target, opt)
end
-- do before link for rules
for _, r in ipairs(target:orderules()) do
local before_link = r:script("link_before")
if before_link then
before_link(target, opt)
end
local before_linkcmd = r:script("linkcmd_before")
if before_linkcmd then
local batchcmds_ = batchcmds.new({target = target})
before_linkcmd(target, batchcmds_, {progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end
end
-- on link
target:script("link", _on_link_target)(target, opt)
-- do after link for target
local after_link = target:script("link_after")
if after_link then
after_link(target, opt)
end
-- do after link for rules
for _, r in ipairs(target:orderules()) do
local after_link = r:script("link_after")
if after_link then
after_link(target, opt)
end
local after_linkcmd = r:script("linkcmd_after")
if after_linkcmd then
local batchcmds_ = batchcmds.new({target = target})
after_linkcmd(target, batchcmds_, {progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end
end
end
-- add batch jobs for building static target
function main(batchjobs, rootjob, target)
-- add link job
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total, opt)
_link_target(target, {progress = opt.progress})
end, {rootjob = rootjob})
-- we only need to return and depend the link job for each target,
-- so we can compile the source files for each target in parallel
--
-- unless call set_policy("build.across_targets_in_parallel", false) to disable to build across targets in parallel.
--
local job_objects = add_batchjobs_for_object(batchjobs, job_link, target)
return target:policy("build.across_targets_in_parallel") == false and job_objects or job_link, job_objects
end
|
0 | repos/xmake/xmake/actions/build | repos/xmake/xmake/actions/build/kinds/shared.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 shared.lua
--
-- imports
import("core.base.option")
import("core.theme.theme")
import("core.tool.linker")
import("core.tool.compiler")
import("core.project.depend")
import("utils.progress")
import("private.utils.batchcmds")
import("object", {alias = "add_batchjobs_for_object"})
import("linkdepfiles", {alias = "get_linkdepfiles"})
-- do link target
function _do_link_target(target, opt)
local linkinst = linker.load(target:kind(), target:sourcekinds(), {target = target})
local linkflags = linkinst:linkflags({target = target})
-- need build this target?
local depfiles = get_linkdepfiles(target)
local dryrun = option.get("dry-run")
local depvalues = {linkinst:program(), linkflags}
depend.on_changed(function ()
local targetfile = target:targetfile()
progress.show(opt.progress, "${color.build.target}linking.$(mode) %s", path.filename(targetfile))
local objectfiles = target:objectfiles()
local verbose = option.get("verbose")
if verbose then
-- show the full link command with raw arguments, it will expand @xxx.args for msvc/link on windows
print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags, rawargs = true}))
end
if not dryrun then
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
end
end, {dependfile = target:dependfile(),
lastmtime = os.mtime(target:targetfile()),
changed = target:is_rebuilt(),
values = depvalues, files = depfiles, dryrun = dryrun})
end
-- on link the given target
function _on_link_target(target, opt)
-- link target with rules
local done = false
for _, r in ipairs(target:orderules()) do
local on_link = r:script("link")
if on_link then
on_link(target, opt)
done = true
end
local on_linkcmd = r:script("linkcmd")
if on_linkcmd then
local batchcmds_ = batchcmds.new({target = target})
on_linkcmd(target, batchcmds_, {progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
done = true
end
end
if done then return end
-- do link
_do_link_target(target, opt)
end
-- link target
function _link_target(target, opt)
-- do before link for target
local before_link = target:script("link_before")
if before_link then
before_link(target, opt)
end
-- do before link for rules
for _, r in ipairs(target:orderules()) do
local before_link = r:script("link_before")
if before_link then
before_link(target, opt)
end
local before_linkcmd = r:script("linkcmd_before")
if before_linkcmd then
local batchcmds_ = batchcmds.new({target = target})
before_linkcmd(target, batchcmds_, {progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end
end
-- on link
target:script("link", _on_link_target)(target, opt)
-- do after link for target
local after_link = target:script("link_after")
if after_link then
after_link(target, opt)
end
-- do after link for rules
for _, r in ipairs(target:orderules()) do
local after_link = r:script("link_after")
if after_link then
after_link(target, opt)
end
local after_linkcmd = r:script("linkcmd_after")
if after_linkcmd then
local batchcmds_ = batchcmds.new({target = target})
after_linkcmd(target, batchcmds_, {progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end
end
end
-- add batch jobs for building shared target
function main(batchjobs, rootjob, target)
-- add link job
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total, opt)
_link_target(target, {progress = opt.progress})
end, {rootjob = rootjob})
-- we only need to return and depend the link job for each target,
-- so we can compile the source files for each target in parallel
--
-- unless call set_policy("build.across_targets_in_parallel", false) to disable to build across targets in parallel.
--
local job_objects = add_batchjobs_for_object(batchjobs, job_link, target)
return target:policy("build.across_targets_in_parallel") == false and job_objects or job_link, job_objects
end
|
0 | repos/xmake/xmake/actions/build | repos/xmake/xmake/actions/build/kinds/object.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 object.lua
--
-- imports
import("core.base.option")
import("core.project.rule")
import("core.project.config")
import("core.project.project")
import("async.runjobs")
import("private.utils.batchcmds")
import("private.utils.rule_groups")
-- has scripts for the custom rule
function _has_scripts_for_rule(ruleinst, suffix)
-- add batch jobs for xx_build_files
local scriptname = "build_files" .. (suffix and ("_" .. suffix) or "")
local script = ruleinst:script(scriptname)
if script then
return true
end
-- add batch jobs for xx_build_file
scriptname = "build_file" .. (suffix and ("_" .. suffix) or "")
script = ruleinst:script(scriptname)
if script then
return true
end
-- add batch jobs for xx_buildcmd_files
scriptname = "buildcmd_files" .. (suffix and ("_" .. suffix) or "")
script = ruleinst:script(scriptname)
if script then
return true
end
-- add batch jobs for xx_buildcmd_file
scriptname = "buildcmd_file" .. (suffix and ("_" .. suffix) or "")
script = ruleinst:script(scriptname)
if script then
return true
end
end
-- has scripts for target
function _has_scripts_for_target(target, suffix)
local scriptname = "build_files" .. (suffix and ("_" .. suffix) or "")
local script = target:script(scriptname)
if script then
return true
else
scriptname = "build_file" .. (suffix and ("_" .. suffix) or "")
script = target:script(scriptname)
if script then
return true
end
end
end
-- has scripts for group
function _has_scripts_for_group(group, suffix)
for _, item in pairs(group) do
if item.target and _has_scripts_for_target(item.target, suffix) then
return true
end
if item.rule and _has_scripts_for_rule(item.rule, suffix) then
return true
end
end
end
-- add batch jobs for the custom rule
function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix)
-- get rule
local rulename = assert(sourcebatch.rulename, "unknown rule for sourcebatch!")
local ruleinst = rule_groups.get_rule(target, rulename)
-- add batch jobs for xx_build_files
local scriptname = "build_files" .. (suffix and ("_" .. suffix) or "")
local script = ruleinst:script(scriptname)
if script then
if ruleinst:extraconf(scriptname, "batch") then
script(target, batchjobs, sourcebatch, {rootjob = rootjob, distcc = ruleinst:extraconf(scriptname, "distcc")})
else
batchjobs:addjob("rule/" .. rulename .. "/" .. scriptname, function (index, total, opt)
script(target, sourcebatch, {progress = opt.progress})
end, {rootjob = rootjob})
end
end
-- add batch jobs for xx_build_file
if not script then
scriptname = "build_file" .. (suffix and ("_" .. suffix) or "")
script = ruleinst:script(scriptname)
if script then
local sourcekind = sourcebatch.sourcekind
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
batchjobs:addjob(sourcefile, function (index, total, opt)
script(target, sourcefile, {sourcekind = sourcekind, progress = opt.progress})
end, {rootjob = rootjob, distcc = ruleinst:extraconf(scriptname, "distcc")})
end
end
end
-- add batch jobs for xx_buildcmd_files
if not script then
scriptname = "buildcmd_files" .. (suffix and ("_" .. suffix) or "")
script = ruleinst:script(scriptname)
if script then
batchjobs:addjob("rule/" .. rulename .. "/" .. scriptname, function (index, total, opt)
local batchcmds_ = batchcmds.new({target = target})
local distcc = ruleinst:extraconf(scriptname, "distcc")
script(target, batchcmds_, sourcebatch, {progress = opt.progress, distcc = distcc})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end, {rootjob = rootjob})
end
end
-- add batch jobs for xx_buildcmd_file
if not script then
scriptname = "buildcmd_file" .. (suffix and ("_" .. suffix) or "")
script = ruleinst:script(scriptname)
if script then
local sourcekind = sourcebatch.sourcekind
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
batchjobs:addjob(sourcefile, function (index, total, opt)
local batchcmds_ = batchcmds.new({target = target})
script(target, batchcmds_, sourcefile, {sourcekind = sourcekind, progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end, {rootjob = rootjob, distcc = ruleinst:extraconf(scriptname, "distcc")})
end
end
end
end
-- add batch jobs for target
function _add_batchjobs_for_target(batchjobs, rootjob, target, sourcebatch, suffix)
-- we just build sourcebatch with on_build_files scripts
--
-- for example, c++.build and c++.build.modules.builder rules have same sourcefiles,
-- but we just build it for c++.build
--
-- @see https://github.com/xmake-io/xmake/issues/3171
--
local rulename = sourcebatch.rulename
if rulename then
local ruleinst = rule_groups.get_rule(target, rulename)
if not ruleinst:script("build_file") and
not ruleinst:script("build_files") then
return
end
end
-- add batch jobs
local scriptname = "build_files" .. (suffix and ("_" .. suffix) or "")
local script = target:script(scriptname)
if script then
if target:extraconf(scriptname, "batch") then
script(target, batchjobs, sourcebatch, {rootjob = rootjob, distcc = target:extraconf(scriptname, "distcc")})
else
batchjobs:addjob(target:name() .. "/" .. scriptname, function (index, total, opt)
script(target, sourcebatch, {progress = opt.progress})
end, {rootjob = rootjob})
end
return true
else
scriptname = "build_file" .. (suffix and ("_" .. suffix) or "")
script = target:script(scriptname)
if script then
local sourcekind = sourcebatch.sourcekind
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
batchjobs:addjob(sourcefile, function (index, total, opt)
script(target, sourcefile, {sourcekind = sourcekind, progress = opt.progress})
end, {rootjob = rootjob, distcc = target:extraconf(scriptname, "distcc")})
end
return true
end
end
end
-- add batch jobs for group
function _add_batchjobs_for_group(batchjobs, rootjob, target, group, suffix)
for _, item in pairs(group) do
local sourcebatch = item.sourcebatch
if item.target then
_add_batchjobs_for_target(batchjobs, rootjob, target, sourcebatch, suffix)
end
-- override on_xxx script in target? we need to ignore rule scripts
if item.rule and (suffix or not _has_scripts_for_target(target, suffix)) then
_add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix)
end
end
end
-- add batch jobs for building source files
function add_batchjobs_for_sourcefiles(batchjobs, rootjob, target, sourcebatches)
-- build sourcebatch groups first
local groups = rule_groups.build_sourcebatch_groups(target, sourcebatches)
-- add batch jobs for build_after
local groups_root
local groups_leaf = rootjob
for idx, group in ipairs(groups) do
if _has_scripts_for_group(group, "after") then
batchjobs:group_enter(target:name() .. "/after_build_files" .. idx)
_add_batchjobs_for_group(batchjobs, groups_leaf, target, group, "after")
groups_leaf = batchjobs:group_leave() or groups_leaf
groups_root = groups_root or groups_leaf
end
end
-- add batch jobs for build
for idx, group in ipairs(groups) do
if _has_scripts_for_group(group) then
batchjobs:group_enter(target:name() .. "/build_files" .. idx)
_add_batchjobs_for_group(batchjobs, groups_leaf, target, group)
groups_leaf = batchjobs:group_leave() or groups_leaf
groups_root = groups_root or groups_leaf
end
end
-- add batch jobs for build_before
for idx, group in ipairs(groups) do
if _has_scripts_for_group(group, "before") then
batchjobs:group_enter(target:name() .. "/before_build_files" .. idx)
_add_batchjobs_for_group(batchjobs, groups_leaf, target, group, "before")
groups_leaf = batchjobs:group_leave() or groups_leaf
groups_root = groups_root or groups_leaf
end
end
return groups_leaf, groups_root or groups_leaf
end
-- add batch jobs for building object files
function main(batchjobs, rootjob, target)
return add_batchjobs_for_sourcefiles(batchjobs, rootjob, target, target:sourcebatches())
end
|
0 | repos/xmake/xmake/actions/build | repos/xmake/xmake/actions/build/kinds/moduleonly.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, Arthapz
-- @file moduleonly.lua
--
-- imports
inherit("object")
|
0 | repos/xmake/xmake/actions/build | repos/xmake/xmake/actions/build/kinds/binary.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 binary.lua
--
-- imports
import("core.base.option")
import("core.theme.theme")
import("core.tool.linker")
import("core.tool.compiler")
import("core.project.depend")
import("utils.progress")
import("private.utils.batchcmds")
import("object", {alias = "add_batchjobs_for_object"})
import("linkdepfiles", {alias = "get_linkdepfiles"})
-- do link target
function _do_link_target(target, opt)
local linkinst = linker.load(target:kind(), target:sourcekinds(), {target = target})
local linkflags = linkinst:linkflags({target = target})
-- need build this target?
local depfiles = get_linkdepfiles(target)
local dryrun = option.get("dry-run")
local depvalues = {linkinst:program(), linkflags}
depend.on_changed(function ()
local targetfile = target:targetfile()
progress.show(opt.progress, "${color.build.target}linking.$(mode) %s", path.filename(targetfile))
local objectfiles = target:objectfiles()
local verbose = option.get("verbose")
if verbose then
-- show the full link command with raw arguments, it will expand @xxx.args for msvc/link on windows
print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags, rawargs = true}))
end
if not dryrun then
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
end
end, {dependfile = target:dependfile(),
lastmtime = os.mtime(target:targetfile()),
changed = target:is_rebuilt(),
values = depvalues, files = depfiles, dryrun = dryrun})
end
-- on link the given target
function _on_link_target(target, opt)
-- link target with rules
local done = false
for _, r in ipairs(target:orderules()) do
local on_link = r:script("link")
if on_link then
on_link(target, opt)
done = true
end
local on_linkcmd = r:script("linkcmd")
if on_linkcmd then
local batchcmds_ = batchcmds.new({target = target})
on_linkcmd(target, batchcmds_, {progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
done = true
end
end
if done then return end
-- do link
_do_link_target(target, opt)
end
-- link target
function _link_target(target, opt)
-- do before link for target
local before_link = target:script("link_before")
if before_link then
before_link(target, opt)
end
-- do before link for rules
for _, r in ipairs(target:orderules()) do
local before_link = r:script("link_before")
if before_link then
before_link(target, opt)
end
local before_linkcmd = r:script("linkcmd_before")
if before_linkcmd then
local batchcmds_ = batchcmds.new({target = target})
before_linkcmd(target, batchcmds_, {progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end
end
-- on link
target:script("link", _on_link_target)(target, opt)
-- do after link for target
local after_link = target:script("link_after")
if after_link then
after_link(target, opt)
end
-- do after link for rules
for _, r in ipairs(target:orderules()) do
local after_link = r:script("link_after")
if after_link then
after_link(target, opt)
end
local after_linkcmd = r:script("linkcmd_after")
if after_linkcmd then
local batchcmds_ = batchcmds.new({target = target})
after_linkcmd(target, batchcmds_, {progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end
end
end
-- add batch jobs for building binary target
function main(batchjobs, rootjob, target)
-- add link job
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total, opt)
_link_target(target, {progress = opt.progress})
end, {rootjob = rootjob})
-- we only need to return and depend the link job for each target,
-- so we can compile the source files for each target in parallel
--
-- unless call set_policy("build.across_targets_in_parallel", false) to disable to build across targets in parallel.
--
local job_objects = add_batchjobs_for_object(batchjobs, job_link, target)
return target:policy("build.across_targets_in_parallel") == false and job_objects or job_link, job_objects
end
|
0 | repos/xmake/xmake/actions/build | repos/xmake/xmake/actions/build/kinds/linkdepfiles.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 linkdepfiles.lua
--
-- get link depfiles
function main(target)
local extrafiles = {}
for _, dep in ipairs(target:orderdeps()) do
if dep:kind() == "static" then
table.insert(extrafiles, dep:targetfile())
end
end
local linkdepfiles = target:data("linkdepfiles")
if linkdepfiles then
table.join2(extrafiles, linkdepfiles)
end
local objectfiles = target:objectfiles()
local depfiles = objectfiles
if #extrafiles > 0 then
depfiles = table.join(objectfiles, extrafiles)
end
return depfiles
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/update/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.semver")
import("core.base.option")
import("core.base.task")
import("core.base.process")
import("core.base.tty")
import("net.http")
import("devel.git")
import("net.fasturl")
import("core.base.privilege")
import("privilege.sudo")
import("async.runjobs")
import("private.action.require.impl.environment")
import("private.action.update.fetch_version")
import("utils.archive")
import("lib.detect.find_file")
import("lib.detect.find_tool")
-- the installer filename for windows
local win_installer_name = "xmake-installer.exe"
-- run program with privilege
function _sudo_v(program, params)
-- attempt to install directly
return try
{
function ()
os.vrunv(program, params)
return true
end,
catch
{
-- failed or not permission? request administrator permission and run it again
function (errors)
-- trace
vprint(errors)
-- try get privilege
if privilege.get() then
local ok = try
{
function ()
os.vrunv(program, params)
return true
end
}
-- release privilege
privilege.store()
-- ok?
if ok then
return true
end
end
-- show tips
local command = program .. " " ..os.args(params)
cprint("\r${bright color.error}error: ${clear}run `%s` failed, may permission denied!", command)
-- continue to install with administrator permission?
if sudo.has() then
-- confirm to install?
local confirm = utils.confirm({ default = true, description = format("try continue to run `%s` with administrator permission again", command) })
if confirm then
sudo.vrunv(program, params)
return true
end
end
end
}
}
end
-- run program witn admin user
function _run_win_v(program, commands, admin)
local sudo_vbs = path.join(os.programdir(), "scripts", "run.vbs")
local temp_vbs = os.tmpfile() .. ".vbs"
os.cp(sudo_vbs, temp_vbs)
local params = table.join("/Nologo", temp_vbs, "W" .. (admin and "A" or "N") , program, commands)
process.openv("cscript", params, {detach = true}):close()
end
-- do uninstall
function _uninstall()
-- remove shell profile
local profiles = {}
if is_host("windows") then
for _, shell in ipairs({"pwsh", "powershell"}) do
for _, type in ipairs({"AllUsersAllHosts", "CurrentUserAllHosts", "CurrentUserCurrentHost"}) do
local psshell = find_tool(shell)
if psshell then
local outdata, errdata = try {function () return os.iorunv(psshell.program, {"-c", "Write-Output $PROFILE." .. type}) end}
if outdata then
table.insert(profiles, outdata:trim())
end
end
end
end
else
for _, filename in ipairs({".zshrc", ".bashrc", ".kshrc", ".bash_profile", ".profile"}) do
table.insert(profiles, path.join(os.getenv("HOME"), filename))
end
end
for _, profile in ipairs(profiles) do
if os.isfile(profile) then
io.gsub(profile, "# >>> xmake >>>.-# <<< xmake <<<", "")
end
end
-- remove program
if is_host("windows") then
local uninstaller = path.join(os.programdir(), "uninstall.exe")
if os.isfile(uninstaller) then
-- UAC on win7
local params = option.get("quiet") and { "/S" } or {}
if winos:version():gt("winxp") then
_run_win_v(uninstaller, params, true)
else
_run_win_v(uninstaller, params, false)
end
else
raise("the uninstaller(%s) not found!", uninstaller)
end
else
if os.programdir():startswith("/usr/") then
_sudo_v(os.programfile(), {"lua", "rm", os.programdir()})
for _, f in ipairs({"/usr/local/bin/xmake", "/usr/local/bin/xrepo", "/usr/bin/xmake", "/usr/bin/xrepo"}) do
if os.isfile(f) then
_sudo_v(os.programfile(), {"lua", "rm", f})
end
end
else
os.rm(os.programdir())
os.rm(os.programfile())
os.rm("~/.local/bin/xmake")
os.rm("~/.local/bin/xrepo")
end
end
end
-- do install
function _install(sourcedir)
-- the install task
local install_task = function ()
-- get the install directory
local installdir = is_host("windows") and os.programdir() or "~/.local/bin"
-- trace
tty.erase_line_to_start().cr()
cprintf("${yellow} => ${clear}installing to %s .. ", installdir)
local ok = try
{
function ()
-- install it
os.cd(sourcedir)
if is_host("windows") then
if os.isfile(win_installer_name) then
-- /D sets the default installation directory ($INSTDIR), overriding InstallDir and InstallDirRegKey. It must be the last parameter used in the command line and must not contain any quotes, even if the path contains spaces. Only absolute paths are supported.
local params = ("/D=" .. os.programdir()):split("%s", { strict = true })
-- @see https://github.com/xmake-io/xmake/issues/1576
local no_admin = try {function () return winos.registry_query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\XMake;NoAdmin") end}
if no_admin == nil then
no_admin = try {function () return winos.registry_query("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\XMake;NoAdmin") end}
end
if no_admin ~= nil then
no_admin = tostring(no_admin):lower() == "true"
else
local testfile = path.join(os.programdir(), "temp-install")
no_admin = os.trycp(path.join(os.programdir(), "scripts", "run.vbs"), testfile)
os.tryrm(testfile)
end
if no_admin then table.insert(params, 1, "/NOADMIN") end
-- need UAC?
if winos:version():gt("winxp") then
_run_win_v(win_installer_name, params, not no_admin)
else
_run_win_v(win_installer_name, params, false)
end
else
raise("the installer(%s) not found!", win_installer_name)
end
else
if os.isfile("./configure") then
os.vrun("./configure")
end
os.vrunv("make", {"-j4"})
process.openv("./scripts/get.sh", {"__local__", "__install_only__"}, {stdout = os.tmpfile(), stderr = os.tmpfile(), detach = true}):close()
end
return true
end,
catch
{
function (errors)
vprint(errors)
end
}
}
-- trace
if ok then
tty.erase_line_to_start().cr()
cprint("${yellow} => ${clear}install to %s .. ${color.success}${text.success}", installdir)
else
raise("install failed!")
end
end
-- do install
if option.get("verbose") then
install_task()
else
runjobs("update/install", install_task, {progress = true})
end
end
-- do install script
function _install_script(sourcedir)
-- trace
cprintf("\r${yellow} => ${clear}install script to %s .. ", os.programdir())
local source = path.join(sourcedir, "xmake")
local dirname = path.filename(os.programdir())
if dirname ~= "xmake" then
local target = path.join(sourcedir, dirname)
os.mv(source, target)
source = target
end
local ok = try
{
function ()
if is_host("windows") then
local script_original = path.join(os.programdir(), "scripts", "update-script.bat")
local script = os.tmpfile() .. ".bat"
os.cp(script_original, script)
local params = { "/c", script, os.programdir(), source }
os.tryrm(script_original .. ".bak")
local access = os.trymv(script_original, script_original .. ".bak")
_run_win_v("cmd", params, not access)
return true
else
local script = path.join(os.programdir(), "scripts", "update-script.sh")
return _sudo_v("sh", { script, os.programdir(), source })
end
end,
catch
{
function (errors)
vprint(errors)
end
}
}
-- trace
if ok then
cprint("${color.success}${text.success}")
else
cprint("${color.failure}${text.failure}")
end
end
-- initialize shells
function _initialize_shell()
local target, command
if is_host("windows") then
local psshell = find_tool("pwsh") or find_tool("powershell")
local outdata, errdata = try {function () return os.iorunv(psshell.program, {"-c", "Write-Output $PROFILE.CurrentUserAllHosts"}) end}
if outdata then
target = outdata:trim()
local profile = path.join(os.programdir(), "scripts", "profile-win.ps1")
command = format("if (Test-Path -Path \"%s\" -PathType Leaf) {\n . \"%s\"\n}", profile, profile)
else
raise("failed to get profile location from powershell!")
end
else
target = "~/.profile"
local shell = os.shell()
if shell:endswith("bash") then target = (is_host("macosx") and "~/.bash_profile" or "~/.bashrc")
elseif shell:endswith("zsh") then target = "~/.zshrc"
elseif shell:endswith("ksh") then target = "~/.kshrc"
elseif shell:endswith("fish") then target = "~/.config/fish/config.fish"
end
local profile_home = path.absolute("~/.xmake/profile")
command = ("test -f \"%s\" && source \"%s\""):format(profile_home, profile_home)
-- write home profile
local profile = "$XMAKE_PROGRAM_DIR/scripts/profile-unix.sh"
local profile_fish = "$XMAKE_PROGRAM_DIR/scripts/profile-unix.fish"
local bridge_command = format([[export XMAKE_ROOTDIR="%s"
export XMAKE_PROGRAM_DIR="%s"
# export PATH="$XMAKE_ROOTDIR:$PATH"
test $FISH_VERSION && test -f "%s" && source "%s" && exit 0
test -f "%s" && source "%s"
]], path.directory(os.programfile()), os.programdir(), profile_fish, profile_fish, profile, profile)
io.writefile(profile_home, bridge_command)
end
-- trace
cprintf("\r${yellow} => ${clear}installing shell integration to %s .. ", target)
local ok = try
{
function ()
local file = ""
if os.isfile(target) then
file = io.readfile(target)
file = file:gsub("# >>> xmake >>>.-# <<< xmake <<<", "")
if file ~= "" and not file:endswith("\n") then
file = file .. "\n"
end
end
file = file .. "# >>> xmake >>>\n" .. command .. "\n# <<< xmake <<<"
io.writefile(target, file)
return true
end,
catch
{
function (errors)
vprint(errors)
end
}
}
-- trace
if ok then
cprint("${color.success}${text.success}")
if not is_host("windows") then
print("Reload shell profile by running the following command now!")
cprint("${bright}source ~/.xmake/profile${clear}")
end
else
cprint("${color.failure}${text.failure}")
end
end
function _check_repo(sourcedir)
-- this file will exists for long time
if not os.isfile(path.join(sourcedir, "xmake/core/_xmake_main.lua")) then
raise("invalid xmake repo, please check your input!")
end
end
function _check_win_installer(sourcedir)
local file = path.join(sourcedir, win_installer_name)
if not os.isfile(file) then
raise("installer not found at " .. sourcedir)
end
local fp = io.open(file, "rb")
local header = fp:read(math.min(1000, fp:size()))
fp:close()
if header:startswith("MZ") then
return
end
if header:find('\0', 1, true) or not option.get("verbose") then
raise("installer is broken")
else
-- may be a text file, print content for debug
raise("installer is broken: " .. header)
end
end
-- main
function main()
-- only uninstall it
if option.get("uninstall") then
-- do uninstall
_uninstall()
-- trace
cprint("${color.success}uninstall ok!")
return
end
-- initialize for shell interaction
if option.get("integrate") then
_initialize_shell()
return
end
-- enter environment
environment.enter()
-- has been installed?
local fetchinfo = assert(fetch_version(option.get("xmakever")), "cannot fetch xmake version info!")
local is_official = fetchinfo.is_official
local mainurls = fetchinfo.urls
local version = fetchinfo.version
if is_official and xmake.version():eq(version) and not option.get("force") then
cprint("${bright}xmake %s has been installed!", version)
return
end
-- get urls on windows
local script_only = option.get("scriptonly")
if is_host("windows") and not script_only then
if not is_official then
raise("not support to update from unofficial source on windows, missing '--scriptonly' flag?")
end
local winarch = os.arch() == "x64" and "win64" or "win32"
if version:find('.', 1, true) then
mainurls = {format("https://github.com/xmake-io/xmake/releases/download/%s/xmake-%s.%s.exe", version, version, winarch),
format("https://fastly.jsdelivr.net/gh/xmake-mirror/xmake-releases@%s/xmake-%s.%s.exe.zip", version, version, winarch),
format("https://gitlab.com/xmake-mirror/xmake-releases/-/raw/%s/xmake-%s.%s.exe.zip", (version:gsub("^v", "")), version, winarch)}
else
-- regard as a git branch, fetch from ci
local tags = fetchinfo.tags
table.sort(tags)
local latest_version = tags[#tags] or ("v" .. xmake.version():shortstr())
mainurls = {format("https://github.com/xmake-io/xmake/releases/download/%s/xmake-%s.%s.exe", latest_version, version, winarch)}
end
-- re-sort mainurls
fasturl.add(mainurls)
mainurls = fasturl.sort(mainurls)
end
-- trace
if is_official then
cprint("update version ${green}%s${clear} from official source ..", version)
else
cprint("update version ${green}%s${clear} from ${underline}%s${clear} ..", version, mainurls[1])
end
-- get the temporary source directory without ramdisk (maybe too large)
local sourcedir = path.join(os.tmpdir({ramdisk = false}), "xmakesrc", version)
vprint("prepared to download to temp dir %s ..", sourcedir)
-- all user provided urls are considered as git url since check has been performed in fetch_version
local install_from_git = not is_official or git.checkurl(mainurls[1])
-- the download task
local download_task = function ()
for idx, url in ipairs(mainurls) do
tty.erase_line_to_start().cr()
cprintf("${yellow} => ${clear}downloading %s .. ", url)
local ok = try
{
function ()
os.tryrm(sourcedir)
if not install_from_git then
os.mkdir(sourcedir)
local installerfile = path.join(sourcedir, win_installer_name)
if url:endswith(".zip") then
http.download(url, installerfile .. ".zip")
archive.extract(installerfile .. ".zip", installerfile .. ".dir")
local file = find_file("*.exe", installerfile .. ".dir")
if file then
os.cp(file, installerfile)
end
else
http.download(url, installerfile)
end
else
git.clone(url, {depth = 1, recurse_submodules = not script_only, branch = version, outputdir = sourcedir})
end
return true
end,
catch
{
function (errors)
vprint(errors)
end
}
}
tty.erase_line_to_start().cr()
if ok then
cprint("${yellow} => ${clear}download %s .. ${color.success}${text.success}", url)
break
else
cprint("${yellow} => ${clear}download %s .. ${color.failure}${text.failure}", url)
end
if not ok and idx == #mainurls then
raise("download failed!")
end
end
end
-- do download
if option.get("verbose") then
download_task()
else
runjobs("update/download", download_task, {progress = true})
end
-- leave environment
environment.leave()
if install_from_git then
_check_repo(sourcedir)
else
_check_win_installer(sourcedir)
end
-- do install
if script_only then
_install_script(sourcedir)
else
_install(sourcedir)
end
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/update/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 xmake.lua
--
-- define task
task("update")
-- set category
set_category("action")
-- on run
on_run("main")
-- set menu
set_menu {
-- usage
usage = "xmake update [options] [xmakever]"
-- description
, description = "Update and uninstall the xmake program."
-- options
, options =
{
{nil, "uninstall", "k", nil, "Uninstall the current xmake program." }
, { }
, {'s', "scriptonly", "k", nil, "Update scripts only." }
, {nil, "integrate", "k", nil, "Integrate xmake with default shell." }
, {'f', "force", "k", nil, "Force to update and reinstall the given version." }
, {nil, "xmakever", "v", nil, "The given xmake version, or a git source (and branch). ",
"e.g.",
" from official source: ",
" latest, ~2.2.3, dev, master",
" from custom source:",
" https://github.com/xmake-io/xmake",
" github:xmake-io/xmake#~2.2.3",
" git://github.com/xmake-io/xmake.git#master",
values = function (complete)
if not complete then
return
end
return try{ function ()
import("private.action.update.fetch_version")
local seg = complete:split('#', { plain = true, limit = 2, strict = true })
if #seg == 1 then
if seg[1]:find(':', 1, true) then
-- incomplete custom source
return
else
seg[1] = ""
end
end
local versions = fetch_version(seg[1])
for i,v in ipairs(versions.tags) do
if v:startswith("v") and #v > 5 then
versions.tags[i] = v:sub(2)
end
end
local candidates = table.join("latest", versions.branches, table.reverse(versions.tags))
if versions.is_official then
return candidates
else
for i, v in ipairs(candidates) do
candidates[i] = seg[1] .. "#" .. v
end
return candidates
end
end }
end}
}
}
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/install/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.task")
import("core.project.config")
import("core.project.project")
import("core.platform.platform")
import("core.base.privilege")
import("privilege.sudo")
import("install")
-- check targets
function _check_targets(targetname, group_pattern)
-- get targets
local targets = {}
if targetname then
table.insert(targets, project.target(targetname))
else
-- install default or all targets
for _, target in pairs(project.targets()) do
local group = target:get("group")
if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then
table.insert(targets, target)
end
end
end
-- filter and check targets with builtin-install script
local targetnames = {}
for _, target in ipairs(targets) do
if target:targetfile() and target:is_enabled() and not target:script("install") then
local targetfile = target:targetfile()
if targetfile and not os.isfile(targetfile) then
table.insert(targetnames, target:name())
end
end
end
-- there are targets that have not yet been built?
if #targetnames > 0 then
raise("please run `$xmake build [target]` to build the following targets first:\n -> " .. table.concat(targetnames, '\n -> '))
end
end
function main()
-- load config first
task.run("config", {require = false}, {disable_dump = true})
-- check targets first
local targetname
local group_pattern = option.get("group")
if group_pattern then
group_pattern = "^" .. path.pattern(group_pattern) .. "$"
else
targetname = option.get("target")
end
_check_targets(targetname, group_pattern)
-- attempt to install directly
try
{
function ()
install(targetname or (option.get("all") and "__all" or "__def"), group_pattern)
cprint("${color.success}install ok!")
end,
catch
{
-- failed or not permission? request administrator permission and install it again
function (errors)
-- try get privilege
if privilege.get() then
local ok = try
{
function ()
install(targetname or (option.get("all") and "__all" or "__def"), group_pattern)
cprint("${color.success}install ok!")
return true
end
}
-- release privilege
privilege.store()
if ok then
return
end
end
-- continue to install with administrator permission?
local ok = false
if sudo.has() and option.get("admin") then
-- install target with administrator permission
sudo.execl(path.join(os.scriptdir(), "install_admin.lua"), {
targetname or (option.get("all") and "__all" or "__def"),
group_pattern or "", option.get("installdir") or "",
option.get("prefix")})
cprint("${color.success}install ok!")
ok = true
end
if not ok then
local syserror = os.syserror()
if syserror == os.SYSERR_NOT_PERM or syserror == os.SYSERR_NOT_ACCESS then
wprint("please pass the --admin parameter to `xmake install` to request administrator permissions!")
end
end
assert(ok, "install failed, %s", errors or "unknown reason")
end
}
}
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/install/install_admin.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 install_admin.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.platform.platform")
import("install")
function main(targetname, group_pattern, installdir, prefix)
local verbose = option.get("verbose")
if group_pattern and #group_pattern == 0 then
group_pattern = nil
end
if installdir and #installdir == 0 then
installdir = nil
end
os.cd(project.directory())
config.load()
platform.load(config.plat())
-- save the current option and push a new option context
option.save()
option.set("verbose", verbose)
if installdir then
option.set("installdir", installdir)
end
if prefix then
option.set("prefix", prefix)
end
-- install target
install(targetname, group_pattern)
option.restore()
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/install/install.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 install.lua
--
-- imports
import("core.base.task")
import("core.project.rule")
import("core.project.project")
import("target.action.install", {alias = "_do_install_target"})
-- on install target
function _on_install_target(target)
-- trace
print("installing %s ..", target:name())
-- build target with rules
local done = false
for _, r in ipairs(target:orderules()) do
local on_install = r:script("install")
if on_install then
on_install(target)
done = true
end
end
if done then return end
-- do install
_do_install_target(target)
end
-- install the given target
function _install_target(target)
-- has been disabled?
if not target:is_enabled() then
return
end
-- enter project directory
local oldir = os.cd(project.directory())
-- enter the environments of the target packages
local oldenvs = os.addenvs(target:pkgenvs())
-- the target scripts
local scripts =
{
target:script("install_before")
, function (target)
for _, r in ipairs(target:orderules()) do
local before_install = r:script("install_before")
if before_install then
before_install(target)
end
end
end
, target:script("install", _on_install_target)
, function (target)
for _, r in ipairs(target:orderules()) do
local after_install = r:script("install_after")
if after_install then
after_install(target)
end
end
end
, target:script("install_after")
}
-- install the target scripts
for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target)
end
end
-- leave the environments of the target packages
os.setenvs(oldenvs)
-- leave project directory
os.cd(oldir)
end
-- install the given targets
function _install_targets(targets)
for _, target in ipairs(targets) do
_install_target(target)
end
end
-- install targets
function main(targetname, group_pattern)
local targets = {}
if targetname and not targetname:startswith("__") then
local target = project.target(targetname)
table.insert(targets, target)
else
for _, target in ipairs(project.ordertargets()) do
local group = target:get("group")
if (target:is_default() and not group_pattern) or targetname == "__all" or (group_pattern and group and group:match(group_pattern)) then
table.insert(targets, target)
end
end
end
if #targets > 0 then
_install_targets(table.unique(targets))
end
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/install/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 xmake.lua
--
task("install")
set_category("action")
on_run("main")
set_menu {
usage = "xmake install|i [options] [target]",
description = "Package and install the target binary files.",
shortname = 'i',
options = {
{'o', "installdir", "kv", nil , "Set the install directory.",
"e.g.",
" $ xmake install -o /usr/local",
"or $ DESTDIR=/usr/local xmake install",
"or $ INSTALLDIR=/usr/local xmake install" },
{'g', "group", "kv", nil , "Install all targets of the given group. It support path pattern matching.",
"e.g.",
" xmake install -g test",
" xmake install -g test_*",
" xmake install --group=benchmark/*" },
{'a', "all", "k", nil , "Install all targets." },
{nil, "nopkgs", "k", nil , "Only install targets without packages." },
{nil, "admin", "k", nil , "Try to request administrator permission to install"},
{},
{nil, "target", "v", nil , "The target name. It will install all default targets if this parameter is not specified.",
values = function (complete, opt)
return import("private.utils.complete_helper.targets")(complete, opt)
end}
}
}
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/service/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("private.service.server_config")
import("private.service.client_config")
import("private.service.start_service")
import("private.service.restart_service")
import("private.service.stop_service")
import("private.service.connect_service")
import("private.service.reconnect_service")
import("private.service.disconnect_service")
import("private.service.clean_files")
import("private.service.sync_files")
import("private.service.pull_files")
import("private.service.add_user")
import("private.service.rm_user")
import("private.service.gen_token")
import("private.service.show_logs")
import("private.service.show_status")
function main()
-- @note we need the load server config before loading the client config,
-- because we need the same local token in both configs
server_config.load()
client_config.load()
if option.get("start") then
start_service({daemon = true})
elseif option.get("restart") then
restart_service()
elseif option.get("stop") then
stop_service()
elseif option.get("connect") then
connect_service()
elseif option.get("reconnect") then
reconnect_service()
elseif option.get("disconnect") then
disconnect_service()
elseif option.get("clean") then
clean_files()
elseif option.get("sync") then
sync_files()
elseif option.get("pull") then
local values = option.get("values") or {}
pull_files(values[1], values[2])
elseif option.get("gen-token") then
gen_token()
elseif option.get("add-user") then
add_user(option.get("add-user"))
elseif option.get("rm-user") then
rm_user(option.get("rm-user"))
elseif option.get("logs") then
show_logs()
elseif option.get("status") then
show_status()
else
start_service()
end
end
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.