Skip to content

Commit

Permalink
Always get version string for dotnet (#5648)
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed Oct 30, 2023
1 parent 9daa1a9 commit 2f0b802
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions lib/compilers/dotnet.ts
Expand Up @@ -54,8 +54,6 @@ class DotNetCompiler extends BaseCompiler {
private readonly crossgen2Path: string;
private readonly sdkMajorVersion: number;

private versionString: string;

constructor(compilerInfo: PreliminaryCompilerInfo, env) {
super(compilerInfo, env);

Expand All @@ -73,7 +71,6 @@ class DotNetCompiler extends BaseCompiler {
this.corerunPath = path.join(this.clrBuildDir, 'corerun');
this.crossgen2Path = path.join(this.clrBuildDir, 'crossgen2', 'crossgen2.dll');
this.asm = new DotNetAsmParser();
this.versionString = '';
this.disassemblyLoaderPath = path.join(this.clrBuildDir, 'DisassemblyLoader', 'DisassemblyLoader.dll');
}

Expand Down Expand Up @@ -476,15 +473,13 @@ class DotNetCompiler extends BaseCompiler {
}
}

async checkRuntimeVersion() {
if (!this.versionString) {
const versionFilePath = `${this.clrBuildDir}/version.txt`;
if (fs.existsSync(versionFilePath)) {
const versionString = await fs.readFile(versionFilePath);
this.versionString = versionString.toString();
} else {
this.versionString = '<unknown version>';
}
async getRuntimeVersion() {
const versionFilePath = `${this.clrBuildDir}/version.txt`;
if (fs.existsSync(versionFilePath)) {
const versionString = await fs.readFile(versionFilePath);
return versionString.toString();
} else {
return '<unknown version>';
}
}

Expand All @@ -496,8 +491,6 @@ class DotNetCompiler extends BaseCompiler {
options: string[],
outputPath: string,
) {
await this.checkRuntimeVersion();

const corerunOptions = ['--clr-path', coreRoot, '--env', envPath].concat([
...options,
this.disassemblyLoaderPath,
Expand All @@ -508,7 +501,9 @@ class DotNetCompiler extends BaseCompiler {

await fs.writeFile(
outputPath,
`// coreclr ${this.versionString}\n\n${result.stdout.map(o => o.text).reduce((a, n) => `${a}\n${n}`, '')}`,
`// coreclr ${await this.getRuntimeVersion()}\n\n${result.stdout
.map(o => o.text)
.reduce((a, n) => `${a}\n${n}`, '')}`,
);

return result;
Expand All @@ -523,8 +518,6 @@ class DotNetCompiler extends BaseCompiler {
toolSwitches: string[],
outputPath: string,
) {
await this.checkRuntimeVersion();

// prettier-ignore
const crossgen2Options = [
this.crossgen2Path,
Expand All @@ -539,7 +532,7 @@ class DotNetCompiler extends BaseCompiler {

await fs.writeFile(
outputPath,
`// crossgen2 ${this.versionString}\n\n${result.stdout
`// crossgen2 ${await this.getRuntimeVersion()}\n\n${result.stdout
.map(o => o.text)
.reduce((a, n) => `${a}\n${n}`, '')}`,
);
Expand Down

0 comments on commit 2f0b802

Please sign in to comment.