compilerBundle.ts 2.79 KB
Newer Older
1 2 3
import { Store } from "./store";

import * as path from "path";
4 5 6
// import * as fs from "fs-extra";
// import * as https from "https";
import { getWorkspaceOrShowError } from "./storeHelper";
7

8 9 10 11 12 13
export function getCompilerPath(store: Store): string {
	if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
		return path.join(store.soicodeExtensionDataPath, "compiler", "g++");
	} else {
		return getWorkspaceOrShowError(store).settings.compiler.manualCompilePath;
	}
14
}
15 16 17 18 19 20 21
export function getDebuggerPath(store: Store): string {
	if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
		return path.join(store.soicodeExtensionDataPath, "compiler", "gdb");
	} else {
		// return settings.compiler.manualCompilePath;  // todo
		return "/usr/bin/gdb";
	}
Timon Stampfli's avatar
Timon Stampfli committed
22
}
23 24 25 26 27 28 29 30 31 32
export function getDebuggerFlavor(store: Store): "gdb" | "lldb" | null {
	let debuggerPath = getDebuggerPath(store);
	if (debuggerPath === null) {
		return null;
	}
	let flavor = path.basename(debuggerPath);
	if (flavor === "gdb" || flavor === "lldb") {
		return flavor;
	}
	return null;
Timon Stampfli's avatar
Timon Stampfli committed
33
}
34 35 36 37 38 39 40 41 42 43 44 45
export function getClangFormatPath(store: Store): string {
	if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
		// todo needs on boolean flag since clangformat and compiler are independant
		return path.join(
			store.soicodeExtensionDataPath,
			"compiler",
			"clang-format"
		);
	} else {
		// return settings.compiler.manualCompilePath;  // todo
		return "";
	}
Timon Stampfli's avatar
Timon Stampfli committed
46 47 48
}

export async function getCppHeaderPath(store: Store): Promise<string | null> {
49 50 51 52 53 54 55
	if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
		// todo needs on boolean flag since headers and compiler are independant
		return path.join(store.soicodeExtensionDataPath, "compiler", "headers");
	} else {
		// return settings.compiler.manualCompilePath;  // todo
		return "";
	}
Timon Stampfli's avatar
Timon Stampfli committed
56 57 58
}

export async function getSoiHeaderPath(store: Store): Promise<string | null> {
59 60 61 62 63 64 65
	if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
		// todo needs on boolean flag since soi headers and compiler are independant
		return path.join(store.soicodeExtensionDataPath, "compiler", "soiHeaders");
	} else {
		// return settings.compiler.manualCompilePath;  // todo
		return "";
	}
Timon Stampfli's avatar
Timon Stampfli committed
66
}
67

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
// export async function downloadCompilerBundle(store: Store) {
// 	let platform = "";
// 	// also look at process.arch
// 	switch (process.platform) {
// 		case "darwin":
// 			platform = "darwin-amd64";
// 		case "win32":
// 			platform = "windows-amd64";
// 		case "linux":
// 			platform = "linux-amd64";
// 	}
// 	await fs.mkdir(store.soicodeExtensionPath);
// 	let file = fs.createWriteStream(
// 		path.join(store.soicodeExtensionPath, "helper")
// 	);
// 	let response = await https.get(
// 		"https://blob.dolansoft.org/soicode/helper-" + platform
// 	);
// 	response.pipe(file);
// }