summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-03-18 22:44:49 +0800
committerruki <[email protected]>2020-03-18 10:28:58 +0800
commit5c3a3168f645495cc5d2ab3472d1e3d366bbb004 (patch)
tree1df244c8d97731a8c94533100a043d90f523f007
parent0c872f6357951a3074c0b03cab8c53d66fe51839 (diff)
decrease to call string.find_last
-rw-r--r--xmake/core/base/io.lua8
-rw-r--r--xmake/core/base/process.lua26
-rw-r--r--xmake/core/base/scheduler.lua5
3 files changed, 27 insertions, 12 deletions
diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua
index 257e3ad3f..264afe59c 100644
--- a/xmake/core/base/io.lua
+++ b/xmake/core/base/io.lua
@@ -37,7 +37,6 @@ io._stdfile = io._stdfile or io.stdfile
-- new a file
function _file.new(filepath, cdata, isstdfile)
local file = table.inherit(_file)
- file._NAME = path.filename(filepath)
file._PATH = isstdfile and filepath or path.absolute(filepath)
file._FILE = cdata
setmetatable(file, _file)
@@ -46,6 +45,9 @@ end
-- get the file name
function _file:name()
+ if not self._NAME then
+ self._NAME = path.filename(self:path())
+ end
return self._NAME
end
@@ -295,7 +297,6 @@ end
-- new an filelock
function _filelock.new(lockpath, lock)
local filelock = table.inherit(_filelock)
- filelock._NAME = path.filename(lockpath)
filelock._PATH = path.absolute(lockpath)
filelock._LOCK = lock
filelock._LOCKED_NUM = 0
@@ -305,6 +306,9 @@ end
-- get the filelock name
function _filelock:name()
+ if not self._NAME then
+ self._NAME = path.filename(self:path())
+ end
return self._NAME
end
diff --git a/xmake/core/base/process.lua b/xmake/core/base/process.lua
index 51fe02ecd..e2cad423f 100644
--- a/xmake/core/base/process.lua
+++ b/xmake/core/base/process.lua
@@ -42,10 +42,10 @@ process.close = nil
process._subprocess = _subprocess
-- new an subprocess
-function _subprocess.new(name, proc)
+function _subprocess.new(program, proc)
local subprocess = table.inherit(_subprocess)
- subprocess._NAME = name
- subprocess._PROC = proc
+ subprocess._PROGRAM = program
+ subprocess._PROC = proc
setmetatable(subprocess, _subprocess)
process._openlist()[subprocess:cdata()] = subprocess
return subprocess
@@ -53,9 +53,17 @@ end
-- get the process name
function _subprocess:name()
+ if not self._NAME then
+ self._NAME = path.filename(self:program())
+ end
return self._NAME
end
+-- get the process program
+function _subprocess:program()
+ return self._PROGRAM
+end
+
-- get cdata of process
function _subprocess:cdata()
return self._PROC
@@ -201,7 +209,7 @@ function process.open(command, opt)
-- open subprocess
local proc = process._open(command, opt)
if proc then
- return _subprocess.new(path.filename(command:split(' ', {plain = true})[1]), proc)
+ return _subprocess.new(command:split(' ', {plain = true})[1], proc)
else
return nil, string.format("open process(%s) failed!", command)
end
@@ -209,13 +217,13 @@ end
-- open a subprocess with the arguments list
--
--- @param shellname the shell name
+-- @param program the program
-- @param argv the arguments list
-- @param opt the option arguments, e.g. {stdout = filepath/file/pipe, stderr = filepath/file/pipe, envs = {"PATH=xxx", "XXX=yyy"}})
--
-- @return the subprocess
--
-function process.openv(shellname, argv, opt)
+function process.openv(program, argv, opt)
-- get stdout and pass to subprocess
opt = opt or {}
@@ -243,11 +251,11 @@ function process.openv(shellname, argv, opt)
end
-- open subprocess
- local proc = process._openv(shellname, argv, opt)
+ local proc = process._openv(program, argv, opt)
if proc then
- return _subprocess.new(path.filename(shellname), proc)
+ return _subprocess.new(program, proc)
else
- return nil, string.format("openv process(%s, %s) failed!", shellname, table.concat(argv, " "))
+ return nil, string.format("openv process(%s, %s) failed!", program, table.concat(argv, " "))
end
end
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua
index 4239c36a9..88c9816c0 100644
--- a/xmake/core/base/scheduler.lua
+++ b/xmake/core/base/scheduler.lua
@@ -165,7 +165,10 @@ function scheduler:_poller_events_cb(obj, events)
-- get poller object data
local pollerdata = self:_poller_data(obj)
- assert(pollerdata, string.format("%s: cannot get poller data!", obj))
+ if not pollerdata then
+ -- we cannot use assert(, ""), because this will cause the object to be serialized in advance
+ raise("%s: cannot get poller data!", obj)
+ end
-- is process object?
if obj:otype() == poller.OT_PROC then