[Bug 257041] [NEW PORT]: devel/py-lief: Parse, modify and abstract ELF, PE and MachO formats.

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 13 Jul 2021 02:25:36 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=257041

Fukang Chen <loader@FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |loader@FreeBSD.org

--- Comment #6 from Fukang Chen <loader@FreeBSD.org> ---
It's unable to generate a correct ${_PYTHONPKGLIST} with USE_PYTHON=autoplist 

# make check-plist
====> Checking for pkg-plist issues (check-plist)
===> Parsing plist
===> Checking for items in STAGEDIR missing from pkg-plist
Error: Orphaned: %%PYTHON_SITELIBDIR%%/lief%%PYTHON_EXT_SUFFIX%%.so
===> Checking for items in pkg-plist which are not in STAGEDIR
Error: Missing: %%PYTHON_SITELIBDIR%%/.11.5/lief%%PYTHON_EXT_SUFFIX%%.so
===> Error: Plist issues found.
*** Error code 1

Stop.
make: stopped in /usr/ports/devel/py-lief

There's a weird path in ${_PYTHONPKGLIST}:
/usr/local/lib/python3.8/site-packages/.11.5/lief.cpython-38.so

The weird path was caused by _mutate_outputs() in
distutils/command/install_lib.py:
https://github.com/python/cpython/blob/v3.8.10/Lib/distutils/command/install_lib.py#L143-L156
   143      def _mutate_outputs(self, has_any, build_cmd, cmd_option,
output_dir):
   144          if not has_any:
   145              return []
   146
   147          build_cmd = self.get_finalized_command(build_cmd)
   148          build_files = build_cmd.get_outputs()
   149          build_dir = getattr(build_cmd, cmd_option)
   150
   151          prefix_len = len(build_dir) + len(os.sep)
   152          outputs = []
   153          for file in build_files:
   154              outputs.append(os.path.join(output_dir, file[prefix_len:]))
   155
   156          return outputs

on my 14.0-CURRENT aarch64:

build_dir => build/lib.freebsd-14.0-CURRENT-arm64-3.8
file => /usr/ports/devel/py-lief/work-py38/LIEF-0.11.5/lief.cpython-38.so
prefix_len => len(build_dir) + len(os.sep) => 40 + 1 => 41
file[prefix_len:] => .11.5/lief.cpython-38.so
output_dir =>
/usr/ports/devel/py-lief/work-py38/stage/usr/local/lib/python3.8/site-packages/

os.path.join(output_dir, file[prefix_len:]) =>
/usr/ports/devel/py-lief/work-py38/stage/usr/local/lib/python3.8/site-packages/.11.5/lief.cpython-38.so

It looks like we are supposed to get a file name
build/lib.freebsd-14.0-CURRENT-arm64-3.8/lief.cpython-38.so
instead of 
/usr/ports/devel/py-lief/work-py38/LIEF-0.11.5/lief.cpython-38.so

https://github.com/python/cpython/blob/v3.8.10/Lib/distutils/command/build_ext.py#L637-L664
   637      # -- Name generators
-----------------------------------------------
   638      # (extension names, filenames, whatever)
   639      def get_ext_fullpath(self, ext_name):
   640          """Returns the path of the filename for a given extension.
   641
   642          The file is located in `build_lib` or directly in the package
   643          (inplace option).
   644          """
   645          fullname = self.get_ext_fullname(ext_name)
   646          modpath = fullname.split('.')
   647          filename = self.get_ext_filename(modpath[-1])
   648
   649          if not self.inplace:
   650              # no further work needed
   651              # returning :
   652              #   build_dir/package/path/filename
   653              filename = os.path.join(*modpath[:-1]+[filename])
   654              return os.path.join(self.build_lib, filename)
   655
   656          # the inplace option requires to find the package directory
   657          # using the build_py command for that
   658          package = '.'.join(modpath[0:-1])
   659          build_py = self.get_finalized_command('build_py')
   660          package_dir =
os.path.abspath(build_py.get_package_dir(package))
   661
   662          # returning
   663          #   package_dir/filename
   664          return os.path.join(package_dir, filename)

inplace == 0
get_ext_fullpath(ext.name) => 
build/lib.freebsd-14.0-CURRENT-arm64-3.8/lief.cpython-38.so

inplace == 1
get_ext_fullpath(ext.name) => 
/usr/ports/devel/py-lief/work-py38/LIEF-0.11.5/lief.cpython-38.so

We could change the inlpace value to 0 in ${WRKSRC}/setup.cfg,
this should make USE_PYTHON=autoplist work:

post-patch:
        @${REINPLACE_CMD} -e 's|^inplace=1|inplace=0|' ${WRKSRC}/setup.cfg

-- 
You are receiving this mail because:
You are on the CC list for the bug.