22
33const os = require ( 'os' ) ;
44const fs = require ( 'fs' ) ;
5+ const path = require ( 'path' ) ;
56const child_process = require ( 'child_process' ) ;
67
78const lldbReleases = {
@@ -52,7 +53,7 @@ if (osName === 'Darwin') {
5253 }
5354
5455 // console.log('lldb_version is ' + lldb_version)
55- var installedHeadersDir = getLinuxHeadersDir ( lldbVersion ) ;
56+ const installedHeadersDir = getLinuxHeadersDir ( lldbVersion ) ;
5657 // console.log('installed_headers_dir is ' + installed_headers_dir);
5758 if ( installedHeadersDir === undefined ) {
5859 // Initialising lldb_headers_branch will cause us to clone them.
@@ -61,6 +62,28 @@ if (osName === 'Darwin') {
6162 } else {
6263 lldbIncludeDir = installedHeadersDir ;
6364 }
65+ } else if ( osName === 'FreeBSD' ) {
66+
67+ lldbExe = getLldbExecutable ( ) ;
68+ lldbVersion = getFreeBSDVersion ( lldbExe ) ;
69+
70+ if ( lldbVersion === undefined ) {
71+ console . log ( 'Unable to locate lldb binary. llnode installation failed.' ) ;
72+ process . exit ( 1 ) ;
73+ }
74+
75+ const installedHeadersDir = getFreeBSDHeadersDir ( lldbVersion ) ;
76+ if ( installedHeadersDir === undefined ) {
77+ // As this is a BSD we know this system is in an improper state
78+ // So we can exit with an error
79+ console . log ( 'The system isn\'t set up correcly.' ) ;
80+ console . log ( 'Try `pkg install llvm39' ) ;
81+ console . log ( 'And `ln -s /usr/local/bin/lldb39 /usr/bin/lldb`' ) ;
82+ process . exit ( 1 ) ;
83+ } else {
84+ lldbIncludeDir = installedHeadersDir ;
85+ }
86+
6487}
6588
6689console . log ( `Installing llnode for ${ lldbExe } , lldb version ${ lldbVersion } ` ) ;
@@ -94,13 +117,18 @@ if (process.env.npm_config_global) {
94117 gypSubDir = 'npm/node_modules/node-gyp' ;
95118}
96119
120+ // npm can be in a different location than the current
121+ // location for global installs so we need find out where the npm is
122+ var npmLocation = child_process . execFileSync ( 'which' , [ 'npm' ] ) ;
123+ var npmModules = path . join ( npmLocation . toString ( ) , '../../lib/node_modules/npm' ) ;
124+
97125// Initialize GYP
98126// We can use the node-gyp that comes with npm.
99127// We can locate it with npm -g explore npm npm explore node-gyp pwd
100128// It might have been neater to make node-gyp one of our dependencies
101129// *but* they don't get installed until after the install step has run.
102130var gypDir = child_process . execFileSync ( 'npm' ,
103- [ '-g' , 'explore' , 'npm' , 'npm' , 'explore' , gypSubDir , 'pwd' ] ,
131+ [ '-g' , 'explore' , npmModules , 'npm' , 'explore' , gypSubDir , 'pwd' ] ,
104132 { cwd : buildDir } ) . toString ( ) . trim ( ) ;
105133child_process . execSync ( 'rm -rf tools' ) ;
106134fs . mkdirSync ( 'tools' ) ;
@@ -193,6 +221,30 @@ function getLinuxVersion(lldbExe) {
193221 return undefined ;
194222}
195223
224+ // Shim this for consistancy in OS naming
225+ function getFreeBSDVersion ( lldbExe ) {
226+ //Strip the dots for BSD
227+ return getLinuxVersion ( lldbExe ) . replace ( '.' , '' ) ;
228+ }
229+
230+ function getFreeBSDHeadersDir ( version ) {
231+
232+ console . log ( 'Checking for headers, version is ' + version ) ;
233+
234+ try {
235+ var includeDir = child_process . execFileSync ( 'llvm-config' + version ,
236+ [ '--prefix' ] ) . toString ( ) . trim ( ) ;
237+ if ( fs . existsSync ( includeDir + '/include/lldb' ) ) {
238+ return includeDir ;
239+ }
240+ } catch ( err ) {
241+ console . log ( includeDir + '/include/lldb doesn\'nt exist' ) ;
242+ console . log ( 'Please see README.md' ) ;
243+ console . log ( err ) ;
244+ process . exit ( 1 ) ;
245+ }
246+ return undefined ;
247+ }
196248function getLinuxHeadersDir ( version ) {
197249 // Get the directory which should contain the headers and
198250 // check if they are present.
0 commit comments