ClashX.Meta/ClashX/goClash/build_clash.py

52 lines
1.3 KiB
Python
Raw Normal View History

2019-09-30 14:42:28 +08:00
import subprocess
import datetime
import plistlib
2019-10-02 21:43:18 +08:00
import os
2019-09-30 14:42:28 +08:00
def get_version():
with open('./go.mod') as file:
for line in file.readlines():
2019-10-02 21:43:18 +08:00
if "clash" in line and "ClashX" not in line:
2019-09-30 14:42:28 +08:00
return line.split(" ")[-1].strip()
return "unknown"
def build_clash(version):
build_time = datetime.datetime.now().strftime("%Y-%m-%d-%H%M")
command = f"""CGO_CFLAGS=-mmacosx-version-min=10.12 \
CGO_LDFLAGS=-mmacosx-version-min=10.10 \
GOBUILD=CGO_ENABLED=0 \
go build -ldflags '-X "github.com/Dreamacro/clash/constant.Version={version}" \
-X "github.com/Dreamacro/clash/constant.BuildTime={build_time}"' \
2020-04-08 10:03:05 +08:00
-buildmode=c-archive -o goClash.a """
2019-09-30 14:42:28 +08:00
subprocess.check_output(command, shell=True)
def write_to_info(version):
path = "../info.plist"
2019-09-30 14:42:28 +08:00
with open(path, 'rb') as f:
contents = plistlib.load(f)
if not contents:
exit(-1)
contents["coreVersion"] = version
with open(path, 'wb') as f:
plistlib.dump(contents, f, sort_keys=False)
def run():
version = get_version()
2019-10-02 21:43:18 +08:00
print("current clash version:", version)
2019-09-30 14:42:28 +08:00
build_clash(version)
print("build static library complete!")
2019-12-08 15:40:06 +08:00
if os.environ.get("CI", False) or os.environ.get("GITHUB_ACTIONS", False):
2019-10-02 21:43:18 +08:00
print("writing info.plist")
write_to_info(version)
2019-09-30 14:42:28 +08:00
print("done")
if __name__ == "__main__":
run()