From a81bf297e7c611a239967b068774f0eec11f07e2 Mon Sep 17 00:00:00 2001 From: zhaozg Date: Thu, 11 May 2023 09:54:15 +0800 Subject: [PATCH] Introduce new `--copy`, `--force` options. --- README.md | 6 ++++-- src/lua/init.lua | 5 ++++- src/lua/luvibundle.lua | 14 ++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 63521a6b..8de8f78d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/lua/init.lua b/src/lua/init.lua index 422341fa..e5f90c23 100644 --- a/src/lua/init.lua +++ b/src/lua/init.lua @@ -46,6 +46,7 @@ local commands = { ["--version"] = "version", ["-h"] = "help", ["--help"] = "help", + ["--copy"] = "copy", ["-s"] = "strip", ["--strip"] = "strip" } @@ -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. diff --git a/src/lua/luvibundle.lua b/src/lua/luvibundle.lua index 53e5e4fa..13a20013 100644 --- a/src/lua/luvibundle.lua +++ b/src/lua/luvibundle.lua @@ -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 @@ -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