feat: generate bindings with ffigen

This commit is contained in:
Aleksey Kulikov 2021-06-01 20:38:32 +03:00
parent 9d81c715ff
commit 1414d5f6d7
95 changed files with 38582 additions and 6 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
.vscode/
.packages
.dart_tool
.pub

View file

@ -4,3 +4,6 @@ linter:
- file_names
- prefer_const_constructors
- sort_constructors_first
analyzer:
exclude:
- lib/src/bindings/libgit2_bindings.dart

View file

2
lib/libgit2dart.dart Normal file
View file

@ -0,0 +1,2 @@
export 'src/repository.dart';
export 'src/error.dart';

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,89 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import '../error.dart';
import 'libgit2_bindings.dart';
import '../util.dart';
/// Attempt to open an already-existing repository at [path].
///
/// The [path] can point to either a normal or bare repository.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<Pointer<git_repository>> open(String path) {
final out = calloc<Pointer<git_repository>>();
final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_repository_open(out, pathC);
calloc.free(pathC);
if (error < 0) {
throw LibGit2Error(error, libgit2.git_error_last());
}
return out;
}
/// Attempt to open an already-existing bare repository at [bare_path].
///
/// The [bare_path] can point to only a bare repository.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<Pointer<git_repository>> openBare(String bare_path) {
final out = calloc<Pointer<git_repository>>();
final error = libgit2.git_repository_open_bare(
out, bare_path.toNativeUtf8().cast<Int8>());
if (error < 0) {
throw LibGit2Error(error, libgit2.git_error_last());
}
return out;
}
/// Returns the path to the `.git` folder for normal repositories or the
/// repository itself for bare repositories.
String path(Pointer<git_repository> repo) {
final path = libgit2.git_repository_path(repo);
return path.cast<Utf8>().toDartString();
}
/// Get the currently active namespace for this repository.
///
/// If there is no namespace, or the namespace is not a valid utf8 string,
/// empty string is returned.
String getNamespace(Pointer<git_repository> repo) {
final namespace = libgit2.git_repository_get_namespace(repo);
if (namespace == nullptr) {
return '';
} else {
return namespace.cast<Utf8>().toDartString();
}
}
/// Tests whether this repository is a bare repository or not.
bool isBare(Pointer<git_repository> repo) {
final result = libgit2.git_repository_is_bare(repo);
return result == 1 ? true : false;
}
/// Find a single object, as specified by a [spec] string.
///
/// Throws a [LibGit2Error] if error occured.
///
/// The returned object should be released when no longer needed.
Pointer<Pointer<git_object>> revParseSingle(
Pointer<git_repository> repo,
String spec,
) {
final out = calloc<Pointer<git_object>>();
final error = libgit2.git_revparse_single(
out,
repo,
spec.toNativeUtf8().cast<Int8>(),
);
if (error < 0) {
throw LibGit2Error(error, libgit2.git_error_last());
}
return out;
}

BIN
libgit2-1.1.0/libgit2.so Executable file

Binary file not shown.

View file

@ -1,6 +1,6 @@
name: libgit2_dart
description: Dart bindings for libgit2
name: libgit2dart
description: Dart bindings to libgit2
version: 0.0.1
environment:
sdk: ">=2.12.0 <3.0.0"
@ -9,15 +9,17 @@ dependencies:
dev_dependencies:
pedantic: ^1.11.0
ffigen: ^3.0.0
ffigen: ^3.1.0-dev.1
ffigen:
output: "./lib/src/libgit2_bindings.dart"
output: "lib/src/libgit2_bindings.dart"
headers:
entry-points:
- "./src/headers/"
- "libgit2-1.1.0/headers/*.h"
name: "Libgit2"
description: "Bindings to libgit2"
comments:
style: any
length: full
llvm-path:
- "/usr/lib64/libclang.so"