summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-23 11:19:33 +0800
committerruki <[email protected]>2020-02-23 11:54:26 +0800
commit9d34862fe5c82c7ac7e8d6dd8a1d951b3f1ed46c (patch)
tree3f34a71e6b7a72ca8750f05acfa5a7a6f6739fdc
parentabffcefe13ed5867a9c340214baa431795e4857f (diff)
regenerate build.ninja
-rw-r--r--xmake/actions/build/main.lua2
-rw-r--r--xmake/actions/clean/main.lua2
-rw-r--r--xmake/actions/config/main.lua2
-rw-r--r--xmake/core/base/interpreter.lua25
-rw-r--r--xmake/core/project/project.lua22
-rw-r--r--xmake/core/sandbox/modules/import/core/project/project.lua11
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/cache.lua2
-rw-r--r--xmake/plugins/project/ninja/build_ninja.lua25
-rw-r--r--xmake/plugins/project/vsxmake/getinfo.lua4
9 files changed, 64 insertions, 31 deletions
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index 4c7224b2d..151a40efa 100644
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -81,7 +81,7 @@ end
function main()
-- try building it using third-party buildsystem if xmake.lua not exists
- if not os.isfile(project.file()) then
+ if not os.isfile(project.rootfile()) then
return _try_build()
end
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua
index f8dabc81a..3c4382acc 100644
--- a/xmake/actions/clean/main.lua
+++ b/xmake/actions/clean/main.lua
@@ -236,7 +236,7 @@ end
function main()
-- try cleaning it using third-party buildsystem if xmake.lua not exists
- if not os.isfile(project.file()) then
+ if not os.isfile(project.rootfile()) then
return _try_clean()
end
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 90f141968..b33267193 100644
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -148,7 +148,7 @@ function main()
-- scan project and generate it if xmake.lua not exists
local autogen = false
local trybuild = option.get("trybuild")
- if not os.isfile(project.file()) and not trybuild then
+ if not os.isfile(project.rootfile()) and not trybuild then
autogen = utils.confirm({default = false, description = "xmake.lua not found, try generating it"})
if autogen then
scangen()
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index c7f1d42ba..579ffec46 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -639,6 +639,7 @@ function interpreter.new()
local instance = { _PUBLIC = {}
, _PRIVATE = { _SCOPES = {}
, _MTIMES = {}
+ , _SCRIPT_FILES = {}
, _FILTER = require("base/filter").new()}}
-- inherit the interfaces of interpreter
@@ -711,6 +712,7 @@ function interpreter:load(file, opt)
-- init the current file
self._PRIVATE._CURFILE = file
+ self._PRIVATE._SCRIPT_FILES = {file}
-- init the root directory
self._PRIVATE._ROOTDIR = path.directory(file)
@@ -737,43 +739,33 @@ function interpreter:make(scope_kind, remove_repeat, enable_filter)
return results
end
+-- get all loaded script files (xmake.lua)
+function interpreter:scriptfiles()
+ assert(self and self._PRIVATE)
+ return self._PRIVATE._SCRIPT_FILES
+end
+
-- get mtimes
function interpreter:mtimes()
-
- -- check
assert(self and self._PRIVATE)
-
- -- get mtimes
return self._PRIVATE._MTIMES
end
-- get filter
function interpreter:filter()
-
- -- check
assert(self and self._PRIVATE)
-
- -- get it
return self._PRIVATE._FILTER
end
-- get root directory
function interpreter:rootdir()
-
- -- check
assert(self and self._PRIVATE)
-
- -- get it
return self._PRIVATE._ROOTDIR
end
-- set root directory
function interpreter:rootdir_set(rootdir)
-
- -- check
assert(self and self._PRIVATE and rootdir)
-
- -- set it
self._PRIVATE._ROOTDIR = rootdir
end
@@ -1545,6 +1537,7 @@ function interpreter:api_builtin_includes(...)
-- update the current file
self._PRIVATE._CURFILE = file
+ table.insert(self._PRIVATE._SCRIPT_FILES, file)
-- load the file script
local script, errors = loadfile(file)
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 2511e3554..bc73dc55b 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -293,11 +293,21 @@ function project.interpreter()
return interp
end
--- get the project file
-function project.file()
+-- get the root project file
+function project.rootfile()
return os.projectfile()
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()
+ end
+end
+
-- get the global rcfile: ~/.xmakerc.lua
function project.rcfile()
local xmakerc = project._XMAKE_RCFILE
@@ -352,7 +362,7 @@ function project._load(force, disable_filter)
local interp = project.interpreter()
-- load script
- local ok, errors = interp:load(project.file(), {on_load_data = function (data)
+ 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)
@@ -446,7 +456,7 @@ end
function project._load_tasks()
-- the project file is not found?
- if not os.isfile(project.file()) then
+ if not os.isfile(project.rootfile()) then
return {}, nil
end
@@ -620,7 +630,7 @@ end
function project._load_options(disable_filter)
-- the project file is not found?
- if not os.isfile(project.file()) then
+ if not os.isfile(project.rootfile()) then
return {}, nil
end
@@ -932,7 +942,7 @@ function project.menu()
-- attempt to load options from the project file
local options = nil
local errors = nil
- if os.isfile(project.file()) then
+ if os.isfile(project.rootfile()) then
options, errors = project._load_options(true)
end
diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua
index 3f197f3b3..67119ec98 100644
--- a/xmake/core/sandbox/modules/import/core/project/project.lua
+++ b/xmake/core/sandbox/modules/import/core/project/project.lua
@@ -138,9 +138,14 @@ function sandbox_core_project.options()
return project.options()
end
--- get the project file
-function sandbox_core_project.file()
- return project.file()
+-- get the root project file
+function sandbox_core_project.rootfile()
+ return project.rootfile()
+end
+
+-- get the all loaded project files
+function sandbox_core_project.allfiles()
+ return project.allfiles()
end
-- get the project rcfile
diff --git a/xmake/core/sandbox/modules/import/lib/detect/cache.lua b/xmake/core/sandbox/modules/import/lib/detect/cache.lua
index 2cf1460e3..cf8a78192 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/cache.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/cache.lua
@@ -36,7 +36,7 @@ local raise = require("sandbox/modules/raise")
function sandbox_lib_detect_cache._instance()
-- get it
- local detectcache = sandbox_lib_detect_cache._INSTANCE or cache(utils.ifelse(os.isfile(project.file()), "local.detect", "memory.detect"))
+ local detectcache = sandbox_lib_detect_cache._INSTANCE or cache(utils.ifelse(os.isfile(project.rootfile()), "local.detect", "memory.detect"))
sandbox_lib_detect_cache._INSTANCE = detectcache
return detectcache
end
diff --git a/xmake/plugins/project/ninja/build_ninja.lua b/xmake/plugins/project/ninja/build_ninja.lua
index 7d8700473..f46730e22 100644
--- a/xmake/plugins/project/ninja/build_ninja.lua
+++ b/xmake/plugins/project/ninja/build_ninja.lua
@@ -37,6 +37,14 @@ function _add_header(ninjafile)
ninjafile:print("")
end
+-- add rules for generator
+function _add_rules_for_generator(ninjafile)
+ ninjafile:print("rule gen")
+ ninjafile:print(" command = xmake project -k ninja")
+ ninjafile:print(" description = regenerating ninja files")
+ ninjafile:print("")
+end
+
-- add rules for complier (gcc)
function _add_rules_for_compiler_gcc(ninjafile, sourcekind, program)
local ccache = find_tool("ccache")
@@ -159,6 +167,9 @@ end
-- add rules
function _add_rules(ninjafile)
+ -- add rules for generator
+ _add_rules_for_generator(ninjafile)
+
-- add rules for complier
_add_rules_for_compiler(ninjafile)
@@ -219,12 +230,26 @@ function _add_build_for_target(ninjafile, target)
end
end
+-- add build rule for generator
+function _add_build_for_generator(ninjafile)
+ ninjafile:print("# build build.ninja")
+ ninjafile:print("build build.ninja: gen $")
+ local allfiles = project.allfiles()
+ for idx, projectfile in ipairs(allfiles) do
+ ninjafile:print(" %s %s", os.args(path.relative(path.absolute(projectfile))), idx < #allfiles and "$" or "")
+ end
+ ninjafile:print("")
+end
+
-- add build rule for targets
function _add_build_for_targets(ninjafile)
-- begin
ninjafile:print("# build targets\n")
+ -- add build rule for generator
+ _add_build_for_generator(ninjafile)
+
-- TODO
-- disable precompiled header first
for _, target in pairs(project.targets()) do
diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua
index d7e923d62..583e10932 100644
--- a/xmake/plugins/project/vsxmake/getinfo.lua
+++ b/xmake/plugins/project/vsxmake/getinfo.lua
@@ -270,8 +270,8 @@ function main(outputdir, vsinfo)
vsinfo.solution_dir = path.absolute(path.join(outputdir, "vsxmake" .. vsinfo.vstudio_version))
vsinfo.programdir = _make_dirs(xmake.programdir())
vsinfo.projectdir = project.directory()
- vsinfo.sln_projectfile = path.relative(project.file(), vsinfo.solution_dir)
- local projectfile = path.filename(project.file())
+ vsinfo.sln_projectfile = path.relative(project.rootfile(), vsinfo.solution_dir)
+ local projectfile = path.filename(project.rootfile())
vsinfo.slnfile = path.filename(project.directory())
-- write only if not default
if projectfile ~= "xmake.lua" then