@ -13,8 +13,8 @@ import shutil
import sys
import sys
# set at init time
# set at init time
dst_dir = Non e
node_prefix = ' /usr/local ' # PREFIX variable from Makefil e
node_prefix = None # dst_dir without DESTDIR prefix
install_path = None # base target directory (DESTDIR + PREFIX from Makefile)
target_defaults = None
target_defaults = None
variables = None
variables = None
@ -47,7 +47,7 @@ def try_mkdir_r(path):
def try_rmdir_r ( path ) :
def try_rmdir_r ( path ) :
path = abspath ( path )
path = abspath ( path )
while path . startswith ( dst_dir ) :
while path . startswith ( install_path ) :
try :
try :
os . rmdir ( path )
os . rmdir ( path )
except OSError , e :
except OSError , e :
@ -58,9 +58,9 @@ def try_rmdir_r(path):
def mkpaths ( path , dst ) :
def mkpaths ( path , dst ) :
if dst . endswith ( ' / ' ) :
if dst . endswith ( ' / ' ) :
target_path = abspath ( dst_dir , dst , os . path . basename ( path ) )
target_path = abspath ( install_path , dst , os . path . basename ( path ) )
else :
else :
target_path = abspath ( dst_dir , dst )
target_path = abspath ( install_path , dst )
return path , target_path
return path , target_path
def try_copy ( path , dst ) :
def try_copy ( path , dst ) :
@ -90,7 +90,7 @@ def npm_files(action):
# don't install npm if the target path is a symlink, it probably means
# don't install npm if the target path is a symlink, it probably means
# that a dev version of npm is installed there
# that a dev version of npm is installed there
if os . path . islink ( abspath ( dst_dir , target_path ) ) : return
if os . path . islink ( abspath ( install_path , target_path ) ) : return
# npm has a *lot* of files and it'd be a pain to maintain a fixed list here
# npm has a *lot* of files and it'd be a pain to maintain a fixed list here
# so we walk its source directory instead...
# so we walk its source directory instead...
@ -100,7 +100,7 @@ def npm_files(action):
action ( paths , target_path + dirname [ 9 : ] + ' / ' )
action ( paths , target_path + dirname [ 9 : ] + ' / ' )
# create/remove symlink
# create/remove symlink
link_path = abspath ( dst_dir , ' bin/npm ' )
link_path = abspath ( install_path , ' bin/npm ' )
if action == uninstall :
if action == uninstall :
action ( [ link_path ] , ' bin/npm ' )
action ( [ link_path ] , ' bin/npm ' )
elif action == install :
elif action == install :
@ -113,7 +113,7 @@ def npm_files(action):
# precompiled bundle should be able to be extracted anywhere and "just work"
# precompiled bundle should be able to be extracted anywhere and "just work"
shebang = ' /bin/sh \n // 2>/dev/null; exec " `dirname " $0 " `/node " " $0 " " $@ " '
shebang = ' /bin/sh \n // 2>/dev/null; exec " `dirname " $0 " `/node " " $0 " " $@ " '
else :
else :
shebang = os . path . join ( node_prefix , ' bin/node ' )
shebang = os . path . join ( node_prefix or ' / ' , ' bin/node ' )
update_shebang ( link_path , shebang )
update_shebang ( link_path , shebang )
else :
else :
assert ( 0 ) # unhandled action type
assert ( 0 ) # unhandled action type
@ -134,7 +134,7 @@ def files(action):
if ' true ' == variables . get ( ' node_install_npm ' ) : npm_files ( action )
if ' true ' == variables . get ( ' node_install_npm ' ) : npm_files ( action )
def run ( args ) :
def run ( args ) :
global dst_dir , node_prefix , target_defaults , variables
global node_prefix , install_path , target_defaults , variables
# chdir to the project's top-level directory
# chdir to the project's top-level directory
os . chdir ( abspath ( os . path . dirname ( __file__ ) , ' .. ' ) )
os . chdir ( abspath ( os . path . dirname ( __file__ ) , ' .. ' ) )
@ -144,8 +144,15 @@ def run(args):
target_defaults = conf [ ' target_defaults ' ]
target_defaults = conf [ ' target_defaults ' ]
# argv[2] is a custom install prefix for packagers (think DESTDIR)
# argv[2] is a custom install prefix for packagers (think DESTDIR)
dst_dir = node_prefix = variables . get ( ' node_prefix ' ) or ' /usr/local '
# argv[3] is a custom install prefix (think PREFIX)
if len ( args ) > 2 : dst_dir = abspath ( args [ 2 ] + ' / ' + dst_dir )
# Difference is that dst_dir won't be included in shebang lines etc.
if len ( args ) > 2 :
dst_dir = args [ 2 ]
if len ( args ) > 3 :
node_prefix = args [ 3 ]
# install_path thus becomes the base target directory.
install_path = dst_dir + node_prefix + ' / '
cmd = args [ 1 ] if len ( args ) > 1 else ' install '
cmd = args [ 1 ] if len ( args ) > 1 else ' install '
if cmd == ' install ' : return files ( install )
if cmd == ' install ' : return files ( install )