Skip to content

OS-dependent libraries

This feature allows you to download and unpack libraries with appropriate binaries for the indicated operating system during the build process. To do this, you need to expand the meta section in the global configuration with the os-dependentLibraries field. This field takes the following attributes:

Property Type Description default value
name* string is the name of the library we want to download. -
version* string is the specific version of the given library. -
dependencies boolean (Optional) is the parameter which determines whether the --no-deps flag will be used when installing the package from pip. When the value is set to true, the library will be installed along with all its dependencies. When the value is set to false (default) {name}={version}, it must be present in packages requirements.txt. false
platform* string is the platform for downloading the specified library. The value depends on the available wheels for a given library, for example, for this wheel, cryptography-41.0.5-cp37-abi3-manylinux_2_28_x86_64.whl, the platform is manylinux_2_28_x86_64. -
python_version* string is the python version compatible with the library. -
target* string is the Path where the selected library will be unpacked. -
os* string is the name of the operating system which the library is intended for. Using this parameter, an appropriate insert into sys.path will be created. It takes 3 values windows, linux, and darwin. -

About wheels files

Generally, the wheel name convention is
{distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl.
For example, for this particular library,
grpcio-1.54.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
, your pip parameters are:

  • name = grpcio
  • version = 1.54.2
  • platform = manylinux_2_17_x86_64 or manylinux2014_x86_64
  • python_version = 37
  • target = your/path/to/target
  • os = linux

and your pip command should look like this:
pip install --no-deps --platform manylinux_2_17_x86_64 --python-version 37 --target your/path/to/target --only-binary=:all: grpcio==1.54.2

A dot in the platform part indicates that a given distribution supports several platforms. In this case, “.” in manylinux_2_17_x86_64.manylinux2014_x86_64 means this distribution supports both manylinux_2_17_x86_64 and manylinux2014_x86_64.

For more informations, see .whl and manylinux platform.

Usage

    ...
    "meta": {
        "name": "<TA name>",
        "restRoot": "<restRoot>",
        "version": "<TA version>",
        "displayName": "<TA display name>",
        "schemaVersion": "<schema version>",
        "os-dependentLibraries": [
            {
                "name": "cryptography",
                "version": "41.0.5",
                "platform": "manylinux2014_x86_64",
                "python_version": "37",
                "os": "linux",
                "target": "3rdparty/linux"
            },
            {
                "name": "cryptography",
                "version": "41.0.5",
                "platform": "win_amd64",
                "python_version": "37",
                "os": "windows",
                "target": "3rdparty/windows"
            },
            {
                "name": "cryptography",
                "version": "41.0.5",
                "dependencies": true,
                "platform": "manylinux2014_x86_64",
                "python_version": "37",
                "os": "linux",
                "target": "3rdparty/linux_with_deps"
            },
            {
                "name": "cffi",
                "version": "1.15.1",
                "platform": "win_amd64",
                "python_version": "37",
                "os": "windows",
                "target": "3rdparty/windows"
            }
        ]
    }

Result

Running the build for the above configuration will result in the creation of the following structure:

output
    └──<TA>
        ├── bin
        ...
        └── lib
            └── 3rdparty
                ├── linux
                │   ├── cryptography
                │   └── cryptography-41.0.5.dist-info
                ├── linux_with_deps
                │   ├── _cffi_backend.cpython-37m-x86_64-linux-gnu.so
                │   ├── cffi
                │   ├── cffi-1.15.1.dist-info
                │   ├── cryptography
                │   ├── cryptography-41.0.5.dist-info
                │   ├── pycparser
                │   └── pycparser-2.21.dist-info
                └── windows
                    ├── _cffi_backend.cp37-win_amd64.pyd
                    ├── cffi
                    ├── cffi-1.15.1.dist-info
                    ├── cryptography
                    └── cryptography-41.0.5.dist-info

During the build process, a python script “import_declare_test.py” will be created in output/ta_name/bin to manipulate system paths. In each input using the specified libraries, this script must be imported. Currently, three operating systems are supported: Windows, Linux, and Darwin. If, for development purposes, there is a need to create other custom manipulations on sys.path, create your own script called “import_declare_test.py” and place it in the package/bin folder. This way, when building the TA, the default script will be replaced with the one created by the developer.
The default script for this configuration will look like this:

import os
import sys
import re
from os.path import dirname

ta_name = 'demo_addon_for_splunk'
pattern = re.compile(r'[\\/]etc[\\/]apps[\\/][^\\/]+[\\/]bin[\\/]?$')
new_paths = [path for path in sys.path if not pattern.search(path) or ta_name in path]
new_paths.insert(0, os.path.join(dirname(dirname(__file__)), "lib"))
new_paths.insert(0, os.path.sep.join([os.path.dirname(__file__), ta_name]))
sys.path = new_paths

bindir = os.path.dirname(os.path.realpath(os.path.dirname(__file__)))
libdir = os.path.join(bindir, "lib")
platform = sys.platform
if platform.startswith("linux"):
    sys.path.insert(0, os.path.join(libdir, "3rdparty/linux_with_deps"))
    sys.path.insert(0, os.path.join(libdir, "3rdparty/linux"))
if platform.startswith("win"):
    sys.path.insert(0, os.path.join(libdir, "3rdparty/windows"))