Expose the naming convention of the jailing process (#8211)

To allow resolc to correctly find in-sandbox named artifacts

See #8164
This commit is contained in:
Matt Godbolt
2025-10-22 11:34:14 -05:00
committed by GitHub
parent 7b0a833a4c
commit b51b8250b0
2 changed files with 13 additions and 7 deletions

View File

@@ -32,6 +32,7 @@ import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.in
import type {Language} from '../../types/languages.interfaces.js';
import {assert} from '../assert.js';
import {BaseCompiler} from '../base-compiler.js';
import {maybeRemapJailedDir} from '../exec.js';
import {PolkaVMAsmParser} from '../parsers/asm-parser-polkavm.js';
import {ResolcRiscVAsmParser} from '../parsers/asm-parser-resolc-riscv.js';
import {changeExtension} from '../utils.js';
@@ -132,7 +133,7 @@ export class ResolcCompiler extends BaseCompiler {
}
private getOutputFilenameWithExtension(dirPath: string, extension: string): string {
const basenamePrefix = dirPath.split(path.sep).join('_');
const basenamePrefix = maybeRemapJailedDir(dirPath).split(path.sep).join('_');
const contractName = this.inputIs(InputKind.Solidity)
? this.getSolidityContractName(dirPath)
: this.getYulContractName(dirPath);

View File

@@ -243,6 +243,8 @@ export function getFirejailProfileFilePath(profileName: string): string {
return profilePath;
}
const jailedHomeDir = '/app';
export function getNsJailOptions(
configName: string,
command: string,
@@ -257,26 +259,25 @@ export function getNsJailOptions(
jailingOptions.push(`--time_limit=${Math.round((options.timeoutMs + ExtraWallClockLeewayMs) / 1000)}`);
}
const homeDir = '/app';
let filenameTransform: FilenameTransformFunc | undefined;
if (options.customCwd) {
let replacement = options.customCwd;
if (options.appHome) {
replacement = options.appHome;
const relativeCwd = path.join(homeDir, path.relative(options.appHome, options.customCwd));
jailingOptions.push('--cwd', relativeCwd, '--bindmount', `${options.appHome}:${homeDir}`);
const relativeCwd = path.join(jailedHomeDir, path.relative(options.appHome, options.customCwd));
jailingOptions.push('--cwd', relativeCwd, '--bindmount', `${options.appHome}:${jailedHomeDir}`);
} else {
jailingOptions.push('--cwd', homeDir, '--bindmount', `${options.customCwd}:${homeDir}`);
jailingOptions.push('--cwd', jailedHomeDir, '--bindmount', `${options.customCwd}:${jailedHomeDir}`);
}
filenameTransform = opt => opt.replaceAll(replacement, '/app');
filenameTransform = opt => opt.replaceAll(replacement, jailedHomeDir);
args = args.map(filenameTransform);
delete options.customCwd;
}
const transform = filenameTransform || (x => x);
const env: Record<string, string> = {...options.env, HOME: homeDir};
const env: Record<string, string> = {...options.env, HOME: jailedHomeDir};
if (options.ldPath) {
const ldPaths = options.ldPath.filter(Boolean).map(path => transform(path));
jailingOptions.push(`--env=LD_LIBRARY_PATH=${ldPaths.join(path.delimiter)}`);
@@ -678,3 +679,7 @@ export async function execute(
const unbuffered = await maybeUnbuffer(command, args);
return await dispatchEntry(unbuffered.command, unbuffered.args, options);
}
export function maybeRemapJailedDir(customCwd: string): string {
return execProps('executionType', 'none') == 'nsjail' ? jailedHomeDir : customCwd;
}