From 19dced6cce6982590d18250bfd876dc8691c0ddb Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 10 Aug 2021 23:19:09 +0800 Subject: fix batchcmds --- xmake/modules/private/utils/batchcmds.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'xmake/modules/private/utils/batchcmds.lua') diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua index 371735321..946135a87 100644 --- a/xmake/modules/private/utils/batchcmds.lua +++ b/xmake/modules/private/utils/batchcmds.lua @@ -128,21 +128,21 @@ end -- run command: os.cp function _runcmd_cp(cmd, opt) if not opt.dryrun then - os.cp(opt.srcpath, opt.dstpath, opt.opt) + os.cp(cmd.srcpath, cmd.dstpath, opt.opt) end end -- run command: os.mv function _runcmd_mv(cmd, opt) if not opt.dryrun then - os.mv(opt.srcpath, opt.dstpath, opt.opt) + os.mv(cmd.srcpath, cmd.dstpath, opt.opt) end end -- run command: os.ln function _runcmd_ln(cmd, opt) if not opt.dryrun then - os.ln(opt.srcpath, opt.dstpath, opt.opt) + os.ln(cmd.srcpath, cmd.dstpath, opt.opt) end end -- cgit v1.3.1 From a01e17a5049bdd02ddc2514bd47af74cf2ff802d Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 9 Oct 2021 11:58:10 +0800 Subject: move private.utils.progress to utils.progress --- tests/apis/rules/xmake.lua | 2 +- xmake/actions/build/build.lua | 2 +- xmake/actions/build/kinds/binary.lua | 2 +- xmake/actions/build/kinds/shared.lua | 2 +- xmake/actions/build/kinds/static.lua | 2 +- xmake/actions/build/main.lua | 2 +- xmake/modules/core/tools/ar.lua | 2 +- xmake/modules/core/tools/cl.lua | 2 +- xmake/modules/core/tools/gcc.lua | 2 +- xmake/modules/core/tools/nvcc.lua | 2 +- xmake/modules/core/tools/sdcc.lua | 2 +- xmake/modules/private/action/build/object.lua | 2 +- .../action/require/impl/install_packages.lua | 2 +- .../private/action/require/impl/package.lua | 2 +- xmake/modules/private/async/runjobs.lua | 4 +- xmake/modules/private/utils/batchcmds.lua | 2 +- xmake/modules/utils/progress.lua | 139 +++++++++++++++++++++ xmake/rules/cuda/devlink/xmake.lua | 2 +- xmake/rules/qt/deploy/android.lua | 2 +- xmake/rules/qt/deploy/macosx.lua | 2 +- xmake/rules/utils/merge_archive/merge_archive.lua | 2 +- xmake/rules/utils/merge_archive/xmake.lua | 2 +- xmake/rules/utils/merge_object/xmake.lua | 2 +- .../rules/utils/symbols/export_all/export_all.lua | 2 +- xmake/rules/utils/symbols/extract/xmake.lua | 2 +- xmake/rules/wdk/inf/xmake.lua | 2 +- xmake/rules/wdk/man/xmake.lua | 2 +- xmake/rules/wdk/mc/xmake.lua | 2 +- xmake/rules/wdk/mof/xmake.lua | 2 +- xmake/rules/wdk/sign/xmake.lua | 2 +- xmake/rules/wdk/tracewpp/xmake.lua | 2 +- xmake/rules/xcode/application/build.lua | 2 +- xmake/rules/xcode/bundle/xmake.lua | 2 +- xmake/rules/xcode/framework/xmake.lua | 2 +- xmake/rules/xcode/info_plist/xmake.lua | 2 +- xmake/rules/xcode/storyboard/xmake.lua | 2 +- xmake/rules/xcode/xcassets/xmake.lua | 2 +- 37 files changed, 176 insertions(+), 37 deletions(-) create mode 100644 xmake/modules/utils/progress.lua (limited to 'xmake/modules/private/utils/batchcmds.lua') diff --git a/tests/apis/rules/xmake.lua b/tests/apis/rules/xmake.lua index 276b4c074..5a6e5d546 100644 --- a/tests/apis/rules/xmake.lua +++ b/tests/apis/rules/xmake.lua @@ -27,7 +27,7 @@ rule("c code") end) on_build_file(function (target, sourcefile, opt) import("core.theme.theme") - import("private.utils.progress") + import("utils.progress") progress.show(opt.progress, "compiling.$(mode) %s", sourcefile) local objectfile_o = os.tmpfile() .. ".o" local sourcefile_c = os.tmpfile() .. ".c" diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua index 0fc15fd81..267a802d3 100644 --- a/xmake/actions/build/build.lua +++ b/xmake/actions/build/build.lua @@ -218,7 +218,7 @@ function main(targetname) if batchjobs and batchjobs:size() > 0 then local curdir = os.curdir() runjobs("build", batchjobs, {comax = option.get("jobs") or 1, on_exit = function (errors) - import("private.utils.progress") + import("utils.progress") if errors and progress.showing_without_scroll() then print("") end diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua index b84b518de..26544c311 100644 --- a/xmake/actions/build/kinds/binary.lua +++ b/xmake/actions/build/kinds/binary.lua @@ -24,7 +24,7 @@ import("core.theme.theme") import("core.tool.linker") import("core.tool.compiler") import("core.project.depend") -import("private.utils.progress") +import("utils.progress") import("private.utils.batchcmds") import("object", {alias = "add_batchjobs_for_object"}) diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua index 376d73af3..99a6d1db5 100644 --- a/xmake/actions/build/kinds/shared.lua +++ b/xmake/actions/build/kinds/shared.lua @@ -24,7 +24,7 @@ import("core.theme.theme") import("core.tool.linker") import("core.tool.compiler") import("core.project.depend") -import("private.utils.progress") +import("utils.progress") import("private.utils.batchcmds") import("object", {alias = "add_batchjobs_for_object"}) diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua index b3ac57e73..56a900572 100644 --- a/xmake/actions/build/kinds/static.lua +++ b/xmake/actions/build/kinds/static.lua @@ -24,7 +24,7 @@ import("core.theme.theme") import("core.tool.linker") import("core.tool.compiler") import("core.project.depend") -import("private.utils.progress") +import("utils.progress") import("private.utils.batchcmds") import("object", {alias = "add_batchjobs_for_object"}) diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua index 864f88185..70d15d75e 100644 --- a/xmake/actions/build/main.lua +++ b/xmake/actions/build/main.lua @@ -27,7 +27,7 @@ import("core.project.config") import("core.project.project") import("core.platform.platform") import("core.theme.theme") -import("private.utils.progress") +import("utils.progress") import("build") import("build_files") import("cleaner") diff --git a/xmake/modules/core/tools/ar.lua b/xmake/modules/core/tools/ar.lua index dc858a19e..abb1e9695 100644 --- a/xmake/modules/core/tools/ar.lua +++ b/xmake/modules/core/tools/ar.lua @@ -20,7 +20,7 @@ -- imports import("core.tool.compiler") -import("private.utils.progress") +import("utils.progress") -- init it function init(self) diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 54eafe227..efea29a14 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -26,7 +26,7 @@ import("core.project.project") import("core.language.language") import("private.tools.vstool") import("private.tools.cl.parse_include") -import("private.utils.progress") +import("utils.progress") -- init it function init(self) diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index c6422d204..2cf31e2dc 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -27,7 +27,7 @@ import("core.project.config") import("core.project.project") import("core.language.language") import("private.tools.ccache") -import("private.utils.progress") +import("utils.progress") -- init it function init(self) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 25a589124..2aad54096 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -26,7 +26,7 @@ import("core.project.project") import("core.platform.platform") import("core.language.language") import("private.tools.ccache") -import("private.utils.progress") +import("utils.progress") -- init it function init(self) diff --git a/xmake/modules/core/tools/sdcc.lua b/xmake/modules/core/tools/sdcc.lua index 526254fe7..82d6cd78a 100644 --- a/xmake/modules/core/tools/sdcc.lua +++ b/xmake/modules/core/tools/sdcc.lua @@ -21,7 +21,7 @@ -- imports import("core.base.option") import("core.base.global") -import("private.utils.progress") +import("utils.progress") -- init it function init(self) diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua index 50397cda4..7a99de91e 100644 --- a/xmake/modules/private/action/build/object.lua +++ b/xmake/modules/private/action/build/object.lua @@ -25,7 +25,7 @@ import("core.tool.compiler") import("core.project.depend") import("private.tools.ccache") import("private.async.runjobs") -import("private.utils.progress") +import("utils.progress") -- do build file function _do_build_file(target, sourcefile, opt) diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index c8bdefbb1..714b98461 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -25,7 +25,7 @@ import("core.base.scheduler") import("core.project.project") import("core.base.tty") import("private.async.runjobs") -import("private.utils.progress") +import("utils.progress") import("actions.install", {alias = "action_install"}) import("actions.download", {alias = "action_download"}) import("net.fasturl") diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index b048b7818..f00d796f6 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -23,7 +23,7 @@ import("core.base.semver") import("core.base.option") import("core.base.global") import("core.base.hashset") -import("private.utils.progress") +import("utils.progress") import("core.cache.memcache") import("core.project.project") import("core.project.config") diff --git a/xmake/modules/private/async/runjobs.lua b/xmake/modules/private/async/runjobs.lua index 0361399dc..a4ea2bc10 100644 --- a/xmake/modules/private/async/runjobs.lua +++ b/xmake/modules/private/async/runjobs.lua @@ -20,7 +20,7 @@ -- imports import("core.base.scheduler") -import("private.utils.progress") +import("utils.progress") -- print back characters function _print_backchars(backnum) @@ -37,7 +37,7 @@ end -- e.g. -- runjobs("test", function (index) print("hello") end, {total = 100, comax = 6, timeout = 1000, on_timer = function (running_jobs_indices) end}) -- runjobs("test", function () os.sleep(10000) end, { progress = true }) --- runjobs("test", function () os.sleep(10000) end, { progress = { chars = {'/','\'} } }) -- see module private.utils.progress +-- runjobs("test", function () os.sleep(10000) end, { progress = { chars = {'/','\'} } }) -- see module utils.progress -- -- local jobs = jobpool.new() -- local root = jobs:addjob("job/root", function (idx, total) diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua index 946135a87..34dd5d583 100644 --- a/xmake/modules/private/utils/batchcmds.lua +++ b/xmake/modules/private/utils/batchcmds.lua @@ -28,7 +28,7 @@ import("core.theme.theme") import("core.tool.linker") import("core.tool.compiler") import("core.language.language") -import("private.utils.progress", {alias = "progress_utils"}) +import("utils.progress", {alias = "progress_utils"}) -- define module local batchcmds = batchcmds or object { _init = {"_TARGET", "_CMDS", "_DEPS", "_tip"}} diff --git a/xmake/modules/utils/progress.lua b/xmake/modules/utils/progress.lua new file mode 100644 index 000000000..074046a69 --- /dev/null +++ b/xmake/modules/utils/progress.lua @@ -0,0 +1,139 @@ +--!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 OpportunityLiu +-- @file progress.lua +-- + +-- imports +import("core.base.option") +import("core.base.object") +import("core.base.colors") +import("core.base.tty") +import("core.theme.theme") + +-- define module +local process = process or object { _init = { "_RUNNING", "_INDEX", "_STREAM", "_OPT" } } + +-- stop the progress indicator, clear written frames +function process:stop() + if self._RUNNING ~= 0 then + self:clear() + self._RUNNING = 0 + self._INDEX = 0 + end +end + +function process:_clear() + if self._RUNNING == 1 then + tty.erase_line_to_end() + self._RUNNING = 2 + return true + end +end + +-- clear previous frame of the progress indicator +function process:clear() + if self:_clear() then + self._STREAM:flush() + end +end + +-- write next frame of the progress indicator +function process:write() + local chars = self._OPT.chars[self._INDEX % #self._OPT.chars + 1] + tty.cursor_and_attrs_save() + self._STREAM:write(chars) + self._STREAM:flush() + tty.cursor_and_attrs_restore() + self._INDEX = self._INDEX + 1 + self._RUNNING = 1 +end + +-- check if the progress indicator is running +function process:running() + return self._RUNNING and true or false +end + +-- showing progress line without scroll? +function showing_without_scroll() + return _g.showing_without_scroll +end + +-- show the message with process +function show(progress, format, ...) + progress = math.floor(progress) + local progress_prefix = "${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} " + if option.get("verbose") then + cprint(progress_prefix .. "${dim}" .. format, progress, ...) + else + local is_scroll = _g.is_scroll + if is_scroll == nil then + is_scroll = theme.get("text.build.progress_style") == "scroll" + _g.is_scroll = is_scroll + end + if is_scroll then + cprint(progress_prefix .. format, progress, ...) + else + tty.erase_line_to_start().cr() + local msg = vformat(progress_prefix .. format, progress, ...) + local msg_plain = colors.translate(msg, {plain = true}) + local maxwidth = os.getwinsize().width + if #msg_plain <= maxwidth then + cprintf(msg) + else + -- windows width is too small? strip the partial message in middle + local partlen = math.floor(maxwidth / 2) - 3 + local sep = msg_plain:sub(partlen + 1, #msg_plain - partlen - 1) + local split = msg:split(sep, {plain = true, strict = true}) + cprintf(table.concat(split, "...")) + end + if math.floor(progress) == 100 then + print("") + _g.showing_without_scroll = false + else + _g.showing_without_scroll = true + end + io.flush() + end + end +end + +-- get the message text with process +function text(progress, format, ...) + progress = math.floor(progress) + local progress_prefix = "${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} " + if option.get("verbose") then + return string.format(progress_prefix .. "${dim}" .. format, progress, ...) + else + return string.format(progress_prefix .. format, progress, ...) + end +end + +-- build a progress indicator +-- @params stream - stream to write to, will use io.stdout if not provided +-- @params opt - options +-- - chars - an array of chars for progress indicator +function new(stream, opt) + + -- set default values + stream = stream or io.stdout + opt = opt or {} + if opt.chars == nil or #opt.chars == 0 then + opt.chars = theme.get("text.spinner.chars") + end + return process {_OPT = opt, _STREAM = stream, _RUNNING = 0, _INDEX = 0} +end diff --git a/xmake/rules/cuda/devlink/xmake.lua b/xmake/rules/cuda/devlink/xmake.lua index e92a0b779..fb1f603b0 100644 --- a/xmake/rules/cuda/devlink/xmake.lua +++ b/xmake/rules/cuda/devlink/xmake.lua @@ -34,7 +34,7 @@ rule("cuda.build.devlink") import("core.project.depend") import("core.tool.linker") import("core.platform.platform") - import("private.utils.progress") + import("utils.progress") -- disable devlink? if target:values("cuda.build.devlink") == false then diff --git a/xmake/rules/qt/deploy/android.lua b/xmake/rules/qt/deploy/android.lua index 97f97ea7a..c1cad3b54 100644 --- a/xmake/rules/qt/deploy/android.lua +++ b/xmake/rules/qt/deploy/android.lua @@ -25,7 +25,7 @@ import("core.base.semver") import("core.project.config") import("core.project.depend") import("core.tool.toolchain") -import("private.utils.progress") +import("utils.progress") -- escape path function _escape_path(p) diff --git a/xmake/rules/qt/deploy/macosx.lua b/xmake/rules/qt/deploy/macosx.lua index 5f7b8390d..26df10b14 100644 --- a/xmake/rules/qt/deploy/macosx.lua +++ b/xmake/rules/qt/deploy/macosx.lua @@ -25,7 +25,7 @@ import("core.project.config") import("core.project.depend") import("core.tool.toolchain") import("lib.detect.find_path") -import("private.utils.progress") +import("utils.progress") -- save Info.plist function _save_info_plist(target, info_plist_file) diff --git a/xmake/rules/utils/merge_archive/merge_archive.lua b/xmake/rules/utils/merge_archive/merge_archive.lua index 96069befb..c98fc6b31 100644 --- a/xmake/rules/utils/merge_archive/merge_archive.lua +++ b/xmake/rules/utils/merge_archive/merge_archive.lua @@ -23,7 +23,7 @@ import("core.base.option") import("core.theme.theme") import("core.project.depend") import("core.project.target", {alias = "project_target"}) -import("private.utils.progress") +import("utils.progress") import("core.tool.toolchain") import("private.tools.vstool") diff --git a/xmake/rules/utils/merge_archive/xmake.lua b/xmake/rules/utils/merge_archive/xmake.lua index 62e3900ff..fd7805d8b 100644 --- a/xmake/rules/utils/merge_archive/xmake.lua +++ b/xmake/rules/utils/merge_archive/xmake.lua @@ -25,7 +25,7 @@ rule("utils.merge.archive") if target:policy("build.merge_archive") and target:is_static() then import("utils.archive.merge_staticlib") import("core.project.depend") - import("private.utils.progress") + import("utils.progress") local libraryfiles = {} for _, dep in ipairs(target:orderdeps()) do if dep:is_static() then diff --git a/xmake/rules/utils/merge_object/xmake.lua b/xmake/rules/utils/merge_object/xmake.lua index 167e9013e..8bebb5f5c 100644 --- a/xmake/rules/utils/merge_object/xmake.lua +++ b/xmake/rules/utils/merge_object/xmake.lua @@ -31,7 +31,7 @@ rule("utils.merge.object") import("core.base.option") import("core.theme.theme") import("core.project.depend") - import("private.utils.progress") + import("utils.progress") -- get object file local objectfile = target:objectfile(sourcefile_obj) diff --git a/xmake/rules/utils/symbols/export_all/export_all.lua b/xmake/rules/utils/symbols/export_all/export_all.lua index 1a40e9820..800157411 100644 --- a/xmake/rules/utils/symbols/export_all/export_all.lua +++ b/xmake/rules/utils/symbols/export_all/export_all.lua @@ -24,7 +24,7 @@ import("core.tool.toolchain") import("core.base.option") import("core.base.hashset") import("core.project.depend") -import("private.utils.progress") +import("utils.progress") -- export all symbols for dynamic library function main (target, opt) diff --git a/xmake/rules/utils/symbols/extract/xmake.lua b/xmake/rules/utils/symbols/extract/xmake.lua index f78cab808..dd1f3a1df 100644 --- a/xmake/rules/utils/symbols/extract/xmake.lua +++ b/xmake/rules/utils/symbols/extract/xmake.lua @@ -46,7 +46,7 @@ rule("utils.symbols.extract") import("core.theme.theme") import("core.project.depend") import("core.platform.platform") - import("private.utils.progress") + import("utils.progress") -- get strip local strip = target:tool("strip") diff --git a/xmake/rules/wdk/inf/xmake.lua b/xmake/rules/wdk/inf/xmake.lua index 6ad91e62d..354fbc5a7 100644 --- a/xmake/rules/wdk/inf/xmake.lua +++ b/xmake/rules/wdk/inf/xmake.lua @@ -54,7 +54,7 @@ rule("wdk.inf") import("core.base.option") import("core.theme.theme") import("core.project.depend") - import("private.utils.progress") + import("utils.progress") -- the target file local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".inf") diff --git a/xmake/rules/wdk/man/xmake.lua b/xmake/rules/wdk/man/xmake.lua index 7843542d7..c5219aa56 100644 --- a/xmake/rules/wdk/man/xmake.lua +++ b/xmake/rules/wdk/man/xmake.lua @@ -57,7 +57,7 @@ rule("wdk.man") import("core.base.option") import("core.theme.theme") import("core.project.depend") - import("private.utils.progress") + import("utils.progress") -- get ctrpp local ctrpp = target:data("wdk.ctrpp") diff --git a/xmake/rules/wdk/mc/xmake.lua b/xmake/rules/wdk/mc/xmake.lua index abc75fdf7..689c9786c 100644 --- a/xmake/rules/wdk/mc/xmake.lua +++ b/xmake/rules/wdk/mc/xmake.lua @@ -57,7 +57,7 @@ rule("wdk.mc") import("core.base.option") import("core.theme.theme") import("core.project.depend") - import("private.utils.progress") + import("utils.progress") -- get mc local mc = target:data("wdk.mc") diff --git a/xmake/rules/wdk/mof/xmake.lua b/xmake/rules/wdk/mof/xmake.lua index 8be25de20..a1a2a0366 100644 --- a/xmake/rules/wdk/mof/xmake.lua +++ b/xmake/rules/wdk/mof/xmake.lua @@ -73,7 +73,7 @@ rule("wdk.mof") import("core.base.option") import("core.theme.theme") import("core.project.depend") - import("private.utils.progress") + import("utils.progress") -- get mofcomp local mofcomp = target:data("wdk.mofcomp") diff --git a/xmake/rules/wdk/sign/xmake.lua b/xmake/rules/wdk/sign/xmake.lua index dd137c5ec..6be72e7b3 100644 --- a/xmake/rules/wdk/sign/xmake.lua +++ b/xmake/rules/wdk/sign/xmake.lua @@ -93,7 +93,7 @@ rule("wdk.sign") import("core.project.config") import("core.project.depend") import("lib.detect.find_file") - import("private.utils.progress") + import("utils.progress") -- need build this object? local tempfile = os.tmpfile(target:targetfile()) diff --git a/xmake/rules/wdk/tracewpp/xmake.lua b/xmake/rules/wdk/tracewpp/xmake.lua index 52d72827f..75f4f37ef 100644 --- a/xmake/rules/wdk/tracewpp/xmake.lua +++ b/xmake/rules/wdk/tracewpp/xmake.lua @@ -57,7 +57,7 @@ rule("wdk.tracewpp") import("core.base.option") import("core.theme.theme") import("core.project.depend") - import("private.utils.progress") + import("utils.progress") -- get tracewpp local tracewpp = target:data("wdk.tracewpp") diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua index 786f5da89..a4862ae86 100644 --- a/xmake/rules/xcode/application/build.lua +++ b/xmake/rules/xcode/application/build.lua @@ -23,7 +23,7 @@ import("core.base.option") import("core.theme.theme") import("core.project.depend") import("private.tools.codesign") -import("private.utils.progress") +import("utils.progress") -- main entry function main (target, opt) diff --git a/xmake/rules/xcode/bundle/xmake.lua b/xmake/rules/xcode/bundle/xmake.lua index 1c1cecf99..322a42418 100644 --- a/xmake/rules/xcode/bundle/xmake.lua +++ b/xmake/rules/xcode/bundle/xmake.lua @@ -60,7 +60,7 @@ rule("xcode.bundle") import("core.theme.theme") import("core.project.depend") import("private.tools.codesign") - import("private.utils.progress") + import("utils.progress") -- get bundle and resources directory local bundledir = path.absolute(target:data("xcode.bundle.rootdir")) diff --git a/xmake/rules/xcode/framework/xmake.lua b/xmake/rules/xcode/framework/xmake.lua index 6b46b3c97..de7d7c93c 100644 --- a/xmake/rules/xcode/framework/xmake.lua +++ b/xmake/rules/xcode/framework/xmake.lua @@ -85,7 +85,7 @@ rule("xcode.framework") import("core.theme.theme") import("core.project.depend") import("private.tools.codesign") - import("private.utils.progress") + import("utils.progress") -- get framework directory local bundledir = path.absolute(target:data("xcode.bundle.rootdir")) diff --git a/xmake/rules/xcode/info_plist/xmake.lua b/xmake/rules/xcode/info_plist/xmake.lua index 57d3c9995..bd991b6e1 100644 --- a/xmake/rules/xcode/info_plist/xmake.lua +++ b/xmake/rules/xcode/info_plist/xmake.lua @@ -32,7 +32,7 @@ rule("xcode.info_plist") import("core.theme.theme") import("core.project.depend") import("core.tool.toolchain") - import("private.utils.progress") + import("utils.progress") -- check assert(path.filename(sourcefile) == "Info.plist", "we only support Info.plist file!") diff --git a/xmake/rules/xcode/storyboard/xmake.lua b/xmake/rules/xcode/storyboard/xmake.lua index 6ec23dd80..d96a1c002 100644 --- a/xmake/rules/xcode/storyboard/xmake.lua +++ b/xmake/rules/xcode/storyboard/xmake.lua @@ -32,7 +32,7 @@ rule("xcode.storyboard") import("core.theme.theme") import("core.project.depend") import("core.tool.toolchain") - import("private.utils.progress") + import("utils.progress") -- get xcode sdk directory local xcode_sdkdir = assert(get_config("xcode"), "xcode not found!") diff --git a/xmake/rules/xcode/xcassets/xmake.lua b/xmake/rules/xcode/xcassets/xmake.lua index 09185b226..9322d10c1 100644 --- a/xmake/rules/xcode/xcassets/xmake.lua +++ b/xmake/rules/xcode/xcassets/xmake.lua @@ -32,7 +32,7 @@ rule("xcode.xcassets") import("core.theme.theme") import("core.project.depend") import("core.tool.toolchain") - import("private.utils.progress") + import("utils.progress") -- get xcode sdk directory local xcode_sdkdir = assert(get_config("xcode"), "xcode not found!") -- cgit v1.3.1 From 2505c46acf19f66d92765854f0853d251be30506 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 29 Oct 2021 00:36:05 +0800 Subject: improve cmakelists --- xmake/modules/private/utils/batchcmds.lua | 14 ++++++++++++++ xmake/plugins/project/cmake/cmakelists.lua | 29 +++++++++++++++-------------- 2 files changed, 29 insertions(+), 14 deletions(-) (limited to 'xmake/modules/private/utils/batchcmds.lua') diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua index 34dd5d583..bb5204072 100644 --- a/xmake/modules/private/utils/batchcmds.lua +++ b/xmake/modules/private/utils/batchcmds.lua @@ -117,6 +117,14 @@ function _runcmd_mkdir(cmd, opt) end end +-- run command: os.cd +function _runcmd_cd(cmd, opt) + local dir = cmd.dir + if not opt.dryrun then + os.cd(dir) + end +end + -- run command: os.rm function _runcmd_rm(cmd, opt) local filepath = cmd.filepath @@ -158,6 +166,7 @@ function _runcmd(cmd, opt) vrunv = _runcmd_vrunv, execv = _runcmd_execv, mkdir = _runcmd_mkdir, + cd = _runcmd_cd, rm = _runcmd_rm, cp = _runcmd_cp, mv = _runcmd_mv, @@ -268,6 +277,11 @@ function batchcmds:ln(srcpath, dstpath, opt) table.insert(self:cmds(), {kind = "ln", srcpath = srcpath, dstpath = dstpath, opt = opt}) end +-- add command: os.cd +function batchcmds:cd(dir, opt) + table.insert(self:cmds(), {kind = "cd", dir = dir, opt = opt}) +end + -- add command: show function batchcmds:show(format, ...) local showtext = string.format(format, ...) diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index a8b64fa95..3223f1c9f 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -482,26 +482,27 @@ end -- get command string function _get_command_string(cmd) local kind = cmd.kind + local opt = cmd.opt if cmd.program then - return os.args(table.join(cmd.program, cmd.argv)) + local command = os.args(table.join(cmd.program, cmd.argv)) + if opt and opt.curdir then + command = "${CMAKE_COMMAND} -E chdir \"" .. opt.curdir .. "\" " .. command + end + return command elseif kind == "cp" then - if is_subhost("windows") then - return string.format("copy /Y %s %s > NUL 2>&1", cmd.srcpath, cmd.dstpath) + if os.isdir(cmd.srcpath) then + return string.format("${CMAKE_COMMAND} -E copy_directory %s %s", cmd.srcpath, cmd.dstpath) else - return string.format("cp %s %s", cmd.srcpath, cmd.dstpath) + return string.format("${CMAKE_COMMAND} -E copy %s %s", cmd.srcpath, cmd.dstpath) end elseif kind == "rm" then - if is_subhost("windows") then - return string.format("del /F /Q %s > NUL 2>&1 || rmdir /S /Q %s > NUL 2>&1", cmd.filepath, cmd.filepath) - else - return string.format("rm -rf %s", cmd.filepath) - end + return string.format("${CMAKE_COMMAND} -E rm -rf %s", cmd.filepath) + elseif kind == "mv" then + return string.format("${CMAKE_COMMAND} -E rename %s %s", cmd.srcpath, cmd.dstpath) + elseif kind == "cd" then + return string.format("cd %s", cmd.dir) elseif kind == "mkdir" then - if is_subhost("windows") then - return string.format("mkdir %s > NUL 2>&1", cmd.dir) - else - return string.format("mkdir -p %s", cmd.dir) - end + return string.format("${CMAKE_COMMAND} -E make_directory %s", cmd.dir) elseif kind == "show" then return string.format("echo %s", cmd.showtext) end -- cgit v1.3.1