bug 1483651 - Dereference symlinks inside vendored Python packages. r=gps
☠☠ backed out by 641b4a378923 ☠ ☠
authorTed Mielczarek <ted@mielczarek.org>
Thu, 23 Aug 2018 07:01:50 -0400
changeset 488793 7f8cad00dc2e9a2a7b2021d676922b433f2255c7
parent 488792 1ecd5ddcdd796533dc7d4f057280ae04da660a5a
child 488794 eb440bc9fed13e4ad4a1fe2ab1a1ed445b269300
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
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
--- a/python/mozbuild/mozbuild/vendor_python.py
+++ b/python/mozbuild/mozbuild/vendor_python.py
@@ -1,15 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # 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/.
 from __future__ import absolute_import, print_function, unicode_literals
 import os
+import shutil
 import subprocess
 import mozfile
 import mozpack.path as mozpath
 from mozbuild.base import MozbuildObject
 from mozfile import NamedTemporaryFile, TemporaryDirectory
 from mozpack.files import FileFinder
@@ -91,8 +92,16 @@ class VendorPython(MozbuildObject):
                 mozfile.extract(os.path.join(finder.base, path), target)
                 # 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)