about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--cmd/hare-gi/main.ha64
-rwxr-xr-xscripts/generate-gtk326
-rwxr-xr-xscripts/generate-gtk432
3 files changed, 92 insertions, 30 deletions
diff --git a/cmd/hare-gi/main.ha b/cmd/hare-gi/main.ha
index 0ea23f8..071a806 100644
--- a/cmd/hare-gi/main.ha
+++ b/cmd/hare-gi/main.ha
@@ -1,12 +1,74 @@
+use errors;
 use fmt;
 use fs;
 use getopt;
 use gir;
 use hare::parse;
 use io;
+use path;
 use os;
 use strings;
 
+fn alternative(x: (str | void), default: str) str = {
+	match (x) {
+	case let s: str =>
+		if (s == "") {
+			return default;
+		} else {
+			return s;
+		};
+	case =>
+		return default;
+	};
+};
+
+fn find_gir(name: str) (io::file | fs::error) = {
+	static let buf = path::buffer { ... };
+
+	if (strings::contains(name, "/")) {
+		match (os::open(name)) {
+		case let err: fs::error =>
+			return err;
+		case let f: io::file =>
+			return f;
+		};
+	};
+
+	let gi_gir_path = strings::split(alternative(os::getenv("GI_GIR_PATH"), ""), ":")!;
+	let xdg_data_dirs = strings::split(alternative(os::getenv("XDG_DATA_DIRS"), "/usr/local/share/:/usr/share/"), ":")!;
+	defer free(gi_gir_path);
+	defer free(xdg_data_dirs);
+
+	let xdg_home = {
+		path::set(&buf, os::getenv("HOME") as str, ".local", "share")!;
+		yield strings::dup(alternative(os::getenv("XDG_DATA_HOME"), path::string(&buf)))!;
+	};
+	defer free(xdg_home);
+
+	for (let list .. [
+		gi_gir_path,
+		[xdg_home],
+		xdg_data_dirs,
+	]) {
+		for (let path .. list) {
+			path::set(&buf, path, "gir-1.0", name)!;
+
+			match (os::open(path::string(&buf))) {
+				case let f: io::file =>
+					return f;
+				case errors::noaccess =>
+					continue;
+				case errors::noentry =>
+					continue;
+				case let err: fs::error =>
+					return err;
+			};
+		};
+	};
+
+	return errors::noentry;
+};
+
 export fn main() void = {
 	const help: [_]getopt::help = [
 		"generate Hare bindings from GObject-Introspection files",
@@ -36,7 +98,7 @@ export fn main() void = {
 	};
 
 	for (let i = 0z; i < len(cmd.args); i += 1) {
-		const f = match (os::open(cmd.args[i])) {
+		const f = match (find_gir(cmd.args[i])) {
 		case let f: io::file =>
 			yield f;
 		case let err: fs::error =>
diff --git a/scripts/generate-gtk3 b/scripts/generate-gtk3
index bf57ff5..329d169 100755
--- a/scripts/generate-gtk3
+++ b/scripts/generate-gtk3
@@ -21,16 +21,16 @@ exec ./hare-gi -B \
 	-m Gdk,${NS}gdk,"$BIND"/gdk/_generated.ha \
 	-m xlib,${NS}xlib,"$BIND"/xlib/_generated.ha \
 	-m Gtk,${NS}gtk,"$BIND"/gtk/_generated.ha \
-	/usr/share/gir-1.0/GLib-2.0.gir \
-	/usr/share/gir-1.0/GObject-2.0.gir \
-	/usr/share/gir-1.0/Gio-2.0.gir \
-	/usr/share/gir-1.0/GModule-2.0.gir \
-	/usr/share/gir-1.0/Atk-1.0.gir \
-	/usr/share/gir-1.0/GdkPixbuf-2.0.gir \
-	/usr/share/gir-1.0/freetype2-2.0.gir \
-	/usr/share/gir-1.0/HarfBuzz-0.0.gir \
-	/usr/share/gir-1.0/cairo-1.0.gir \
-	/usr/share/gir-1.0/Pango-1.0.gir \
-	/usr/share/gir-1.0/Gdk-3.0.gir \
-	/usr/share/gir-1.0/xlib-2.0.gir \
-	/usr/share/gir-1.0/Gtk-3.0.gir
+	GLib-2.0.gir \
+	GObject-2.0.gir \
+	Gio-2.0.gir \
+	GModule-2.0.gir \
+	Atk-1.0.gir \
+	GdkPixbuf-2.0.gir \
+	freetype2-2.0.gir \
+	HarfBuzz-0.0.gir \
+	cairo-1.0.gir \
+	Pango-1.0.gir \
+	Gdk-3.0.gir \
+	xlib-2.0.gir \
+	Gtk-3.0.gir
diff --git a/scripts/generate-gtk4 b/scripts/generate-gtk4
index c285a4e..e872da8 100755
--- a/scripts/generate-gtk4
+++ b/scripts/generate-gtk4
@@ -25,19 +25,19 @@ exec ./hare-gi \
 	-m Graphene,${NS}graphene,"$BIND"/graphene/_generated.ha \
 	-m Gsk,${NS}gsk,"$BIND"/gsk/_generated.ha \
 	-m Gtk,${NS}gtk4,"$BIND"/gtk4/_generated.ha \
-	/usr/share/gir-1.0/GLib-2.0.gir \
-	/usr/share/gir-1.0/GObject-2.0.gir \
-	/usr/share/gir-1.0/Gio-2.0.gir \
-	/usr/share/gir-1.0/GModule-2.0.gir \
-	/usr/share/gir-1.0/Atk-1.0.gir \
-	/usr/share/gir-1.0/GdkPixbuf-2.0.gir \
-	/usr/share/gir-1.0/freetype2-2.0.gir \
-	/usr/share/gir-1.0/HarfBuzz-0.0.gir \
-	/usr/share/gir-1.0/cairo-1.0.gir \
-	/usr/share/gir-1.0/Pango-1.0.gir \
-	/usr/share/gir-1.0/PangoCairo-1.0.gir \
-	/usr/share/gir-1.0/Gdk-4.0.gir \
-	/usr/share/gir-1.0/xlib-2.0.gir \
-	/usr/share/gir-1.0/Graphene-1.0.gir \
-	/usr/share/gir-1.0/Gsk-4.0.gir \
-	/usr/share/gir-1.0/Gtk-4.0.gir
+	GLib-2.0.gir \
+	GObject-2.0.gir \
+	Gio-2.0.gir \
+	GModule-2.0.gir \
+	Atk-1.0.gir \
+	GdkPixbuf-2.0.gir \
+	freetype2-2.0.gir \
+	HarfBuzz-0.0.gir \
+	cairo-1.0.gir \
+	Pango-1.0.gir \
+	PangoCairo-1.0.gir \
+	Gdk-4.0.gir \
+	xlib-2.0.gir \
+	Graphene-1.0.gir \
+	Gsk-4.0.gir \
+	Gtk-4.0.gir