soiworkspace-0-8-0.ts 3.7 KB
Newer Older
1 2 3 4 5 6
import { determinePlatform } from "../util";
import { Store } from "../store";
import * as path from "path";

export function soiWorkspaceTemplate_0_8_0(store: Store): string {
	if (determinePlatform() === "windows-amd64") {
7 8 9 10 11 12 13 14 15 16 17 18
		return JSON.stringify({
			workspace: {
				templateVersion: "0.8.0"
			},
			settings: {
				compilerPath: path.join(
					store.soicodeExtensionDataPath,
					"bundle",
					"soiheaders",
					"bundle",
					"compiler",
					"bin",
19
					"g++.exe"
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
				),
				debuggerPath: "no/gdb",
				soiHeaderPath: path.join(
					store.soicodeExtensionDataPath,
					"bundle",
					"soiheaders",
					"bundle",
					"soiheader"
				),
				cppHeaderPath: path.join(
					store.soicodeExtensionDataPath,
					"bundle",
					"soiheaders",
					"bundle",
					"compiler",
					"include"
				),
				flags: "-Wall -Wextra -std=c++17 -g3 -ggdb3 -D_GLIBCXX_DEBUG",
				useBundledSoiHeaders: true
			}
		});
41 42
	}
	if (determinePlatform() === "darwin-amd64") {
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
		return JSON.stringify({
			workspace: {
				templateVersion: "0.8.0"
			},
			settings: {
				compilerPath: "/usr/bin/c++",
				debuggerPath: "/usr/bin/gdb",
				cppHeaderPath: "",
				soiHeaderPath: path.join(
					store.soicodeExtensionDataPath,
					"bundle",
					"soiheaders",
					"bundle",
					"soiheader"
				),
				flags: "-Wall -Wextra -std=c++17 -g3 -ggdb3 -D_GLIBCXX_DEBUG",
				useBundledSoiHeaders: true
			}
		});
62
	}
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
	return JSON.stringify({
		workspace: {
			templateVersion: "0.8.0"
		},
		settings: {
			compilerPath: "/usr/bin/c++",
			debuggerPath: "/usr/bin/gdb",
			cppHeaderPath: "",
			soiHeaderPath: path.join(
				store.soicodeExtensionDataPath,
				"bundle",
				"soiheaders",
				"bundle",
				"soiheader"
			),
			flags:
				"-Wall -Wextra -std=c++17 -g3 -ggdb3 -fsanitize=address,undefined -D_GLIBCXX_DEBUG",
			useBundledSoiHeaders: true
		}
	});
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
}

export interface WorkspaceSettings {
	workspace: {
		templateVersion: string;
	};
	settings: {
		compilerPath: string;
		debuggerPath: string;
		cppHeaderPath: string;
		soiHeaderPath: string;
		flags: string;
		useBundledSoiheaders: boolean;
	};
}

export function checkIsWorkspaceSettings(o: any): WorkspaceSettings {
	if (typeof o.workspace !== "object") {
		throw new Error("workspace needs to be an Object.");
	}
	if (typeof o.workspace.templateVersion !== "string") {
		throw new Error(
			"workspace: invalid or missing templateVersion (should be a string)."
		);
	}
	if (o.workspace.templateVersion !== "0.8.0") {
		throw new Error(
			"workspace.templateVersion: You use a unsupported versionnumber. Update the plugin"
		);
	}
	if (typeof o.settings !== "object") {
		throw new Error(
			"settings: invalid or missing settings entry (should be an object)"
		);
	}
	if (typeof o.settings.compilerPath !== "string") {
		throw new Error(
			"settings.compilerPath: invalid or missing settings.compilerPath setting (should be a string)"
		);
	}
	if (typeof o.settings.debuggerPath !== "string") {
		throw new Error(
			"settings.debuggerPath: invalid or missing settings.debuggerPath setting (should be a string)"
		);
	}
	if (typeof o.settings.cppHeaderPath !== "string") {
		throw new Error(
			"settings.cppHeaderPath: invalid or missing settings.cppHeaderPath setting (should be a string)"
		);
	}
	if (typeof o.settings.soiHeaderPath !== "string") {
		throw new Error(
			"settings.soiHeaderPath: invalid or missing settings.soiHeaderPath setting (should be a string)"
		);
	}
	if (typeof o.settings.flags !== "string") {
		throw new Error(
			"settings.flags: invalid or missing settings.flags setting (should be a string)"
		);
	}
	if (typeof o.settings.flags !== "string") {
		throw new Error(
			"settings.useBundledSoiheaders: invalid or missing settings.useBundledSoiheaders setting (should be a boolean)"
		);
	}
	return o;
}