diff options
author | partouf <partouf@gmail.com> | 2023-09-30 18:50:52 +0200 |
---|---|---|
committer | partouf <partouf@gmail.com> | 2023-09-30 18:50:52 +0200 |
commit | 082ff8c2cfe1e42067f18223dec398f63bf14eb9 (patch) | |
tree | e2bc0053ce0011a12129d21506be93192d966df8 /lib/compilers/fortran.ts | |
parent | 0d7357a657a9a3fd5ffe9f1bf2c1eb4d8bb9baf7 (diff) | |
download | compiler-explorer-gh-8883.tar.gz compiler-explorer-gh-8883.zip |
working executiongh-8883
Diffstat (limited to 'lib/compilers/fortran.ts')
-rw-r--r-- | lib/compilers/fortran.ts | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/lib/compilers/fortran.ts b/lib/compilers/fortran.ts index d69fbacdb..bc1fbf69a 100644 --- a/lib/compilers/fortran.ts +++ b/lib/compilers/fortran.ts @@ -34,6 +34,7 @@ import * as utils from '../utils.js'; import {GccFortranParser} from './argument-parsers.js'; import {SelectedLibraryVersion} from '../../types/libraries/libraries.interfaces.js'; import _ from 'underscore'; +import * as fs from 'fs'; export class FortranCompiler extends BaseCompiler { static get key() { @@ -48,22 +49,44 @@ export class FortranCompiler extends BaseCompiler { return 'Change the Fortran standard version of the compiler.'; } - override getSharedLibraryPaths(libraries: CompileChildLibraries[]) { + getExactStaticLibNameAndPath(lib: string, libPaths: string[]): string { + const libFilename = 'lib' + lib + '.a'; + + // note: fortran doesn't use -llibname, + // you have to add the full filename to the commandline instead + // this thus requires the libraries to be downloaded before we can figure out the compiler arguments + for (const dir of libPaths) { + const testpath = path.join(dir, libFilename); + if (fs.existsSync(testpath)) { + return testpath; + } + } + + return ''; + } + + override getStaticLibraryLinks(libraries: CompileChildLibraries[], libPaths: string[] = []) { + return this.getSortedStaticLibraries(libraries) + .filter(lib => lib) + .map(lib => this.getExactStaticLibNameAndPath(lib, libPaths)); + } + + override getSharedLibraryPaths(libraries: CompileChildLibraries[], dirPath?: string): string[] { return libraries .map(selectedLib => { const foundVersion = this.findLibVersion(selectedLib); if (!foundVersion) return false; const paths = [...foundVersion.libpath]; - if (this.buildenvsetup && !this.buildenvsetup.extractAllToRoot) { - paths.push(`/app/${selectedLib.id}/lib`); + if (this.buildenvsetup && !this.buildenvsetup.extractAllToRoot && dirPath) { + paths.push(path.join(dirPath, selectedLib.id, 'lib')); } return paths; }) - .flat(); + .flat() as string[]; } - override getIncludeArguments(libraries: SelectedLibraryVersion[]): string[] { + override getIncludeArguments(libraries: SelectedLibraryVersion[], dirPath: string): string[] { const includeFlag = this.compiler.includeFlag || '-I'; return libraries.flatMap(selectedLib => { const foundVersion = this.findLibVersion(selectedLib); @@ -71,8 +94,10 @@ export class FortranCompiler extends BaseCompiler { const paths = foundVersion.path.map(path => includeFlag + path); if (foundVersion.packagedheaders) { - paths.push(`-I/app/${selectedLib.id}/mod`); - paths.push(includeFlag + `/app/${selectedLib.id}/include`); + const modPath = path.join(dirPath, selectedLib.id, 'mod'); + const includePath = path.join(dirPath, selectedLib.id, 'include'); + paths.push(`-I${modPath}`); + paths.push(includeFlag + includePath); } return paths; }); @@ -80,8 +105,9 @@ export class FortranCompiler extends BaseCompiler { override getSharedLibraryPathsAsArguments( libraries: CompileChildLibraries[], - libDownloadPath?: string, - toolchainPath?: string, + libDownloadPath: string, + toolchainPath: string, + dirPath: string, ) { const pathFlag = this.compiler.rpathFlag || this.defaultRpathFlag; const libPathFlag = this.compiler.libpathFlag || '-L'; @@ -100,8 +126,8 @@ export class FortranCompiler extends BaseCompiler { [pathFlag + libDownloadPath], this.compiler.libPath.map(path => pathFlag + path), toolchainLibraryPaths.map(path => pathFlag + path), - this.getSharedLibraryPaths(libraries).map(path => pathFlag + path), - this.getSharedLibraryPaths(libraries).map(path => libPathFlag + path), + this.getSharedLibraryPaths(libraries, dirPath).map(path => pathFlag + path), + this.getSharedLibraryPaths(libraries, dirPath).map(path => libPathFlag + path), ) as string[]; } |