diff options
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/base/io.lua | 7 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 42 |
2 files changed, 46 insertions, 3 deletions
diff --git a/xmake/scripts/base/io.lua b/xmake/scripts/base/io.lua index c1808f731..c6be077be 100644 --- a/xmake/scripts/base/io.lua +++ b/xmake/scripts/base/io.lua @@ -62,7 +62,7 @@ function io._save_with_level(file, object, level) -- save key if type(k) == "string" then - file:write(k, " = ") + file:write(string.format("[%q]", k), " = ") end -- save value @@ -154,7 +154,7 @@ function io.load(filepath) if data and type(data) == "string" then -- load script - local script = loadstring("return " .. data) + local script, errs = loadstring("return " .. data) if script then -- load object @@ -168,7 +168,8 @@ function io.load(filepath) -- error errors = string.format("load %s failed!", filepath) end - end + -- errors + else errors = errs end end -- close file diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index 9e4d9e979..90454ecf2 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -158,6 +158,9 @@ function project._api_add_subdirs(env, ...) -- check assert(env) + -- init mtime for files + project._MTIMES = project._MTIMES or {} + -- done for _, subdir in ipairs(table.join(...)) do if subdir and type(subdir) == "string" then @@ -181,6 +184,9 @@ function project._api_add_subdirs(env, ...) utils.error(errors) assert(false) end + + -- get mtime of the file + project._MTIMES[file] = os.mtime(file) end end end @@ -192,6 +198,9 @@ function project._api_add_subfiles(env, ...) -- check assert(env) + -- init mtime for files + project._MTIMES = project._MTIMES or {} + -- done for _, subfile in ipairs(table.join(...)) do if subfile and type(subfile) == "string" then @@ -214,6 +223,9 @@ function project._api_add_subfiles(env, ...) utils.error(errors) assert(false) end + + -- get mtime of the file + project._MTIMES[file] = os.mtime(subfile) end end end @@ -481,6 +493,36 @@ function project._make_targets(configs) target[k] = v end end + + -- init mtime for the project file + project._MTIMES = project._MTIMES or {} + project._MTIMES[xmake._PROJECT_FILE] = os.mtime(xmake._PROJECT_FILE) + + -- get the mtimes for configure + local mtimes_config = config.get("__mtimes") + if mtimes_config then + + -- check for all project files and we need reconfig and rebuild it if them have been modified + for file, mtime in pairs(project._MTIMES) do + + -- modified? reconfig and rebuild it + local mtime_old = mtimes_config[file] + if not mtime_old or mtime > mtime_old then + config._RECONFIG = true + config.set("__rebuild", true) + break + end + end + end + + -- update mtimes + config.set("__mtimes", project._MTIMES) + + -- reconfig it? we need reprobe it + if config._RECONFIG then + project.probe() + config.clearup() + end end -- make option for checking links |
