forked from tsolomko/SWCompression
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
executable file
·135 lines (117 loc) · 5.82 KB
/
utils.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
import argparse
import os
import subprocess
import sys
def _sprun(cmd: list, *args, **kwargs):
print("+ " + " ".join(cmd))
subprocess.run(cmd, check=True, *args, **kwargs)
def _sprun_shell(cmd: str, *args, **kwargs):
print("+ " + cmd)
subprocess.run(cmd, check=True, shell=True, *args, **kwargs)
def _ci_before_deploy():
docs_json_file = open("docs.json", "w")
_sprun(["sourcekitten", "doc", "--spm", "--module-name", "SWCompression"], stdout=docs_json_file)
docs_json_file.close()
_sprun(["jazzy"])
def _ci_install_macos():
script = """if brew ls --versions "git-lfs" >/dev/null; then
HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade "git-lfs"
else
HOMEBREW_NO_AUTO_UPDATE=1 brew install "git-lfs"
fi"""
_sprun_shell(script)
_sprun(["git", "lfs", "install"])
def _ci_install_linux():
_sprun_shell("eval \"$(curl -sL https://swiftenv.fuller.li/install.sh)\"")
def _ci_script_macos():
_sprun_shell("xcodebuild -version")
_sprun(["swift", "--version"])
xcodebuild_command_parts = ["xcodebuild", "-quiet", "-project", "SWCompression.xcodeproj", "-scheme", "SWCompression"]
destinations_actions = [(["-destination 'platform=OS X'"], ["clean", "test"]),
(["-destination 'platform=iOS Simulator,name=iPhone 8'"], ["clean", "test"]),
(["-destination 'platform=watchOS Simulator,name=" + os.environ["WATCHOS_SIMULATOR"] + "'"], [os.environ["WATCHOS_ACTIONS"]]),
(["-destination 'platform=tvOS Simulator,name=Apple TV'"], ["clean", "test"])]
for destination, actions in destinations_actions:
xcodebuild_command = xcodebuild_command_parts + destination + actions
# If xcodebuild is not run inside shell, then destination parameters are ignored for some reason.
_sprun_shell(" ".join(xcodebuild_command))
def _ci_script_linux():
env = os.environ.copy()
env["SWIFTENV_ROOT"] = env["HOME"] +"/.swiftenv"
env["PATH"] = env["SWIFTENV_ROOT"] + "/bin:" + env["SWIFTENV_ROOT"] + "/shims:"+ env["PATH"]
_sprun(["swift", "--version"], env=env)
_sprun(["swift", "build"], env=env)
_sprun(["swift", "build", "-c", "release"], env=env)
def action_ci(args):
if args.cmd == "before-deploy":
_ci_before_deploy()
elif args.cmd == "install-macos":
_ci_install_macos()
elif args.cmd == "install-linux":
_ci_install_linux()
elif args.cmd == "script-macos":
_ci_script_macos()
elif args.cmd == "script-linux":
_ci_script_linux()
else:
raise Exception("Unknown CI command")
def action_cw(args):
_sprun(["rm", "-rf", "build/"])
_sprun(["rm", "-rf", "Carthage/"])
_sprun(["rm", "-rf", "docs/"])
_sprun(["rm", "-rf", "Pods/"])
_sprun(["rm", "-rf", ".build/"])
_sprun(["rm", "-f", "Cartfile.resolved"])
_sprun(["rm", "-f", "docs.json"])
_sprun(["rm", "-f", "Package.resolved"])
_sprun(["rm", "-f", "SWCompression.framework.zip"])
def _pw_macos(debug, xcf):
print("=> Downloading dependency (BitByteData) using Carthage")
script = ["carthage", "bootstrap", "--no-use-binaries"]
if debug:
script += ["--configuration", "Debug"]
if xcf:
script += ["--use-xcframeworks"]
_sprun(script)
def action_pw(args):
if args.os == "macos":
_pw_macos(args.debug, args.xcf)
elif args.os == "other":
pass
else:
raise Exception("Unknown OS")
if not args.no_test_files:
print("=> Downloading files used for testing")
_sprun(["git", "submodule", "update", "--init", "--recursive"])
_sprun(["cp", "Tests/Test Files/gitattributes-copy", "Tests/Test Files/.gitattributes"])
_sprun(["git", "lfs", "pull"], cwd="Tests/Test Files/")
_sprun(["git", "lfs", "checkout"], cwd="Tests/Test Files/")
parser = argparse.ArgumentParser(description="A tool with useful commands for developing SWCompression")
subparsers = parser.add_subparsers(title="commands", help="a command to perform", metavar="CMD")
# Parser for 'ci' command.
parser_ci = subparsers.add_parser("ci", help="a subset of commands used by CI",
description="a subset of commands used by CI")
parser_ci.add_argument("cmd", choices=["before-deploy", "install-macos", "install-linux", "script-macos", "script-linux"],
help="a command to perform on CI", metavar="CI_CMD")
parser_ci.add_argument("--new-watchos-simulator", action="store_true", dest="new_watchos_simulator",
help="use the newest watchos simulator which is necessary for xcode 12+ \
(used only by 'script-macos' subcommand)")
parser_ci.set_defaults(func=action_ci)
# Parser for 'cleanup-workspace' command.
parser_cw = subparsers.add_parser("cleanup-workspace", help="cleanup workspace",
description="cleans workspace from files produced by various build systems")
parser_cw.set_defaults(func=action_cw)
# Parser for 'prepare-workspace' command.
parser_pw = subparsers.add_parser("prepare-workspace", help="prepare workspace",
description="prepares workspace for developing SWCompression")
parser_pw.add_argument("os", choices=["macos", "other"], help="development operating system", metavar="OS")
parser_pw.add_argument("--no-test-files", "-T", action="store_true", dest="no_test_files",
help="don't download example files used for testing")
parser_pw.add_argument("--debug", "-d", action="store_true", dest="debug",
help="build BitByteData in Debug configuration")
parser_pw.add_argument("--xcf", action="store_true", dest="xcf",
help="build BitByteData as a XCFramework")
parser_pw.set_defaults(func=action_pw)
args = parser.parse_args()
args.func(args)