summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-02-03 10:09:03 +0800
committerruki <[email protected]>2019-02-03 10:09:03 +0800
commit7c1534d1baf59d58a98293ec8b5a82de7c09de18 (patch)
treee1ce678c7029aa86470e777dde8b4f73f3ff3076
parent7a52e6ce0473fcc334746ce32232ff6db99281db (diff)
add set_configvar
-rw-r--r--tests/apis/add_configfiles/hello.man2
-rw-r--r--tests/apis/add_configfiles/xmake.lua9
-rw-r--r--xmake/actions/config/configfiles.lua44
-rw-r--r--xmake/core/base/interpreter.lua4
-rw-r--r--xmake/core/project/target.lua1
5 files changed, 26 insertions, 34 deletions
diff --git a/tests/apis/add_configfiles/hello.man b/tests/apis/add_configfiles/hello.man
index fc4db6267..011859cf1 100644
--- a/tests/apis/add_configfiles/hello.man
+++ b/tests/apis/add_configfiles/hello.man
@@ -1 +1 @@
-${module} ${hello}
+${module} ${ARCH}
diff --git a/tests/apis/add_configfiles/xmake.lua b/tests/apis/add_configfiles/xmake.lua
index 6e66a1572..070488198 100644
--- a/tests/apis/add_configfiles/xmake.lua
+++ b/tests/apis/add_configfiles/xmake.lua
@@ -1,11 +1,15 @@
+set_configvar("ARCH", get_config("arch"))
+set_configvar("PLAT", get_config("plat"))
+
target("test")
set_kind("binary")
add_files("main.c")
+ set_configvar("module", "test")
set_configdir("$(buildir)/config")
add_configfiles("test.c.in", {filename = "mytest.c"})
- add_configfiles("config.h.in", {variables = {hello = "xmake", module = "test"}, prefixdir = "header"})
+ add_configfiles("config.h.in", {variables = {hello = "xmake"}, prefixdir = "header"})
add_configfiles("*.man", {copyonly = true, prefixdir = "man"})
add_includedirs("$(buildir)/config/header")
@@ -14,8 +18,9 @@ target("test2")
set_kind("binary")
add_files("main2.c")
+ set_configvar("module", "test2")
set_configdir("$(buildir)/config2")
add_configfiles("test.c.in", {filename = "mytest.c"})
- add_configfiles("config2.h.in", {variables = {hello = "xmake2", module = "test"}, pattern = "@(.-)@", prefixdir = "header"})
+ add_configfiles("config2.h.in", {variables = {hello = "xmake2"}, pattern = "@(.-)@", prefixdir = "header"})
add_configfiles("*.man", {onlycopy = true, prefixdir = "man"})
add_includedirs("$(buildir)/config2/header")
diff --git a/xmake/actions/config/configfiles.lua b/xmake/actions/config/configfiles.lua
index 1bdf268a2..afa153a07 100644
--- a/xmake/actions/config/configfiles.lua
+++ b/xmake/actions/config/configfiles.lua
@@ -26,7 +26,6 @@
import("core.base.option")
import("core.project.config")
import("core.project.project")
-import("core.platform.platform")
-- get all configuration files
function _get_configfiles()
@@ -87,39 +86,22 @@ function _generate_configfile(srcfile, dstfile, fileinfo, targets)
os.tryrm(dstfile_tmp)
os.cp(srcfile, dstfile_tmp)
- -- replace all variables
+ -- get all variables
local variables = fileinfo.variables or {}
- local pattern = fileinfo.pattern or "%${(.-)}"
- io.gsub(dstfile_tmp, "(" .. pattern .. ")", function(_, variable)
-
- -- to lower
- variable = variable:trim():lower()
-
- -- hack buildir first
- if variable == "buildir" then
- return config.buildir()
- end
-
- -- attempt to get it directly from the configure
- local result = variables[variable] or config.get(variable)
- if not result or type(result) ~= "string" then
-
- -- init maps
- local maps =
- {
- host = os.host()
- , projectdir = os.projectdir()
- }
- result = maps[variable]
-
- -- attempt to get it from the platform tools, e.g. cc, cxx, ld ..
- -- because these values may not exist in config cache when call `config.get()`, we need check and get it.
- --
- if not result then
- result = platform.tool(variable)
+ for _, target in ipairs(targets) do
+ for name, value in pairs(target:get("configvar")) do
+ if variables[name] == nil then
+ variables[name] = table.unwrap(value)
end
end
- return result
+ end
+
+ -- replace all variables
+ local pattern = fileinfo.pattern or "%${(.-)}"
+ io.gsub(dstfile_tmp, "(" .. pattern .. ")", function(_, variable)
+ local value = variables[variable:trim()]
+ assert(value ~= nil, "cannot get variable(%s) in %s.", variable, srcfile)
+ return value
end)
-- update file if the content is changed
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index ab55921da..544c2dd5e 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -1107,6 +1107,10 @@ function interpreter:api_register_set_keyvalues(scope_kind, ...)
local name_key = name .. "." .. key
scope[name_key] = values
+ -- fix override attributes
+ scope["__override_" .. name] = false
+ scope["__override_" .. name_key] = true
+
-- save extra config
if extra_config then
scope["__extra_" .. name_key] = scope["__extra_" .. name_key] or {}
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index de1cd6f47..f1762177f 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -77,6 +77,7 @@ function target.apis()
{
-- target.set_xxx
"target.set_values"
+ , "target.set_configvar"
-- target.add_xxx
, "target.add_values"
}