diff options
| author | Martin Ridgers <[email protected]> | 2022-03-16 14:58:34 +0100 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2022-03-16 14:58:34 +0100 |
| commit | ef2f48fbfa3dc5d7a61baf6ccfd6e41b6c3eb895 (patch) | |
| tree | 2afa4ea4993869a10e37baa6062f8f4f3eca91f0 /scripts | |
| parent | Corrected linux install (diff) | |
| parent | Fixed typo (diff) | |
| download | zen-ef2f48fbfa3dc5d7a61baf6ccfd6e41b6c3eb895.tar.xz zen-ef2f48fbfa3dc5d7a61baf6ccfd6e41b6c3eb895.zip | |
Merge branch 'dashboard-zipfs'
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/bundle.lua | 106 |
1 files changed, 91 insertions, 15 deletions
diff --git a/scripts/bundle.lua b/scripts/bundle.lua index 90fb13657..01268ab14 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 @@ -35,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 @@ -62,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") @@ -90,6 +145,21 @@ local function _find_vcpkg_binary(triple, port, binary) 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") @@ -102,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", @@ -129,9 +201,11 @@ 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") + -- 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( @@ -140,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) @@ -159,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) |