diff options
| author | OpportunityLiu <[email protected]> | 2019-07-17 08:56:26 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-19 11:48:32 +0800 |
| commit | d9560889580bfe3c58f2f3f09b2f52ed3a03a36f (patch) | |
| tree | 452dcd8369d43d233424cd14740729b5af45a2a5 | |
| parent | 948e157842d7498486067c05708cf5cfd9a0b509 (diff) | |
fix code style
| -rw-r--r-- | xmake/core/base/os.lua | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index fe88c65bb..6be21560c 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -11,7 +11,7 @@ -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. --- +-- -- Copyright (C) 2015 - 2019, TBOOX Open Source Group. -- -- @author ruki @@ -39,15 +39,15 @@ os._setenv = os._setenv or os.setenv os._getenvs = os._getenvs or os.getenvs os._readlink = os._readlink or os.readlink --- copy single file or directory +-- copy single file or directory function os._cp(src, dst) - + -- check assert(src and dst) -- is file? if os.isfile(src) then - + -- the destination is directory? append the filename if os.isdir(dst) or path.islastsep(dst) then dst = path.join(dst, path.filename(src)) @@ -59,7 +59,7 @@ function os._cp(src, dst) end -- is directory? elseif os.isdir(src) then - + -- the destination directory exists? append the filename if os.isdir(dst) or path.islastsep(dst) then dst = path.join(dst, path.filename(path.translate(src))) @@ -74,20 +74,20 @@ function os._cp(src, dst) else return false, string.format("cannot copy file %s, error: not found this file", src) end - + -- ok return true end -- move single file or directory function os._mv(src, dst) - + -- check assert(src and dst) -- exists file or directory? if os.exists(src) then - + -- the destination directory exists? append the filename if os.isdir(dst) or path.islastsep(dst) then dst = path.join(dst, path.filename(path.translate(src))) @@ -101,14 +101,14 @@ function os._mv(src, dst) else return false, string.format("cannot move %s to %s, not found this file %s", src, dst, os.strerror()) end - + -- ok return true end --- remove single file or directory +-- remove single file or directory function os._rm(filedir) - + -- check assert(filedir) @@ -136,7 +136,7 @@ function os.argw(argv) -- match all arguments local results = {} for _, arg in ipairs(table.wrap(argv)) do - + -- exists wildcards? if arg:find("([%+%-%^%$%*%[%]%%])") then local pathes = os.match(arg, 'a') @@ -185,7 +185,7 @@ end -- match files or directories -- --- @param pattern the search pattern +-- @param pattern the search pattern -- uses "*" to match any part of a file or directory name, -- uses "**" to recurse into subdirectories. -- @@ -198,7 +198,7 @@ end -- @code -- local dirs, count = os.match("./src/*", true) -- local files, count = os.match("./src/**.c") --- local file = os.match("./src/test.c", 'f', function (filepath, isdir) +-- local file = os.match("./src/test.c", 'f', function (filepath, isdir) -- return true -- continue it -- return false -- break it -- end) @@ -235,7 +235,7 @@ function os.match(pattern, mode, callback) assert(mode, "invalid match mode: %s", mode) elseif mode then mode = 1 - else + else mode = 0 end @@ -314,7 +314,7 @@ end -- copy files or directories function os.cp(...) - + -- check arguments local args = {...} if #args < 2 then @@ -341,7 +341,7 @@ end -- move files or directories function os.mv(...) - + -- check arguments local args = {...} if #args < 2 then @@ -368,7 +368,7 @@ end -- remove files or directories function os.rm(...) - + -- check arguments local args = {...} if #args < 1 then @@ -433,14 +433,14 @@ function os.cd(dir) else return nil, string.format("cannot change directory %s, not found this directory %s", dir, os.strerror()) end - + -- ok return oldir end -- create directories function os.mkdir(...) - + -- check arguments local args = {...} if #args < 1 then @@ -460,7 +460,7 @@ end -- remove directories function os.rmdir(...) - + -- check arguments local args = {...} if #args < 1 then @@ -564,7 +564,7 @@ function os.runv(program, argv, opt) return true end --- execute command +-- execute command function os.exec(cmd, outfile, errfile) -- parse arguments @@ -581,8 +581,8 @@ end -- -- @param program "clang", "xcrun -sdk macosx clang", "~/dir/test\ xxx/clang" -- filename "clang", "xcrun"", "~/dir/test\ xxx/clang" --- @param argv the arguments --- @param opt the options, .e.g {wildcards = false, stdout = outfile, stderr = errfile, +-- @param argv the arguments +-- @param opt the options, .e.g {wildcards = false, stdout = outfile, stderr = errfile, -- envs = {PATH = "xxx;xx", CFLAGS = "xx"}} -- function os.execv(program, argv, opt) @@ -631,7 +631,7 @@ function os.execv(program, argv, opt) -- wait process local waitok = -1 - local status = -1 + local status = -1 if coroutine.running() then -- save the current directory @@ -688,7 +688,7 @@ function os.iorunv(program, argv, opt) local errfile = os.tmpfile() -- run command - local ok = os.execv(program, argv, table.join(opt, {stdout = outfile, stderr = errfile})) + local ok = os.execv(program, argv, table.join(opt, {stdout = outfile, stderr = errfile})) -- get output and error data local outdata = io.readfile(outfile) @@ -983,13 +983,11 @@ function os.addenvp(name, values, sep) if #values > 0 then local oldenv = os.getenv(name) local appendenv = table.concat(values, sep) - local newenv if oldenv == "" or oldenv == nil then - newenv = appendenv + return os._setenv(name, appendenv) else - newenv = appendenv .. sep .. oldenv + return os._setenv(name, appendenv .. sep .. oldenv) end - return os._setenv(name, newenv) else return true end |
