mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
fix: lookup library in Flutter's .pub_cache folder
This commit is contained in:
parent
48e2240c73
commit
279e4a474d
1 changed files with 16 additions and 0 deletions
|
@ -6,6 +6,7 @@ import 'dart:io';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_opts_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_opts_bindings.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
import 'package:pub_cache/pub_cache.dart';
|
||||||
|
|
||||||
const libgit2Version = '1.4.3';
|
const libgit2Version = '1.4.3';
|
||||||
final libDir = path.join('.dart_tool', 'libgit2');
|
final libDir = path.join('.dart_tool', 'libgit2');
|
||||||
|
@ -52,6 +53,21 @@ String? _resolveLibPath(String name) {
|
||||||
libPath = path.join(path.dirname(Platform.resolvedExecutable), 'lib', name);
|
libPath = path.join(path.dirname(Platform.resolvedExecutable), 'lib', name);
|
||||||
if (_doesFileExist(libPath)) return libPath;
|
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 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;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue