File: build-release.py

package info (click to toggle)
swiftlang 6.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,856,264 kB
  • sloc: cpp: 9,995,718; ansic: 2,234,019; asm: 1,092,167; python: 313,940; objc: 82,726; f90: 80,126; lisp: 38,373; pascal: 25,580; sh: 20,378; ml: 5,058; perl: 4,751; makefile: 4,725; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (60 lines) | stat: -rwxr-xr-x 1,878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
#
# Builds the release tarball of the wasmkit binary

import os
import sys
import subprocess
import shutil
import tarfile

SOURCE_ROOT = os.path.relpath(os.path.join(os.path.dirname(__file__), ".."))

def run(arguments):
    print("Running: " + " ".join(arguments))
    subprocess.run(arguments, check=True)


def is_elf(file_path):
    """Check if the file is an ELF binary."""
    with open(file_path, 'rb') as f:
        header = f.read(4)
    return header == b'\x7fELF'


def main():
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("-o", "--output", required=True)
    parser.add_argument("extra_build_args", nargs="*")

    args = parser.parse_args()

    build_args = ["swift", "build", "-c", "release", "--product", "wasmkit-cli", "--package-path", SOURCE_ROOT] + args.extra_build_args
    bin_path = subprocess.check_output(build_args + ["--show-bin-path"], text=True).strip()

    run(build_args)

    if not args.output.endswith(".tar.gz"):
        raise ValueError("Output file name must end with .tar.gz")
    archive_path = args.output[:-len(".tar.gz")]
    shutil.rmtree(archive_path, ignore_errors=True)
    os.makedirs(archive_path)

    src_exe_path = os.path.join(bin_path, "wasmkit-cli")
    dest_exe_path = os.path.join(archive_path, "wasmkit")
    if is_elf(src_exe_path):
        # For ELF binaries, use strip to remove debug symbols because
        # most of static archives in static linux Swift SDK contains
        # debug sections.
        run(["llvm-strip", src_exe_path, "--strip-debug", "-o", dest_exe_path])
    else:
        shutil.copy(src_exe_path, dest_exe_path)

    with tarfile.open(args.output, "w:gz") as tar:
        tar.add(archive_path, arcname=os.path.basename(archive_path))

    print(f"Release binary is available at {args.output}")

if __name__ == "__main__":
    main()