summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-16 22:10:43 +0800
committerruki <[email protected]>2015-06-16 22:10:43 +0800
commit8c8d7af7135b400a44cc58d3f0d74a72164f9b2a (patch)
treec491d0d3cd0f512b5c5e916f20264b3e7603f69e
parent3d97768287a089f862d841cb697b48852941b002 (diff)
check for the mtime of project file
-rwxr-xr-xcore/src/xmake/machine.c2
-rwxr-xr-xcore/src/xmake/makefile1
-rwxr-xr-xcore/src/xmake/os/mtime.c55
-rw-r--r--tests/console/xmake.lua2
-rw-r--r--xmake/scripts/base/io.lua7
-rw-r--r--xmake/scripts/base/project.lua42
6 files changed, 105 insertions, 4 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index 018020b5c..0898f9807 100755
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -56,6 +56,7 @@ tb_int_t xm_os_rmdir(lua_State* lua);
tb_int_t xm_os_mkdir(lua_State* lua);
tb_int_t xm_os_cpdir(lua_State* lua);
tb_int_t xm_os_chdir(lua_State* lua);
+tb_int_t xm_os_mtime(lua_State* lua);
tb_int_t xm_os_curdir(lua_State* lua);
tb_int_t xm_os_tmpdir(lua_State* lua);
tb_int_t xm_os_isfile(lua_State* lua);
@@ -88,6 +89,7 @@ static luaL_Reg const g_os_functions[] =
, { "mkdir", xm_os_mkdir }
, { "cpdir", xm_os_cpdir }
, { "chdir", xm_os_chdir }
+, { "mtime", xm_os_mtime }
, { "curdir", xm_os_curdir }
, { "tmpdir", xm_os_tmpdir }
, { "isfile", xm_os_isfile }
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index 932737fe8..3cb152e16 100755
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -20,6 +20,7 @@ xmake_C_FILES += \
os/mkdir \
os/cpdir \
os/chdir \
+ os/mtime \
os/curdir \
os/tmpdir \
os/isfile \
diff --git a/core/src/xmake/os/mtime.c b/core/src/xmake/os/mtime.c
new file mode 100755
index 000000000..623cdbd56
--- /dev/null
+++ b/core/src/xmake/os/mtime.c
@@ -0,0 +1,55 @@
+/*!The Automatic Cross-platform Build Tool
+ *
+ * XMake is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * XMake is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with XMake;
+ * If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+ *
+ * Copyright (C) 2009 - 2015, ruki All rights reserved.
+ *
+ * @author ruki
+ * @file mtime.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "mtime"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_mtime(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // get the path
+ tb_char_t const* path = luaL_checkstring(lua, 1);
+ tb_check_return_val(path, 0);
+
+ // done os.mtime(path)
+ tb_file_info_t info = {0};
+ if (tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_FILE))
+ lua_pushinteger(lua, (lua_Integer)info.mtime);
+ else lua_pushinteger(lua, 0);
+
+ // ok
+ return 1;
+}
diff --git a/tests/console/xmake.lua b/tests/console/xmake.lua
index 9f45c4cce..57c9f641a 100644
--- a/tests/console/xmake.lua
+++ b/tests/console/xmake.lua
@@ -22,7 +22,7 @@ if modes("profile") then
set_warnings("none")
set_optimize("fastest")
end
-
+
if archs("x86", "x64") then
add_defines("ARCH=\"$(arch)\"", "PLAT=$(plat)", "MODE=$(mode)", "HOST=$(host)")
end
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