@@ -46,10 +46,18 @@ function getLibPath(libDir) {
4646 return path . join ( libDir , lib ) ;
4747}
4848
49+ /**
50+ * Check if the installed version of git supports sparse checkout. Notably,
51+ * Ubuntu 18.04 (which is not EOL at time of writing) has git 2.17, which does
52+ * not support sparse-checkout.
53+ */
54+ function doesGitSupportSparseCheckout ( ) {
55+ const returnCode = child_process . spawnSync ( 'git' , [ 'sparse-checkout' , '--help' ] ) . status ;
56+ return returnCode === 0 ;
57+ }
58+
4959/**
5060 * Check out source code of the lldb for headers
51- * TODO: The llvm project is probably moving to github soon at that point we
52- * should stop using the mirror.
5361 * @param {string } lldbVersion Version of lldb, either like 3.9 or 39
5462 * @param {string } buildDir Path to the llnode module directory
5563 * @returns {string } The include directory in the downloaded lldb source code
@@ -60,26 +68,39 @@ function cloneHeaders(lldbVersion, buildDir) {
6068
6169 if ( ! fs . existsSync ( lldbInstallDir ) ) {
6270 console . log ( `\nCloning lldb ${ lldbHeadersBranch } into ${ lldbInstallDir } ` ) ;
63- // use `git clone --filter` in git v2.19 to only download `lldb` dir of `llvm-project` monorepo
64- // see: https://stackoverflow.com/a/52269934/3117331
65- // see: https://github.blog/2020-01-17-bring-your-monorepo-down-to-size-with-sparse-checkout/
66- child_process . execFileSync (
67- 'git' , [ 'clone' ,
68- '--depth' , '1' ,
69- '--filter=blob:none' ,
70- '--sparse' ,
71- '--branch' , lldbHeadersBranch ,
72- 'https://github.com/llvm/llvm-project.git' ,
73- lldbInstallDir
74- ] ,
75- { stdio : 'inherit' } ) ; // show progress
76- child_process . execFileSync (
77- 'git' , [
78- '-C' , lldbInstallDir ,
79- 'sparse-checkout' ,
80- 'set' , 'lldb'
81- ] ,
82- { stdio : 'inherit' } ) ; // show progress
71+ if ( doesGitSupportSparseCheckout ( ) ) {
72+ // use `git clone --filter` in git v2.19 to only download `lldb` dir of `llvm-project` monorepo
73+ // see: https://stackoverflow.com/a/52269934/3117331
74+ // see: https://github.blog/2020-01-17-bring-your-monorepo-down-to-size-with-sparse-checkout/
75+ child_process . execFileSync (
76+ 'git' , [ 'clone' ,
77+ '--depth' , '1' ,
78+ '--filter=blob:none' ,
79+ '--sparse' ,
80+ '--branch' , lldbHeadersBranch ,
81+ 'https://github.com/llvm/llvm-project.git' ,
82+ lldbInstallDir
83+ ] ,
84+ { stdio : 'inherit' } ) ; // show progress
85+ child_process . execFileSync (
86+ 'git' , [
87+ '-C' , lldbInstallDir ,
88+ 'sparse-checkout' ,
89+ 'set' , 'lldb'
90+ ] ,
91+ { stdio : 'inherit' } ) ; // show progress
92+ } else {
93+ // There's no sparse checkout support, so we need to clone the entire
94+ // repo.
95+ child_process . execFileSync (
96+ 'git' , [ 'clone' ,
97+ '--depth' , '1' ,
98+ '--branch' , lldbHeadersBranch ,
99+ 'https://github.com/llvm/llvm-project.git' ,
100+ lldbInstallDir
101+ ] ,
102+ { stdio : 'inherit' } ) ; // show progress
103+ }
83104 } else {
84105 console . log ( `\nSkip cloning lldb headers because ${ lldbInstallDir } exists` ) ;
85106 }
0 commit comments