Skip to content

Helpers for discovering dynamic dependencies of dylibs #191

@dcharkes

Description

@dcharkes

When dealing with:

We'd like users to not have to manually make the transitive closure of dependencies. We should provide some helper code to do this.

Rough sketch:

Set<String> transitiveDeps(String dylib) {
  final all = <String>{};
  final worklist = [dylib];
  while (worklist.isNotEmpty) {
    final current = worklist.removeLast();
    for (final path in depsOfDylib(current)) {
      if (all.add(path)) {
        worklist.add(path);
      }
    }
  }
  return all;
}

Set<String> depsOfDylib(String dylib) {
  final result = Process.runSync('otool', ['-L', dylib]);
  return regexp
      .allMatches(result.stdout)
      .map((match) => match.namedGroup('path')!)
      .toSet();
}

final regexp = RegExp(r'^\s+(?<path>[^\s]*)\s+', multiLine: true);
final homebrewDir = '${Platform.environment['HOME']}/.homebrew';

We'd need something for all OSes.

Thanks @mkustermann for reporting and the sketch!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions