mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 07:04:04 -05:00
gocache limit stat on construct and also support cache for trunk
This commit is contained in:
@@ -57,7 +57,6 @@ type GoEnv = {
|
||||
|
||||
export class GolangCompiler extends BaseCompiler {
|
||||
private readonly GOENV: GoEnv;
|
||||
private readonly sourceCachePath?: string;
|
||||
|
||||
static get key() {
|
||||
return 'golang';
|
||||
@@ -87,7 +86,6 @@ export class GolangCompiler extends BaseCompiler {
|
||||
this.GOENV = {};
|
||||
if (goroot) {
|
||||
this.GOENV.GOROOT = goroot;
|
||||
this.sourceCachePath = path.join(goroot, '..', 'cache');
|
||||
}
|
||||
if (goarch) {
|
||||
this.GOENV.GOARCH = goarch.toString();
|
||||
@@ -97,6 +95,18 @@ export class GolangCompiler extends BaseCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
async getSourceCachePath(): Promise<string | undefined> {
|
||||
if (!this.GOENV.GOROOT) return undefined;
|
||||
|
||||
let sourceCachePath = path.join(this.GOENV.GOROOT, '..', 'cache');
|
||||
if (await utils.dirExists(sourceCachePath)) return sourceCachePath;
|
||||
|
||||
sourceCachePath = path.join(this.GOENV.GOROOT, 'cache');
|
||||
if (await utils.dirExists(sourceCachePath)) return sourceCachePath;
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
override async runCompiler(
|
||||
compiler: string,
|
||||
options: string[],
|
||||
@@ -108,25 +118,20 @@ export class GolangCompiler extends BaseCompiler {
|
||||
execOptions = this.getDefaultExecOptions();
|
||||
}
|
||||
|
||||
if (this.sourceCachePath) {
|
||||
const inputDir = path.dirname(inputFilename);
|
||||
const tempCachePath = path.join(inputDir, 'cache');
|
||||
const inputDir = path.dirname(inputFilename);
|
||||
const tempCachePath = path.join(inputDir, 'cache');
|
||||
|
||||
execOptions.env = {
|
||||
...execOptions.env,
|
||||
GOCACHE: tempCachePath,
|
||||
};
|
||||
execOptions.env = {
|
||||
...execOptions.env,
|
||||
GOCACHE: tempCachePath,
|
||||
};
|
||||
|
||||
const sourceCachePath = await this.getSourceCachePath();
|
||||
if (sourceCachePath) {
|
||||
try {
|
||||
await fs.mkdir(tempCachePath, {recursive: true});
|
||||
|
||||
try {
|
||||
// todo: add actual check instead of relying on exceptions
|
||||
await fs.access(this.sourceCachePath);
|
||||
await fs.cp(this.sourceCachePath, tempCachePath, {recursive: true, force: false});
|
||||
} catch {
|
||||
// Source cache doesn't exist, use empty cache
|
||||
}
|
||||
await fs.cp(sourceCachePath, tempCachePath, {recursive: true, force: false});
|
||||
} catch {
|
||||
// Cache setup failed, continue without cache
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user