Skip to content

Commit

Permalink
Fix visualization process (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaisnan authored Mar 31, 2023
1 parent 591727f commit d34a4e8
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/ui/reportView/callReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import process = require('process');
import * as vscode from 'vscode';

import { KaniArguments, KaniConstants } from '../../constants';
import { checkCargoExist, getRootDir } from '../../utils';
import { getKaniPath } from '../../model/kaniRunner';
import { CommandArgs, checkCargoExist, getRootDir, splitCommand } from '../../utils';

const { execFile } = require('child_process');
const { promisify } = require('util');
Expand Down Expand Up @@ -51,22 +52,16 @@ export async function callViewerReport(

const platform: NodeJS.Platform = process.platform;
const harnessName: string = harnessObj.harnessName;
const harnessFile: string = harnessObj.harnessFile;
const harnessType: boolean = harnessObj.harnessType;

// Detect source file
const terminal = vscode.window.activeTerminal ?? vscode.window.createTerminal();

// Generate the final visualize command for the supported platforms
if (platform === 'darwin' || platform == 'linux') {
const responseObject: htmlMetaData = createCommand(
commandURI,
harnessFile,
harnessName,
harnessType,
);
const responseObject: htmlMetaData = createCommand(commandURI, harnessName, harnessType);
const crateURI: string = getRootDir();
finalCommand = `cd ${crateURI} && ${responseObject.finalCommand}`;
finalCommand = `${responseObject.finalCommand}`;
searchDir = responseObject.searchDir;
}

Expand Down Expand Up @@ -125,28 +120,20 @@ async function showReportMetadata(
// Check if cargo toml exists and create corresponding kani command
function createCommand(
commandURI: string,
harnessFile: string,
harnessName: string,
harnessType: boolean,
): htmlMetaData {
// Check if cargo toml exists
const isCargo = checkCargoExist();
let finalCommand: string = '';
let searchDir: string = '';

if (!isCargo) {
const command: string = commandURI === 'Kani.runViewerReport' ? 'kani' : 'cargo kani';
finalCommand = `${command} ${harnessFile} --harness ${harnessName} --enable-unstable --visualize`;
searchDir = path.join(getRootDir());
if (harnessType) {
const command: string = commandURI === 'Kani.runViewerReport' ? 'cargo kani' : 'kani';
finalCommand = `${command} --harness ${harnessName} --enable-unstable --visualize`;
searchDir = path.join(getRootDir(), 'target');
} else {
if (harnessType) {
const command: string = commandURI === 'Kani.runViewerReport' ? 'cargo kani' : 'kani';
finalCommand = `${command} --harness ${harnessName} --enable-unstable --visualize`;
searchDir = path.join(getRootDir(), 'target');
} else {
finalCommand = `${KaniConstants.CargoKaniExecutableName} ${KaniArguments.testsFlag} ${KaniArguments.harnessFlag} ${harnessName} --enable-unstable --visualize`;
searchDir = path.join(getRootDir(), 'target');
}
finalCommand = `${KaniConstants.CargoKaniExecutableName} ${KaniArguments.testsFlag} ${KaniArguments.harnessFlag} ${harnessName} --enable-unstable --visualize`;
searchDir = path.join(getRootDir(), 'target');
}

return { finalCommand, searchDir };
Expand All @@ -160,9 +147,22 @@ function createCommand(
*/
async function runVisualizeCommand(command: string, harnessName: string): Promise<reportMetadata> {
try {
// Get the full resolved path for the root directory of the crate
const directory = path.resolve(getRootDir());
const commmandSplit: CommandArgs = splitCommand(command);

// Get args for the command to be executed
const args = commmandSplit.args;

const options = {
shell: false,
cwd: directory,
};

const kaniBinaryPath = await getKaniPath('cargo-kani');
vscode.window.showInformationMessage(`Generating viewer report for ${harnessName}`);
vscode.window.showWarningMessage(warningMessage);
const { stdout, stderr } = await execPromise(command);
const { stdout, stderr } = await execPromise(kaniBinaryPath, args, options);
const parseResult = await parseReportOutput(stdout);
if (parseResult === undefined) {
return { statusCode: 2, result: undefined, error: stderr };
Expand Down

0 comments on commit d34a4e8

Please sign in to comment.