From b0b806720319b42c3ec4b0200535aa0fa6b0392f Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Wed, 8 Jun 2022 15:31:27 +0300 Subject: [PATCH 1/2] fix: lookup library in correct locations (#64) --- README.md | 4 ++-- bin/setup.dart | 16 ++++++++++++---- lib/src/util.dart | 33 +++++++-------------------------- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 575e785..8c17eb4 100644 --- a/README.md +++ b/README.md @@ -49,13 +49,13 @@ print(Libgit2.version); **Note**: The following steps only required if you are using package in Dart application (Flutter application will have libgit2 library bundled automatically when you build for release). -After compiling the application you should run: +After adding the package as dependency you should run: ```shell dart run libgit2dart:setup ``` -That'll copy the prebuilt libgit2 library for your platform into `.dart_tool/libgit2//` which you'll need to add to the same folder as your executable. +That'll copy the prebuilt libgit2 library for your platform into `.dart_tool/libgit2//` which you'll need to add to the same folder as your executable after compilation. If you upgrade the version of libgit2dart package in your dependencies you should run the following commands to have the latest libgit2 library for your platform to provide with your application: diff --git a/bin/setup.dart b/bin/setup.dart index 524d017..a71be0d 100644 --- a/bin/setup.dart +++ b/bin/setup.dart @@ -23,15 +23,23 @@ Future copyLibrary(String platform) async { ); } } else { - final pubCache = PubCache(); - final pubCacheDir = - pubCache.getLatestVersion('libgit2dart')!.resolve()!.location; + String? checkCache(PubCache pubCache) => + pubCache.getLatestVersion('libgit2dart')?.resolve()?.location.path; + + final libPath = checkCache(PubCache()) ?? + checkCache( + PubCache( + Directory( + path.join(Platform.environment['FLUTTER_ROOT']!, '.pub-cache'), + ), + ), + ); final libName = getLibName(); stdout.writeln('Copying libgit2 for $platform'); final destination = path.join(libDir, platform); Directory(destination).createSync(recursive: true); - File(path.join(pubCacheDir.path, platform, libName)).copySync( + File(path.join(libPath!, platform, libName)).copySync( path.join(destination, libName), ); diff --git a/lib/src/util.dart b/lib/src/util.dart index 11ae887..001e488 100644 --- a/lib/src/util.dart +++ b/lib/src/util.dart @@ -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 ' From a708d54b0aa917f056d3570d8ee54fcbd572d3da Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Wed, 8 Jun 2022 15:39:19 +0300 Subject: [PATCH 2/2] chore: v1.1.1 --- CHANGELOG.md | 8 +++++++- macos/libgit2dart.podspec | 2 +- pubspec.yaml | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4917c66..7156b40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.1.1 + +- fix: lookup library in correct locations + +- feat: add ability to pass optional notes location to `Note.list(...)` method + ## 1.1.0 - feat: add ability to get and set libgit2 global options @@ -6,7 +12,7 @@ - feat: add ability to remove entries in index with `resetDefault(...)` method -- feat: add ability to compare objects (value based equality). +- feat: add ability to compare objects (value based equality) Note: comparison of Repository objects have naive implementation. Comparison is based on repository path, and previously loaded into memory index, odb, etc. might be different. Use with caution. diff --git a/macos/libgit2dart.podspec b/macos/libgit2dart.podspec index 2a2ab92..756018f 100644 --- a/macos/libgit2dart.podspec +++ b/macos/libgit2dart.podspec @@ -4,7 +4,7 @@ # Pod::Spec.new do |s| s.name = 'libgit2dart' - s.version = '1.1.0' + s.version = '1.1.1' s.summary = 'Dart bindings to libgit2.' s.description = <<-DESC Dart bindings to libgit2. diff --git a/pubspec.yaml b/pubspec.yaml index f4591ed..696d650 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: libgit2dart description: Dart bindings to libgit2, provides ability to use libgit2 library in Dart and Flutter. -version: 1.1.0 +version: 1.1.1 homepage: https://github.com/SkinnyMind/libgit2dart