mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat: add library setup for linux
This commit is contained in:
parent
4717aab57f
commit
6cbf954337
97 changed files with 190 additions and 23192 deletions
|
@ -3,13 +3,73 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cli_util/cli_logging.dart' show Ansi, Logger;
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
|
||||
DynamicLibrary loadLibrary() {
|
||||
if (Platform.isLinux || Platform.isAndroid || Platform.isFuchsia) {
|
||||
const tag = 'libs-v1.3.0';
|
||||
const libUrl =
|
||||
'https://github.com/SkinnyMind/libgit2dart/releases/download/$tag/';
|
||||
const libgit2Version = '1.3.0';
|
||||
const libDir = '.dart_tool/libgit2/';
|
||||
|
||||
String getLibName(String platform) {
|
||||
var ext = 'so';
|
||||
|
||||
if (Platform.isWindows) {
|
||||
ext = 'dll';
|
||||
} else if (Platform.isMacOS) {
|
||||
ext = 'dylib';
|
||||
} else if (!(Platform.isLinux || Platform.isAndroid)) {
|
||||
throw Exception('Unsupported platform.');
|
||||
}
|
||||
|
||||
return 'libgit2-$libgit2Version.$ext';
|
||||
}
|
||||
|
||||
/// Checks if [File]/[Link] exists for an [uri].
|
||||
bool _doesFileExist(Uri uri) {
|
||||
return File.fromUri(uri).existsSync() || Link.fromUri(uri).existsSync();
|
||||
}
|
||||
|
||||
String? _resolveLibUri(String name) {
|
||||
var libUri = Directory.current.uri.resolve(name);
|
||||
final dartTool = '.dart_tool/libgit2/${Platform.operatingSystem}';
|
||||
|
||||
// If lib is in Present Working Directory.
|
||||
if (_doesFileExist(libUri)) {
|
||||
return libUri.toFilePath(windows: Platform.isWindows);
|
||||
}
|
||||
|
||||
// If lib is in Present Working Directory's .dart_tool folder.
|
||||
libUri = Directory.current.uri.resolve('$dartTool/$name');
|
||||
if (_doesFileExist(libUri)) {
|
||||
return libUri.toFilePath(windows: Platform.isWindows);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
DynamicLibrary loadLibrary(String name) {
|
||||
try {
|
||||
return DynamicLibrary.open(
|
||||
'${Directory.current.path}/libgit2/libgit2.so.1.3.0',
|
||||
_resolveLibUri(name) ?? name,
|
||||
);
|
||||
} catch (e) {
|
||||
final logger = Logger.standard();
|
||||
final ansi = Ansi(Ansi.terminalSupportsAnsi);
|
||||
|
||||
logger.stderr(
|
||||
'${ansi.red}Failed to open the library. Make sure that required '
|
||||
'library is in place.${ansi.none}',
|
||||
);
|
||||
logger.stdout(
|
||||
'To download the library, please run the following command from the '
|
||||
'root of your project:',
|
||||
);
|
||||
logger.stdout('${ansi.yellow}dart run libgit2dart:setup${ansi.none}');
|
||||
logger.stdout(ansi.none);
|
||||
rethrow;
|
||||
}
|
||||
// if (Platform.isMacOS) {
|
||||
// return DynamicLibrary.open(
|
||||
|
@ -19,10 +79,26 @@ DynamicLibrary loadLibrary() {
|
|||
// return DynamicLibrary.open(
|
||||
// '${Directory.current.path}/libgit2/libgit2-1.2.0.dll');
|
||||
// }
|
||||
throw Exception('Platform not implemented');
|
||||
}
|
||||
|
||||
final libgit2 = Libgit2(loadLibrary());
|
||||
final libgit2 = Libgit2(loadLibrary(getLibName(Platform.operatingSystem)));
|
||||
|
||||
String getVersionNumber() {
|
||||
libgit2.git_libgit2_init();
|
||||
|
||||
final major = calloc<Int32>();
|
||||
final minor = calloc<Int32>();
|
||||
final rev = calloc<Int32>();
|
||||
libgit2.git_libgit2_version(major, minor, rev);
|
||||
|
||||
final version = '${major.value}.${minor.value}.${rev.value}';
|
||||
|
||||
calloc.free(major);
|
||||
calloc.free(minor);
|
||||
calloc.free(rev);
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
bool isValidShaHex(String str) {
|
||||
final hexRegExp = RegExp(r'^[0-9a-fA-F]+$');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue