@ -13,8 +13,8 @@ import shutil
import sys
# set at init time
dst_dir = Non e
node_prefix = None # dst_dir without DESTDIR prefix
node_prefix = ' /usr/local ' # PREFIX variable from Makefil e
install_path = None # base target directory (DESTDIR + PREFIX from Makefile)
target_defaults = None
variables = None
@ -47,7 +47,7 @@ def try_mkdir_r(path):
def try_rmdir_r ( path ) :
path = abspath ( path )
while path . startswith ( dst_dir ) :
while path . startswith ( install_path ) :
try :
os . rmdir ( path )
except OSError , e :
@ -58,9 +58,9 @@ def try_rmdir_r(path):
def mkpaths ( path , dst ) :
if dst . endswith ( ' / ' ) :
target_path = abspath ( dst_dir , dst , os . path . basename ( path ) )
target_path = abspath ( install_path , dst , os . path . basename ( path ) )
else :
target_path = abspath ( dst_dir , dst )
target_path = abspath ( install_path , dst )
return path , target_path
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
# 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
# so we walk its source directory instead...
@ -100,7 +100,7 @@ def npm_files(action):
action ( paths , target_path + dirname [ 9 : ] + ' / ' )
# create/remove symlink
link_path = abspath ( dst_dir , ' bin/npm ' )
link_path = abspath ( install_path , ' bin/npm ' )
if action == uninstall :
action ( [ link_path ] , ' bin/npm ' )
elif action == install :
@ -113,7 +113,7 @@ def npm_files(action):
# precompiled bundle should be able to be extracted anywhere and "just work"
shebang = ' /bin/sh \n // 2>/dev/null; exec " `dirname " $0 " `/node " " $0 " " $@ " '
else :
shebang = os . path . join ( node_prefix , ' bin/node ' )
shebang = os . path . join ( node_prefix or ' / ' , ' bin/node ' )
update_shebang ( link_path , shebang )
else :
assert ( 0 ) # unhandled action type
@ -134,7 +134,7 @@ def files(action):
if ' true ' == variables . get ( ' node_install_npm ' ) : npm_files ( action )
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
os . chdir ( abspath ( os . path . dirname ( __file__ ) , ' .. ' ) )
@ -144,8 +144,15 @@ def run(args):
target_defaults = conf [ ' target_defaults ' ]
# argv[2] is a custom install prefix for packagers (think DESTDIR)
dst_dir = node_prefix = variables . get ( ' node_prefix ' ) or ' /usr/local '
if len ( args ) > 2 : dst_dir = abspath ( args [ 2 ] + ' / ' + dst_dir )
# argv[3] is a custom install prefix (think PREFIX)
# 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 '
if cmd == ' install ' : return files ( install )