summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-11-17 23:38:54 +0800
committerruki <[email protected]>2019-11-17 23:38:54 +0800
commitcf984b4a0e9e4ea733f2c35deca3b714baa2a227 (patch)
treea543106b0ceca6f81d7528749bc3812adbeefdc1
parentf5258628ba215481571ce1e957737b2ed97c45ab (diff)
add .xmakerc.lua
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/core/_xmake_main.lua5
-rw-r--r--xmake/core/base/interpreter.lua8
-rw-r--r--xmake/core/project/project.lua21
4 files changed, 33 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 706a408c5..517c4398f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
* [#569](https://github.com/xmake-io/xmake/pull/569): Add c++ modules build rules
* Add `xmake project -k xmakefile` generator
+* [620](https://github.com/xmake-io/xmake/issues/620): Add global `~/.xmakerc.lua` for all projects.
### Change
@@ -653,6 +654,7 @@
* [#569](https://github.com/xmake-io/xmake/pull/569): 增加对c++模块的实验性支持
* 添加`xmake project -k xmakefile`生成器
+* [620](https://github.com/xmake-io/xmake/issues/620): 添加全局`~/.xmakerc.lua`配置文件,对所有本地工程生效.
### 改进
diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua
index 9e80593fe..93f225c56 100644
--- a/xmake/core/_xmake_main.lua
+++ b/xmake/core/_xmake_main.lua
@@ -66,6 +66,11 @@ function _loadfile_impl(filepath, mode, opt)
end
io.file_close(file)
+ -- do on_load()
+ if opt.on_load then
+ data = opt.on_load(data) or data
+ end
+
-- load script from string
return load(data, "@" .. displaypath, mode)
end
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 12dc62fa4..2c3cfc52d 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -691,13 +691,17 @@ function interpreter.new()
end
-- load script file, e.g. xmake.lua
-function interpreter:load(file)
+--
+-- @param opt {on_load_data = function (data) return data end}
+--
+function interpreter:load(file, opt)
-- check
assert(self and self._PUBLIC and self._PRIVATE and file)
-- load the script
- local script, errors = loadfile(file)
+ opt = opt or {}
+ local script, errors = loadfile(file, "bt", {on_load = opt.on_load_data})
if not script then
return nil, errors
end
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 4baa8ab5c..0a6451b80 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -291,6 +291,16 @@ function project.file()
return os.projectfile()
end
+-- get the global rcfile: ~/.xmakerc.lua
+function project.rcfile()
+ local xmakerc = project._XMAKE_RCFILE
+ if xmakerc == nil then
+ xmakerc = os.getenv("XMAKE_RCFILE") or "~/.xmakerc.lua"
+ project._XMAKE_RCFILE = xmakerc
+ end
+ return xmakerc
+end
+
-- get the project directory
function project.directory()
return os.projectdir()
@@ -329,7 +339,16 @@ function project._load(force, disable_filter)
local interp = project.interpreter()
-- load script
- local ok, errors = interp:load(project.file())
+ local ok, errors = interp:load(project.file(), {on_load_data = function (data)
+ local xmakerc_file = project.rcfile()
+ if xmakerc_file and os.isfile(xmakerc_file) then
+ local rcdata = io.readfile(xmakerc_file)
+ if rcdata then
+ data = rcdata .. "\n" .. data
+ end
+ end
+ return data
+ end})
if not ok then
return false, (errors or "load project file failed!")
end