leonardt / pycoreir

Python bindings for coreir
BSD 3-Clause "New" or "Revised" License
10 stars 6 forks source link

`pycoreir` clobbers `coreir` if installed to `/usr/local/bin/` #125

Closed hofstee closed 4 years ago

hofstee commented 4 years ago

If coreir is installed in /usr/local/bin/coreir, then pycoreir will take the fast-path through setup.py and not rebuild coreir. However, it will then put the python entry script into /usr/local/bin/coreir if you're not using a virtualenv. Then when you try to run coreir afterwards, it will fail because of RuntimeError: No library at /aha/pycoreir/coreir/libcoreir-c.so.

root@4b56f8c1efa2:/aha/pycoreir# which coreir
/usr/local/bin/coreir

root@4b56f8c1efa2:/aha/pycoreir# file `which coreir`
/usr/local/bin/coreir: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/l, for GNU/Linux 2.6.32, BuildID[sha1]=fa85a4ec808d4189a4d0b970c9c1e00a16b60b43, not stripped

root@4b56f8c1efa2:/aha/pycoreir# pip install -e .
Obtaining file:///aha/pycoreir
Requirement already satisfied: hwtypes>=1.0.* in /aha/hwtypes (from coreir==2.0.61) (1.3.5)
Requirement already satisfied: pysmt in /usr/local/lib/python3.7/dist-packages (from hwtypes>=1.0.*->coreir==2.0.61) (0.8.0)
Requirement already satisfied: z3-solver in /usr/local/lib/python3.7/dist-packages (from hwtypes>=1.0.*->coreir==2.0.61) (4.8.7.0)
Requirement already satisfied: gmpy2 in /usr/local/lib/python3.7/dist-packages (from hwtypes>=1.0.*->coreir==2.0.61) (2.0.8)
Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from pysmt->hwtypes>=1.0.*->coreir==2.0.61) (1.14.0)
Installing collected packages: coreir
  Attempting uninstall: coreir
    Found existing installation: coreir 2.0.61
    Can't uninstall 'coreir'. No files were found to uninstall.
  Running setup.py develop for coreir
Successfully installed coreir

root@4b56f8c1efa2:/aha/pycoreir# which coreir
/usr/local/bin/coreir

root@4b56f8c1efa2:/aha/pycoreir# file `which coreir`
/usr/local/bin/coreir: Python script, ASCII text executable

root@4b56f8c1efa2:/aha/pycoreir# coreir
Traceback (most recent call last):
  File "/usr/local/bin/coreir", line 7, in <module>
    exec(compile(f.read(), __file__, 'exec'))
  File "/aha/pycoreir/bin/coreir", line 10, in <module>
    import coreir
  File "/aha/pycoreir/coreir/__init__.py", line 5, in <module>
    from coreir.global_value import COREGlobalValue_p
  File "/aha/pycoreir/coreir/global_value.py", line 1, in <module>
    from .base import CoreIRType
  File "/aha/pycoreir/coreir/base.py", line 2, in <module>
    from .lib import libcoreir_c
  File "/aha/pycoreir/coreir/lib.py", line 74, in <module>
    libcoreir_c = load_coreir_lib("c")
  File "/aha/pycoreir/coreir/lib.py", line 71, in load_coreir_lib
    return load_shared_lib('libcoreir-{}'.format(suffix))
  File "/aha/pycoreir/coreir/lib.py", line 65, in load_shared_lib
    raise RuntimeError('No library at {}.'.format(lib_path))
RuntimeError: No library at /aha/pycoreir/coreir/libcoreir-c.so.
leonardt commented 4 years ago

Can you try out https://github.com/leonardt/pycoreir/pull/126 and see if it resolves the issue? I added logic to skip installing the script if the binary is present during setup.py time

hofstee commented 4 years ago

Seems to work!