Skip to content

Commit

Permalink
display crossgen2 version in asm output (#4526)
Browse files Browse the repository at this point in the history
dotnet 6 and 7 will also show the version once there is a new deployment. for now they are showing 7.0.0-dev and <unknown version> respectively
  • Loading branch information
kasperk81 committed Jan 2, 2023
1 parent 3fc6171 commit f7c9406
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
32 changes: 19 additions & 13 deletions etc/config/csharp.defaults.properties
@@ -1,19 +1,25 @@
compilers=&csharpdef
compilers=&csharp
supportsBinary=true
needsMulti=false
compilerType=csharp
defaultCompiler=dotnet7csharpdef
defaultCompiler=dotnet700csharp

group.csharpdef.compilers=dotnet6csharpdef:dotnet7csharpdef
group.csharp.compilers=dotnettrunkcsharp:dotnet700csharp:dotnet6011csharp

compiler.dotnet6csharpdef.exe=/opt/compiler-explorer/dotnet-v6.0.11/.dotnet/dotnet
compiler.dotnet6csharpdef.name=.NET 6.0.403
compiler.dotnet6csharpdef.clrDir=/opt/compiler-explorer/dotnet-v6.0.11
compiler.dotnet6csharpdef.buildConfig=Release
compiler.dotnet6csharpdef.langVersion=latest
compiler.dotnet6011csharp.exe=/opt/compiler-explorer/dotnet-v6.0.11/.dotnet/dotnet
compiler.dotnet6011csharp.name=.NET 6.0.403
compiler.dotnet6011csharp.clrDir=/opt/compiler-explorer/dotnet-v6.0.11
compiler.dotnet6011csharp.buildConfig=Release
compiler.dotnet6011csharp.langVersion=latest

compiler.dotnet7csharpdef.exe=/opt/compiler-explorer/dotnet-v7.0.0/.dotnet/dotnet
compiler.dotnet7csharpdef.name=.NET 7.0.100
compiler.dotnet7csharpdef.clrDir=/opt/compiler-explorer/dotnet-v7.0.0
compiler.dotnet7csharpdef.buildConfig=Release
compiler.dotnet7csharpdef.langVersion=latest
compiler.dotnet700csharp.exe=/opt/compiler-explorer/dotnet-v7.0.0/.dotnet/dotnet
compiler.dotnet700csharp.name=.NET 7.0.100
compiler.dotnet700csharp.clrDir=/opt/compiler-explorer/dotnet-v7.0.0
compiler.dotnet700csharp.buildConfig=Release
compiler.dotnet700csharp.langVersion=latest

compiler.dotnettrunkcsharp.exe=/opt/compiler-explorer/dotnet-trunk/.dotnet/dotnet
compiler.dotnettrunkcsharp.name=.NET (main)
compiler.dotnettrunkcsharp.clrDir=/opt/compiler-explorer/dotnet-trunk
compiler.dotnettrunkcsharp.buildConfig=Release
compiler.dotnettrunkcsharp.langVersion=preview
48 changes: 35 additions & 13 deletions lib/compilers/dotnet.ts
Expand Up @@ -40,12 +40,15 @@ import {DotNetAsmParser} from '../parsers/asm-parser-dotnet';
import * as utils from '../utils';

class DotNetCompiler extends BaseCompiler {
private sdkBaseDir: string;
private sdkVersion: string;
private targetFramework: string;
private buildConfig: string;
private clrBuildDir: string;
private langVersion: string;
private readonly sdkBaseDir: string;
private readonly sdkVersion: string;
private readonly targetFramework: string;
private readonly buildConfig: string;
private readonly clrBuildDir: string;
private readonly langVersion: string;
private readonly crossgen2Path: string;

private crossgen2VersionString: string;

constructor(compilerInfo, env) {
super(compilerInfo, env);
Expand All @@ -59,7 +62,10 @@ class DotNetCompiler extends BaseCompiler {
this.buildConfig = this.compilerProps<string>(`compiler.${this.compiler.id}.buildConfig`);
this.clrBuildDir = this.compilerProps<string>(`compiler.${this.compiler.id}.clrDir`);
this.langVersion = this.compilerProps<string>(`compiler.${this.compiler.id}.langVersion`);

this.crossgen2Path = path.join(this.clrBuildDir, 'crossgen2', 'crossgen2');
this.asm = new DotNetAsmParser();
this.crossgen2VersionString = '';
}

get compilerOptions() {
Expand Down Expand Up @@ -128,6 +134,7 @@ class DotNetCompiler extends BaseCompiler {
// Some versions of .NET complain if they can't work out what the user's directory is. We force it to the output
// directory here.
execOptions.env.DOTNET_CLI_HOME = programDir;
execOptions.env.DOTNET_ROOT = path.join(this.clrBuildDir, '.dotnet');
// Place nuget packages in the output directory.
execOptions.env.NUGET_PACKAGES = path.join(programDir, '.nuget');
// Try to be less chatty
Expand Down Expand Up @@ -190,7 +197,6 @@ class DotNetCompiler extends BaseCompiler {
inputFilename: string,
execOptions: ExecutionOptions,
): Promise<CompilationResult> {
const crossgen2Path = path.join(this.clrBuildDir, 'crossgen2', 'crossgen2.dll');
const crossgen2Options: string[] = [];
const configurableOptions = this.configurableOptions;
const programDir = path.dirname(inputFilename);
Expand Down Expand Up @@ -221,9 +227,7 @@ class DotNetCompiler extends BaseCompiler {
}

const crossgen2Result = await this.runCrossgen2(
compiler,
execOptions,
crossgen2Path,
this.clrBuildDir,
programDllPath,
crossgen2Options,
Expand Down Expand Up @@ -280,9 +284,27 @@ class DotNetCompiler extends BaseCompiler {
}
}

async runCrossgen2(compiler, execOptions, crossgen2Path, bclPath, dllPath, options, outputPath) {
async ensureCrossgen2Version(execOptions) {
if (!this.crossgen2VersionString) {
this.crossgen2VersionString = '// crossgen2 ';

const versionFilePath = `${this.clrBuildDir}/version.txt`;
const versionResult = await this.exec(this.crossgen2Path, ['--version'], execOptions);
if (versionResult.code === 0) {
this.crossgen2VersionString += versionResult.stdout;
} else if (fs.existsSync(versionFilePath)) {
const versionString = await fs.readFile(versionFilePath);
this.crossgen2VersionString += versionString;
} else {
this.crossgen2VersionString += '<unknown version>';
}
}
}

async runCrossgen2(execOptions, bclPath, dllPath, options, outputPath) {
await this.ensureCrossgen2Version(execOptions);

const crossgen2Options = [
crossgen2Path,
'-r',
path.join(bclPath, '/'),
dllPath,
Expand All @@ -300,12 +322,12 @@ class DotNetCompiler extends BaseCompiler {
'--compilebubblegenerics',
].concat(options);

const compilerExecResult = await this.exec(compiler, crossgen2Options, execOptions);
const compilerExecResult = await this.exec(this.crossgen2Path, crossgen2Options, execOptions);
const result = this.transformToCompilationResult(compilerExecResult, dllPath);

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

return result;
Expand Down

0 comments on commit f7c9406

Please sign in to comment.