Commit 7cfec2d5 authored by Timon Stampfli's avatar Timon Stampfli

Merge branch 'patch-process-exec' into 'master'

Make execution platform independent

See merge request !3
parents c83e9b33 b66f616c
Pipeline #4932 passed with stages
in 54 seconds
......@@ -35,7 +35,7 @@ build-helper:
GO111MODULE: "on"
script:
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./out/helper-linux-amd64 ./helper
- CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ./out/helper-windows-amd64 ./helper
- CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ./out/helper-windows-amd64.exe ./helper
- CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./out/helper-darwin-amd64 ./helper
artifacts:
......
......@@ -2,6 +2,9 @@ package main
import (
"sort"
"strings"
"path/filepath"
"github.com/fatih/color"
......@@ -87,6 +90,11 @@ func mapToSortedKeys(m map[string]Sample) []string {
return keys
}
func normalizeString(in string) string {
in = strings.ReplaceAll(in, "\r\n", "\n")
return strings.TrimSpace(in)
}
func runOneSample() {
runOneSampleCmd := flag.NewFlagSet("runOneSample", flag.ExitOnError)
binaryPath := runOneSampleCmd.String("binaryPath", "", "path of binary which is executed")
......@@ -119,15 +127,26 @@ func runOneSample() {
if err != nil {
panic(err)
}
dir, err := os.Getwd()
if err != nil {
fmt.Printf("%v", err)
os.Exit(5)
}
fullBinaryPath := filepath.Join(dir, *binaryPath)
fullSoitaskPath := filepath.Join(dir, *soitaskPath)
sample, err := parseSample(*soitaskPath, *sampleName)
sample, err := parseSample(fullSoitaskPath, *sampleName)
if err != nil {
panic(err)
}
input := normalizeString(sample.Input)
printRunSampleInfo(*binaryPath, *sampleName)
executionResult := runSample(*binaryPath, bytes.NewBufferString(sample.Input), os.Stdout, os.Stderr)
printSampleVerdict(*binaryPath, *sampleName, executionResult.Stdout, sample.Output, executionResult.ProcessError)
executionResult := runSample(fullBinaryPath, bytes.NewBufferString(input), os.Stdout, os.Stderr)
expectedOutput := normalizeString(sample.Output)
gotOutput := normalizeString(executionResult.Stdout)
gotStderr := normalizeString(executionResult.Stderr)
printSampleVerdict(fullBinaryPath, *sampleName, gotOutput, expectedOutput, gotStderr)
sendResult(conn, *binaryPath, *sampleName, executionResult)
......@@ -161,16 +180,30 @@ func runAllSamples() {
panic(err)
}
samples, err := parseAllSamples(*soitaskPath)
dir, err := os.Getwd()
if err != nil {
fmt.Printf("%v", err)
os.Exit(5)
}
fullBinaryPath := filepath.Join(dir, *binaryPath)
fullSoitaskPath := filepath.Join(dir, *soitaskPath)
samples, err := parseAllSamples(fullSoitaskPath)
if err != nil {
panic(err)
}
for _, sampleName := range mapToSortedKeys(samples) {
sample := samples[sampleName]
input := normalizeString(sample.Input)
printRunSampleInfo(*binaryPath, sampleName)
// executionResult := runSample(*binaryPath, bytes.NewBufferString(sample.Input), ioutil.Discard, ioutil.Discard)
executionResult := runSample(*binaryPath, bytes.NewBufferString(sample.Input), os.Stdout, os.Stderr)
printSampleVerdict(*binaryPath, sampleName, executionResult.Stdout, sample.Output, executionResult.ProcessError)
executionResult := runSample(fullBinaryPath, bytes.NewBufferString(input), os.Stdout, os.Stderr)
expectedOutput := normalizeString(sample.Output)
gotOutput := normalizeString(executionResult.Stdout)
gotStderr := normalizeString(executionResult.Stderr)
printSampleVerdict(fullBinaryPath, sampleName, gotOutput, expectedOutput, gotStderr)
sendResult(conn, *binaryPath, sampleName, executionResult)
}
......@@ -200,8 +233,15 @@ func runWithManualInput() {
panic(err)
}
dir, err := os.Getwd()
if err != nil {
fmt.Printf("%v", err)
os.Exit(5)
}
fullBinaryPath := filepath.Join(dir, *binaryPath)
printRunManualInput(*binaryPath)
executionResult := runSample(*binaryPath, os.Stdin, os.Stdout, os.Stderr)
executionResult := runSample(fullBinaryPath, os.Stdin, os.Stdout, os.Stderr)
sendResult(conn, *binaryPath, "manualInput", executionResult)
}
......@@ -3,31 +3,15 @@ import { Store } from "./store";
import * as path from "path";
import * as child_process from "child_process";
import * as vscode from "vscode";
import { determinePlatform, executableFileEnding } from "./util";
export function getHelperPath(store: Store): string {
return path.join(
store.soicodeExtensionOutPath,
`helper-${determinePlatform()}`
`helper-${determinePlatform()}${executableFileEnding()}`
);
}
function determinePlatform() {
// also look at process.arch
switch (process.platform) {
case "darwin":
return "darwin-amd64";
case "win32":
return "windows-amd64";
case "linux":
return "linux-amd64";
default:
vscode.window.showErrorMessage(
"You seem to be running on an unsupported platform"
);
throw new Error("You seem to be running on an unsupported platform");
}
}
export async function downloadCompilerBundle(store: Store) {
return new Promise(async resolve => {
let platform = determinePlatform();
......@@ -35,16 +19,13 @@ export async function downloadCompilerBundle(store: Store) {
let flavor = "soiheaders";
let url = `https://blob.dolansoft.org/soicode/compilerbundle-${platform}-${flavor}.tar.xz`;
let targetDir = path.join(store.soicodeExtensionDataPath, "bundle", flavor);
let proc = child_process.exec(
`'${getHelperPath(
store
)}' fetchBundle --url '${url}' --targetDir '${targetDir}'`
);
console.log(
`'${getHelperPath(
store
)}' fetchBundle --url '${url}' --targetDir '${targetDir}'`
);
let proc = child_process.execFile(getHelperPath(store), [
"fetchBundle",
"--url",
url,
"--targetDir",
targetDir
]);
let stdout = "";
proc.stdout.on("data", chunk => {
stdout += chunk;
......
......@@ -46,26 +46,27 @@ export class Runner {
}
let compileTaskDefinition = {
label: "build " + taskname + " development",
type: "shell",
// "command": "clang++",
// "args": ,
type: "process",
group: {
kind: "build",
isDefault: true
}
};
let headerAsFlag = (path: string) => path === '' ? [] : ["-I", path];
let headerAsFlag = (path: string) => (path === "" ? [] : ["-I", path]);
// Todo: allow customizable flags
let execute = new vscode.ShellExecution(
let execute = new vscode.ProcessExecution(
compilerPath,
[
soitaskFiles.solutionWorkspacePath!,
...getCompilationFlags(this.store),
...headerAsFlag(getCppHeaderPath(this.store)),
...headerAsFlag(getSoiHeaderPath(this.store)),
"-o", taskname
"-o",
taskname
],
{
cwd: workspace
......@@ -193,7 +194,7 @@ export class Runner {
await this.runTask(taskname, "User Input", [
"runWithManualInput",
"--binaryPath",
"./" + soitaskFile.binaryWorkspacePath
soitaskFile.binaryWorkspacePath
]);
}
async runAllSamples(
......@@ -206,9 +207,9 @@ export class Runner {
await this.runTask(taskname, "All Samples", [
"runAllSamples",
"--binaryPath",
"./" + soitaskFile.binaryWorkspacePath,
soitaskFile.binaryWorkspacePath,
"--soitaskPath",
"./" + soitaskFile.soitaskWorkspacePath
soitaskFile.soitaskWorkspacePath!
]);
}
async runOneSample(
......@@ -224,9 +225,9 @@ export class Runner {
await this.runTask(taskname, "sample", [
"runOneSample",
"--binaryPath",
"./" + soitaskFiles.binaryWorkspacePath,
soitaskFiles.binaryWorkspacePath,
"--soitaskPath",
"./" + soitaskFiles.soitaskWorkspacePath,
soitaskFiles.soitaskWorkspacePath!,
"--sampleName",
sample
]);
......
......@@ -6,6 +6,7 @@ import * as fs from "fs-extra";
import { taskTreeResourceEntry } from "./taskTreeView";
import { Store } from "./store";
import { getWorkspaceOrShowError, listFullTasksOrError } from "./storeHelper";
import { executableFileEnding } from "./util";
export type SoitaskFiles = {
taskname: string; // Relative to workspace, no file ending
......@@ -61,10 +62,10 @@ export async function listSoitasks(
taskname: taskname,
solutionFsPath: undefinedToNullMapString(cppTasknames.get(taskname)),
soitaskFsPath: undefinedToNullMapString(soitaskTasknames.get(taskname)),
binaryFsPath: path.join(workspace, taskname),
binaryFsPath: path.join(workspace, taskname + executableFileEnding()),
solutionWorkspacePath: toRelativePath(cppTasknames.get(taskname)),
soitaskWorkspacePath: toRelativePath(soitaskTasknames.get(taskname)),
binaryWorkspacePath: taskname
binaryWorkspacePath: taskname + executableFileEnding()
});
}
return tasks;
......
import * as vscode from "vscode";
export function toSortedKeys<T>(map: Map<string, T>): string[] {
// Todo can I ignore the map value type in a better way
return Array.from(map.keys()).sort();
}
export function executableFileEnding() {
if (determinePlatform() === "windows-amd64") {
return ".exe";
} else {
return "";
}
}
export function determinePlatform() {
// also look at process.arch
switch (process.platform) {
case "darwin":
return "darwin-amd64";
case "win32":
return "windows-amd64";
case "linux":
return "linux-amd64";
default:
vscode.window.showErrorMessage(
"You seem to be running on an unsupported platform"
);
throw new Error("You seem to be running on an unsupported platform");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment