summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-08-24 00:05:33 +0800
committerruki <[email protected]>2019-08-23 18:33:23 +0800
commit863b2c74551f802b460b228e341bd96aa8aeaba1 (patch)
treeedb9799f1056f1942b3ec5c5292f698cb1ed0106
parent8e5875a886b5a4a82cf1350ebfcbc55f34262e80 (diff)
bcsave for directory
-rw-r--r--xmake/core/base/os.lua4
-rw-r--r--xmake/core/sandbox/modules/import/core/base/option.lua29
-rw-r--r--xmake/modules/private/utils/bcsave.lua86
3 files changed, 104 insertions, 15 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 2c3b5e877..fa8576825 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -767,8 +767,10 @@ function os.raiselevel(level, msg, ...)
else
error(errors, level)
end
- else
+ elseif msg ~= nil then
error(tostring(msg), level)
+ else
+ error(msg, level)
end
end
diff --git a/xmake/core/sandbox/modules/import/core/base/option.lua b/xmake/core/sandbox/modules/import/core/base/option.lua
index 660560a22..fab7d3dc4 100644
--- a/xmake/core/sandbox/modules/import/core/base/option.lua
+++ b/xmake/core/sandbox/modules/import/core/base/option.lua
@@ -81,17 +81,21 @@ function sandbox_core_base_option.parse(argv, options, ...)
table.insert(options, 2, {'h', "help", "k", nil, "Print this help message and exit." })
table.insert(options, 3, {})
+ -- show help
+ local descriptions = {...}
+ local function show_help()
+ for _, description in ipairs(descriptions) do
+ print(description)
+ end
+ option.show_options(options)
+ end
+
-- parse it
local results, errors = option.parse(argv, options)
if not results then
- -- show descriptions
- for _, description in ipairs({...}) do
- print(description)
- end
-
- -- show options
- option.show_options(options)
+ -- show help
+ show_help()
-- raise errors
raise(errors)
@@ -100,16 +104,13 @@ function sandbox_core_base_option.parse(argv, options, ...)
-- help?
if results.help then
- -- show descriptions
- for _, description in ipairs({...}) do
- print(description)
- end
-
- -- show options
- option.show_options(options)
+ -- show help
+ show_help()
-- exit
raise()
+ else
+ results.help = show_help
end
-- ok
diff --git a/xmake/modules/private/utils/bcsave.lua b/xmake/modules/private/utils/bcsave.lua
new file mode 100644
index 000000000..591626127
--- /dev/null
+++ b/xmake/modules/private/utils/bcsave.lua
@@ -0,0 +1,86 @@
+--!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 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file bcsave.lua
+--
+
+-- imports
+import("core.base.option")
+import("lib.luajit.bcsave")
+
+-- the options
+local options =
+{
+ {'s', "strip", "k", false, "Strip the debug info." }
+, {'o', "outputdir", "kv", nil, "Set the output directory of bitcode files." }
+, {nil, "sourcedir", "v", os.programdir(), "Set the directory of lua source files." }
+}
+
+-- save lua files to bitcode files in the given directory
+function save(sourcedir, outputdir, opt)
+
+ -- check
+ assert(outputdir, "no output directory!")
+
+ -- init source directory and options
+ opt = opt or {}
+ sourcedir = sourcedir or os.programdir()
+ assert(os.isdir(sourcedir), "%s not found!", sourcedir)
+
+ -- trace
+ print("generating bitcode files from %s ..", sourcedir)
+
+ -- save all lua files to bitcode files
+ local oldir = os.cd(sourcedir)
+ for _, luafile in ipairs(os.files(path.join(sourcedir, "**.lua"))) do
+
+ -- get relative lua file path to decrease bitcode file size (without strip)
+ luafile = path.relative(luafile, sourcedir)
+
+ -- trace
+ vprint("generating %s ..", luafile)
+
+ -- get bitcode file path
+ local bcfile = path.join(outputdir, luafile)
+
+ -- generate bitcode file
+ bcsave(luafile, bcfile, {strip = opt.strip})
+ end
+ os.cd(oldir)
+
+ -- trace
+ cprint("${bright}bitcode files have been generated in %s", outputdir)
+end
+
+-- main entry
+function main(...)
+
+ -- parse arguments
+ local argv = {...}
+ local opt = option.parse(argv, options, "Save all lua files to bitcode files."
+ , ""
+ , "Usage: xmake l private.utils.bcsave [options]")
+
+ -- check outputdir
+ if not opt.outputdir then
+ opt.help()
+ raise("please set output directory!")
+ end
+
+ -- save bitcode files
+ save(opt.sourcedir, opt.outputdir, opt)
+end