resolveDylibPath function

String resolveDylibPath(
  1. String baseName, {
  2. String? path,
  3. String? dartDefine,
  4. String? environmentVariable,
})

Resolves the path to a dynamic library. The library name can be specified in a cross-platform manner as a base name.

Furthermore, the lookup path and/or the name of a Dart define or an environment variable can be optionally passed to specify the lookup location.

Implementation

String resolveDylibPath(
  String baseName, {
  String? path,
  String? dartDefine,
  String? environmentVariable,
}) {
  // Dart define or environment variable
  final variable = _resolveVariable(dartDefine, environmentVariable);

  // LIBFOO_PATH=/path/to/libfoo.so (full file path) specified
  if (_isFile(variable)) return variable;

  // Resolve potential library names
  final baseDylib = resolveDylibName(baseName);
  final variableDylib = resolveDylibName(variable);

  // LIBFOO_PATH=/path/to/ (only path) specified
  if (_isDirectory(variable)) return p.join(variable, baseDylib);

  return p.join(path ?? '', variableDylib.isEmpty ? baseDylib : variableDylib);
}