Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
OpportunityLiu committed Jul 17, 2019
1 parent 8bc9809 commit 3d2756f
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions xmake/core/base/os.lua
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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)))
Expand All @@ -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)))
Expand All @@ -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)

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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.
--
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -314,7 +314,7 @@ end

-- copy files or directories
function os.cp(...)

-- check arguments
local args = {...}
if #args < 2 then
Expand All @@ -341,7 +341,7 @@ end

-- move files or directories
function os.mv(...)

-- check arguments
local args = {...}
if #args < 2 then
Expand All @@ -368,7 +368,7 @@ end

-- remove files or directories
function os.rm(...)

-- check arguments
local args = {...}
if #args < 1 then
Expand Down Expand Up @@ -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
Expand All @@ -460,7 +460,7 @@ end

-- remove directories
function os.rmdir(...)

-- check arguments
local args = {...}
if #args < 1 then
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3d2756f

Please sign in to comment.