Merge pull request #119 from plasma-umass/custom-prefix

Fix for custom prefix library search. Fixes #111 and #113
This commit is contained in:
Charlie Curtsinger 2019-09-26 16:03:01 -05:00 committed by GitHub
commit 5e0550c0e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 5 deletions

View File

@ -12,6 +12,7 @@ install:: all
@$(INSTALL) -D coz $(DESTDIR)$(bindir)/coz
@$(INSTALL) -D libcoz/libcoz.so $(DESTDIR)$(pkglibdir)/libcoz.so
@$(INSTALL) -D include/coz.h $(DESTDIR)$(incdir)/coz.h
@mkdir -p $(DESTDIR)$(man1dir)
@$(RST2MAN) docs/coz.rst $(DESTDIR)$(man1dir)/coz.1
bench::

34
coz
View File

@ -44,11 +44,35 @@ def _coz_run(args):
sys.exit(1)
env = copy.deepcopy(os.environ)
if os.path.exists('/usr/lib/coz-profiler/libcoz.so'):
coz_runtime = '/usr/lib/coz-profiler/libcoz.so'
else:
coz_prefix = dirname(realpath(sys.argv[0]))
coz_runtime = coz_prefix + path_sep + 'libcoz' + path_sep + 'libcoz.so'
# Find libcoz
coz_prefix = dirname(realpath(sys.argv[0]))
# Candidate runtime library locations
library_locations = [
# Check for library adjacent to this script
os.path.join(coz_prefix, '..', 'lib', 'libcoz.so'),
# Check for library under the coz-profiler subdirectory
os.path.join(coz_prefix, '..', 'lib', 'coz-profiler', 'libcoz.so'),
# Local library under development directory
os.path.join(coz_prefix, 'libcoz', 'libcoz.so') # Local library during development
]
# Find the first library location that exists
coz_runtime_found = False
coz_runtime = None
while len(library_locations) > 0 and not coz_runtime_found:
candidate = library_locations.pop(0)
if os.path.exists(candidate):
coz_runtime_found = True
coz_runtime = candidate
if not coz_runtime_found:
sys.stderr.write('error: unable to locate coz runtime library\n')
sys.exit(1)
if 'LD_PRELOAD' in env:
env['LD_PRELOAD'] += ':' + coz_runtime