|
| 1 | +# |
| 2 | +# Copyright (c) 2018 Microsoft Corporation |
| 3 | +# |
| 4 | + |
| 5 | +# 1. download releases from github |
| 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 urllib.request |
| 15 | +import zipfile |
| 16 | +import sys |
| 17 | +import os.path |
| 18 | +import shutil |
| 19 | +import subprocess |
| 20 | +import mk_util |
| 21 | +import mk_project |
| 22 | + |
| 23 | +#release_data = json.loads(urllib.request.urlopen("https://api.github.com/repos/Z3Prover/z3/releases/latest").read().decode()) |
| 24 | +#release_tag_name = release_data['tag_name'] |
| 25 | +#release_tag_ref_data = json.loads(urllib.request.urlopen("https://api.github.com/repos/Z3Prover/z3/git/refs/tags/%s" % release_tag_name).read().decode()) |
| 26 | +#release_tag_sha = release_tag_ref_data['object']['sha'] |
| 27 | + |
| 28 | +#release_version = release_tag_name[3:] |
| 29 | +#release_commit = release_tag_sha # release_tag_data['object']['sha'] |
| 30 | + |
| 31 | +#print(release_version) |
| 32 | + |
| 33 | +def mk_dir(d): |
| 34 | + if not os.path.exists(d): |
| 35 | + os.makedirs(d) |
| 36 | + |
| 37 | + |
| 38 | +os_info = {"z64-ubuntu-14" : ('so', 'ubuntu.14.04-x64'), |
| 39 | + 'ubuntu-16' : ('so', 'ubuntu-x64'), |
| 40 | + 'x64-win' : ('dll', 'win-x64'), |
| 41 | +# Skip x86 as I can't get dotnet build to produce AnyCPU TargetPlatform |
| 42 | +# 'x86-win' : ('dll', 'win-x86'), |
| 43 | + 'osx' : ('dylib', 'macos'), |
| 44 | + 'debian' : ('so', 'debian.8-x64') } |
| 45 | + |
| 46 | +def classify_package(f): |
| 47 | + for os_name in os_info: |
| 48 | + if os_name in f: |
| 49 | + ext, dst = os_info[os_name] |
| 50 | + return os_name, f[:-4], ext, dst |
| 51 | + return None |
| 52 | + |
| 53 | + |
| 54 | +def unpack(packages): |
| 55 | + # unzip files in packages |
| 56 | + # out |
| 57 | + # +- runtimes |
| 58 | + # +- win-x64 |
| 59 | + # +- win-x86 |
| 60 | + # +- ubuntu.16.04-x64 |
| 61 | + # +- ubuntu.14.04-x64 |
| 62 | + # +- debian.8-x64 |
| 63 | + # +- macos |
| 64 | + # + |
| 65 | + for f in os.listdir(packages): |
| 66 | + print(f) |
| 67 | + if f.endswith(".zip") and classify_package(f): |
| 68 | + os_name, package_dir, ext, dst = classify_package(f) |
| 69 | + path = os.path.abspath(os.path.join(packages, f)) |
| 70 | + zip_ref = zipfile.ZipFile(path, 'r') |
| 71 | + zip_ref.extract("%s/bin/libz3.%s" % (package_dir, ext), "tmp") |
| 72 | + mk_dir("out/runtimes/%s/native" % dst) |
| 73 | + shutil.move("tmp/%s/bin/libz3.%s" % (package_dir, ext), "out/runtimes/%s/native/." % dst, "/y") |
| 74 | + if "x64-win" in f: |
| 75 | + mk_dir("out/lib/netstandard1.4/") |
| 76 | + for b in ["Microsoft.Z3.dll"]: |
| 77 | + zip_ref.extract("%s/bin/%s" % (package_dir, b), "tmp") |
| 78 | + shutil.move("tmp/%s/bin/%s" % (package_dir, b), "out/lib/netstandard1.4/%s" % b) |
| 79 | + |
| 80 | +def mk_targets(): |
| 81 | + mk_dir("out/build") |
| 82 | + shutil.copy("../src/api/dotnet/Microsoft.Z3.targets.in", "out/build/Microsoft.Z3.targets") |
| 83 | + |
| 84 | +def create_nuget_spec(): |
| 85 | + contents = """<?xml version="1.0" encoding="utf-8"?> |
| 86 | +<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> |
| 87 | + <metadata> |
| 88 | + <id>Microsoft.Z3.x64</id> |
| 89 | + <version>{0}</version> |
| 90 | + <authors>Microsoft</authors> |
| 91 | + <description> |
| 92 | +Z3 is a satisfiability modulo theories solver from Microsoft Research. |
| 93 | +
|
| 94 | +Linux Dependencies: |
| 95 | + libgomp.so.1 installed |
| 96 | + </description> |
| 97 | + <copyright>© Microsoft Corporation. All rights reserved.</copyright> |
| 98 | + <tags>smt constraint solver theorem prover</tags> |
| 99 | + <iconUrl>https://raw.githubusercontent.com/Z3Prover/z3/{1}/package/icon.jpg</iconUrl> |
| 100 | + <projectUrl>https://github.com/Z3Prover/z3</projectUrl> |
| 101 | + <licenseUrl>https://raw.githubusercontent.com/Z3Prover/z3/{1}/LICENSE.txt</licenseUrl> |
| 102 | + <repository |
| 103 | + type="git" |
| 104 | + url="https://github.com/Z3Prover/z3.git" |
| 105 | + branch="master" |
| 106 | + commit="{1}" |
| 107 | + /> |
| 108 | + <requireLicenseAcceptance>true</requireLicenseAcceptance> |
| 109 | + <language>en</language> |
| 110 | + </metadata> |
| 111 | +</package>""".format(release_version, release_commit) |
| 112 | + |
| 113 | + with open("out/Microsoft.Z3.x64.nuspec", 'w') as f: |
| 114 | + f.write(contents) |
| 115 | + |
| 116 | +def create_nuget_package(): |
| 117 | + subprocess.call(["nuget", "pack"], cwd="out") |
| 118 | + |
| 119 | +nuget_sign_input = """ |
| 120 | +{ |
| 121 | + "Version": "1.0.0", |
| 122 | + "SignBatches" |
| 123 | + : |
| 124 | + [ |
| 125 | + { |
| 126 | + "SourceLocationType": "UNC", |
| 127 | + "SourceRootDirectory": "%s", |
| 128 | + "DestinationLocationType": "UNC", |
| 129 | + "DestinationRootDirectory": "%s", |
| 130 | + "SignRequestFiles": [ |
| 131 | + { |
| 132 | + "CustomerCorrelationId": "42fc9577-af9e-4ac9-995d-1788d8721d17", |
| 133 | + "SourceLocation": "Microsoft.Z3.x64.%s.nupkg", |
| 134 | + "DestinationLocation": "Microsoft.Z3.x64.%s.nupkg" |
| 135 | + } |
| 136 | + ], |
| 137 | + "SigningInfo": { |
| 138 | + "Operations": [ |
| 139 | + { |
| 140 | + "KeyCode" : "CP-401405", |
| 141 | + "OperationCode" : "NuGetSign", |
| 142 | + "Parameters" : {}, |
| 143 | + "ToolName" : "sign", |
| 144 | + "ToolVersion" : "1.0" |
| 145 | + }, |
| 146 | + { |
| 147 | + "KeyCode" : "CP-401405", |
| 148 | + "OperationCode" : "NuGetVerify", |
| 149 | + "Parameters" : {}, |
| 150 | + "ToolName" : "sign", |
| 151 | + "ToolVersion" : "1.0" |
| 152 | + } |
| 153 | + ] |
| 154 | + } |
| 155 | + } |
| 156 | + ] |
| 157 | +}""" |
| 158 | + |
| 159 | +def sign_nuget_package(): |
| 160 | + package_name = "Microsoft.Z3.x64.%s.nupkg" % release_version |
| 161 | + input_file = "out/nuget_sign_input.json" |
| 162 | + output_path = os.path.abspath("out").replace("\\","\\\\") |
| 163 | + with open(input_file, 'w') as f: |
| 164 | + f.write(nuget_sign_input % (output_path, output_path, release_version, release_version)) |
| 165 | + subprocess.call(["EsrpClient.exe", "sign", "-a", "authorization.json", "-p", "policy.json", "-i", input_file, "-o", "out\\diagnostics.json"]) |
| 166 | + |
| 167 | + |
| 168 | +def main(): |
| 169 | + packages = sys.argv[0] |
| 170 | + print(packages) |
| 171 | + mk_dir(packages) |
| 172 | + unpack(packages) |
| 173 | + mk_targets() |
| 174 | + create_nuget_spec() |
| 175 | + create_nuget_package() |
| 176 | + sign_nuget_package() |
| 177 | + |
| 178 | + |
| 179 | +main() |
0 commit comments