Skip to content

Commit 9d45c19

Browse files
libarchive-sys-provided: let user override paths
let the user override assumed paths via environment. lib_dir is probed first from LD_LIBRARY_PATH. Path to libarchive can be specified via LIBARCHIVE environment variable. If not found it falls back to lib_dir/libarchive.so. With this patch it possible to run scancode is buildsystems like YOCTO, which heaviily rely on overriding paths via environment to pick the correct implementation from the build workspace Signed-off-by: Konrad Weihmann <kweihmann@outlook.com>
1 parent 9ee0cd0 commit 9d45c19

File tree

1 file changed

+27
-23
lines changed
  • builtins/extractcode_libarchive_system_provided/src/extractcode_libarchive

1 file changed

+27
-23
lines changed

builtins/extractcode_libarchive_system_provided/src/extractcode_libarchive/__init__.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
# See https://aboutcode.org for more information about nexB OSS projects.
88
#
99

10-
from os import path
1110
import platform
11+
from os import environ
12+
from os import path
1213

1314
from plugincode.location_provider import LocationProviderPlugin
1415

@@ -20,30 +21,33 @@ def get_locations(self):
2021
locations of the libarchive shared library as installed on various Linux
2122
distros or on FreeBSD.
2223
"""
23-
system_arch = platform.machine()
24-
mainstream_system = platform.system().lower()
25-
if mainstream_system == 'linux':
26-
distribution = platform.linux_distribution()[0].lower()
27-
debian_based_distro = ['ubuntu', 'mint', 'debian']
28-
rpm_based_distro = ['fedora', 'redhat']
29-
30-
if distribution in debian_based_distro:
31-
lib_dir = '/usr/lib/'+system_arch+'-linux-gnu'
32-
33-
elif distribution in rpm_based_distro:
34-
lib_dir = '/usr/lib64'
35-
36-
else:
37-
raise Exception('Unsupported system: {}'.format(distribution))
38-
39-
elif mainstream_system == 'freebsd':
40-
if path.isdir('/usr/local/'):
41-
lib_dir = '/usr/local/lib'
42-
else:
43-
lib_dir = '/usr/lib'
24+
lib_dir = environ.get('LD_LIBRARY_PATH')
25+
if not lib_dir:
26+
system_arch = platform.machine()
27+
mainstream_system = platform.system().lower()
28+
if mainstream_system == 'linux':
29+
distribution = platform.linux_distribution()[0].lower()
30+
debian_based_distro = ['ubuntu', 'mint', 'debian']
31+
rpm_based_distro = ['fedora', 'redhat']
32+
33+
if distribution in debian_based_distro:
34+
lib_dir = '/usr/lib/'+system_arch+'-linux-gnu'
35+
36+
elif distribution in rpm_based_distro:
37+
lib_dir = '/usr/lib64'
38+
39+
else:
40+
raise Exception('Unsupported system: {}'.format(distribution))
41+
42+
elif mainstream_system == 'freebsd':
43+
if path.isdir('/usr/local/'):
44+
lib_dir = '/usr/local/lib'
45+
else:
46+
lib_dir = '/usr/lib'
47+
lib_archive = environ.get('LIBARCHIVE', path.join(lib_dir, 'libarchive.so'))
4448

4549
locations = {
4650
'extractcode.libarchive.libdir': lib_dir,
47-
'extractcode.libarchive.dll': path.join(lib_dir, 'libarchive.so'),
51+
'extractcode.libarchive.dll': lib_archive,
4852
}
4953
return locations

0 commit comments

Comments
 (0)