summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-18 11:25:38 +0800
committerruki <[email protected]>2015-05-18 11:25:38 +0800
commitc94218b659016aadb3f1dc63cc82c3ae8dc14320 (patch)
treeddbbf771f33ae55180816403473623846a79750b
parent7be8238f634969e80e678f59ab418900f846b094 (diff)
add some interfaces for changing directory
-rw-r--r--core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h2
-rwxr-xr-xcore/pkg/tbox.pkg/inc/tbox/platform/directory.h8
-rwxr-xr-xcore/pkg/tbox.pkg/inc/tbox/platform/file.h10
-rwxr-xr-xcore/pkg/tbox.pkg/inc/tbox/platform/path.h21
-rwxr-xr-xcore/pkg/tbox.pkg/inc/tbox/prefix/arch.h10
-rwxr-xr-xcore/src/xmake/machine.c10
-rwxr-xr-xcore/src/xmake/makefile4
-rwxr-xr-xcore/src/xmake/os/chdir.c52
-rwxr-xr-xcore/src/xmake/os/curdir.c50
-rwxr-xr-xcore/src/xmake/os/tmpdir.c50
-rwxr-xr-xcore/src/xmake/path/relative.c56
-rw-r--r--xmake/scripts/action/_config.lua1
-rw-r--r--xmake/scripts/base/makefile.lua27
-rw-r--r--xmake/scripts/base/os.lua41
14 files changed, 329 insertions, 13 deletions
diff --git a/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h b/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h
index 0617c7331..45f612bee 100644
--- a/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h
+++ b/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h
@@ -14,7 +14,7 @@
#define TB_CONFIG_VERSION_ALTER 8
// build version
-#define TB_CONFIG_VERSION_BUILD 201505141040
+#define TB_CONFIG_VERSION_BUILD 201505181121
// small
#define TB_CONFIG_SMALL (0)
diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/directory.h b/core/pkg/tbox.pkg/inc/tbox/platform/directory.h
index e011ad0ac..ea474114e 100755
--- a/core/pkg/tbox.pkg/inc/tbox/platform/directory.h
+++ b/core/pkg/tbox.pkg/inc/tbox/platform/directory.h
@@ -79,6 +79,14 @@ tb_size_t tb_directory_home(tb_char_t* path, tb_size_t maxn);
*/
tb_size_t tb_directory_current(tb_char_t* path, tb_size_t maxn);
+/*! set the current directory
+ *
+ * @param path the directory path
+ *
+ * @return tb_true or tb_false
+ */
+tb_bool_t tb_directory_current_set(tb_char_t const* path);
+
/*! the temporary directory
*
* @param path the directory path data
diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/file.h b/core/pkg/tbox.pkg/inc/tbox/platform/file.h
index b53d5a4ff..0590e47a2 100755
--- a/core/pkg/tbox.pkg/inc/tbox/platform/file.h
+++ b/core/pkg/tbox.pkg/inc/tbox/platform/file.h
@@ -295,16 +295,6 @@ tb_bool_t tb_file_remove(tb_char_t const* path);
*/
tb_bool_t tb_file_rename(tb_char_t const* path, tb_char_t const* dest);
-/*! the file full path
- *
- * @param path the file path
- * @param full the full path
- * @param maxn the path maxn
- *
- * @return the full path
- */
-tb_char_t const* tb_file_full(tb_char_t const* path, tb_char_t* full, tb_size_t maxn);
-
/*! link the file
*
* @param path the source file path
diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/path.h b/core/pkg/tbox.pkg/inc/tbox/platform/path.h
index 878c34e84..c08eb4f6c 100755
--- a/core/pkg/tbox.pkg/inc/tbox/platform/path.h
+++ b/core/pkg/tbox.pkg/inc/tbox/platform/path.h
@@ -88,6 +88,27 @@ tb_char_t const* tb_path_absolute(tb_char_t const* path, tb_char_t* data,
*/
tb_char_t const* tb_path_absolute_to(tb_char_t const* root, tb_char_t const* path, tb_char_t* data, tb_size_t maxn);
+/*! get the path which relative to the current directory
+ *
+ * @param path the path
+ * @param data the path data
+ * @param maxn the path maxn
+ *
+ * @return the relative path
+ */
+tb_char_t const* tb_path_relative(tb_char_t const* path, tb_char_t* data, tb_size_t maxn);
+
+/*! get the path which relative to the given root directory
+ *
+ * @param root the root path
+ * @param path the path
+ * @param data the path data
+ * @param maxn the path maxn
+ *
+ * @return the relative path
+ */
+tb_char_t const* tb_path_relative_to(tb_char_t const* root, tb_char_t const* path, tb_char_t* data, tb_size_t maxn);
+
/* //////////////////////////////////////////////////////////////////////////////////////
* extern
*/
diff --git a/core/pkg/tbox.pkg/inc/tbox/prefix/arch.h b/core/pkg/tbox.pkg/inc/tbox/prefix/arch.h
index a8b6293eb..722bfad25 100755
--- a/core/pkg/tbox.pkg/inc/tbox/prefix/arch.h
+++ b/core/pkg/tbox.pkg/inc/tbox/prefix/arch.h
@@ -79,7 +79,15 @@
# define TB_ARCH_ARM
# if defined(__ARM_ARCH)
# define TB_ARCH_ARM_VERSION __ARM_ARCH
-# if __ARM_ARCH >= 7
+# if __ARM_ARCH >= 8
+# define TB_ARCH_ARM_v8
+# if defined(__arm64) || defined(__arm64__)
+# define TB_ARCH_ARM64
+# define TB_ARCH_STRING "arm64"
+# else
+# define TB_ARCH_STRING "armv7s"
+# endif
+# elif __ARM_ARCH >= 7
# define TB_ARCH_ARM_v7
# define TB_ARCH_STRING "armv7"
# elif __ARM_ARCH >= 6
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index dd4ae864c..3fc303002 100755
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -54,6 +54,9 @@ tb_int_t xm_os_isdir(lua_State* lua);
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_curdir(lua_State* lua);
+tb_int_t xm_os_tmpdir(lua_State* lua);
tb_int_t xm_os_isfile(lua_State* lua);
tb_int_t xm_os_rmfile(lua_State* lua);
tb_int_t xm_os_cpfile(lua_State* lua);
@@ -61,6 +64,7 @@ tb_int_t xm_os_rename(lua_State* lua);
tb_int_t xm_os_exists(lua_State* lua);
// the path functions
+tb_int_t xm_path_relative(lua_State* lua);
tb_int_t xm_path_absolute(lua_State* lua);
tb_int_t xm_path_translate(lua_State* lua);
tb_int_t xm_path_is_absolute(lua_State* lua);
@@ -82,6 +86,9 @@ static luaL_Reg const g_os_functions[] =
, { "rmdir", xm_os_rmdir }
, { "mkdir", xm_os_mkdir }
, { "cpdir", xm_os_cpdir }
+, { "chdir", xm_os_chdir }
+, { "curdir", xm_os_curdir }
+, { "tmpdir", xm_os_tmpdir }
, { "isfile", xm_os_isfile }
, { "rmfile", xm_os_rmfile }
, { "cpfile", xm_os_cpfile }
@@ -93,7 +100,8 @@ static luaL_Reg const g_os_functions[] =
// the path functions
static luaL_Reg const g_path_functions[] =
{
- { "absolute", xm_path_absolute }
+ { "relative", xm_path_relative }
+, { "absolute", xm_path_absolute }
, { "translate", xm_path_translate }
, { "is_absolute", xm_path_is_absolute }
, { tb_null, tb_null }
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index 899ceaf3a..8d848e904 100755
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -18,11 +18,15 @@ xmake_C_FILES += \
os/rmdir \
os/mkdir \
os/cpdir \
+ os/chdir \
+ os/curdir \
+ os/tmpdir \
os/isfile \
os/rmfile \
os/cpfile \
os/rename \
os/exists \
+ path/relative \
path/absolute \
path/translate \
path/is_absolute \
diff --git a/core/src/xmake/os/chdir.c b/core/src/xmake/os/chdir.c
new file mode 100755
index 000000000..478ce6948
--- /dev/null
+++ b/core/src/xmake/os/chdir.c
@@ -0,0 +1,52 @@
+/*!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 chdir.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "chdir"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_chdir(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.chdir(path)
+ lua_pushboolean(lua, tb_directory_current_set(path));
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/os/curdir.c b/core/src/xmake/os/curdir.c
new file mode 100755
index 000000000..38dafdeaf
--- /dev/null
+++ b/core/src/xmake/os/curdir.c
@@ -0,0 +1,50 @@
+/*!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 curdir.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "curdir"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_curdir(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // done os.curdir()
+ tb_char_t path[TB_PATH_MAXN];
+ if (tb_directory_current(path, sizeof(path))) lua_pushstring(lua, path);
+ else lua_pushnil(lua);
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/os/tmpdir.c b/core/src/xmake/os/tmpdir.c
new file mode 100755
index 000000000..7b2d7f85d
--- /dev/null
+++ b/core/src/xmake/os/tmpdir.c
@@ -0,0 +1,50 @@
+/*!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 tmpdir.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "tmpdir"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_tmpdir(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // done os.tmpdir()
+ tb_char_t path[TB_PATH_MAXN];
+ if (tb_directory_temporary(path, sizeof(path))) lua_pushstring(lua, path);
+ else lua_pushnil(lua);
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/path/relative.c b/core/src/xmake/path/relative.c
new file mode 100755
index 000000000..02b3b3523
--- /dev/null
+++ b/core/src/xmake/path/relative.c
@@ -0,0 +1,56 @@
+/*!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 relative.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "relative"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_path_relative(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);
+
+ // get the root
+ tb_char_t const* root = luaL_optstring(lua, 2, tb_null);
+
+ // done path:relative(root)
+ tb_char_t data[TB_PATH_MAXN];
+ lua_pushstring(lua, tb_path_relative_to(root, path, data, sizeof(data) - 1));
+
+ // ok
+ return 1;
+}
diff --git a/xmake/scripts/action/_config.lua b/xmake/scripts/action/_config.lua
index 3bc9dba5a..53e41b651 100644
--- a/xmake/scripts/action/_config.lua
+++ b/xmake/scripts/action/_config.lua
@@ -27,6 +27,7 @@ local _config = _config or {}
local os = require("base/os")
local utils = require("base/utils")
local config = require("base/config")
+local makefile = require("base/makefile")
-- done the given config
function _config.done()
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua
new file mode 100644
index 000000000..5f71538c2
--- /dev/null
+++ b/xmake/scripts/base/makefile.lua
@@ -0,0 +1,27 @@
+--!The Automatic Crmakefiles-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 makefile.lua
+--
+
+-- define module: makefile
+local makefile = makefile or {}
+
+-- return module: makefile
+return makefile
diff --git a/xmake/scripts/base/os.lua b/xmake/scripts/base/os.lua
index e87eb1ec9..7da3d9dcd 100644
--- a/xmake/scripts/base/os.lua
+++ b/xmake/scripts/base/os.lua
@@ -98,5 +98,46 @@ function os.rm(path)
return true
end
+-- change to directory
+function os.cd(path)
+
+ -- check
+ assert(path)
+
+ -- change to the previous directory?
+ if path == "-" then
+ -- exists the previous directory?
+ if os._PREDIR then
+ path = os._PREDIR
+ os._PREDIR = nil
+ else
+ -- error
+ return false, string.format("not found the previous directory!")
+ end
+ end
+
+ -- is directory?
+ if os.isdir(path) then
+
+ -- get the current directory
+ local current = os.curdir()
+
+ -- change to directory
+ if not os.chdir(path) then
+ return false, string.format("cannot change directory %s!", path)
+ end
+
+ -- save the previous directory
+ os._PREDIR = current
+
+ -- not exists?
+ else
+ return false, string.format("cannot change directory %s, not found this directory!", path)
+ end
+
+ -- ok
+ return true
+end
+
-- return module: os
return os