-
Notifications
You must be signed in to change notification settings - Fork 10
/
checks.ts
87 lines (83 loc) · 3.32 KB
/
checks.ts
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
import * as util from "./util";
import * as config from "./config";
import * as path from "path";
import * as fs from "fs-extra";
import { PrustiLocation } from "./dependencies";
export async function hasPrerequisites(): Promise<[boolean, string]> {
util.log("Checking Java home...");
if (await config.javaHome() === null) {
const msg = "Could not find the Java home. Please install Java 11+ " +
"64bit or set the 'javaHome' setting, then restart the IDE.";
return [false, msg];
}
util.log("Checking Rustup and Cargo...");
try {
await util.spawn("rustup", ["--version"]);
await util.spawn("cargo", ["--version"]);
} catch (err) {
util.log(`Error: ${err}`);
const msg = "Could not run Rustup. Please visit " +
"[https://rustup.rs/](https://rustup.rs/) and install Rustup, " +
"then restart the IDE.";
return [false, msg];
}
util.log("Checking Java...");
try {
const javaPath = path.join(
(await config.javaHome())!.javaExecutable
);
await util.spawn(javaPath, ["-version"]);
} catch (err) {
util.log(`Error: ${err}`);
const msg = "Could not run Java. Please install Java 11+ 64bit " +
"or set the 'javaHome' setting, then restart the IDE.";
return [false, msg];
}
return [true, ""];
}
export async function checkPrusti(prusti: PrustiLocation): Promise<[boolean, string]> {
util.log("Checking Z3...");
try {
await util.spawn(prusti.z3, ["--version"]);
} catch (err) {
util.log(`Error: ${err}`);
const msg = "Could not run Z3. " +
"Please try updating the verifier, then restart the IDE.";
return [false, msg];
}
util.log("Checking Prusti...");
try {
await util.spawn(prusti.prustiRustc, ["--version"]);
} catch (err) {
util.log("Could not run prusti-rustc");
util.log(`Error: ${err}`);
const msg = "Could not run Prusti. " +
"Please try updating the verifier, then restart the IDE.";
return [false, msg];
}
util.log("Checking Cargo-Prusti...");
try {
await util.spawn(prusti.cargoPrusti, ["--help"]);
} catch (err) {
util.log("Could not run cargo-prusti");
util.log(`Error: ${err}`);
const msg = "Could not run Prusti. " +
"Please try updating the verifier, then restart the IDE.";
return [false, msg];
}
return [true, ""];
}
// Check if Prusti is older than numDays or is older than the VS Code extension.
export async function isOutdated(prusti: PrustiLocation, numDays = 30): Promise<boolean> {
// No need to update a fixed Prusti version
if (config.prustiVersion() !== config.PrustiVersion.Latest) {
return false;
}
// TODO: Lookup on GitHub if there actually is a more recent version to download.
const prustiDownloadDate = (await fs.stat(prusti.rustToolchainFile.path())).ctime.getTime();
const pastNumDays = new Date(new Date().setDate(new Date().getDate() - numDays)).getTime();
const olderThanNumDays = prustiDownloadDate < pastNumDays;
const extensionDownloadDate = (await fs.stat(__filename)).ctime.getTime();
const olderThanExtension = prustiDownloadDate < extensionDownloadDate;
return olderThanNumDays || olderThanExtension;
}