bug 1483651 - Dereference symlinks inside vendored Python packages. r=gps
authorTed Mielczarek <ted@mielczarek.org>
Wed, 10 Oct 2018 19:59:52 +0000
changeset 488964 f5c1a7734493d3cf9e1ded5731bba0528b01155f
parent 488963 ec133330b1ec04135b786d0d3dc9a2fe4460d874
child 488965 abf2e04e30e4bb0b9cb534926e4df492b9fecf0b
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersgps
bugs1483651
milestone64.0a1
bug 1483651 - Dereference symlinks inside vendored Python packages. r=gps At least one Python package that got vendored via `mach vendor python` contains a symlink, which hg.mozilla.org rejects. This change makes it so symlinks get replaced with the contents of the file they point to. Differential Revision: https://phabricator.services.mozilla.com/D4135
python/mozbuild/mozbuild/vendor_python.py
--- a/python/mozbuild/mozbuild/vendor_python.py
+++ b/python/mozbuild/mozbuild/vendor_python.py
@@ -115,8 +115,16 @@ class VendorPython(MozbuildObject):
                 os.mkdir(target)
                 mozfile.extract(os.path.join(finder.base, path), target)
             else:
                 # packages extract into package-version directory name and we strip the version
                 tld = mozfile.extract(os.path.join(finder.base, path), dest)[0]
                 target = os.path.join(dest, tld.rpartition('-')[0])
                 mozfile.remove(target)  # remove existing version of vendored package
                 mozfile.move(tld, target)
+            # If any files inside the vendored package were symlinks, turn them into normal files
+            # because hg.mozilla.org forbids symlinks in the repository.
+            link_finder = FileFinder(target)
+            for _, f in link_finder.find('**'):
+                if os.path.islink(f.path):
+                    link_target = os.path.realpath(f.path)
+                    os.unlink(f.path)
+                    shutil.copyfile(link_target, f.path)