From 86dcc1f78cd9e84b9e09673eb602ca77661841cf Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 6 Feb 2020 23:25:22 +0800 Subject: move process module to core.base.process --- tests/modules/process/sched_process.lua | 1 + tests/modules/process/sched_process_pipe.lua | 1 + tests/modules/process/test.lua | 1 + xmake/actions/build/cleaner.lua | 1 + xmake/actions/build/statistics.lua | 1 + xmake/actions/update/main.lua | 1 + .../sandbox/modules/import/core/base/process.lua | 117 +++++++++++++++++++++ xmake/core/sandbox/modules/process.lua | 117 --------------------- 8 files changed, 123 insertions(+), 117 deletions(-) create mode 100644 xmake/core/sandbox/modules/import/core/base/process.lua delete mode 100644 xmake/core/sandbox/modules/process.lua diff --git a/tests/modules/process/sched_process.lua b/tests/modules/process/sched_process.lua index a94e25b65..ec5794eef 100644 --- a/tests/modules/process/sched_process.lua +++ b/tests/modules/process/sched_process.lua @@ -1,3 +1,4 @@ +import("core.base.process") import("core.base.scheduler") function _session(id, program, ...) diff --git a/tests/modules/process/sched_process_pipe.lua b/tests/modules/process/sched_process_pipe.lua index de87f5f4e..02bf70a93 100644 --- a/tests/modules/process/sched_process_pipe.lua +++ b/tests/modules/process/sched_process_pipe.lua @@ -1,5 +1,6 @@ import("core.base.pipe") import("core.base.bytes") +import("core.base.process") import("core.base.scheduler") function _session_read_pipe(id, rpipeopt) diff --git a/tests/modules/process/test.lua b/tests/modules/process/test.lua index 3835272b4..bafd619c0 100644 --- a/tests/modules/process/test.lua +++ b/tests/modules/process/test.lua @@ -1,3 +1,4 @@ +import("core.base.process") import("core.base.scheduler") local inftimeout = 5000 diff --git a/xmake/actions/build/cleaner.lua b/xmake/actions/build/cleaner.lua index 7d629b978..596ee9315 100644 --- a/xmake/actions/build/cleaner.lua +++ b/xmake/actions/build/cleaner.lua @@ -21,6 +21,7 @@ -- imports import("core.base.option") import("core.base.global") +import("core.base.process") import("core.project.config") import("core.package.package") import("core.platform.platform") diff --git a/xmake/actions/build/statistics.lua b/xmake/actions/build/statistics.lua index 1e29cb666..729af55e7 100644 --- a/xmake/actions/build/statistics.lua +++ b/xmake/actions/build/statistics.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.base.process") import("core.project.config") import("core.platform.platform") import("core.platform.environment") diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 33e726e17..b4216c632 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -22,6 +22,7 @@ import("core.base.semver") import("core.base.option") import("core.base.task") +import("core.base.process") import("net.http") import("devel.git") import("devel.git.submodule") diff --git a/xmake/core/sandbox/modules/import/core/base/process.lua b/xmake/core/sandbox/modules/import/core/base/process.lua new file mode 100644 index 000000000..b05939028 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/base/process.lua @@ -0,0 +1,117 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file process.lua +-- + +-- load modules +local process = require("base/process") +local sandbox = require("sandbox/sandbox") +local raise = require("sandbox/modules/raise") +local vformat = require("sandbox/modules/vformat") + +-- define module +local sandbox_core_base_process = sandbox_core_base_process or {} +local sandbox_core_base_instance = sandbox_core_base_instance or {} +sandbox_core_base_process._subprocess = sandbox_core_base_process._subprocess or process._subprocess + +-- wait subprocess +function sandbox_core_base_instance.wait(proc, timeout) + local ok, status, errors = proc:_wait(timeout) + if errors then + raise(errors) + end + return ok, status +end + +-- close subprocess +function sandbox_core_base_instance.close(proc) + local ok, errors = proc:_close() + if not ok then + raise(errors) + end +end + +-- open process +--- +-- @param command the command +-- @param opt the arguments option, {outpath = "", errpath = "", envs = {"PATH=xxx", "XXX=yyy"} +-- +function sandbox_core_base_process.open(command, opt) + + -- check + assert(command) + + -- format command first + command = vformat(command) + + -- open process + local proc, errors = process.open(command, opt) + if not proc then + raise(errors) + end + + -- hook subprocess interfaces + local hooked = {} + for name, func in pairs(sandbox_core_base_instance) do + if not name:startswith("_") and type(func) == "function" then + hooked["_" .. name] = proc["_" .. name] or proc[name] + hooked[name] = func + end + end + for name, func in pairs(hooked) do + proc[name] = func + end + return proc +end + +-- open process with arguments +-- +-- @param filename the command/file name +-- @param argv the command arguments +-- @param opt the arguments option, {outpath = "", errpath = "", envs = {"PATH=xxx", "XXX=yyy"} +-- +function sandbox_core_base_process.openv(filename, argv, opt) + + -- check + assert(argv) + + -- format filename first + filename = vformat(filename) + + -- open process + local proc, errors = process.openv(filename, argv, opt) + if not proc then + raise(errors) + end + + -- hook subprocess interfaces + local hooked = {} + for name, func in pairs(sandbox_core_base_instance) do + if not name:startswith("_") and type(func) == "function" then + hooked["_" .. name] = proc["_" .. name] or proc[name] + hooked[name] = func + end + end + for name, func in pairs(hooked) do + proc[name] = func + end + return proc +end + +-- return module +return sandbox_core_base_process diff --git a/xmake/core/sandbox/modules/process.lua b/xmake/core/sandbox/modules/process.lua deleted file mode 100644 index 6b9a16728..000000000 --- a/xmake/core/sandbox/modules/process.lua +++ /dev/null @@ -1,117 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file process.lua --- - --- load modules -local process = require("base/process") -local sandbox = require("sandbox/sandbox") -local raise = require("sandbox/modules/raise") -local vformat = require("sandbox/modules/vformat") - --- define module -local sandbox_process = sandbox_process or {} -local sandbox_process_subprocess = sandbox_process_subprocess or {} -sandbox_process._subprocess = sandbox_process._subprocess or process._subprocess - --- wait subprocess -function sandbox_process_subprocess.wait(proc, timeout) - local ok, status, errors = proc:_wait(timeout) - if errors then - raise(errors) - end - return ok, status -end - --- close subprocess -function sandbox_process_subprocess.close(proc) - local ok, errors = proc:_close() - if not ok then - raise(errors) - end -end - --- open process ---- --- @param command the command --- @param opt the arguments option, {outpath = "", errpath = "", envs = {"PATH=xxx", "XXX=yyy"} --- -function sandbox_process.open(command, opt) - - -- check - assert(command) - - -- format command first - command = vformat(command) - - -- open process - local proc, errors = process.open(command, opt) - if not proc then - raise(errors) - end - - -- hook subprocess interfaces - local hooked = {} - for name, func in pairs(sandbox_process_subprocess) do - if not name:startswith("_") and type(func) == "function" then - hooked["_" .. name] = proc["_" .. name] or proc[name] - hooked[name] = func - end - end - for name, func in pairs(hooked) do - proc[name] = func - end - return proc -end - --- open process with arguments --- --- @param filename the command/file name --- @param argv the command arguments --- @param opt the arguments option, {outpath = "", errpath = "", envs = {"PATH=xxx", "XXX=yyy"} --- -function sandbox_process.openv(filename, argv, opt) - - -- check - assert(argv) - - -- format filename first - filename = vformat(filename) - - -- open process - local proc, errors = process.openv(filename, argv, opt) - if not proc then - raise(errors) - end - - -- hook subprocess interfaces - local hooked = {} - for name, func in pairs(sandbox_process_subprocess) do - if not name:startswith("_") and type(func) == "function" then - hooked["_" .. name] = proc["_" .. name] or proc[name] - hooked[name] = func - end - end - for name, func in pairs(hooked) do - proc[name] = func - end - return proc -end - --- return module -return sandbox_process -- cgit v1.3.1