Skip to content

Commit

Permalink
scripts: installation without sparse-checkout
Browse files Browse the repository at this point in the history
Old versions of Ubuntu (and likely other LTS distros) have `git`
versions which do not support `git-sparse-checkout`.
`git-sparse-checkout` is used as of #389.

Dynamically check if `git sparse-checkout` is supported, and if not then
fallback to cloning the whole repo. Cloning the whole repo is _slow_,
but at least it works.

I tested this patch on Ubuntu 18.04 without any lldb headers installed,
and it worked successfully.
  • Loading branch information
kvakil authored and No9 committed Nov 6, 2022
1 parent 2769d40 commit de1f01d
Showing 1 changed file with 43 additions and 22 deletions.
65 changes: 43 additions & 22 deletions scripts/lldb.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ function getLibPath(libDir) {
return path.join(libDir, lib);
}

/**
* Check if the installed version of git supports sparse checkout. Notably,
* Ubuntu 18.04 (which is not EOL at time of writing) has git 2.17, which does
* not support sparse-checkout.
*/
function doesGitSupportSparseCheckout() {
const returnCode = child_process.spawnSync('git', ['sparse-checkout', '--help']).status;
return returnCode === 0;
}

/**
* Check out source code of the lldb for headers
* TODO: The llvm project is probably moving to github soon at that point we
* should stop using the mirror.
* @param {string} lldbVersion Version of lldb, either like 3.9 or 39
* @param {string} buildDir Path to the llnode module directory
* @returns {string} The include directory in the downloaded lldb source code
Expand All @@ -60,26 +68,39 @@ function cloneHeaders(lldbVersion, buildDir) {

if (!fs.existsSync(lldbInstallDir)) {
console.log(`\nCloning lldb ${lldbHeadersBranch} into ${lldbInstallDir}`);
// use `git clone --filter` in git v2.19 to only download `lldb` dir of `llvm-project` monorepo
// see: https://stackoverflow.com/a/52269934/3117331
// see: https://github.blog/2020-01-17-bring-your-monorepo-down-to-size-with-sparse-checkout/
child_process.execFileSync(
'git', ['clone',
'--depth', '1',
'--filter=blob:none',
'--sparse',
'--branch', lldbHeadersBranch,
'https://github.com/llvm/llvm-project.git',
lldbInstallDir
],
{ stdio: 'inherit' }); // show progress
child_process.execFileSync(
'git', [
'-C', lldbInstallDir,
'sparse-checkout',
'set', 'lldb'
],
{ stdio: 'inherit' }); // show progress
if (doesGitSupportSparseCheckout()) {
// use `git clone --filter` in git v2.19 to only download `lldb` dir of `llvm-project` monorepo
// see: https://stackoverflow.com/a/52269934/3117331
// see: https://github.blog/2020-01-17-bring-your-monorepo-down-to-size-with-sparse-checkout/
child_process.execFileSync(
'git', ['clone',
'--depth', '1',
'--filter=blob:none',
'--sparse',
'--branch', lldbHeadersBranch,
'https://github.com/llvm/llvm-project.git',
lldbInstallDir
],
{ stdio: 'inherit' }); // show progress
child_process.execFileSync(
'git', [
'-C', lldbInstallDir,
'sparse-checkout',
'set', 'lldb'
],
{ stdio: 'inherit' }); // show progress
} else {
// There's no sparse checkout support, so we need to clone the entire
// repo.
child_process.execFileSync(
'git', ['clone',
'--depth', '1',
'--branch', lldbHeadersBranch,
'https://github.com/llvm/llvm-project.git',
lldbInstallDir
],
{ stdio: 'inherit' }); // show progress
}
} else {
console.log(`\nSkip cloning lldb headers because ${lldbInstallDir} exists`);
}
Expand Down

0 comments on commit de1f01d

Please sign in to comment.