diff options
| author | ruki <[email protected]> | 2015-06-11 15:08:30 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-11 15:08:30 +0800 |
| commit | ef4fe60273da742248fe9111e9141df51185c204 (patch) | |
| tree | e114a7fabbf363772e4c3247f68b9631c64418aa /xmake/scripts/base | |
| parent | d81ff2a9fbfefbfd58697f918a879a59e14321c1 (diff) | |
open new file and create directory
Diffstat (limited to 'xmake/scripts/base')
| -rw-r--r-- | xmake/scripts/base/compiler.lua | 5 | ||||
| -rw-r--r-- | xmake/scripts/base/io.lua | 19 | ||||
| -rw-r--r-- | xmake/scripts/base/makefile.lua | 7 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 3 |
4 files changed, 24 insertions, 10 deletions
diff --git a/xmake/scripts/base/compiler.lua b/xmake/scripts/base/compiler.lua index f078c598f..23796d403 100644 --- a/xmake/scripts/base/compiler.lua +++ b/xmake/scripts/base/compiler.lua @@ -24,6 +24,7 @@ local compiler = compiler or {} -- load modules +local io = require("base/io") local path = require("base/path") local rule = require("base/rule") local utils = require("base/utils") @@ -328,7 +329,7 @@ function compiler.check_include(opt, include, srcpath, objpath) assert(opt and srcpath and objpath) -- open the checking source file - local srcfile = io.open(srcpath, "w") + local srcfile = io.openmk(srcpath) if not srcfile then return end -- make include @@ -402,7 +403,7 @@ function compiler.check_function(opt, interface, srcpath, objpath) assert(opt and interface) -- open the checking source file - local srcfile = io.open(srcpath, "w") + local srcfile = io.openmk(srcpath) if not srcfile then return end -- get the compiler diff --git a/xmake/scripts/base/io.lua b/xmake/scripts/base/io.lua index 7be2d6d3a..db7c2b934 100644 --- a/xmake/scripts/base/io.lua +++ b/xmake/scripts/base/io.lua @@ -24,6 +24,7 @@ local io = io or {} -- load modules +local path = require("base/path") local utils = require("base/utils") -- save object with the level @@ -96,11 +97,27 @@ function io._save(file, object) return io._save_with_level(file, object, 0) end +-- create directory and open a writable file +function io.openmk(filepath) + + -- check + assert(filepath) + + -- get the file directory + local dir = path.directory(filepath) + + -- ensure the file directory + if not os.isdir(dir) then os.mkdir(dir) end + + -- open it + return io.open(filepath, "w") +end + -- save object the the given filepath function io.save(filepath, object) -- open the file - local file = io.open(filepath, "w") + local file = io.openmk(filepath) if not file then -- error return false, string.format("open %s failed!", filepath) diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua index 0453df95d..6ad63490b 100644 --- a/xmake/scripts/base/makefile.lua +++ b/xmake/scripts/base/makefile.lua @@ -213,11 +213,6 @@ function makefile.make() local buildir = config.get("buildir") assert(buildir) - -- make the build directory - if not os.isdir(buildir) then - assert(os.mkdir(buildir)) - end - -- init the log file local logfile = rule.logfile() if logfile and os.isfile(logfile) then @@ -230,7 +225,7 @@ function makefile.make() -- open the makefile local path = buildir .. "/makefile" - local file = io.open(path, "w") + local file = io.openmk(path) if not file then -- error utils.error("open %s failed!", path) diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index 39cfa7c42..fc168851e 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -259,7 +259,8 @@ function project._makeconf_for_target(target_name, target) local prefix = target_name:upper() .. "_CONFIG" -- open the file - local file = project._CONFILES[configfile] or io.open(configfile, "w") + local file = project._CONFILES[configfile] or io.openmk(configfile) + assert(file) -- make the head if project._CONFILES[configfile] then file:write("\n") end |
