| 1 |
# |
| 2 |
# Copyright (c) 2018 Microsoft Corporation |
| 3 |
# |
| 4 |
|
| 5 |
# 1. copy over dlls |
| 6 |
# 2. copy over libz3.dll for the different architectures |
| 7 |
# 3. copy over Microsoft.Z3.dll from suitable distribution |
| 8 |
# 4. copy nuspec file from packages |
| 9 |
# 5. call nuget pack |
| 10 |
# 6. sign package |
| 11 |
|
| 12 |
import json |
| 13 |
import os |
| 14 |
import zipfile |
| 15 |
import sys |
| 16 |
import os.path |
| 17 |
import shutil |
| 18 |
import subprocess |
| 19 |
|
| 20 |
def mk_dir(d): |
| 21 |
if not os.path.exists(d): |
| 22 |
os.makedirs(d) |
| 23 |
|
| 24 |
os_info = { 'x64-ubuntu-latest' : ('so', 'linux-x64'), |
| 25 |
'x64-ubuntu-18' : ('so', 'linux-x64'), |
| 26 |
'x64-ubuntu-20' : ('so', 'linux-x64'), |
| 27 |
'x64-ubuntu-22' : ('so', 'linux-x64'), |
| 28 |
'x64-glibc-2.35' : ('so', 'linux-x64'), |
| 29 |
'x64-win' : ('dll', 'win-x64'), |
| 30 |
'x86-win' : ('dll', 'win-x86'), |
| 31 |
'x64-osx' : ('dylib', 'osx-x64'), |
| 32 |
'debian' : ('so', 'linux-x64') } |
| 33 |
|
| 34 |
# Nuget not supported for ARM |
| 35 |
#'arm-glibc-2.35' : ('so', 'linux-arm64'), |
| 36 |
#'arm64-osx' : ('dylib', 'osx-arm64'), |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
def classify_package(f, arch): |
| 41 |
for os_name in os_info: |
| 42 |
if os_name in f: |
| 43 |
ext, dst = os_info[os_name] |
| 44 |
return os_name, f[:-4], ext, dst |
| 45 |
print("Could not classify", f) |
| 46 |
return None |
| 47 |
|
| 48 |
def replace(src, dst): |
| 49 |
try: |
| 50 |
os.remove(dst) |
| 51 |
except: |
| 52 |
shutil.move(src, dst) |
| 53 |
|
| 54 |
def unpack(packages, symbols, arch): |
| 55 |
# unzip files in packages |
| 56 |
# out |
| 57 |
# +- runtimes |
| 58 |
# +- win-x64 |
| 59 |
# +- win-x86 |
| 60 |
# +- linux-x64 |
| 61 |
# +- osx-x64 |
| 62 |
# + |
| 63 |
tmp = "tmp" if not symbols else "tmpsym" |
| 64 |
for f in os.listdir(packages): |
| 65 |
print(f) |
| 66 |
if f.endswith(".zip") and classify_package(f, arch): |
| 67 |
os_name, package_dir, ext, dst = classify_package(f, arch) |
| 68 |
path = os.path.abspath(os.path.join(packages, f)) |
| 69 |
zip_ref = zipfile.ZipFile(path, 'r') |
| 70 |
zip_ref.extract(f"{package_dir}/bin/libz3.{ext}", f"{tmp}") |
| 71 |
mk_dir(f"out/runtimes/{dst}/native") |
| 72 |
replace(f"{tmp}/{package_dir}/bin/libz3.{ext}", f"out/runtimes/{dst}/native/libz3.{ext}") |
| 73 |
if "x64-win" in f or "x86-win" in f: |
| 74 |
mk_dir("out/lib/netstandard2.0/") |
| 75 |
if symbols: |
| 76 |
zip_ref.extract(f"{package_dir}/bin/libz3.pdb", f"{tmp}") |
| 77 |
replace(f"{tmp}/{package_dir}/bin/libz3.pdb", f"out/runtimes/{dst}/native/libz3.pdb") |
| 78 |
files = ["Microsoft.Z3.dll"] |
| 79 |
if symbols: |
| 80 |
files += ["Microsoft.Z3.pdb", "Microsoft.Z3.xml"] |
| 81 |
for b in files: |
| 82 |
file = f"{package_dir}/bin/{b}" |
| 83 |
if os.path.exists(file): |
| 84 |
zip_ref.extract(file, f"{tmp}") |
| 85 |
replace(f"{tmp}/{package_dir}/bin/{b}", f"out/lib/netstandard2.0/{b}") |
| 86 |
file = os.path.join(file,"netstandard2.0") |
| 87 |
if os.path.exists(file): |
| 88 |
zip_ref.extract(file, f"{tmp}") |
| 89 |
replace(f"{tmp}/{package_dir}/bin/netstandard2.0/{b}", f"out/lib/netstandard2.0/{b}") |
| 90 |
|
| 91 |
|
| 92 |
def mk_targets(source_root): |
| 93 |
mk_dir("out/build") |
| 94 |
shutil.copy(f"{source_root}/src/api/dotnet/Microsoft.Z3.targets.in", "out/build/Microsoft.Z3.targets") |
| 95 |
|
| 96 |
def mk_icon(source_root): |
| 97 |
mk_dir("out/content") |
| 98 |
shutil.copy(f"{source_root}/resources/icon.jpg", "out/content/icon.jpg") |
| 99 |
# shutil.copy(f"{source_root}/src/api/dotnet/README.md", "out/content/README.md") |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
def create_nuget_spec(version, repo, branch, commit, symbols, arch): |
| 104 |
arch = f".{arch}" if arch == "x86" else "" |
| 105 |
contents = """<?xml version="1.0" encoding="utf-8"?> |
| 106 |
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> |
| 107 |
<metadata> |
| 108 |
<id>Microsoft.Z3{4}</id> |
| 109 |
<version>{0}</version> |
| 110 |
<authors>Microsoft</authors> |
| 111 |
<description> |
| 112 |
Z3 is a satisfiability modulo theories solver from Microsoft Research. |
| 113 |
|
| 114 |
Linux Dependencies: |
| 115 |
libgomp.so.1 installed |
| 116 |
</description> |
| 117 |
<copyright>© Microsoft Corporation. All rights reserved.</copyright> |
| 118 |
<tags>smt constraint solver theorem prover</tags> |
| 119 |
<icon>content/icon.jpg</icon> |
| 120 |
<projectUrl>https://github.com/Z3Prover/z3</projectUrl> |
| 121 |
<license type="expression">MIT</license> |
| 122 |
<repository type="git" url="{1}" branch="{2}" commit="{3}" /> |
| 123 |
<requireLicenseAcceptance>true</requireLicenseAcceptance> |
| 124 |
<language>en</language> |
| 125 |
<dependencies> |
| 126 |
<group targetFramework=".netstandard2.0" /> |
| 127 |
</dependencies> |
| 128 |
</metadata> |
| 129 |
</package>""".format(version, repo, branch, commit, arch) |
| 130 |
print(contents) |
| 131 |
sym = "sym." if symbols else "" |
| 132 |
file = f"out/Microsoft.Z3{arch}.{sym}nuspec" |
| 133 |
print(file) |
| 134 |
with open(file, 'w') as f: |
| 135 |
f.write(contents) |
| 136 |
|
| 137 |
class Env: |
| 138 |
def __init__(self, argv): |
| 139 |
self.packages = argv[1] |
| 140 |
self.version = argv[2] |
| 141 |
self.repo = argv[3] |
| 142 |
self.branch = argv[4] |
| 143 |
self.commit = argv[5] |
| 144 |
self.source_root = argv[6] |
| 145 |
self.symbols = False |
| 146 |
self.arch = "x64" |
| 147 |
if len(argv) > 7 and "symbols" == argv[7]: |
| 148 |
self.symbols = True |
| 149 |
if len(argv) > 8: |
| 150 |
self.arch = argv[8] |
| 151 |
|
| 152 |
def create(self): |
| 153 |
mk_dir(self.packages) |
| 154 |
unpack(self.packages, self.symbols, self.arch) |
| 155 |
mk_targets(self.source_root) |
| 156 |
mk_icon(self.source_root) |
| 157 |
create_nuget_spec(self.version, self.repo, self.branch, self.commit, self.symbols, self.arch) |
| 158 |
|
| 159 |
def main(): |
| 160 |
env = Env(sys.argv) |
| 161 |
print(env.packages) |
| 162 |
env.create() |
| 163 |
|
| 164 |
main() |