()
| 8 | const baseDir = path.join(__dirname, '..', '..') |
| 9 | |
| 10 | async function main() { |
| 11 | const binaryTarget = await getBinaryTargetForCurrentPlatform() |
| 12 | const cacheDir = (await getCacheDir('master', '_local_', binaryTarget))! |
| 13 | const branch = enginesOverride?.['branch'] as string | undefined |
| 14 | let folder = enginesOverride?.['folder'] as string | undefined |
| 15 | |
| 16 | const engineCachePaths = { |
| 17 | [BinaryType.SchemaEngineBinary]: path.join(cacheDir, BinaryType.SchemaEngineBinary), |
| 18 | } |
| 19 | |
| 20 | if (branch !== undefined) { |
| 21 | const enginesRepoUri = 'git@github.com:prisma/prisma-engines.git' |
| 22 | const enginesRepoDir = path.join(baseDir, 'dist', 'prisma-engines') |
| 23 | |
| 24 | // we try to get the engines branch name, it fails if repo isn't cloned |
| 25 | const currentBranch = await execa('git', ['branch', '--show-current'], { |
| 26 | cwd: enginesRepoDir, |
| 27 | }).catch(() => ({ failed: true, stdout: '' })) |
| 28 | |
| 29 | // if the branch isn't the one we wanted or the repo hasn't been cloned |
| 30 | if (currentBranch.failed === true || currentBranch.stdout !== branch) { |
| 31 | await fs.promises.rm(enginesRepoDir, { recursive: true, force: true }) |
| 32 | |
| 33 | await execa('git', ['clone', enginesRepoUri, '--depth', '1', '--branch', branch], { |
| 34 | cwd: path.join(baseDir, 'dist'), |
| 35 | stdio: 'inherit', |
| 36 | }) |
| 37 | } |
| 38 | |
| 39 | // we make sure that we always have the latest changes from the branch |
| 40 | await execa('git', ['pull', 'origin', branch], { |
| 41 | cwd: enginesRepoDir, |
| 42 | stdio: 'inherit', |
| 43 | }) |
| 44 | |
| 45 | // we use cargo to build all the engines for the branch we checked out |
| 46 | await execa('cargo', ['build', '--release'], { |
| 47 | cwd: enginesRepoDir, |
| 48 | stdio: 'inherit', |
| 49 | }) |
| 50 | |
| 51 | folder = path.join(enginesRepoDir, 'target', 'release') |
| 52 | } |
| 53 | |
| 54 | // we copy the engines from the compiled output folder to the cache dir |
| 55 | if (folder !== undefined) { |
| 56 | folder = path.isAbsolute(folder) ? folder : path.join(baseDir, folder) |
| 57 | const binExt = binaryTarget.includes('windows') ? '.exe' : '' |
| 58 | |
| 59 | const engineOutputPaths = { |
| 60 | [BinaryType.SchemaEngineBinary]: path.join(folder, BinaryType.SchemaEngineBinary.concat(binExt)), |
| 61 | } |
| 62 | |
| 63 | for (const [binaryType, outputPath] of Object.entries(engineOutputPaths)) { |
| 64 | await fs.promises.copyFile(outputPath, engineCachePaths[binaryType]) |
| 65 | } |
| 66 | } |
| 67 | } |
no test coverage detected