Skip to content

Commit 627608d

Browse files
libarchive-sys-provided: let user override paths
let the user override assumed paths via environment. Path to libarchive can be specified via EXTRACTCODE_LIBARCHIVE_PATH environment variable. If not found it falls back to previously calculation from distro data. 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 54790d1 commit 627608d

2 files changed

Lines changed: 34 additions & 24 deletions

File tree

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
A ScanCode Toolkit plugin to use pre-installed system binary libraries and utilities.
1+
A ScanCode Toolkit plugin to use pre-installed libarchive library
2+
=================================================================
3+
4+
the path of libarchive.so is either determined by distro data or explicitily
5+
taken from ``EXTRACTCODE_LIBARCHIVE_PATH`` environment variable

builtins/extractcode_libarchive_system_provided/src/extractcode_libarchive/__init__.py

Lines changed: 29 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,35 @@ 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_archive = environ.get('EXTRACTCODE_LIBARCHIVE_PATH')
25+
if not lib_archive:
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 = path.join(lib_dir, 'libarchive.so')
48+
else:
49+
lib_dir = path.dirname(lib_archive)
4450

4551
locations = {
4652
'extractcode.libarchive.libdir': lib_dir,
47-
'extractcode.libarchive.dll': path.join(lib_dir, 'libarchive.so'),
53+
'extractcode.libarchive.dll': lib_archive,
4854
}
4955
return locations

0 commit comments

Comments
 (0)