mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-05-16 19:31:45 -04:00
resolve triple from toolchain + set sysroot if available
This commit is contained in:
@@ -79,10 +79,15 @@ import type {IAsmParser} from './parsers/asm-parser.interfaces.js';
|
||||
import {LlvmPassDumpParser} from './parsers/llvm-pass-dump-parser.js';
|
||||
import type {PropertyGetter} from './properties.interfaces.js';
|
||||
import {
|
||||
clang_style_sysroot_flag,
|
||||
getSpecificTargetBasedOnToolchainPath,
|
||||
getSysrootByToolchainPath,
|
||||
getToolchainFlagFromOptions,
|
||||
getToolchainPath,
|
||||
hasSysrootArg,
|
||||
hasToolchainArg,
|
||||
removeToolchainArg,
|
||||
replaceSysrootArg,
|
||||
replaceToolchainArg,
|
||||
} from './toolchain-utils.js';
|
||||
import type {ITool} from './tooling/base-tool.interface.js';
|
||||
@@ -938,6 +943,70 @@ export class BaseCompiler implements ICompiler {
|
||||
return this.toolchainPath;
|
||||
}
|
||||
|
||||
getOverridenToolchainPath(overrides: ConfiguredOverrides): string | false {
|
||||
for (const override of overrides) {
|
||||
if (override.value) {
|
||||
const possible = this.compiler.possibleOverrides?.find(ov => ov.name === override.name);
|
||||
if (possible && possible.name === CompilerOverrideType.toolchain) {
|
||||
return override.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
changeOptionsBasedOnOverrides(options: string[], overrides: ConfiguredOverrides): string[] {
|
||||
let sysrootPath: string | undefined;
|
||||
const overriddenToolchainPath = this.getOverridenToolchainPath(overrides);
|
||||
if (overriddenToolchainPath) {
|
||||
sysrootPath = getSysrootByToolchainPath(overriddenToolchainPath);
|
||||
}
|
||||
|
||||
for (const override of overrides) {
|
||||
if (override.value) {
|
||||
const possible = this.compiler.possibleOverrides?.find(ov => ov.name === override.name);
|
||||
if (possible) {
|
||||
if (possible.name === CompilerOverrideType.toolchain) {
|
||||
if (hasToolchainArg(options)) {
|
||||
options = replaceToolchainArg(options, override.value);
|
||||
} else {
|
||||
for (const flag of possible.flags) {
|
||||
options.push(flag.replace('<value>', override.value));
|
||||
}
|
||||
}
|
||||
|
||||
if (sysrootPath) {
|
||||
if (hasSysrootArg(options)) {
|
||||
options = replaceSysrootArg(options, sysrootPath);
|
||||
} else {
|
||||
options.push(clang_style_sysroot_flag + sysrootPath);
|
||||
}
|
||||
}
|
||||
} else if (possible.name === CompilerOverrideType.arch) {
|
||||
let betterTarget = override.value;
|
||||
if (overriddenToolchainPath) {
|
||||
betterTarget = getSpecificTargetBasedOnToolchainPath(
|
||||
override.value,
|
||||
overriddenToolchainPath,
|
||||
);
|
||||
}
|
||||
|
||||
for (const flag of possible.flags) {
|
||||
options.push(flag.replace('<value>', betterTarget));
|
||||
}
|
||||
} else {
|
||||
for (const flag of possible.flags) {
|
||||
options.push(flag.replace('<value>', override.value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
prepareArguments(
|
||||
userOptions: string[],
|
||||
filters: ParseFiltersAndOutputOptions,
|
||||
@@ -976,21 +1045,7 @@ export class BaseCompiler implements ICompiler {
|
||||
|
||||
userOptions = this.filterUserOptions(userOptions) || [];
|
||||
options = this.fixIncompatibleOptions(options, userOptions);
|
||||
|
||||
for (const override of overrides) {
|
||||
if (override.value) {
|
||||
const possible = this.compiler.possibleOverrides?.find(ov => ov.name === override.name);
|
||||
if (possible) {
|
||||
if (possible.name === CompilerOverrideType.toolchain) {
|
||||
options = replaceToolchainArg(options, override.value);
|
||||
} else {
|
||||
for (const flag of possible.flags) {
|
||||
options.push(flag.replace('<value>', override.value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
options = this.changeOptionsBasedOnOverrides(options, overrides);
|
||||
|
||||
return this.orderArguments(
|
||||
options,
|
||||
|
||||
@@ -29,8 +29,9 @@ import {splitArguments} from './utils.js';
|
||||
import {PreliminaryCompilerInfo} from '../types/compiler.interfaces.js';
|
||||
import {CompilerOverrideOptions} from '../types/compilation/compiler-overrides.interfaces.js';
|
||||
|
||||
const clang_style_toolchain_flag = '--gcc-toolchain=';
|
||||
const icc_style_toolchain_flag = '--gxx-name=';
|
||||
export const clang_style_toolchain_flag = '--gcc-toolchain=';
|
||||
export const icc_style_toolchain_flag = '--gxx-name=';
|
||||
export const clang_style_sysroot_flag = '--sysroot=';
|
||||
|
||||
export function getToolchainPathWithOptionsArr(compilerExe: string | null, options: string[]): string | false {
|
||||
const existingChain = options.find(elem => elem.includes(clang_style_toolchain_flag));
|
||||
@@ -57,6 +58,10 @@ export function removeToolchainArg(compilerOptions: string[]): string[] {
|
||||
);
|
||||
}
|
||||
|
||||
export function removeSysrootArg(compilerOptions: string[]): string[] {
|
||||
return compilerOptions.filter(elem => !elem.includes(clang_style_sysroot_flag));
|
||||
}
|
||||
|
||||
export function replaceToolchainArg(compilerOptions: string[], newPath: string): string[] {
|
||||
return compilerOptions.map(elem => {
|
||||
if (elem.includes(clang_style_toolchain_flag)) {
|
||||
@@ -69,11 +74,14 @@ export function replaceToolchainArg(compilerOptions: string[], newPath: string):
|
||||
});
|
||||
}
|
||||
|
||||
export function hasToolchainArg(options: string[]): boolean {
|
||||
const existingChain = options.find(
|
||||
elem => elem.includes(clang_style_toolchain_flag) || elem.includes(icc_style_toolchain_flag),
|
||||
);
|
||||
return !!existingChain;
|
||||
export function replaceSysrootArg(compilerOptions: string[], newPath: string): string[] {
|
||||
return compilerOptions.map(elem => {
|
||||
if (elem.includes(clang_style_sysroot_flag)) {
|
||||
return clang_style_sysroot_flag + path.normalize(newPath);
|
||||
}
|
||||
|
||||
return elem;
|
||||
});
|
||||
}
|
||||
|
||||
export function getToolchainFlagFromOptions(options: string[]): string | false {
|
||||
@@ -85,6 +93,22 @@ export function getToolchainFlagFromOptions(options: string[]): string | false {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function hasToolchainArg(options: string[]): boolean {
|
||||
return !!getToolchainFlagFromOptions(options);
|
||||
}
|
||||
|
||||
export function getSysrootFlagFromOptions(options: string[]): string | false {
|
||||
for (const elem of options) {
|
||||
if (elem.includes(clang_style_sysroot_flag)) return clang_style_sysroot_flag;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function hasSysrootArg(options: string[]): boolean {
|
||||
return !!getSysrootFlagFromOptions(options);
|
||||
}
|
||||
|
||||
export async function getPossibleGccToolchainsFromCompilerInfo(
|
||||
compilers: PreliminaryCompilerInfo[],
|
||||
): Promise<CompilerOverrideOptions> {
|
||||
@@ -114,3 +138,20 @@ export async function getPossibleGccToolchainsFromCompilerInfo(
|
||||
}
|
||||
return overrideOptions;
|
||||
}
|
||||
|
||||
export function getSpecificTargetBasedOnToolchainPath(target: string, toolchainPath: string) {
|
||||
const lastPathBit = path.basename(toolchainPath);
|
||||
if (lastPathBit.startsWith(target)) {
|
||||
return lastPathBit;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
export function getSysrootByToolchainPath(toolchainPath: string): string | undefined {
|
||||
const lastPathBit = path.basename(toolchainPath);
|
||||
const possibleSysrootPath = path.join(toolchainPath, lastPathBit, 'sysroot');
|
||||
if (fs.existsSync(possibleSysrootPath)) {
|
||||
return possibleSysrootPath;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user