summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-01-29 00:39:42 +0800
committerruki <[email protected]>2021-01-29 00:39:42 +0800
commitbfd7b2f37b94ab28ddb5aed1e6bb492708c52d1f (patch)
treed5b7672e35d59e1bc11aed3a8394ffa2aa7b1f78
parentd4e0263d7452fa502f8e4c2914d22dd186a14950 (diff)
add rcfiles
-rw-r--r--xmake/core/project/project.lua50
-rw-r--r--xmake/core/sandbox/modules/import/core/project/project.lua2
-rw-r--r--xmake/plugins/show/lists/envs.lua2
3 files changed, 32 insertions, 22 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index bb96c79f0..f9ee0d0db 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -167,11 +167,12 @@ function project._load(force, disable_filter)
-- load script
local ok, errors = interp:load(project.rootfile(), {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
+ for _, xmakerc_file in ipairs(project.rcfiles()) do
+ if xmakerc_file and os.isfile(xmakerc_file) then
+ local rcdata = io.readfile(xmakerc_file)
+ if rcdata then
+ data = rcdata .. "\n" .. data
+ end
end
end
return data
@@ -837,28 +838,35 @@ end
-- get all loaded project files with subfiles (xmake.lua)
function project.allfiles()
- local rcfile = project.rcfile()
- if rcfile and os.isfile(rcfile) then
- return table.join(project.interpreter():scriptfiles(), rcfile)
- else
- return project.interpreter():scriptfiles()
+ local files = {}
+ table.join2(files, project.interpreter():scriptfiles())
+ for _, rcfile in ipairs(project.rcfiles()) do
+ if rcfile and os.isfile(rcfile) then
+ table.insert(files, rcfile)
+ end
end
+ return files
end
--- get the global rcfile: ~/.xmakerc.lua
-function project.rcfile()
- local xmakerc = project._XMAKE_RCFILE
- if xmakerc == nil then
- xmakerc = "/etc/xmakerc.lua"
- if not os.isfile(xmakerc) then
- xmakerc = "~/.xmakerc.lua"
- if not os.isfile(xmakerc) then
- xmakerc = path.join(global.directory(), "xmakerc.lua")
+-- get the global rcfiles: ~/.xmakerc.lua
+function project.rcfiles()
+ local rcfiles = project._XMAKE_RCFILES
+ if rcfiles == nil then
+ rcfiles = {}
+ local rcpaths = {}
+ local rcpaths_env = os.getenv("XMAKE_RCFILES")
+ if rcpaths_env then
+ table.join2(rcpaths, path.splitenv(rcpaths_env))
+ end
+ table.join2(rcpaths, {"/etc/xmakerc.lua", "~/.xmakerc.lua", path.join(global.directory(), "xmakerc.lua")})
+ for _, rcfile in ipairs(rcpaths) do
+ if os.isfile(rcfile) then
+ table.insert(rcfiles, rcfile)
end
end
- project._XMAKE_RCFILE = xmakerc
+ project._XMAKE_RCFILES = rcfiles
end
- return xmakerc
+ return rcfiles
end
-- get the project directory
diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua
index 11bbb3a19..24e146ee9 100644
--- a/xmake/core/sandbox/modules/import/core/project/project.lua
+++ b/xmake/core/sandbox/modules/import/core/project/project.lua
@@ -48,7 +48,7 @@ sandbox_core_project.option = project.option
sandbox_core_project.options = project.options
sandbox_core_project.rootfile = project.rootfile
sandbox_core_project.allfiles = project.allfiles
-sandbox_core_project.rcfile = project.rcfile
+sandbox_core_project.rcfiles = project.rcfiles
sandbox_core_project.directory = project.directory
sandbox_core_project.name = project.name
sandbox_core_project.modes = project.modes
diff --git a/xmake/plugins/show/lists/envs.lua b/xmake/plugins/show/lists/envs.lua
index 63cad89f7..1f13b4cb1 100644
--- a/xmake/plugins/show/lists/envs.lua
+++ b/xmake/plugins/show/lists/envs.lua
@@ -22,6 +22,7 @@
import("core.base.text")
import("core.base.global")
import("core.project.config")
+import("core.project.project")
-- show all toolchains
function main()
@@ -33,6 +34,7 @@ function main()
XMAKE_LOGFILE = {"Set the log output file path.", os.getenv("XMAKE_LOGFILE")},
XMAKE_ROOT = {"Allow xmake to run under root.", os.getenv("XMAKE_ROOT")},
XMAKE_RAMDIR = {"Set the ramdisk directory.", os.getenv("XMAKE_RAMDIR")},
+ XMAKE_RCFILES = {"Set the runtime configuration files.", path.joinenv(project.rcfiles())},
XMAKE_TMPDIR = {"Set the temporary directory.", os.tmpdir()}}
local width = 24
for name, env in pairs(envs) do