summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-03-31 21:49:38 +0800
committerruki <[email protected]>2024-03-31 21:49:38 +0800
commit536ad613e5c7b2ba8581c740548bf359b0fea91f (patch)
treead27d72cdbf1149df60d18092d608c68c93e1e58
parentc587c4f4499b32698b1240b7cd43617ef4181662 (diff)
add signal module
-rw-r--r--xmake/core/base/os.lua11
-rw-r--r--xmake/core/base/signal.lua46
-rw-r--r--xmake/core/sandbox/modules/import/core/base/signal.lua24
-rw-r--r--xmake/core/sandbox/modules/os.lua6
4 files changed, 70 insertions, 17 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index f143b5f51..2d7023ac4 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -45,7 +45,6 @@ os._getenvs = os._getenvs or os.getenvs
os._cpuinfo = os._cpuinfo or os.cpuinfo
os._meminfo = os._meminfo or os.meminfo
os._readlink = os._readlink or os.readlink
-os._signal = os._signal or os.signal
-- syserror code
os.SYSERR_UNKNOWN = -1
@@ -54,11 +53,6 @@ os.SYSERR_NOT_PERM = 1
os.SYSERR_NOT_FILEDIR = 2
os.SYSERR_NOT_ACCESS = 3
--- signal code
-os.SIGINT = 1
-os.SIGDFL = 1
-os.SIGIGN = 2
-
-- copy single file or directory
function os._cp(src, dst, rootdir, opt)
opt = opt or {}
@@ -1421,11 +1415,6 @@ function os.readlink(symlink)
return os._readlink(path.absolute(symlink))
end
--- register signal handler
-function os.signal(signo, handler)
- os._signal(signo, handler)
-end
-
-- get the program directory
function os.programdir()
return xmake._PROGRAM_DIR
diff --git a/xmake/core/base/signal.lua b/xmake/core/base/signal.lua
new file mode 100644
index 000000000..afcbdb684
--- /dev/null
+++ b/xmake/core/base/signal.lua
@@ -0,0 +1,46 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- 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-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file signal.lua
+--
+
+-- define module: signal
+local signal = signal or {}
+
+-- load modules
+local os = require("base/os")
+
+-- signal code
+signal.SIGINT = 1
+
+-- register signal handler
+function signal.register(signo, handler)
+ os.signal(signo, handler)
+end
+
+-- reset signal, SIGDFL
+function signal.reset(signo)
+ os.signal(signo, 1)
+end
+
+-- ignore signal, SIGIGN
+function signal.ignore(signo)
+ os.signal(signo, 2)
+end
+
+-- return module: signal
+return signal
diff --git a/xmake/core/sandbox/modules/import/core/base/signal.lua b/xmake/core/sandbox/modules/import/core/base/signal.lua
new file mode 100644
index 000000000..2cf3fc0bb
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/base/signal.lua
@@ -0,0 +1,24 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- 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-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file signal.lua
+--
+
+-- load modules
+return require("base/signal")
+
+
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index 9a12650f4..9004f66ee 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -82,7 +82,6 @@ sandbox_os.projectdir = os.projectdir
sandbox_os.projectfile = os.projectfile
sandbox_os.getwinsize = os.getwinsize
sandbox_os.getpid = os.getpid
-sandbox_os.signal = os.signal
-- syserror code
sandbox_os.SYSERR_UNKNOWN = os.SYSERR_UNKNOWN
@@ -91,11 +90,6 @@ sandbox_os.SYSERR_NOT_PERM = os.SYSERR_NOT_PERM
sandbox_os.SYSERR_NOT_FILEDIR = os.SYSERR_NOT_FILEDIR
sandbox_os.SYSERR_NOT_ACCESS = os.SYSERR_NOT_ACCESS
--- signal code
-sandbox_os.SIGINT = os.SIGINT
-sandbox_os.SIGDFL = os.SIGDFL
-sandbox_os.SIGIGN = os.SIGIGN
-
-- copy file or directory
function sandbox_os.cp(srcpath, dstpath, opt)
assert(srcpath and dstpath)