update interface

This commit is contained in:
Zengtudor 2024-08-11 15:58:01 +08:00
parent 28624c15c0
commit 6245631894
7 changed files with 42 additions and 13 deletions

View File

@ -1,4 +1,4 @@
export default abstract class Compiler{
abstract compilerPath:string;
abstract compilerVersion:string;
export default interface Compiler{
compilerPath:string;
compilerVersion:string;
}

View File

@ -1,14 +1,11 @@
import { execSync } from "child_process";
import getExecutablePathsFromEnv from "../Tools/GetExecutablePathsFromEnv";
import getFilesFromPath from "../Tools/GetPathsFromEnv";
import tryGetCompilerVersion from "../Tools/TryGetCompilerVersion";
import Compiler from "./Compiler";
export default class GppCompiler extends Compiler{
export default class GppCompiler implements Compiler{
compilerPath: string;
compilerVersion: string;
constructor(){
super()
const compilerPaths = getExecutablePathsFromEnv("g++")
if(compilerPaths.length==0)throw Error("cannot find g++ compiler")
this.compilerPath=`"${compilerPaths[0]}"`

21
src/Project/CppProject.ts Normal file
View File

@ -0,0 +1,21 @@
import GppCompiler from "../Compiler/GppCompiler";
import SourceFiles from "./interface/SourceFiles";
import Project from "./Project";
export default class CppProject implements Project , SourceFiles {
name: string;
compiler: GppCompiler;
sourceFiles: string[]=[];
constructor(name:string)
constructor(name:string,compiler:GppCompiler)
constructor(name:string,compiler?:GppCompiler){
if(compiler){
this.compiler=compiler
}else{
this.compiler=new GppCompiler()
}
this.name=name
}
}

View File

@ -1,6 +1,6 @@
import Compiler from "../Compiler/Compiler"
export default abstract class Project{
abstract name:string
abstract compiler:Compiler
export default interface Project{
name:string
compiler:Compiler
}

View File

@ -0,0 +1,3 @@
export default interface SourceFiles{
sourceFiles:string[]
}

View File

@ -6,7 +6,13 @@ const execPromise =util.promisify(exec);
const tryGetCompilerVersion =(path:string,command:string):string=>{
const exec_command = `${path} ${command}`
printDebug(exec_command)
return execSync(exec_command).toString().trim()
let ret:string = ""
try{
ret = execSync(exec_command).toString().trim()
}catch(e){
throw Error("cannot get compiler version!")
}
return ret
}
export default tryGetCompilerVersion

View File

@ -1,7 +1,9 @@
import { execSync } from "child_process";
import GppCompiler from "../../src/Compiler/GppCompiler";
(global as any).isDebug=true;
const a = new GppCompiler()
console.log(a.compilerVersion)
// const a = new GppCompiler()
// console.log(a.compilerVersion)
console.log(execSync("g++ -v").toLocaleString())
// console.log(execSync("g++ --version").toString().trim())