summaryrefslogtreecommitdiff
path: root/buildscripts/build_system_options.py
blob: 66a303bf3205888b8b1781937e458452fa5c5acc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Options used for building process."""
import re


class PathOptions:
    """Get options/methods to resolve path-related stuff."""

    main_binary_folder_name = "bin"
    shared_library_folder_name = "lib"

    # extend the below list if there are new types of shared libraries
    _shared_library_file_patterns = [r".+\.so(\.\d{1,})?$", r".+\.dylib$"]
    _compiled_shared_library_file_patterns = None

    @property
    def shared_library_file_patterns(self) -> list:
        """Cache & return compiled regex patterns for further usage."""

        if not self._compiled_shared_library_file_patterns:
            self._compiled_shared_library_file_patterns = tuple(
                map(re.compile, self._shared_library_file_patterns))
        return self._compiled_shared_library_file_patterns

    def is_shared_library_file(self, path: str) -> bool:
        """Check if given path points to a shared library file."""

        for pattern in self.shared_library_file_patterns:
            if pattern.match(path):
                return True
        return False

    def get_binary_folder_name(self, path: str) -> str:
        """Analyze path/file and return name of folder which contains that file."""

        if self.is_shared_library_file(path):
            return self.shared_library_folder_name
        # fallback to default, main binary folder
        return self.main_binary_folder_name