summaryrefslogtreecommitdiff
path: root/xmake/scripts/base
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 /xmake/scripts/base
parent7be8238f634969e80e678f59ab418900f846b094 (diff)
add some interfaces for changing directory
Diffstat (limited to 'xmake/scripts/base')
-rw-r--r--xmake/scripts/base/makefile.lua27
-rw-r--r--xmake/scripts/base/os.lua41
2 files changed, 68 insertions, 0 deletions
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