mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 12:49:08 -04:00
fix: lookup library in correct locations
This commit is contained in:
parent
5739de545b
commit
7aadefc7b5
3 changed files with 21 additions and 32 deletions
|
@ -6,7 +6,6 @@ import 'dart:io';
|
|||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_opts_bindings.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:pub_cache/pub_cache.dart';
|
||||
|
||||
const libgit2Version = '1.4.3';
|
||||
final libDir = path.join('.dart_tool', 'libgit2');
|
||||
|
@ -32,13 +31,8 @@ bool _doesFileExist(String path) {
|
|||
|
||||
/// Returns path to dynamic library if found.
|
||||
String? _resolveLibPath(String name) {
|
||||
var libPath = path.join(Directory.current.path, name);
|
||||
|
||||
// If lib is in Present Working Directory.
|
||||
if (_doesFileExist(libPath)) return libPath;
|
||||
|
||||
// If lib is in Present Working Directory's '.dart_tool/libgit2/[platform]' folder.
|
||||
libPath = path.join(
|
||||
var libPath = path.join(
|
||||
Directory.current.path,
|
||||
libDir,
|
||||
Platform.operatingSystem,
|
||||
|
@ -50,33 +44,20 @@ String? _resolveLibPath(String name) {
|
|||
libPath = path.join(Directory.current.path, Platform.operatingSystem, name);
|
||||
if (_doesFileExist(libPath)) return libPath;
|
||||
|
||||
String checkCache(PubCache pubCache) {
|
||||
final pubCacheDir =
|
||||
pubCache.getLatestVersion('libgit2dart')!.resolve()!.location;
|
||||
return path.join(pubCacheDir.path, Platform.operatingSystem, name);
|
||||
}
|
||||
|
||||
// If lib is in Dart's '.pub_cache' folder.
|
||||
libPath = checkCache(PubCache());
|
||||
// If lib is in executable's folder.
|
||||
libPath = path.join(path.dirname(Platform.resolvedExecutable), name);
|
||||
if (_doesFileExist(libPath)) return libPath;
|
||||
|
||||
// If lib is in Flutter's '.pub_cache' folder.
|
||||
final env = Platform.environment;
|
||||
if (env.containsKey('FLUTTER_ROOT')) {
|
||||
final flutterPubCache =
|
||||
PubCache(Directory(path.join(env['FLUTTER_ROOT']!, '.pub-cache')));
|
||||
libPath = checkCache(flutterPubCache);
|
||||
if (_doesFileExist(libPath)) return libPath;
|
||||
}
|
||||
// If lib is in executable's bundled 'lib' folder.
|
||||
libPath = path.join(path.dirname(Platform.resolvedExecutable), 'lib', name);
|
||||
if (_doesFileExist(libPath)) return libPath;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
DynamicLibrary loadLibrary(String name) {
|
||||
try {
|
||||
return DynamicLibrary.open(
|
||||
_resolveLibPath(name) ?? name,
|
||||
);
|
||||
return DynamicLibrary.open(_resolveLibPath(name) ?? name);
|
||||
} catch (e) {
|
||||
stderr.writeln(
|
||||
'Failed to open the library. Make sure that libgit2 library is bundled '
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue