(
compiler: string,
args: string[],
options?: ExecutionOptionsWithEnv,
)
| 443 | } |
| 444 | |
| 445 | public async execCompilerCached( |
| 446 | compiler: string, |
| 447 | args: string[], |
| 448 | options?: ExecutionOptionsWithEnv, |
| 449 | ): Promise<UnprocessedExecResult> { |
| 450 | if (this.mtime === null) { |
| 451 | throw new Error('Attempt to access cached compiler before initialise() called'); |
| 452 | } |
| 453 | |
| 454 | if (!options) { |
| 455 | options = this.getDefaultExecOptions(); |
| 456 | options.timeoutMs = 0; |
| 457 | options.ldPath = this.getSharedLibraryPathsAsLdLibraryPaths([]); |
| 458 | } |
| 459 | |
| 460 | // Take a (shallow) copy of the options before we add a random customCwd: The fact we have createAndUseTempDir |
| 461 | // set is enough to make us different from an otherwise identical run without createAndUseTempDir. However, the |
| 462 | // actual random path is unimportant for caching; and its presence prevents cache hits. |
| 463 | const optionsForCache = {...options}; |
| 464 | if (options.createAndUseTempDir) { |
| 465 | options.customCwd = await this.newTempDir(); |
| 466 | } |
| 467 | |
| 468 | const key = this.getCompilerCacheKey(compiler, args, optionsForCache); |
| 469 | const hash = BaseCache.hash(key); |
| 470 | |
| 471 | let result = await this.env.compilerCacheGet(key); |
| 472 | if (result) { |
| 473 | if (exec.hasNsjailPermissionsIssue(result)) { |
| 474 | logger.info(`Throwing out faulty cached result with nsjail permissions issue for ${compiler}`); |
| 475 | result = undefined; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | if (!result && this.env.willBeInCacheSoon(hash)) { |
| 480 | result = await this.env.enqueue(async () => { |
| 481 | return await this.env.compilerCacheGet(key); |
| 482 | }); |
| 483 | } |
| 484 | |
| 485 | if (!result) { |
| 486 | this.env.setCachingInProgress(hash); |
| 487 | result = await this.env.enqueue(async () => { |
| 488 | const res = await this.exec(compiler, args, options); |
| 489 | if (res.okToCache) { |
| 490 | try { |
| 491 | await this.env.compilerCachePut(key, res, undefined); |
| 492 | } catch (e) { |
| 493 | logger.info('Uncaught exception caching compilation results', e); |
| 494 | } |
| 495 | } |
| 496 | this.env.clearCachingInProgress(hash); |
| 497 | return res; |
| 498 | }); |
| 499 | } |
| 500 | |
| 501 | if (options.createAndUseTempDir) { |
| 502 | fs.rm(options.customCwd!, {recursive: true, force: true}).catch(() => {}); |
no test coverage detected