-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
199 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import * as util from "./util"; | ||
import * as config from "./config"; | ||
import * as dependencies from "./dependencies"; | ||
|
||
interface CargoMetadata { | ||
target_directory: string; | ||
workspace_root?: string; | ||
} | ||
|
||
/** | ||
* Parses the output of `cargo metadata` into a `CargoMetadata` object. | ||
* | ||
* @param output The output to parse. | ||
*/ | ||
function parseCargoMetadata(output: string): CargoMetadata { | ||
return JSON.parse(output) as CargoMetadata; | ||
} | ||
|
||
export enum MetadataStatus { | ||
Crash, | ||
Errors, | ||
Ok | ||
} | ||
|
||
/** | ||
* Queries for the metadata of a Rust crate using cargo-prusti. | ||
* | ||
* @param prusti The location of Prusti files. | ||
* @param cratePath The path of a Rust crate. | ||
* @param destructors Where to store the destructors of the spawned processes. | ||
* @returns A tuple containing the metadata, the exist status, and the duration of the query. | ||
*/ | ||
export async function queryCrateMetadata(prusti: dependencies.PrustiLocation, cratePath: string, destructors: Set<util.KillFunction>): Promise<[CargoMetadata, MetadataStatus, util.Duration]> { | ||
const cargoPrustiArgs = ["--no-deps", "--offline", "--format-version=1"].concat( | ||
config.extraCargoPrustiArgs() | ||
); | ||
const cargoPrustiEnv = { | ||
...process.env, // Needed to run Rustup | ||
...{ | ||
PRUSTI_CARGO_COMMAND: "metadata", | ||
PRUSTI_QUIET: "true", | ||
}, | ||
...config.extraPrustiEnv(), | ||
}; | ||
const output = await util.spawn( | ||
prusti.cargoPrusti, | ||
cargoPrustiArgs, | ||
{ | ||
options: { | ||
cwd: cratePath, | ||
env: cargoPrustiEnv, | ||
} | ||
}, | ||
destructors, | ||
); | ||
let status = MetadataStatus.Crash; | ||
if (output.code === 0) { | ||
status = MetadataStatus.Ok; | ||
} | ||
if (output.code === 1) { | ||
status = MetadataStatus.Errors; | ||
} | ||
if (output.code === 101) { | ||
status = MetadataStatus.Errors; | ||
} | ||
if (/error: internal compiler error/.exec(output.stderr) !== null) { | ||
status = MetadataStatus.Crash; | ||
} | ||
if (/^thread '.*' panicked at/.exec(output.stderr) !== null) { | ||
status = MetadataStatus.Crash; | ||
} | ||
const metadata: CargoMetadata = parseCargoMetadata(output.stdout); | ||
return [metadata, status, output.duration]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[workspace] | ||
members = [ | ||
"first", | ||
"second", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "first" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
prusti-contracts = "*" |
11 changes: 11 additions & 0 deletions
11
src/test/scenarios/shared/crates/workspace/first/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use prusti_contracts::*; | ||
|
||
#[requires(dividend != 0)] | ||
#[ensures(divisor == result * dividend + (divisor % dividend))] | ||
pub fn divide_by(divisor: usize, dividend: usize) -> usize { | ||
divisor / dividend | ||
} | ||
|
||
pub fn generate_error() { | ||
assert!(false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "second" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
prusti-contracts = "*" | ||
first = { path = "../first" } |
4 changes: 4 additions & 0 deletions
4
src/test/scenarios/shared/crates/workspace/second/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
let result = first::divide_by(10, 2); | ||
assert!(result == 5); | ||
} |
Oops, something went wrong.