summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-22 23:50:51 +0800
committerruki <[email protected]>2020-04-22 17:05:10 +0800
commit00f34ec89f7735b45a3ecdb55f0952d545d73cbb (patch)
tree805b1ebb127cc86f94f1ecc6dd883294337ef00d
parent05df31effcfc9bc701387e1383b678f0914241be (diff)
pass engine name
-rw-r--r--core/src/demo/xmake.c2
-rw-r--r--core/src/xmake/engine.c16
-rw-r--r--core/src/xmake/engine.h9
-rw-r--r--tests/projects/xmake_cli/hello/src/lni/main.c2
-rw-r--r--tests/projects/xmake_cli/xmake/src/main.c2
-rw-r--r--xmake/core/_xmake_main.lua1
-rw-r--r--xmake/core/base/global.lua7
-rw-r--r--xmake/core/base/os.lua3
-rw-r--r--xmake/core/base/xmake.lua5
-rw-r--r--xmake/core/project/config.lua4
-rw-r--r--xmake/core/ui/log.lua2
11 files changed, 34 insertions, 19 deletions
diff --git a/core/src/demo/xmake.c b/core/src/demo/xmake.c
index d6605f7d0..b29a28806 100644
--- a/core/src/demo/xmake.c
+++ b/core/src/demo/xmake.c
@@ -8,5 +8,5 @@
*/
tb_int_t main(tb_int_t argc, tb_char_t** argv)
{
- return xm_engine_run(argc, argv, tb_null);
+ return xm_engine_run("xmake", argc, argv, tb_null);
}
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index 6ccada916..2d0bbd4ef 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -743,7 +743,7 @@ static tb_void_t xm_engine_init_features(xm_engine_t* engine)
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-xm_engine_ref_t xm_engine_init(xm_engine_lni_initalizer_cb_t lni_initalizer)
+xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_cb_t lni_initalizer)
{
// done
tb_bool_t ok = tb_false;
@@ -825,6 +825,10 @@ xm_engine_ref_t xm_engine_init(xm_engine_lni_initalizer_cb_t lni_initalizer)
lua_pushstring(engine->lua, version_cstr);
lua_setglobal(engine->lua, "_VERSION_SHORT");
+ // init engine name
+ lua_pushstring(engine->lua, name? name : "xmake");
+ lua_setglobal(engine->lua, "_NAME");
+
// init namespace: xmake
lua_newtable(engine->lua);
lua_setglobal(engine->lua, "xmake");
@@ -960,12 +964,12 @@ tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const* module, luaL
luaL_register(engine->lua, tb_null, funcs);
lua_rawset(engine->lua, -3);
}
-tb_int_t xm_engine_run(tb_int_t argc, tb_char_t** argv, xm_engine_lni_initalizer_cb_t lni_initalizer)
+tb_int_t xm_engine_run(tb_char_t const* name, tb_int_t argc, tb_char_t** argv, xm_engine_lni_initalizer_cb_t lni_initalizer)
{
tb_int_t ok = -1;
if (xm_init())
{
- xm_engine_ref_t engine = xm_engine_init(lni_initalizer);
+ xm_engine_ref_t engine = xm_engine_init(name, lni_initalizer);
if (engine)
{
ok = xm_engine_main(engine, argc, argv);
@@ -975,7 +979,7 @@ tb_int_t xm_engine_run(tb_int_t argc, tb_char_t** argv, xm_engine_lni_initalizer
}
return ok;
}
-tb_int_t xm_engine_run_lua(tb_int_t argc, tb_char_t** argv, xm_engine_lni_initalizer_cb_t lni_initalizer, tb_char_t const* luaopts)
+tb_int_t xm_engine_run_lua(tb_char_t const* name, tb_int_t argc, tb_char_t** argv, xm_engine_lni_initalizer_cb_t lni_initalizer, tb_char_t const* luaopts)
{
if (luaopts)
{
@@ -987,7 +991,7 @@ tb_int_t xm_engine_run_lua(tb_int_t argc, tb_char_t** argv, xm_engine_lni_inital
argv2[3] = "lua.main";
if (argc > 1) tb_memcpy(argv2 + 4, argv + 1, (argc - 1) * sizeof(tb_char_t*));
argv2[argc2] = tb_null;
- return xm_engine_run(argc2, argv2, lni_initalizer);
+ return xm_engine_run(name, argc2, argv2, lni_initalizer);
}
else
{
@@ -998,6 +1002,6 @@ tb_int_t xm_engine_run_lua(tb_int_t argc, tb_char_t** argv, xm_engine_lni_inital
argv2[2] = "lua.main";
if (argc > 1) tb_memcpy(argv2 + 3, argv + 1, (argc - 1) * sizeof(tb_char_t*));
argv2[argc2] = tb_null;
- return xm_engine_run(argc2, argv2, lni_initalizer);
+ return xm_engine_run(name, argc2, argv2, lni_initalizer);
}
}
diff --git a/core/src/xmake/engine.h b/core/src/xmake/engine.h
index 7b0042dfc..6a014b3af 100644
--- a/core/src/xmake/engine.h
+++ b/core/src/xmake/engine.h
@@ -47,11 +47,12 @@ typedef tb_bool_t (*xm_engine_lni_initalizer_cb_t)(xm_engine_ref_t engine, lua_S
/*! init the engine
*
+ * @param name the engine name
* @param lni_initalizer the lni initializer
*
* @return the engine
*/
-xm_engine_ref_t xm_engine_init(xm_engine_lni_initalizer_cb_t lni_initalizer);
+xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_cb_t lni_initalizer);
/*! exit the engine
*
@@ -79,18 +80,20 @@ tb_void_t xm_engine_register(xm_engine_ref_t engine, tb_char_t
/*! run main entry of the engine singleton
*
+ * @param name the engine name
* @param argc the argument count of the console
* @param argv the argument list of the console
* @param lni_initalizer the lni initializer
*
* @return the error code of main()
*/
-tb_int_t xm_engine_run(tb_int_t argc, tb_char_t** argv, xm_engine_lni_initalizer_cb_t lni_initalizer);
+tb_int_t xm_engine_run(tb_char_t const* name, tb_int_t argc, tb_char_t** argv, xm_engine_lni_initalizer_cb_t lni_initalizer);
/*! run lua action entry of the engine singleton for `xmake lua [-vD] lua.main`
*
* @note we need set $XMAKE_MODULES_DIR with the directory of "lua\\*.lua"
*
+ * @param name the engine name
* @param argc the argument count of the console
* @param argv the argument list of the console
* @param lni_initalizer the lni initializer
@@ -98,7 +101,7 @@ tb_int_t xm_engine_run(tb_int_t argc, tb_char_t** argv, xm_en
*
* @return the error code of main()
*/
-tb_int_t xm_engine_run_lua(tb_int_t argc, tb_char_t** argv, xm_engine_lni_initalizer_cb_t lni_initalizer, tb_char_t const* luaopts);
+tb_int_t xm_engine_run_lua(tb_char_t const* name, tb_int_t argc, tb_char_t** argv, xm_engine_lni_initalizer_cb_t lni_initalizer, tb_char_t const* luaopts);
/* //////////////////////////////////////////////////////////////////////////////////////
* extern
diff --git a/tests/projects/xmake_cli/hello/src/lni/main.c b/tests/projects/xmake_cli/hello/src/lni/main.c
index d1ab0b0fb..298d34d57 100644
--- a/tests/projects/xmake_cli/hello/src/lni/main.c
+++ b/tests/projects/xmake_cli/hello/src/lni/main.c
@@ -21,5 +21,5 @@ tb_int_t main(tb_int_t argc, tb_char_t** argv)
#else
tb_char_t const* luaopts = "-D";
#endif
- return xm_engine_run_lua(argc, argv, lni_initalizer, luaopts);
+ return xm_engine_run_lua("hello", argc, argv, lni_initalizer, luaopts);
}
diff --git a/tests/projects/xmake_cli/xmake/src/main.c b/tests/projects/xmake_cli/xmake/src/main.c
index 68403c6c4..852658071 100644
--- a/tests/projects/xmake_cli/xmake/src/main.c
+++ b/tests/projects/xmake_cli/xmake/src/main.c
@@ -2,5 +2,5 @@
tb_int_t main(tb_int_t argc, tb_char_t** argv)
{
- return xm_engine_run(argc, argv, tb_null);
+ return xm_engine_run("xmake", argc, argv, tb_null);
}
diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua
index a525f56cf..883e71f4c 100644
--- a/xmake/core/_xmake_main.lua
+++ b/xmake/core/_xmake_main.lua
@@ -20,6 +20,7 @@
-- init namespace: xmake
xmake = xmake or {}
+xmake._NAME = _NAME
xmake._ARGV = _ARGV
xmake._HOST = _HOST
xmake._ARCH = _ARCH
diff --git a/xmake/core/base/global.lua b/xmake/core/base/global.lua
index b70e139fd..577eed0a9 100644
--- a/xmake/core/base/global.lua
+++ b/xmake/core/base/global.lua
@@ -88,23 +88,24 @@ end
-- get the configure file
function global.filepath()
- return path.join(global.directory(), "xmake.conf")
+ return path.join(global.directory(), xmake._NAME .. ".conf")
end
-- get the global configure directory
function global.directory()
if global._DIRECTORY == nil then
+ local name = "." .. xmake._NAME
local rootdir = os.getenv("XMAKE_GLOBALDIR")
if not rootdir then
-- compatible with the old `%appdata%/.xmake` directory if it exists
local appdata = (os.host() == "windows") and os.getenv("APPDATA")
- if appdata and os.isdir(path.join(appdata, ".xmake")) then
+ if appdata and os.isdir(path.join(appdata, name)) then
rootdir = appdata
else
rootdir = path.translate("~")
end
end
- global._DIRECTORY = path.join(rootdir, ".xmake")
+ global._DIRECTORY = path.join(rootdir, name)
end
return global._DIRECTORY
end
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index b6334a922..f4acb808c 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -555,7 +555,8 @@ function os.tmpdir(opt)
-- make sub-directory name
local subdir = os._TMPSUBDIR
if not subdir then
- subdir = path.join((os._FAKEROOT and ".xmakefake" or ".xmake") .. (os.uid().euid or ""), os.date("%y%m%d"))
+ local name = "." .. xmake._NAME
+ subdir = path.join((os._FAKEROOT and (name .. "fake") or name) .. (os.uid().euid or ""), os.date("%y%m%d"))
os._TMPSUBDIR = subdir
end
diff --git a/xmake/core/base/xmake.lua b/xmake/core/base/xmake.lua
index 973b66ace..e4db4851f 100644
--- a/xmake/core/base/xmake.lua
+++ b/xmake/core/base/xmake.lua
@@ -24,6 +24,11 @@ local xmake = xmake or {}
-- load modules
local semver = require("base/semver")
+-- get name
+function xmake.name()
+ return xmake._NAME or "xmake"
+end
+
-- get xmake version
function xmake.version()
if xmake._VERSION_CACHE == nil then
diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua
index a7e474338..49d093663 100644
--- a/xmake/core/project/config.lua
+++ b/xmake/core/project/config.lua
@@ -142,14 +142,14 @@ end
-- get the configure file
function config.filepath()
- return path.join(config.directory(), "xmake.conf")
+ return path.join(config.directory(), xmake._NAME .. ".conf")
end
-- get the configure directory on the current host/arch platform
function config.directory()
if config._DIRECTORY == nil then
local rootdir = os.getenv("XMAKE_CONFIGDIR") or os.projectdir()
- config._DIRECTORY = path.join(rootdir, ".xmake", os.host(), os.arch())
+ config._DIRECTORY = path.join(rootdir, "." .. xmake._NAME, os.host(), os.arch())
end
return config._DIRECTORY
end
diff --git a/xmake/core/ui/log.lua b/xmake/core/ui/log.lua
index 165dbe9ae..3fd8ef922 100644
--- a/xmake/core/ui/log.lua
+++ b/xmake/core/ui/log.lua
@@ -28,7 +28,7 @@ local log = log or (function ()
-- get log directory
local logdir = nil
if os.isfile(os.projectfile()) then
- logdir = path.join(os.projectdir(), ".xmake")
+ logdir = path.join(os.projectdir(), "." .. xmake._NAME)
else
logdir = os.tmpdir()
end