Bug 1382697 - Teach nsinstall.py to handle symlinks; r?glandium draft
authorGregory Szorc <gps@mozilla.com>
Fri, 21 Jul 2017 22:11:20 -0700
changeset 613684 7d780ef4062536589cf48639d6923da628fe0566
parent 613683 bd64d5cb56abdfbb48e278c03f8fe85edb4c0b04
child 613685 9fb09527dc2c06f8b3b3755203401a7d9739bbc8
push id69832
push usergszorc@mozilla.com
push dateSat, 22 Jul 2017 06:27:51 +0000
reviewersglandium
bugs1382697
milestone56.0a1
Bug 1382697 - Teach nsinstall.py to handle symlinks; r?glandium The main difference between nsinstall.py and nsinstall.c is that nsinstall.py doesn't support symlinks. This prevents nsinstall.py from being used as a drop-in replacement for nsinstall.c on non-Windows platforms. Unlike nsinstall.c, nsinstall.py uses absolute paths. So change the help docs for -R to not specify that the symlink is relative. We use absolute symlinks in many other places. So it shouldn't be a big deal. MozReview-Commit-ID: IBifwA8RIuj
config/nsinstall.py
--- a/config/nsinstall.py
+++ b/config/nsinstall.py
@@ -2,25 +2,24 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # This is a partial python port of nsinstall.
 # It's intended to be used when there's no natively compile nsinstall
 # available, and doesn't intend to be fully equivalent.
 # Its major use is for l10n repackaging on systems that don't have
 # a full build environment set up.
-# The basic limitation is, it doesn't even try to link and ignores
-# all related options.
+
 from __future__ import print_function
 
 from optparse import OptionParser
 import errno
 import os
+import shutil
 import sys
-import shutil
 
 import mozfile
 
 
 def _nsinstall_internal(argv):
     usage = "usage: %prog [options] arg1 [arg2 ...] target-directory"
     p = OptionParser(usage=usage)
 
@@ -28,17 +27,17 @@ def _nsinstall_internal(argv):
                  help="Create a single directory only")
     p.add_option('-t', action="store_true",
                  help="Preserve time stamp")
     p.add_option('-m', action="store",
                  help="Set mode", metavar="mode")
     p.add_option('-d', action="store_true",
                  help="Create directories in target")
     p.add_option('-R', action="store_true",
-                 help="Use relative symbolic links (ignored)")
+                 help="Use symbolic links")
     p.add_option('-L', action="store", metavar="linkprefix",
                  help="Link prefix (ignored)")
     p.add_option('-X', action="append", metavar="file",
                  help="Ignore a file when installing a directory recursively.")
 
     options, args = p.parse_args(argv)
 
     if options.m:
@@ -118,20 +117,25 @@ def _nsinstall_internal(argv):
                     os.chmod(targetpath, options.m)
 
                 entries = [os.path.join(srcpath, e)
                            for e in os.listdir(srcpath)]
                 copy_all_entries(entries, targetpath)
             else:
                 mozfile.remove(targetpath)
 
-                if options.t:
-                    shutil.copy2(srcpath, targetpath)
+                # -R shouldn't be passed in unless configure detected
+                # symlink support.
+                if options.R:
+                    os.symlink(srcpath, targetpath)
                 else:
-                    shutil.copy(srcpath, targetpath)
+                    if options.t:
+                        shutil.copy2(srcpath, targetpath)
+                    else:
+                        shutil.copy(srcpath, targetpath)
 
     # the last argument is the target directory
     target = args.pop()
     # ensure target directory (importantly, we do not apply a mode to the directory
     # because we want to copy files into it and the mode might be read-only)
     rv = maybe_create_dir(target, None, True)
     if rv != 0:
         return rv