mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 07:04:04 -05:00
fix tool invokations include paths for libraries (#8096)
This commit is contained in:
@@ -35,8 +35,8 @@ import {ToolInfo, ToolResult} from '../../types/tool.interfaces.js';
|
||||
import * as exec from '../exec.js';
|
||||
import {logger} from '../logger.js';
|
||||
import {OptionsHandlerLibrary} from '../options-handler.js';
|
||||
import {propsFor} from '../properties.js';
|
||||
import {parseOutput} from '../utils.js';
|
||||
|
||||
import {ITool, ToolEnv} from './base-tool.interface.js';
|
||||
|
||||
const toolCounter = new PromClient.Counter({
|
||||
@@ -51,6 +51,7 @@ export class BaseTool implements ITool {
|
||||
protected addOptionsToToolArgs = true;
|
||||
public readonly id: string;
|
||||
public readonly type: string;
|
||||
public readonly sandboxType: string;
|
||||
|
||||
constructor(toolInfo: ToolInfo, env: ToolEnv) {
|
||||
this.tool = toolInfo;
|
||||
@@ -58,6 +59,9 @@ export class BaseTool implements ITool {
|
||||
this.addOptionsToToolArgs = true;
|
||||
this.id = toolInfo.id;
|
||||
this.type = toolInfo.type || 'independent';
|
||||
|
||||
const execProps = propsFor('execution');
|
||||
this.sandboxType = execProps('sandboxType', 'none');
|
||||
}
|
||||
|
||||
getUniqueFilePrefix() {
|
||||
@@ -125,10 +129,23 @@ export class BaseTool implements ITool {
|
||||
return _.find(foundLib.versions, (o, versionId) => versionId === selectedLib.version);
|
||||
}
|
||||
|
||||
// mostly copy&paste from base-compiler.js
|
||||
protected replacePathsIfNeededForSandbox(args: string[], physicalPath: string): string[] {
|
||||
if (this.sandboxType !== 'nsjail' || !physicalPath) return args;
|
||||
|
||||
return args.map(arg => {
|
||||
if (arg && arg.length > 1) {
|
||||
return arg.replace(physicalPath, '/app');
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// mostly copy&paste from base-compiler.js, but has diverged a lot :(
|
||||
getIncludeArguments(
|
||||
libraries: SelectedLibraryVersion[],
|
||||
supportedLibraries: Record<string, OptionsHandlerLibrary>,
|
||||
dirPath?: string,
|
||||
): string[] {
|
||||
const includeFlag = '-I';
|
||||
|
||||
@@ -136,6 +153,11 @@ export class BaseTool implements ITool {
|
||||
const foundVersion = this.findLibVersion(selectedLib, supportedLibraries);
|
||||
if (!foundVersion) return [];
|
||||
|
||||
if (foundVersion.packagedheaders && dirPath) {
|
||||
const includePath = path.join(dirPath, selectedLib.id, 'include');
|
||||
return [includeFlag + includePath];
|
||||
}
|
||||
|
||||
return foundVersion.path.map(path => includeFlag + path);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import path from 'node:path';
|
||||
import {splitArguments} from '../../shared/common-utils.js';
|
||||
import {CompilationInfo} from '../../types/compilation/compilation.interfaces.js';
|
||||
import {ToolInfo} from '../../types/tool.interfaces.js';
|
||||
@@ -50,7 +51,9 @@ export class BrontoRefactorTool extends BaseTool {
|
||||
) {
|
||||
const sourcefile = inputFilepath;
|
||||
const options = compilationInfo.options;
|
||||
const includeflags = super.getIncludeArguments(compilationInfo.libraries, supportedLibraries || {});
|
||||
const pathDir = inputFilepath ? path.dirname(inputFilepath) : undefined;
|
||||
|
||||
const includeflags = super.getIncludeArguments(compilationInfo.libraries, supportedLibraries || {}, pathDir);
|
||||
const libOptions = super.getLibraryOptions(compilationInfo.libraries, supportedLibraries || {});
|
||||
|
||||
let compileFlags = ['compiler-explorer']
|
||||
|
||||
@@ -54,7 +54,7 @@ export class ClangTidyTool extends BaseTool {
|
||||
const sourcefile = inputFilepath;
|
||||
const options = compilationInfo.options;
|
||||
const dir = path.dirname(sourcefile);
|
||||
const includeflags = super.getIncludeArguments(compilationInfo.libraries, supportedLibraries || {});
|
||||
const includeflags = super.getIncludeArguments(compilationInfo.libraries, supportedLibraries || {}, dir);
|
||||
const libOptions = super.getLibraryOptions(compilationInfo.libraries, supportedLibraries || {});
|
||||
|
||||
let source = '';
|
||||
@@ -81,6 +81,8 @@ export class ClangTidyTool extends BaseTool {
|
||||
compileFlags = compileFlags.concat(manualCompileFlags);
|
||||
compileFlags = compileFlags.concat(this.tool.options);
|
||||
|
||||
compileFlags = this.replacePathsIfNeededForSandbox(compileFlags, dir);
|
||||
|
||||
// TODO: do we want compile_flags.txt rather than prefixing everything with -extra-arg=
|
||||
await fs.writeFile(path.join(dir, 'compile_flags.txt'), compileFlags.join('\n'));
|
||||
const result = await super.runTool(compilationInfo, sourcefile, args);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import path from 'node:path';
|
||||
import {splitArguments} from '../../shared/common-utils.js';
|
||||
import {CompilationInfo} from '../../types/compilation/compilation.interfaces.js';
|
||||
import {ToolInfo, ToolResult} from '../../types/tool.interfaces.js';
|
||||
@@ -111,8 +112,9 @@ export class CompilerDropinTool extends BaseTool {
|
||||
supportedLibraries?: Record<string, OptionsHandlerLibrary>,
|
||||
): Promise<ToolResult> {
|
||||
const sourcefile = inputFilepath;
|
||||
const pathDir = inputFilepath ? path.dirname(inputFilepath) : undefined;
|
||||
|
||||
const includeflags = this.getIncludeArguments(compilationInfo.libraries, supportedLibraries || {});
|
||||
const includeflags = this.getIncludeArguments(compilationInfo.libraries, supportedLibraries || {}, pathDir);
|
||||
const libOptions = this.getLibraryOptions(compilationInfo.libraries, supportedLibraries || {});
|
||||
|
||||
const compileFlags = this.getOrderedArguments(compilationInfo, includeflags, libOptions, args, sourcefile);
|
||||
|
||||
@@ -86,7 +86,11 @@ export class MicrosoftAnalysisTool extends BaseTool {
|
||||
const sourcefile = inputFilepath;
|
||||
const options = compilationInfo.options;
|
||||
const libOptions = super.getLibraryOptions(compilationInfo.libraries, unwrap(supportedLibraries));
|
||||
const includeflags = super.getIncludeArguments(compilationInfo.libraries, unwrap(supportedLibraries));
|
||||
const includeflags = super.getIncludeArguments(
|
||||
compilationInfo.libraries,
|
||||
unwrap(supportedLibraries),
|
||||
inputFilepath ? path.dirname(inputFilepath) : undefined,
|
||||
);
|
||||
|
||||
let compileFlags = splitArguments(compilationInfo.compiler.options);
|
||||
compileFlags = compileFlags.concat(includeflags, libOptions);
|
||||
|
||||
@@ -62,7 +62,7 @@ export class PvsStudioTool extends BaseTool {
|
||||
// Collecting the flags of compilation
|
||||
let compileFlags = splitArguments(compilationInfo.compiler.options);
|
||||
|
||||
const includeflags = super.getIncludeArguments(compilationInfo.libraries, compilationInfo.compiler);
|
||||
const includeflags = super.getIncludeArguments(compilationInfo.libraries, compilationInfo.compiler, sourceDir);
|
||||
compileFlags = compileFlags.concat(includeflags);
|
||||
|
||||
const libOptions = super.getLibraryOptions(compilationInfo.libraries, compilationInfo.compiler);
|
||||
|
||||
@@ -189,7 +189,11 @@ export class SonarTool extends BaseTool {
|
||||
// Collecting the flags of compilation
|
||||
|
||||
let compileFlags: string[] = splitArguments(compilationInfo.compiler.options);
|
||||
const includeflags = super.getIncludeArguments(compilationInfo.libraries, supportedLibraries || {});
|
||||
const includeflags = super.getIncludeArguments(
|
||||
compilationInfo.libraries,
|
||||
supportedLibraries || {},
|
||||
inputFilePath ? path.dirname(inputFilePath) : undefined,
|
||||
);
|
||||
compileFlags = compileFlags.concat(includeflags);
|
||||
const libOptions = super.getLibraryOptions(compilationInfo.libraries, supportedLibraries || {});
|
||||
compileFlags = compileFlags.concat(libOptions);
|
||||
|
||||
@@ -528,6 +528,7 @@ describe('Options handler', () => {
|
||||
id: 'faketool',
|
||||
type: 'independent',
|
||||
addOptionsToToolArgs: true,
|
||||
sandboxType: 'none',
|
||||
tool: {
|
||||
args: undefined,
|
||||
compilerLanguage: 'fake',
|
||||
@@ -549,6 +550,7 @@ describe('Options handler', () => {
|
||||
id: 'someothertool',
|
||||
type: 'independent',
|
||||
addOptionsToToolArgs: true,
|
||||
sandboxType: 'none',
|
||||
tool: {
|
||||
args: undefined,
|
||||
compilerLanguage: 'fake',
|
||||
|
||||
Reference in New Issue
Block a user