summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-05-13 18:01:22 +0800
committerruki <[email protected]>2016-05-13 18:01:22 +0800
commit99965a2a7889e93c308f860c692555ae5c5f604e (patch)
tree3cc7e47e6f5ac9f9bb9192c47a98a00b4abbf8fc
parent4b32ac0799e14663522b8b6c42c4343041342183 (diff)
fix project option bug and impl auto-config for build and clean action
-rwxr-xr-xxmake/actions/build/builder.lua11
-rwxr-xr-xxmake/actions/build/main.lua60
-rwxr-xr-xxmake/actions/clean/main.lua16
-rwxr-xr-xxmake/actions/config/main.lua53
-rw-r--r--xmake/core/platform/platform.lua2
-rw-r--r--xmake/core/project/config.lua41
-rw-r--r--xmake/core/project/project.lua6
-rw-r--r--xmake/core/sandbox/modules/import.lua37
-rw-r--r--xmake/core/sandbox/modules/import/core/project/config.lua7
9 files changed, 133 insertions, 100 deletions
diff --git a/xmake/actions/build/builder.lua b/xmake/actions/build/builder.lua
index aa71721cf..83302fb78 100755
--- a/xmake/actions/build/builder.lua
+++ b/xmake/actions/build/builder.lua
@@ -31,13 +31,6 @@ import("core.tool.linker")
import("core.tool.compiler")
import("core.platform.environment")
--- get target
-function _target(targetname)
-
- -- get and check it
- return assert(project.target(targetname), "unknown target: %s", targetname)
-end
-
-- make the object for the *.[o|obj] source file
function _make_object_for_object(target, srcfile, objfile)
@@ -156,7 +149,7 @@ function _make_target_and_deps(target)
-- make for all dependent targets
for _, depname in ipairs(target:get("deps")) do
- _make_target_and_deps(_target(depname))
+ _make_target_and_deps(project.target(depname))
end
-- make target
@@ -185,7 +178,7 @@ function make(targetname)
else
-- make target
- _make_target_and_deps(_target(targetname))
+ _make_target_and_deps(project.target(targetname))
end
-- leave toolchains environment
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index 58e77edf7..3053d2b77 100755
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -30,36 +30,6 @@ import("core.platform.platform")
import("core.tool.tool")
import("builder")
--- project files(xmake.lua) have been changed?
-function _project_changed(targetname)
-
- -- get the current mtimes
- local mtimes = project.mtimes()
-
- -- get the previous mtimes
- local changed = false
- local mtimes_prev = cache.get("mtimes")
- if mtimes_prev then
-
- -- check for all project files
- for file, mtime in pairs(mtimes) do
-
- -- modified? reconfig and rebuild it
- local mtime_prev = mtimes_prev[file]
- if not mtime_prev or mtime > mtime_prev then
- changed = true
- break
- end
- end
- end
-
- -- update mtimes
- cache.set("mtimes", mtimes)
-
- -- changed?
- return changed
-end
-
-- main
function main()
@@ -71,33 +41,11 @@ function main()
-- get the target name
local targetname = option.get("target")
- -- load project configure
- config.load(targetname)
-
- -- enter cache scope: build
- cache.enter("local.build")
-
- -- host changed?
- if config.host() ~= os.host() then
-
- -- reinit config
- config.init()
-
- -- reconfig it
- task.run("config", {target = targetname, clean = true})
-
- -- project changed?
- elseif _project_changed(targetname) then
-
- -- reconfig it
- task.run("config", {target = targetname})
- end
-
- -- load platform
- platform.load(config.plat())
+ -- config it first
+ task.run("config", {target = targetname})
- -- load project
- project.load()
+ -- enter cache scope
+ cache.enter("local.config")
-- rebuild?
if option.get("rebuild") or cache.get("rebuild") then
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua
index acbba6d72..979027d17 100755
--- a/xmake/actions/clean/main.lua
+++ b/xmake/actions/clean/main.lua
@@ -22,6 +22,7 @@
-- imports
import("core.base.option")
+import("core.project.task")
import("core.project.config")
import("core.project.global")
import("core.project.project")
@@ -156,19 +157,8 @@ function main()
-- get the target name
local targetname = option.get("target")
- -- load project configure
- config.load(targetname)
-
- -- load platform
- platform.load(config.plat())
-
- -- load project
- project.load()
-
- -- check target
- if targetname and targetname ~= "all" and nil == project.target(targetname) then
- raise("unknown target: %s", targetname)
- end
+ -- config it first
+ task.run("config", {target = targetname})
-- enter project directory
os.cd(project.directory())
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 2fb51e0a5..1f8943c4c 100755
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -34,9 +34,49 @@ function _option_filter(name)
return name and name ~= "target" and name ~= "file" and name ~= "project" and name ~= "verbose" and name ~= "clean"
end
+-- need check
+function _need_check()
+
+ -- the configure has been changed? reconfig it
+ if config.changed() then
+ return true
+ end
+
+ -- get the current mtimes
+ local mtimes = project.mtimes()
+
+ -- get the previous mtimes
+ local changed = false
+ local mtimes_prev = cache.get("mtimes")
+ if mtimes_prev then
+
+ -- check for all project files
+ for file, mtime in pairs(mtimes) do
+
+ -- modified? reconfig and rebuild it
+ local mtime_prev = mtimes_prev[file]
+ if not mtime_prev or mtime > mtime_prev then
+ changed = true
+ break
+ end
+ end
+ end
+
+ -- update mtimes
+ cache.set("mtimes", mtimes)
+
+ -- changed?
+ return changed
+end
+
-- main
function main()
+ -- avoid to run this task repeatly
+ if _g.finished then
+ return
+ end
+
-- check xmake.lua
if not os.isfile(project.file()) then
raise("xmake.lua not found!")
@@ -75,9 +115,14 @@ function main()
end
end
+ -- enter cache scope
+ cache.enter("local.config")
+
-- merge the checked configure
- config.check()
- project.check()
+ if _need_check() then
+ config.check()
+ project.check()
+ end
-- merge the cached configure
if not option.get("clean") then
@@ -107,7 +152,6 @@ function main()
end
-- need rebuild it
- cache.enter("local.build")
cache.set("rebuild", true)
cache.flush()
@@ -120,6 +164,9 @@ function main()
-- dump it
config.dump()
+ -- finished
+ _g.finished = true
+
-- trace
print("configure ok!")
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index f54b96952..139375b50 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -190,7 +190,7 @@ function _instance:get(name)
-- load it
local ok, errors = sandbox.load(info.load)
if not ok then
- raise(errors)
+ os.raise(errors)
end
-- save _g
diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua
index 918729894..a79292bea 100644
--- a/xmake/core/project/config.lua
+++ b/xmake/core/project/config.lua
@@ -198,5 +198,46 @@ function config.dump()
end
+-- the configure has been changed for the given target?
+function config.changed(targetname)
+
+ -- get the target name
+ targetname = targetname or "all"
+
+ -- load configure from the file
+ local fileinfo = {}
+ local filepath = config._file()
+ if os.isfile(filepath) then
+
+ -- load it
+ local results = io.load(filepath)
+ if results then
+
+ -- get the target configure first
+ if targetname ~= "all" and results._TARGETS then
+ for name, value in pairs(table.wrap(results._TARGETS[targetname])) do
+ fileinfo[name] = value
+ end
+ end
+
+ -- merge the root configure
+ for name, value in pairs(results) do
+ if fileinfo[name] == nil then
+ fileinfo[name] = value
+ end
+ end
+ end
+ end
+
+ -- compare the current configure
+ for name, value in pairs(config.options()) do
+
+ -- changed?
+ if fileinfo[name] ~= value then
+ return true
+ end
+ end
+end
+
-- return module
return config
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 599a9fa22..5c3288435 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -551,6 +551,12 @@ function project.check()
opt:clear()
end
+
+ -- no check
+ elseif config.get(name) then
+
+ -- save this option to configure directly
+ opt:save()
end
end
diff --git a/xmake/core/sandbox/modules/import.lua b/xmake/core/sandbox/modules/import.lua
index 6871abd53..8aff5f3bd 100644
--- a/xmake/core/sandbox/modules/import.lua
+++ b/xmake/core/sandbox/modules/import.lua
@@ -240,6 +240,25 @@ function sandbox_import.import(name, args)
-- the arguments
args = args or {}
+ -- get the parent scope
+ local scope_parent = getfenv(2)
+ assert(scope_parent)
+
+ -- get module name
+ local modulename = sandbox_import._modulename(name)
+ if not modulename then
+ raise("cannot get module name for %s", name)
+ end
+
+ -- the imported name
+ local imported_name = args.alias or modulename
+
+ -- this module has been imported?
+ local module = rawget(scope_parent, imported_name)
+ if module ~= nil then
+ return module
+ end
+
-- get the current sandbox instance
local instance = sandbox.instance()
assert(instance)
@@ -267,19 +286,6 @@ function sandbox_import.import(name, args)
-- get module script
local script = errors
- -- get module name
- local modulename = sandbox_import._modulename(name)
- if not modulename then
- raise("cannot get module name for %s", name)
- end
-
- -- get the parent scope
- local scope_parent = getfenv(2)
- assert(scope_parent)
-
- -- the imported name
- local imported_name = args.alias or modulename
-
-- inherit?
if args.inherit then
@@ -312,11 +318,6 @@ function sandbox_import.import(name, args)
end
- -- this module has been imported?
- if rawget(scope_parent, imported_name) then
- raise("this module: %s has been imported!", name)
- end
-
-- import this module into the parent scope
scope_parent[imported_name] = module
diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua
index 729bfa105..9e54b2428 100644
--- a/xmake/core/sandbox/modules/import/core/project/config.lua
+++ b/xmake/core/sandbox/modules/import/core/project/config.lua
@@ -116,6 +116,13 @@ function sandbox_core_project_config.save(targetname)
end
end
+-- the configure has been changed for the given target?
+function sandbox_core_project_config.changed(targetname)
+
+ -- changed?
+ return config.changed(targetname)
+end
+
-- init the configure
function sandbox_core_project_config.init()