-
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.
Merge pull request #253 from viperproject/fix-workspaces
Fix error reporting
- Loading branch information
Showing
16 changed files
with
246 additions
and
57 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
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,62 @@ | ||
import * as util from "./util"; | ||
import * as config from "./config"; | ||
import * as dependencies from "./dependencies"; | ||
|
||
export interface CrateMetadata { | ||
target_directory: string; | ||
workspace_root?: string; | ||
} | ||
|
||
export enum CrateMetadataStatus { | ||
Error, | ||
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<[CrateMetadata, CrateMetadataStatus, 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 = CrateMetadataStatus.Error; | ||
if (output.code === 0) { | ||
status = CrateMetadataStatus.Ok; | ||
} | ||
if (/error: internal compiler error/.exec(output.stderr) !== null) { | ||
status = CrateMetadataStatus.Error; | ||
} | ||
if (/^thread '.*' panicked at/.exec(output.stderr) !== null) { | ||
status = CrateMetadataStatus.Error; | ||
} | ||
const metadata = JSON.parse(output.stdout) as CrateMetadata; | ||
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
Oops, something went wrong.