Skip to content

Commit

Permalink
Introduce new --copy, --force options.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaozg committed May 11, 2023
1 parent bf8f45d commit a81bf29
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,13 @@ Usage: luvi bundle+ [options] [-- extra args]

bundle Path to directory or zip file containing bundle source.
`bundle` can be specified multiple times to layer bundles
on top of eachother.
on top of each other.
--version Show luvi version and compiled in options.
--output target Build a luvi app by zipping the bundle and inserting luvi.
--main path Specify a custom main bundle path (normally main.lua)
--strip Compile lua code and strip debug info
--copy Do not compile, just copy Lua code and compress.
--strip Compile Lua code and strip debug info.
--force Force build then bundle, ignore Lua compile error.
--help Show this help file.
-- All args after this go to the luvi app itself.

Expand Down
5 changes: 4 additions & 1 deletion src/lua/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ local commands = {
["--version"] = "version",
["-h"] = "help",
["--help"] = "help",
["--copy"] = "copy",
["-s"] = "strip",
["--strip"] = "strip"
}
Expand All @@ -66,7 +67,9 @@ Usage: $(LUVI) bundle+ [options] [-- extra args]
--version Show luvi version and compiled in options.
--output target Build a luvi app by zipping the bundle and inserting luvi.
--main path Specify a custom main bundle path (normally main.lua)
--strip Compile lua code and strip debug info
--copy Do not compile, just copy Lua code and compress.
--strip Compile Lua code and strip debug info.
--force Force build then bundle, ignore Lua compile error.
--help Show this help file.
-- All args after this go to the luvi app itself.
Expand Down
14 changes: 10 additions & 4 deletions src/lua/luvibundle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ end
local function buildBundle(options, bundle)
assert(type(options)=='table')
local target = assert(options.output, "missing output target")
local strip = options.strip
target = pathJoin(uv.cwd(), target)
print("Creating new binary: " .. target)
local fd = assert(uv.fs_open(target, "w", 511)) -- 0777
Expand Down Expand Up @@ -192,9 +191,16 @@ local function buildBundle(options, bundle)
elseif stat.type == "file" then
print(" " .. child)
local ctx = bundle.readfile(child)
if strip and name ~= "package.lua" and child:sub(-4, -1)=='.lua' then
ctx = assert(load(ctx, child))
ctx = string.dump(ctx, strip)
local isLua = name:sub(-4, -1) == ".lua"

-- compile, strip lua code, but skip package.lua
if isLua and name ~= 'package.lua' and not options.copy then
local fn, err = load(ctx, child)
if not fn and not options.force then
error(err)
else
ctx = string.dump(fn, options.strip)
end
end
writer:add(child, ctx, 9)
end
Expand Down

0 comments on commit a81bf29

Please # to comment.