Skip to content

Commit

Permalink
Merge pull request #18 from glacambre/build_neovim_nightly_on_downloa…
Browse files Browse the repository at this point in the history
…d_failure

Build neovim nightly on download failure
  • Loading branch information
rhysd authored Oct 1, 2021
2 parents f832533 + 59032a9 commit 4803534
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/install_linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Installed } from './install';
import type { Config } from './config';
import { exec } from './shell';
import { buildVim } from './vim';
import { downloadNeovim, downloadStableNeovim } from './neovim';
import { buildNeovim, downloadNeovim, downloadStableNeovim } from './neovim';

async function isUbuntu18OrEarlier(): Promise<boolean> {
const version = await getUbuntuVersion();
Expand Down Expand Up @@ -35,7 +35,13 @@ export function install(config: Config): Promise<Installed> {
if (config.version === 'stable') {
return downloadStableNeovim('linux', config.token);
} else {
return downloadNeovim(config.version, 'linux');
try {
return downloadNeovim(config.version, 'linux');
} catch (e) {
const message = e instanceof Error ? e.message : e;
core.debug(`Neovim download failure: ${message}.`);
}
return buildNeovim(config.version, 'linux');
}
} else {
if (config.version === 'stable') {
Expand Down
44 changes: 44 additions & 0 deletions src/neovim.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { strict as assert } from 'assert';
import { homedir } from 'os';
import * as path from 'path';
import { promises as fs } from 'fs';
Expand Down Expand Up @@ -118,3 +119,46 @@ export async function downloadStableNeovim(os: Os, token: string | null = null):
throw err;
}
}

export async function buildNeovim(version: string, os: Os): Promise<Installed> {
assert.equal(version, 'nightly');
assert.equal(os, 'linux');

await exec('sudo', [
'apt-get',
'install',
'-y',
'ninja-build',
'gettext',
'libtool',
'libtool-bin',
'autoconf',
'automake',
'cmake',
'g++',
'pkg-config',
'unzip',
'curl',
]);

const installDir = path.join(homedir(), 'nvim');
core.debug(`Building and installing Neovim to ${installDir}.`);
const dir = path.join(await makeTmpdir(), 'neovim');

await exec('git', ['clone', '--depth=1', 'https://github.com/neovim/neovim', dir]);

const opts = { cwd: dir };
await exec(
'make',
['-j', `CMAKE_EXTRA_FLAGS=-DCMAKE_INSTALL_PREFIX=${installDir}`, 'CMAKE_BUILD_TYPE=RelWithDebug'],
opts,
);
core.debug(`Built Neovim in ${opts.cwd}.`);
await exec('make', ['install'], opts);
core.debug(`Installed Neovim to ${installDir}.`);

return {
executable: exeName(true, os),
binDir: path.join(installDir, 'bin'),
};
}

0 comments on commit 4803534

Please sign in to comment.