forked from viperproject/prusti-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathx.py
More file actions
executable file
·328 lines (289 loc) · 9.68 KB
/
x.py
File metadata and controls
executable file
·328 lines (289 loc) · 9.68 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/usr/bin/env python3
"""A wrapper for cargo that sets up the Prusti environment."""
import sys
if sys.version_info[0] < 3:
print('You need to run this script with Python 3.')
sys.exit(1)
import os
import platform
import subprocess
import glob
import csv
import time
import json
import signal
import shutil
import traceback
import datetime
sys.path.append(os.path.join(os.path.dirname(__file__), 'scripts'))
import reporting
from reporting import (
report, error
)
import benchmark
from helper_functions import (
get_env, run_command, extract_test_compile_flags
)
import verify_test
dry_run = False
RUSTFMT_CRATES = [
'analysis',
'jni-gen',
'prusti',
#'prusti-common',
'prusti-contracts/prusti-contracts',
'prusti-contracts/prusti-contracts-std',
'prusti-contracts/prusti-contracts-impl',
'prusti-contracts/prusti-contracts-internal',
#'prusti-contracts/prusti-specs',
'prusti-contracts/prusti-utils',
'prusti-contracts-build',
'prusti-interface',
'prusti-launch',
'prusti-rustc-interface',
'prusti-server',
'prusti-smt-solver',
'prusti-tests',
#'prusti-viper',
'smt-log-analyzer',
#'test-crates',
'viper',
'viper-sys',
'vir',
'vir-gen',
]
RUSTFMT_PATHS = [
'prusti-common/src/report/mod.rs',
'prusti-common/src/utils/mod.rs',
'prusti-common/src/vir/to_viper.rs',
'prusti-common/src/vir/low_to_viper/mod.rs',
'prusti-common/src/vir/optimizations/mod.rs',
'prusti-interface/src/environment/mir_dump/mod.rs',
'prusti-interface/src/environment/mir_analyses/mod.rs',
'prusti-interface/src/environment/mir_sets/mod.rs',
'prusti-interface/src/environment/mir_body/mod.rs',
'prusti-interface/src/environment/debug_utils/mod.rs',
'prusti-interface/src/environment/mir_utils/mod.rs',
'prusti-tests/tests/verify_partial/**/*.rs',
'prusti-viper/src/encoder/foldunfold/mod.rs',
'prusti-viper/src/encoder/mir/mod.rs',
'prusti-viper/src/encoder/high/mod.rs',
'prusti-viper/src/encoder/typed/mod.rs',
'prusti-viper/src/encoder/middle/mod.rs',
'prusti-viper/src/encoder/snapshot/mod.rs',
'prusti-viper/src/encoder/lifetimes/mod.rs',
'prusti-viper/src/encoder/definition_collector.rs',
'prusti-viper/src/encoder/counterexamples/mod.rs',
'vir/defs/high/mod.rs',
'vir/defs/middle/mod.rs',
'vir/defs/polymorphic/mod.rs',
'vir/defs/components/mod.rs',
'vir/defs/typed/mod.rs',
'vir/defs/low/mod.rs',
]
def shell(command, term_on_nzec=True):
"""Run a shell command."""
print("Running a shell command: ", command)
if not dry_run:
completed = subprocess.run(command.split())
if completed.returncode != 0 and term_on_nzec:
sys.exit(completed.returncode)
return completed.returncode
def cargo(args):
"""Run cargo with the given arguments."""
run_command(['cargo'] + args)
def viper_version():
with open("viper-toolchain", "r") as file:
return file.read().strip()
def setup_ubuntu():
"""Install the dependencies on Ubuntu."""
# Install dependencies.
shell('sudo apt-get update')
shell('sudo apt-get install -y '
'build-essential pkg-config '
'curl gcc libssl-dev')
# Download Viper.
shell(
'curl https://github.com/viperproject/viper-ide/releases/'
'download/{}/ViperToolsLinux.zip -Lo ViperToolsLinux.zip'.format(viper_version())
)
if os.path.exists('viper_tools'):
shutil.rmtree('viper_tools')
shell('unzip ViperToolsLinux.zip -d viper_tools')
os.remove('ViperToolsLinux.zip')
def setup_linux():
"""Install the dependencies on generic Linux."""
shell(
'curl https://github.com/viperproject/viper-ide/releases/'
'download/{}/ViperToolsLinux.zip -Lo ViperToolsLinux.zip'.format(viper_version())
)
if os.path.exists('viper_tools'):
shutil.rmtree('viper_tools')
shell('unzip ViperToolsLinux.zip -d viper_tools')
os.remove('ViperToolsLinux.zip')
def setup_mac():
"""Install the dependencies on Mac."""
# Non-Viper dependencies must be installed manually.
# Download Viper.
shell(
'curl https://github.com/viperproject/viper-ide/releases/'
'download/{}/ViperToolsMac.zip -Lo ViperToolsMac.zip'.format(viper_version())
)
if os.path.exists('viper_tools'):
shutil.rmtree('viper_tools')
shell('unzip ViperToolsMac.zip -d viper_tools')
os.remove('ViperToolsMac.zip')
def setup_win():
"""Install the dependencies on Windows."""
# Non-Viper dependencies must be installed manually.
# Download Viper.
shell(
'curl https://github.com/viperproject/viper-ide/releases/'
'download/{}/ViperToolsWin.zip -Lo ViperToolsWin.zip'.format(viper_version())
)
if os.path.exists('viper_tools'):
shutil.rmtree('viper_tools')
os.mkdir('viper_tools')
shell('tar -xf ViperToolsWin.zip -C viper_tools')
os.remove('ViperToolsWin.zip')
def setup_rustup():
# Update rustup
shell('rustup self update', term_on_nzec=False)
def setup(args):
"""Install the dependencies."""
rustup_only = False
if len(args) == 1 and args[0] == '--dry-run':
global dry_run
dry_run = True
elif len(args) == 1 and args[0] == '--rustup-only':
rustup_only = True
elif args:
error("unexpected arguments: {}", args)
if not rustup_only:
if sys.platform in ("linux", "linux2"):
if 'Ubuntu' in platform.platform():
setup_ubuntu()
else:
setup_linux()
elif sys.platform == "darwin":
setup_mac()
elif sys.platform == "win32":
setup_win()
else:
error("unsupported platform: {}", sys.platform)
setup_rustup()
def ide(args):
"""Start VS Code with the given arguments."""
run_command(['code'] + args)
def run_viper_server(port=None):
"""Start the Viper server."""
env = get_env()
viper_home = env['VIPER_HOME']
jar_path = glob.glob(os.path.join(viper_home, '*.jar'))
command = ['java', '-Xmx512m', '-Xss512m', '-jar', ':'.join(jar_path)]
if port is not None:
command.extend(['--port', str(port)])
run_command(command)
def clippy_in(cwd):
"""Run cargo clippy in given subproject."""
run_command(['cargo', 'clippy', '--', '-D', 'warnings'], cwd=cwd)
def fmt_in(cwd):
"""Run cargo fmt in given subproject."""
run_command(['cargo', 'fmt'], cwd=cwd)
def fmt_all():
"""Run rustfmt on all formatted files."""
for crate in RUSTFMT_CRATES:
fmt_in(crate)
for path in RUSTFMT_PATHS:
for file in glob.glob(path, recursive=True):
run_command(['rustfmt', file])
def fmt_check_in(cwd):
"""Run cargo fmt check in the given subproject."""
run_command(['cargo', 'fmt', '--', '--check'], cwd=cwd)
def fmt_check_all():
"""Run rustfmt check on all formatted files."""
for crate in RUSTFMT_CRATES:
fmt_check_in(crate)
for path in RUSTFMT_PATHS:
for file in glob.glob(path, recursive=True):
run_command(['rustfmt', '--check', file])
def check_smir():
"""Check that `extern crate` is used only in `prusti_rustc_interface` (TODO: `prusti_interface` is also ignored for now)."""
for folder in os.listdir('.'):
if folder == 'prusti-rustc-interface' or folder == 'prusti-interface':
continue
if os.path.exists(os.path.join(folder, 'Cargo.toml')):
completed = subprocess.run(
['grep', 'extern crate', '-nr', folder],
capture_output=True
)
lines = [
line
for line in completed.stdout.decode().splitlines()
if '.rs:' in line and not line.startswith('prusti-tests/tests')
]
assert not lines, (
'found `extern crate` outside '
'prusti_rustc_interface:\n{}'.format(
'\n'.join(lines)
)
)
def main(argv):
for i, arg in enumerate(argv):
if arg.startswith('+'):
if arg == '+v' or arg == '++verbose':
reporting.verbose = True
continue
else:
error('unknown option: {}', arg)
elif arg == 'setup':
setup(argv[i+1:])
break
elif arg == 'ide':
ide(argv[i+1:])
break
elif arg == 'run-benchmarks':
cargo(['build', '--all', '--release'])
benchmark.run_benchmarks(argv[i+1:])
break
elif arg == 'run-viper-server':
run_viper_server(*argv[i+1:])
break
elif arg == 'verify-test':
verify_test.verify_test(argv[i+1:])
break
elif arg == 'exec':
run_command(argv[i+1:])
break
elif arg == 'clippy-in':
clippy_in(*argv[i+1:])
break
elif arg == 'fmt-check':
fmt_check_in(*argv[i+1:])
break
elif arg == 'fmt-check-all':
fmt_check_all(*argv[i+1:])
break
elif arg == 'fmt':
fmt_in(*argv[i+1:])
break
elif arg == 'fmt-all':
fmt_all(*argv[i+1:])
break
elif arg == 'check-smir':
check_smir(*argv[i+1:])
break
elif arg == 'build':
# First builds `prusti`
cargo(argv[i:])
# Second runs build script to build `prusti-contracts`
argv.extend(["--features", "prusti-contracts-dep"])
cargo(argv[i:])
break
else:
cargo(argv[i:])
break
if not argv:
cargo(argv)
if __name__ == '__main__':
main(sys.argv[1:])