diff --git a/.gitignore b/.gitignore index ffaea7a..7af4e85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,11 @@ -.vscode + .flatpak-builder builddir build export *~ -/subprojects/blueprint-compiler -/subprojects/libcsv - +subprojects/* +!subprojects/*.wrap /.cache /build-aux diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index f1730ce..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -fail_fast: false -repos: - - repo: https://github.com/ppvan/pre-commit-hooks - rev: 2ce5a35bba2a6031563657dd4421250d644dd914 - hooks: - - id: uncrustify - args: [--no-diff, -l, VALA, -c, uncrustify.cfg, --replace, --no-backup] \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..664e7a4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + // Debug with CoreLLDB extension + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Launch", + "program": "${workspaceFolder}/build/src/${workspaceFolderBasename}", + "cwd": "${workspaceFolder}", + "preLaunchTask": "Compile" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..45e2698 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "mesonbuild.configureOnOpen": true, + "lldb.showDisassembly": "never", + "lldb.dereferencePointers": true, + "lldb.consoleMode": "commands" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..ba46a02 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,22 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Compile", + "type": "shell", + "command": "meson compile -C build", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Setup", + "type": "shell", + "command": "meson setup build --reconfigure", + } + ] +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 500b16d..c2ffa42 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,29 +1,26 @@ -# Psequel +# Dependencies -Remind future me: -``` - . -├──  application.vala -├──  gtk -> blue print, will compile to .ui files (2) -│ ├──  box.blp -│ ├──  help-overlay.ui -│ └──  window.blp -├── 謹 psequel.gresource.xml <- List the ui files in this file (3) -├──  main.vala -├──  meson.build <- List the blue prints in this files to make the compiler running. (1) -├──  ui <- Create a class (.vala file) to load template in this file (4) -└──  window.vala +```sh +# Install gtk4, vala, meson and postgresql (provide libpq) +## ArchLinux since I use arch btw +yay -S gtk4 vala meson postgresql flatpak-builder ``` -Remind me 2: - Please install the schema for each change. - `ninja install` -Prefer setting: -- Editor font -- Color scheme +# Psequel + +```sh +# config meson + +cd psequel/ +meson setup build/ + +# install glib schema (rerun each time change setting schemas) +cd build +sudo ninja install -- Connection timeout -- Query timeout -- Query limit. \ No newline at end of file +# back to the project dir and run +cd .. +make debug +``` \ No newline at end of file diff --git a/Makefile b/Makefile index b6f7aa8..0794b81 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,9 @@ # This is just a file for me to type command faster, not the build file. +SHELL := /bin/bash +VALA_FILES := $(shell find $(SRC_DIR) -name '*.vala') +PROJECT_NAME := psequel + debug: rm -rf build/resources/gtk meson configure -Dbuildtype=debug build @@ -9,6 +13,10 @@ release: meson configure -Dbuildtype=release build ninja -C build/ && G_MESSAGES_DEBUG=Psequel ./build/src/psequel +format: + @echo "Formatting Vala files..." + uncrustify -l VALA -c uncrustify.cfg --replace --no-backup $(VALA_FILES) + clean: rm -rf build/resources @@ -16,7 +24,7 @@ test: ninja -C build/ && ./build/test/psequel-test flatpak: - flatpak-builder --install-deps-from=flathub build-aux/ me.ppvan.psequel.json --force-clean + flatpak-builder --install-deps-from=flathub build-aux/ pkgs/flatpak/me.ppvan.psequel.yml --force-clean flatpak build-export export build-aux flatpak build-bundle export ./build-aux/me.ppvan.psequel.flatpak me.ppvan.psequel --runtime-repo=https://flathub.org/repo/flathub.flatpakrepo diff --git a/README.md b/README.md index 20ae107..1d5124e 100644 --- a/README.md +++ b/README.md @@ -68,32 +68,15 @@ Next, it can be installed by `meson install`. # Dependencies If you use GNOME Builder or Flatpak, dependencies will be installed automatically. If you use pure Meson, dependencies will be: - vala >= 0.56 -- gtk >= 4.10 +- gtk >= 4.16 - gtksourceview >= 5.0 -- gio >= 2.74 +- gio >= 2.80 - json-glib >= 1.6 -- libadwaita >= 1.4 -- postgres-libs >= 15.3 +- libadwaita >= 1.6 +- postgres-libs >= 16.2 - libcsv >= 3.0 (built as subproject if missing) - pgquery-vala -``` -pg_dump -s --no-comments -t "actor" -O -x --dbname "user=postgres password=postgres port=5432 dbname=dvdrental"| grep -v '^$' | grep -v '^(--\s*|SET\s+\w+\s*=).*$' -SELECT pg_catalog.set_config('search_path', '', false); -CREATE TABLE public.actor ( - actor_id integer DEFAULT nextval('public.actor_actor_id_seq'::regclass) NOT NULL, - first_name character varying(45) NOT NULL, - last_name character varying(45) NOT NULL, - last_update timestamp without time zone DEFAULT now() NOT NULL -); -ALTER TABLE ONLY public.actor - ADD CONSTRAINT actor_pkey PRIMARY KEY (actor_id); -CREATE INDEX idx_actor_last_name ON public.actor USING btree (last_name); -CREATE TRIGGER last_updated BEFORE UPDATE ON public.actor FOR EACH ROW EXECUTE FUNCTION public.last_updated(); - -``` - - # Contributions Contributions are welcome. diff --git a/me.ppvan.psequel.json b/me.ppvan.psequel.json deleted file mode 100644 index e78889c..0000000 --- a/me.ppvan.psequel.json +++ /dev/null @@ -1,97 +0,0 @@ -{ - "app-id": "me.ppvan.psequel", - "runtime": "org.gnome.Platform", - "runtime-version": "46", - "sdk": "org.gnome.Sdk", - "command": "psequel", - "finish-args": [ - "--share=network", - "--share=ipc", - "--socket=fallback-x11", - "--device=dri", - "--socket=wayland" - ], - "build-options": { - "append-path": "/usr/lib/sdk/vala/bin", - "prepend-ld-library-path": "/usr/lib/sdk/vala/lib" - }, - "cleanup": [ - "/include", - "/lib/pkgconfig", - "/man", - "/share/doc", - "/share/gtk-doc", - "/share/man", - "/share/pkgconfig", - "/share/vala", - "*.la", - "*.a" - ], - "modules": [ - { - "name": "psequel", - "buildsystem": "meson", - "sources": [ - { - "type": "dir", - "path": "." - } - ], - "modules": [ - { - "name": "blueprint-compiler", - "buildsystem": "meson", - "sources": [ - { - "type": "git", - "url": "https://gitlab.gnome.org/jwestman/blueprint-compiler", - "tag": "v0.10.0" - } - ], - "cleanup": [ - "*" - ] - }, - { - "name": "postgresql-libs", - "buildsystem": "simple", - "build-commands": [ - "./configure --prefix=/app --with-ssl=openssl", - "make -C src/include install", - "make -C src/interfaces/libpq install", - "make -C src/bin/pg_dump install" - ], - "sources": [ - { - "type": "archive", - "url": "https://ftp.postgresql.org/pub/source/v16.2/postgresql-16.2.tar.bz2", - "sha256": "446e88294dbc2c9085ab4b7061a646fa604b4bec03521d5ea671c2e5ad9b2952" - } - ] - }, - { - "name": "libcsv", - "buildsystem": "meson", - "sources": [ - { - "type": "git", - "url": "https://github.com/ppvan/libcsv", - "commit": "c8f01b8b4aa8d8156a624405b8a4c646e3f6efaa" - } - ] - }, - { - "name": "libquery-vala", - "buildsystem": "meson", - "sources": [ - { - "type": "git", - "url": "https://github.com/ppvan/pg_query_vala", - "commit": "807ad2773c43c9415b361e15cf51422f5123406f" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/pkgs/flatpak/me.ppvan.psequel.yml b/pkgs/flatpak/me.ppvan.psequel.yml new file mode 100644 index 0000000..cfeced4 --- /dev/null +++ b/pkgs/flatpak/me.ppvan.psequel.yml @@ -0,0 +1,63 @@ +app-id: me.ppvan.psequel +runtime: org.gnome.Platform +runtime-version: '47' +sdk: org.gnome.Sdk +command: psequel +finish-args: + - --share=network + - --share=ipc + - --socket=fallback-x11 + - --device=dri + - --socket=wayland +build-options: + append-path: /usr/lib/sdk/vala/bin + prepend-ld-library-path: /usr/lib/sdk/vala/lib +cleanup: + - /include + - /lib/pkgconfig + - /man + - /share/doc + - /share/gtk-doc + - /share/man + - /share/pkgconfig + - /share/vala + - '*.la' + - '*.a' +modules: + - name: psequel + buildsystem: meson + sources: + - type: dir + path: ../../ + modules: + - name: blueprint-compiler + buildsystem: meson + sources: + - type: git + url: https://gitlab.gnome.org/jwestman/blueprint-compiler + tag: v0.14.0 + cleanup: + - '*' + - name: postgresql-libs + buildsystem: simple + build-commands: + - ./configure --prefix=/app --with-ssl=openssl + - make -C src/include install + - make -C src/interfaces/libpq install + - make -C src/bin/pg_dump install + sources: + - type: archive + url: https://ftp.postgresql.org/pub/source/v17.0/postgresql-17.0.tar.bz2 + sha256: 7e276131c0fdd6b62588dbad9b3bb24b8c3498d5009328dba59af16e819109de + - name: libcsv + buildsystem: meson + sources: + - type: git + url: https://github.com/ppvan/libcsv + commit: c8f01b8b4aa8d8156a624405b8a4c646e3f6efaa + - name: libquery-vala + buildsystem: meson + sources: + - type: git + url: https://github.com/ppvan/pg_query_vala + commit: 1672a38f04d4c8ba61f0ddc11e1203c824e704e9 diff --git a/script/formater.sh b/script/formater.sh deleted file mode 100755 index d961e2f..0000000 --- a/script/formater.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/bash -# git diff --name-only --diff-filter=ACM - -for i in $(git diff --name-only --staged --diff-filter=ACM|grep .vala$); -do - uncrustify -l VALA -c uncrustify.cfg --replace --no-backup $i; -done \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index aa21f08..c51c1ac 100644 --- a/src/meson.build +++ b/src/meson.build @@ -84,26 +84,23 @@ conf.set_quoted( ) configure_file(output: 'config.h', configuration: conf) -csv_dep = dependency('csv', required: false) -if not csv_dep.found() - libsimple_proj = subproject('libcsv') - libsimple_dep = libsimple_proj.get_variable('libcsv_deps') -endif - cc = meson.get_compiler('c') math_dep = cc.find_library('m', required: false) psequel_deps = [ - dependency('glib-2.0', version: '>=2.74'), - dependency('gtk4', version: '>=4.10'), - dependency('libadwaita-1', version: '>= 1.4'), + # assume exists typical gtk system + dependency('glib-2.0', version: '>=2.80'), + dependency('gtk4', version: '>=4.16'), + dependency('libadwaita-1', version: '>= 1.6'), dependency('json-glib-1.0', version: '>= 1.6'), dependency('gtksourceview-5', version: '>= 5.0'), dependency('libpq', version: '>= 15.3'), - dependency('sqlite3', version: '>= 3'), - csv_dep, math_dep, + + # custom, fallback to subproject + dependency('sqlite3', version: '>= 3.46'), dependency('pgquery-vala'), + dependency('csv'), valac.find_library('config', dirs: vapi_dir), ] @@ -112,16 +109,20 @@ add_project_arguments( '--target-glib=2.80', '--vapidir', vapi_dir, '--gresourcesdir', psequel_resources_dir, - '--enable-deprecated' + '--enable-deprecated', + '--pkg', 'csv' ], language: 'vala', ) + + add_project_arguments( '-include', 'config.h', '-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name()), language: 'c', ) -add_global_arguments( + +add_project_arguments( [ '-Wno-pointer-sign', '-Wno-deprecated-declarations', diff --git a/src/vapi/libgvc.vapi b/src/vapi/libgvc.vapi deleted file mode 100644 index dff35c4..0000000 --- a/src/vapi/libgvc.vapi +++ /dev/null @@ -1,249 +0,0 @@ -/* - * libgvc.vapi - * - * Copyright (C) 2009 Martin Olsson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: - * Martin Olsson - */ - -[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "gvc.h")] -namespace Gvc { - - [CCode (cname = "aginitlib")] - public void initlib ( size_t graphinfo, size_t nodeinfo, size_t edgeinfo); - - [CCode (cname = "aginit")] -#if WITH_CGRAPH - public void init (Graph g, int kind, char[] rec_name, bool move_to_front); -#else - public void init (); -#endif - -#if WITH_CGRAPH - [SimpleType] - [CCode (cname = "Agdesc_t")] - public struct Desc { - } - - public Desc Agdirected; // Desc.DIRECTED | Desc.MAINGRAPH; - public Desc Agstrictdirected; // Desc.DIRECTED | Desc.STRICT | Desc.MAINGRAPH; - public Desc Agundirected; // Desc.MAINGRAPH; - public Desc Agstrictundirected; // Desc.STRICT | Desc.MAINGRAPH; -#else - [CCode (cprefix = "", has_type_id = false)] - public enum GraphKind { - AGRAPH, - AGRAPHSTRICT, - AGDIGRAPH, - AGDIGRAPHSTRICT, - AGMETAGRAPH, - } -#endif - - [CCode (cname = "agerrlevel_t", cprefix = "", has_type_id = false)] - public enum ErrorLevel { - AGWARN, - AGERR, - AGMAX, - AGPREV - } - - [Compact] - [CCode (cname = "GVC_t", free_function = "gvFreeContext")] - public class Context { - [CCode (cname = "gvContext")] - public Context (); - - [CCode (cname = "gvParseArgs")] - public int parse_args ( [CCode (array_length_pos = 0.9)] string[] argv ); - - [CCode (cname = "gvLayout")] - public int layout (Graph graph, [CCode (type = "char*")] string layout_engine); - - [CCode (cname = "gvFreeLayout")] - public int free_layout (Graph graph); - - [CCode (cname = "gvRender")] - public int render (Graph graph, [CCode (type = "char*")] string file_type, GLib.FileStream? file); - - [CCode (cname = "gvRenderFilename")] - public int render_filename (Graph graph, [CCode (type = "char*")] string file_type, [CCode (type = "char*")] string filename); - - [CCode (cname = "gvLayoutJobs")] - public int layout_jobs (Graph graph); - - [CCode (cname = "gvRenderJobs")] - public int render_jobs (Graph graph); - - [CCode (cname = "gvRenderData")] - public int render_data (Graph graph, [CCode (type = "char*")] string file_type, [CCode (array_length_type = "unsigned int", type = "char**")] out uint8[] output_data); - } - - [Compact] - [CCode (cname = "Agnode_t", ref_function = "", unref_function = "", free_function = "")] - public class Node { - [CCode (cname = "agnameof")] - public unowned string name (); - - [CCode (cname = "agget")] - public unowned string? get ([CCode (type = "char*")] string attribute_name); - - [CCode (cname = "agset")] - public int set ([CCode (type = "char*")] string attribute_name, [CCode (type = "char*")] string attribute_value); - - [CCode (cname = "agsafeset")] - public void safe_set ([CCode (type = "char*")] string attribute_name, [CCode (type = "char*")] string attribute_value, [CCode (type = "char*")] string? default_value); - } - - [Compact] - [CCode (cname = "Agedge_t", ref_function = "", unref_function = "", free_function = "")] - public class Edge { - [CCode (cname = "agget")] - public unowned string? get ([CCode (type = "char*")] string attribute_name); - - [CCode (cname = "agset")] - public int set ([CCode (type = "char*")] string attribute_name, [CCode (type = "char*")] string attribute_value); - - [CCode (cname = "agsafeset")] - public int safe_set ([CCode (type = "char*")] string attribute_name, [CCode (type = "char*")] string attribute_value, [CCode (type = "char*")] string? default_value); - } - - [Compact] - [CCode (cname = "Agraph_t", free_function = "agclose")] - public class Graph { - [CCode (cname = "agopen")] -#if WITH_CGRAPH - public Graph ([CCode (type = "char*")] string graph_name, Desc desc, int disc = 0); -#else - public Graph ([CCode (type = "char*")] string graph_name, GraphKind kind); -#endif - - [CCode (cname = "agread")] - public static Graph read (GLib.FileStream file); - - [CCode (cname = "agmemread")] - public static Graph read_string (string str); - - [CCode (cname = "agnode")] -#if WITH_CGRAPH - public unowned Node create_node ([CCode (type = "char*")] string node_name, int createflag = 1); -#else - public unowned Node create_node ([CCode (type = "char*")] string node_name); -#endif - - [CCode (cname = "agedge")] -#if WITH_CGRAPH - public unowned Edge create_edge (Node from, Node to, string? name = null, int createflag = 1); -#else - public unowned Edge create_edge (Node from, Node to); -#endif - - [CCode (cname = "agfindedge")] - public unowned Edge? find_edge (Node from, Node tO); - - [CCode (cname = "agsubg")] -#if WITH_CGRAPH - public unowned Graph create_subgraph ([CCode (type = "char*")] string? name, int createflag = 1); -#else - public unowned Graph create_subgraph ([CCode (type = "char*")] string? name); -#endif - - [CCode (cname = "agfindsubg")] - public unowned Graph? find_subgraph ([CCode (type = "char*")] string name); - - [CCode (cname = "agidsubg")] -#if WITH_CGRAPH - public unowned Graph create_subgraph_id (ulong id, int createflag = 1); -#else - public unowned Graph create_subgraph_id (ulong id); -#endif - - [CCode (cname = "agfstsubg")] - public unowned Graph? get_first_subgraph (); - - [CCode (cname = "agnxtsubg")] - public unowned Graph? get_next_subgraph (); - - [CCode (cname = "agparent")] - public unowned Graph? get_parent_graph (); - - [CCode (cname = "agdelsubg")] - public int delete_subgraph (Graph subgraph); - - [CCode (cname = "agfindnode")] - public unowned Node? find_node ([CCode (type = "char*")] string node_name); - - [CCode (cname = "agfstnode")] - public unowned Node? get_first_node (); - - [CCode (cname = "agnxtnode")] - public unowned Node? get_next_node (Node node); - - [CCode (cname = "agget")] - public unowned string? get ([CCode (type = "char*")] string attribute_name); - - [CCode (cname = "agset")] - public int set ([CCode (type = "char*")] string attribute_name, [CCode (type = "char*")] string attribute_value); - - [CCode (cname = "agsafeset")] - public int safe_set ([CCode (type = "char*")] string attribute_name, [CCode (type = "char*")] string attribute_value, [CCode (type = "char*")] string? default_value); - - [CCode (cname = "AG_IS_DIRECTED")] - public bool is_directed (); - - [CCode (cname = "AG_IS_STRICT")] - public bool is_strict (); - } - - [CCode (cname = "char", copy_function = "agdupstr_html", free_function = "")] - public class HtmlString : string { - [CCode (cname = "agstrdup_html")] - public static HtmlString make_html (Graph graph, string markup); - - [CCode (cname = "agstrfree")] - public static HtmlString free_html (Graph graph, string markup); - } - - [CCode(cprefix = "ag")] - namespace Error { - [CCode (cname = "agerrno")] - public static ErrorLevel errno; - - [CCode (cname = "agerr")] - [PrintfFormat] - public static int error (ErrorLevel level, string fmt, ...); - - [CCode (cname = "agerrors")] - public static int errors (); - - [CCode (cname = "agseterr")] - public static void set_error (ErrorLevel err); - - [CCode (cname = "aglasterr")] - public static string? last_error (); - - [CCode (cname = "agerrorf")] - [PrintfFormat] - public static void errorf (string format, ...); - - [CCode (cname = "agwarningf")] - [PrintfFormat] - void warningf (string fmt, ...); - } - -} diff --git a/subprojects/libcsv.wrap b/subprojects/libcsv.wrap index 2a3fb2c..47159db 100644 --- a/subprojects/libcsv.wrap +++ b/subprojects/libcsv.wrap @@ -4,3 +4,5 @@ url = https://github.com/ppvan/libcsv.git revision = master depth = 1 +[provide] +csv = libcsv_deps \ No newline at end of file diff --git a/subprojects/pgquery-vala.wrap b/subprojects/pgquery-vala.wrap new file mode 100644 index 0000000..b179e78 --- /dev/null +++ b/subprojects/pgquery-vala.wrap @@ -0,0 +1,9 @@ +[wrap-git] +directory = pgquery_vala +url = https://github.com/ppvan/pg_query_vala.git +clone-recursive = true +revision = main +depth = 1 + +[provide] +pgquery-vala = pgquery_vala_dep \ No newline at end of file diff --git a/subprojects/sqlite3.wrap b/subprojects/sqlite3.wrap new file mode 100644 index 0000000..bb03a37 --- /dev/null +++ b/subprojects/sqlite3.wrap @@ -0,0 +1,13 @@ +[wrap-file] +directory = sqlite-amalgamation-3460100 +source_url = https://www.sqlite.org/2024/sqlite-amalgamation-3460100.zip +source_filename = sqlite-amalgamation-3460100.zip +source_hash = 77823cb110929c2bcb0f5d48e4833b5c59a8a6e40cdea3936b99e199dbbe5784 +patch_filename = sqlite3_3.46.1-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/sqlite3_3.46.1-1/get_patch +patch_hash = 1358b931e30a454e55dbedbc28d5844946a17c68b45a5333093152d7af75982b +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/sqlite3_3.46.1-1/sqlite-amalgamation-3460100.zip +wrapdb_version = 3.46.1-1 + +[provide] +sqlite3 = sqlite3_dep