@@ -10,7 +10,23 @@ const fs = require('fs');
1010 * @returns {string } Branch of the corresponding lldb release
1111 */
1212function versionToBranch ( version ) {
13- return 'release_' + version . replace ( '.' , '' ) ;
13+ // `llvm-project` v1-3 branches are in the form `release/major.minor.x`:
14+ // release/1.0.x ... release/3.9.x
15+ // `llvm-project` v4-latest branches are in the form `release/major.x`:
16+ // release/4.x ... release/12.x
17+
18+ // split into array of semver components
19+ var chars = ( version . indexOf ( '.' ) === - 1
20+ ? version . split ( '' ) // split `39` into ['3', '9']
21+ : version . split ( '.' ) . filter ( x => x !== '.' ) // split `3.9` into ['3', '9']
22+ ) ;
23+
24+ // if version < 4, keep `major.minor` components
25+ // if version >= 4, only keep `major` component
26+ chars = chars . slice ( 0 , ( + chars [ 0 ] >= 4 ) ? 1 : 2 ) ;
27+
28+ // join components into the form `release/3.9.x`
29+ return 'release/' + chars . concat ( 'x' ) . join ( '.' ) ;
1430}
1531
1632/**
@@ -44,18 +60,30 @@ function cloneHeaders(lldbVersion, buildDir) {
4460
4561 if ( ! fs . existsSync ( lldbInstallDir ) ) {
4662 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/
4766 child_process . execFileSync (
4867 'git' , [ 'clone' ,
4968 '--depth' , '1' ,
69+ '--filter=blob:none' ,
70+ '--sparse' ,
5071 '--branch' , lldbHeadersBranch ,
51- 'https://github.com/llvm-mirror/lldb .git' ,
72+ 'https://github.com/llvm/llvm-project .git' ,
5273 lldbInstallDir
5374 ] ,
5475 { 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
5583 } else {
5684 console . log ( `\nSkip cloning lldb headers because ${ lldbInstallDir } exists` ) ;
5785 }
58- return path . join ( lldbInstallDir , 'include' ) ;
86+ return path . join ( lldbInstallDir , 'lldb' , ' include') ;
5987}
6088
6189/**
0 commit comments