bug 1483651 - Dereference symlinks inside vendored Python packages. r=gps
authorTed Mielczarek <ted@mielczarek.org>
Wed, 10 Oct 2018 19:59:52 +0000
changeset 496346 f5c1a7734493d3cf9e1ded5731bba0528b01155f
parent 496345 ec133330b1ec04135b786d0d3dc9a2fe4460d874
child 496347 abf2e04e30e4bb0b9cb534926e4df492b9fecf0b
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1483651
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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)