From f8170856b601089ba89a69047ccbcd57f16b872b Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Thu, 3 Mar 2022 13:23:42 +0100 Subject: Allow nil arguments when bundle.lua launches processes --- scripts/bundle.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'scripts/bundle.lua') diff --git a/scripts/bundle.lua b/scripts/bundle.lua index 90fb13657..e2e43cd87 100644 --- a/scripts/bundle.lua +++ b/scripts/bundle.lua @@ -2,8 +2,15 @@ -------------------------------------------------------------------------------- local function _exec(cmd, ...) - print("--", cmd, ...) - local ret = os.execv(cmd, {...}) + local args = {} + for _, arg in pairs({...}) do + if arg then + table.insert(args, arg) + end + end + + print("--", cmd, table.unpack(args)) + local ret = os.execv(cmd, args) print() return ret end -- cgit v1.2.3 From 7c4d93104f51cc4ad4f9c643a308aa0551f40cd9 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Thu, 3 Mar 2022 13:24:45 +0100 Subject: Zip up the frontend content and append to executable when bundling --- scripts/bundle.lua | 93 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 12 deletions(-) (limited to 'scripts/bundle.lua') diff --git a/scripts/bundle.lua b/scripts/bundle.lua index e2e43cd87..238a04bc1 100644 --- a/scripts/bundle.lua +++ b/scripts/bundle.lua @@ -42,23 +42,52 @@ local function _build(arch, debug, config_args) end -------------------------------------------------------------------------------- -local function _zip(zip_path, ...) +local function _zip(store_only, zip_path, ...) + -- Here's the rules; if len(...) is 1 and it is a dir then create a zip with + -- archive paths like this; + -- + -- glob(foo/bar/**) -> foo/bar/abc, foo/bar/dir/123 -> zip(abc, dir/123) + -- + -- Otherwise assume ... is file paths and add without leading directories; + -- + -- foo/abc, bar/123 -> zip(abc, 123) + + zip_path = path.absolute(zip_path) os.tryrm(zip_path) + local inputs = {...} + + local source_dir = nil + if #inputs == 1 and os.isdir(inputs[1]) then + source_dir = inputs[1] + end + import("detect.tools.find_7z") local cmd = find_7z() if cmd then - -- A ./ prefix makes 7z ignore the directory structure input_paths = {} - for _, input_path in ipairs({...}) do - input_path = path.relative(input_path, ".") - if input_path:sub(2,2) ~= ":" then - input_path = "./"..input_path + if source_dir then + -- Suffixing a directory path with a "/." will have 7z set the path + -- for archived files relative to that directory. + input_paths = { path.join(source_dir, ".") } + else + for _, input_path in pairs(inputs) do + -- If there is a "/./" anywhere in file paths then 7z drops all + -- directory information and just archives the file by name + input_path = path.relative(input_path, ".") + if input_path:sub(2,2) ~= ":" then + input_path = "./"..input_path + end + table.insert(input_paths, input_path) end - table.insert(input_paths, input_path) end - local ret = _exec("7z", "a", zip_path, table.unpack(input_paths)) + compression_level = "-mx9" + if store_only then + compression_level = "-mx0" + end + + local ret = _exec("7z", "a", "-r", compression_level, zip_path, table.unpack(input_paths)) if ret > 0 then raise("Received error from 7z") end @@ -69,10 +98,29 @@ local function _zip(zip_path, ...) import("detect.tools.find_zip") cmd = find_zip() if cmd then - local ret = _exec("zip", "--junk-paths", zip_path, ...) + local input_paths = inputs + local cwd = os.curdir() + if source_dir then + os.cd(source_dir) + input_paths = { "." } + end + + compression_level = "-9" + if store_only then + compression_level = "-0" + end + + local strip_leading_path = nil + if not source_dir then + strip_leading_path = "--junk-paths" + end + + local ret = _exec("zip", "-r", compression_level, strip_leading_path, zip_path, table.unpack(input_paths)) if ret > 0 then raise("Received error from zip") end + + os.cd(cwd) return end print("zip not found") @@ -96,6 +144,21 @@ local function _find_vcpkg_binary(triple, port, binary) return bin_path end +-------------------------------------------------------------------------------- +local function _append_content_zip(bin_path) + local zip_path = "build/frontend.zip" + local content_dir = "zenserver/frontend/html/" + _zip(true, zip_path, content_dir) + + zip_file = io.open(zip_path, "rb") + local zip_data = zip_file:read("*all") + zip_file:close() + + bin_file = io.open(bin_path, "ab") + bin_file:write(zip_data) + bin_file:close() +end + -------------------------------------------------------------------------------- local function main_windows() import("core.base.option") @@ -109,12 +172,14 @@ local function main_windows() _build("x64", false, config_args) + _append_content_zip("build/windows/x64/release/zenserver.exe") + local crashpad_handler_path = _find_vcpkg_binary( "x64-windows-static", "sentry-native", "crashpad_handler.exe") - _zip( + _zip(false, zip_path, "build/windows/x64/release/zenserver.exe", "build/windows/x64/release/zenserver.pdb", @@ -139,6 +204,8 @@ local function main_mac() raise("Failed creating univeral binary") end + _append_content_zip("build/macosx/universal/release/zenserver") + -- At the time of writing vcpkg does not support sentry-native on arm64. Once -- it does we can create a univeral binary for this. For now just bundle x64 local crashpad_handler_path = _find_vcpkg_binary( @@ -147,7 +214,7 @@ local function main_mac() "crashpad_handler") -- Zip - _zip( + _zip(false, "build/zenserver-macos.zip", "build/macosx/universal/release/zenserver", crashpad_handler_path) @@ -166,9 +233,11 @@ local function main_linux() "crashpad_handler") --]] + _append_content_zip("build/linux/x86_64/release/zenserver") + _exec("scripts/bundle_linux.sh") - _zip( + _zip(false, "build/zenserver-linux.zip", "build/appimage/zenserver", crashpad_handler_path) -- cgit v1.2.3 From c057edd241483139107365426873a6dcf825f1af Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Thu, 3 Mar 2022 13:25:09 +0100 Subject: Fixed typo --- scripts/bundle.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/bundle.lua') diff --git a/scripts/bundle.lua b/scripts/bundle.lua index 238a04bc1..01268ab14 100644 --- a/scripts/bundle.lua +++ b/scripts/bundle.lua @@ -201,7 +201,7 @@ local function main_mac() "build/macosx/arm64/release/zenserver" ) if ret > 0 then - raise("Failed creating univeral binary") + raise("Failed creating universal binary") end _append_content_zip("build/macosx/universal/release/zenserver") -- cgit v1.2.3