summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-29 23:52:17 +0800
committerruki <[email protected]>2020-04-29 17:13:44 +0800
commitdcb9bf2b3ad1248fbe1ac472a4b851dc841067a9 (patch)
treedf0ded62efcfb04b9676536217ad66ba26d2de5b
parentcf92ed9d8ed9d833458ffcb94466f7b7c32c91b7 (diff)
fix os.args
-rw-r--r--core/src/xmake/os/args.c21
-rw-r--r--tests/projects/c/static library with spaces/xmake.lua42
-rw-r--r--xmake/modules/core/tools/cl.lua7
-rw-r--r--xmake/plugins/project/clang/compile_commands.lua9
4 files changed, 33 insertions, 46 deletions
diff --git a/core/src/xmake/os/args.c b/core/src/xmake/os/args.c
index aabede414..abe5aebd1 100644
--- a/core/src/xmake/os/args.c
+++ b/core/src/xmake/os/args.c
@@ -33,7 +33,7 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* private implementation
*/
-static tb_void_t tb_os_args_append(tb_string_ref_t result, tb_char_t const* cstr, tb_size_t size, tb_bool_t escape)
+static tb_void_t tb_os_args_append(tb_string_ref_t result, tb_char_t const* cstr, tb_size_t size, tb_bool_t escape, tb_bool_t nowrap)
{
// check
tb_assert_and_check_return(size < TB_PATH_MAXN);
@@ -60,7 +60,7 @@ static tb_void_t tb_os_args_append(tb_string_ref_t result, tb_char_t const* cstr
buff[n] = '\0';
// wrap "" if exists escape characters and spaces?
- if (wrap_quote)
+ if (wrap_quote && !nowrap)
{
tb_string_chrcat(result, '\"');
tb_size_t i = 0;
@@ -90,13 +90,24 @@ tb_int_t xm_os_args(lua_State* lua)
tb_bool_t escape = tb_false;
if (lua_istable(lua, 2))
{
- // is detached?
+ // is escape?
lua_pushstring(lua, "escape");
lua_gettable(lua, 2);
escape = lua_toboolean(lua, -1);
lua_pop(lua, 1);
}
+ // disable to wrap quote characters in global?
+ tb_bool_t nowrap = tb_false;
+ if (lua_istable(lua, 2))
+ {
+ // is nowrap?
+ lua_pushstring(lua, "nowrap");
+ lua_gettable(lua, 2);
+ nowrap = lua_toboolean(lua, -1);
+ lua_pop(lua, 1);
+ }
+
// init result
tb_string_t result;
tb_string_init(&result);
@@ -117,7 +128,7 @@ tb_int_t xm_os_args(lua_State* lua)
size_t size = 0;
tb_char_t const* cstr = luaL_checklstring(lua, -1, &size);
if (cstr && size)
- tb_os_args_append(&result, cstr, size, escape);
+ tb_os_args_append(&result, cstr, size, escape, nowrap);
lua_pop(lua, 1);
}
}
@@ -126,7 +137,7 @@ tb_int_t xm_os_args(lua_State* lua)
size_t size = 0;
tb_char_t const* cstr = luaL_checklstring(lua, 1, &size);
if (cstr && size)
- tb_os_args_append(&result, cstr, size, escape);
+ tb_os_args_append(&result, cstr, size, escape, nowrap);
}
// return result
diff --git a/tests/projects/c/static library with spaces/xmake.lua b/tests/projects/c/static library with spaces/xmake.lua
index b35709072..3febc19f3 100644
--- a/tests/projects/c/static library with spaces/xmake.lua
+++ b/tests/projects/c/static library with spaces/xmake.lua
@@ -1,45 +1,13 @@
--- the debug mode
-if is_mode("debug") then
-
- -- enable the debug symbols
- set_symbols("debug")
+add_rules("mode.release", "mode.debug")
- -- disable optimization
- set_optimize("none")
-end
-
--- the release mode
-if is_mode("release") then
-
- -- set the symbols visibility: hidden
- set_symbols("hidden")
-
- -- enable fastest optimization
- set_optimize("fastest")
-
- -- strip all symbols
- set_strip("all")
-end
-
--- add target
-target("static_library_c")
-
- -- set kind
+target("test")
set_kind("static")
-
- -- add files
add_files("s r c/interface.c")
+ add_includedirs("$(projectdir)/s r c", {public = true})
--- add target
-target("test")
-
- -- set kind
+target("demo")
set_kind("binary")
-
- -- add deps
- add_deps("static_library_c")
-
- -- add files
+ add_deps("test")
add_files("s r c/test.c")
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index 7284e973b..3a050fd64 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -235,6 +235,8 @@ end
-- make the includedir flag
function nf_includedir(self, dir)
+ -- @note we use os.args() to escape and wrap it,
+ -- because all flags will be preprocessed in `builder:_preprocess_flags`/`os.argv()`
return "-I" .. os.args(path.translate(dir))
end
@@ -310,7 +312,7 @@ function _compargv_pch(self, pcheaderfile, pcoutputfile, flags)
end
-- make the compile arguments list
- return self:program(), table.join("-c", "-Yc", pchflags, "-Fp" .. os.args(pcoutputfile), "-Fo" .. os.args(pcoutputfile .. ".obj"), pcheaderfile)
+ return self:program(), table.join("-c", "-Yc", pchflags, "-Fp" .. pcoutputfile, "-Fo" .. pcoutputfile .. ".obj", pcheaderfile)
end
-- make the compile arguments list
@@ -323,7 +325,8 @@ function compargv(self, sourcefile, objectfile, flags)
end
-- make the compile arguments list
- return self:program(), table.join("-c", flags, "-Fo" .. os.args(objectfile), sourcefile)
+ -- @note only flags in nf_xxx() need be wrapped via os.args, @see nf_includedir
+ return self:program(), table.join("-c", flags, "-Fo" .. objectfile, sourcefile)
end
-- compile the source file
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua
index 4ded1e11a..cf352642e 100644
--- a/xmake/plugins/project/clang/compile_commands.lua
+++ b/xmake/plugins/project/clang/compile_commands.lua
@@ -23,6 +23,11 @@ import("core.tool.compiler")
import("core.project.project")
import("core.language.language")
+-- escape path
+function _escape_path(p)
+ return os.args(p, {escape = true, nowrap = true})
+end
+
-- make the object
function _make_object(jsonfile, target, sourcefile, objectfile)
@@ -40,7 +45,7 @@ function _make_object(jsonfile, target, sourcefile, objectfile)
-- escape '"', '\'
local arguments_escape = {}
for _, arg in ipairs(arguments) do
- table.insert(arguments_escape, os.args(arg, {escape = true}))
+ table.insert(arguments_escape, _escape_path(arg))
end
-- make body
@@ -49,7 +54,7 @@ function _make_object(jsonfile, target, sourcefile, objectfile)
"directory": "%s",
"arguments": ["%s"],
"file": "%s"
-}]], (_g.firstline and "" or ",\n"), os.args(os.projectdir(), {escape = true}), table.concat(arguments_escape, "\", \""), os.args(sourcefile, {escape = true}))
+}]], (_g.firstline and "" or ",\n"), _escape_path(os.projectdir()), table.concat(arguments_escape, "\", \""), _escape_path(sourcefile))
-- clear first line marks
_g.firstline = false