diff options
| author | Per Larsson <[email protected]> | 2022-03-19 10:41:08 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2022-03-19 10:41:08 +0100 |
| commit | 703c252710cdae35a35be700fade144e994777c0 (patch) | |
| tree | 03268a46ea32553c4777ee30cc617f140665938a /scripts | |
| parent | Minor cleanup. (diff) | |
| parent | Suppress C4305 in third party includes (diff) | |
| download | zen-703c252710cdae35a35be700fade144e994777c0.tar.xz zen-703c252710cdae35a35be700fade144e994777c0.zip | |
Merge branch 'main' into streamapi
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/bundle.lua | 106 | ||||
| -rw-r--r-- | scripts/formatcode.py | 19 | ||||
| -rw-r--r-- | scripts/remote_build.py | 12 |
3 files changed, 116 insertions, 21 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) diff --git a/scripts/formatcode.py b/scripts/formatcode.py index dc13ae117..49a8753da 100644 --- a/scripts/formatcode.py +++ b/scripts/formatcode.py @@ -1,8 +1,9 @@ import argparse -import os import fileinput +import os import pathlib import re +import subprocess match_expressions = [] valid_extensions = [] @@ -89,6 +90,20 @@ def parse_match_expressions(wildcards, matches): print(f'Could not parse input --match expression \'{regex}\': {str(ex)}') quit() +def validate_clang_format(): + vstring = subprocess.check_output("clang-format --version", shell=True).decode().rstrip() + + match = re.search(r'(\d+)\.(\d+)(\.(\d+))?$', vstring) + if not match: + raise ValueError("invalid version number '%s'" % vstring) + + (major, minor, patch) = match.group(1, 2, 4) + + if int(major) < 13: + if int(minor) == 0: + if int(patch) < 1: + raise ValueError(f'invalid clang-format version -- we require at least v12.0.1') + def _main(): global root_dir, use_batching @@ -106,6 +121,8 @@ def _main(): root_dir = pathlib.Path(__file__).parent.parent.resolve() use_batching = options.use_batching + validate_clang_format() + while True: if (os.path.isfile(".clang-format")): scan_zen(".") diff --git a/scripts/remote_build.py b/scripts/remote_build.py index 08e44c9ad..70f9cf9bf 100644 --- a/scripts/remote_build.py +++ b/scripts/remote_build.py @@ -106,13 +106,15 @@ def _local(args): _header("Validating remote host and credentials") - # Validate key file. OpenSSL needs a trailing EOL, LibreSSL doesn't + # Validate key file. Git's SSH uses OpenSSL which needs UNIX line-endings if args.keyfile: with open(args.keyfile, "rt") as key_file: - lines = [x for x in key_file] - if not lines[-1].endswith("\n"): - print("!! ERROR: key file must end with a new line") - return 1 + lines = [x.strip() for x in key_file] + + with open(args.keyfile, "wb") as key_file: + for line in lines: + key_file.write(line.encode() + b"\n") + identity = ("-i", args.keyfile) else: identity = () |