Browse Source

Add WIP Python REPL interface

- Requires Python >= 3.0.0 and linenoise or linenoise-ng
- WIP: not built into the browser itself
master
Aqua-sama 4 months ago
parent
commit
914e2be5f5
Signed by: Aqua-sama <aqua@iserlohn-fortress.net> GPG Key ID: 5378B8349C1D5ADA

+ 1
- 1
3rd-party/SingleApplication/meson.build View File

@@ -1,6 +1,6 @@
1 1
 SingleApplication_inc = include_directories('SingleApplication.git')
2 2
 
3
-SingleApplication_moc = qt5.preprocess(
3
+SingleApplication_moc = mod_qt5.preprocess(
4 4
     moc_headers: ['SingleApplication.git/singleapplication.h', 'SingleApplication.git/singleapplication_p.h'],
5 5
     moc_extra_arguments: ['-DQAPPLICATION_CLASS=QApplication'],
6 6
     dependencies: dep_qt5

+ 1
- 1
lang/meson.build View File

@@ -1,4 +1,4 @@
1 1
 
2 2
 # translations
3
-qt5.compile_translations(ts_files: 'bg.ts', install: get_option('translations').enabled(), install_dir: get_option('datadir') / 'smolbote/translations' , build_by_default: false)
3
+mod_qt5.compile_translations(ts_files: 'bg.ts', install: get_option('translations').enabled(), install_dir: get_option('datadir') / 'smolbote/translations' , build_by_default: false)
4 4
 

+ 5
- 9
lib/about/meson.build View File

@@ -1,16 +1,12 @@
1
-about_moc = qt5.preprocess(
1
+about_moc = mod_qt5.preprocess(
2 2
     moc_headers: ['aboutdialog.h', 'aboutplugin.h'],
3 3
     ui_files: ['aboutdialog.ui', 'aboutplugin.ui'],
4 4
     dependencies: dep_qt5
5 5
 )
6 6
 
7
-about_inc = include_directories('.')
8
-about_lib = static_library('about', ['aboutdialog.cpp', 'aboutplugin.cpp', about_moc],
9
-    dependencies: [dep_qt5, dep_genheaders]
10
-)
11
-
12 7
 dep_about = declare_dependency(
13
-    include_directories: about_inc,
14
-    link_with: about_lib,
15
-    sources: ['aboutdialog.cpp', about_moc]
8
+    include_directories: include_directories('.'),
9
+    link_with: static_library('about', 
10
+        ['aboutdialog.cpp', 'aboutplugin.cpp', about_moc],
11
+        dependencies: [dep_qt5, dep_genheaders])
16 12
 )

+ 2
- 3
lib/addressbar/meson.build View File

@@ -1,5 +1,5 @@
1 1
 addressbar_inc = include_directories('.')
2
-addressbar_moc = qt5.preprocess(
2
+addressbar_moc = mod_qt5.preprocess(
3 3
     moc_headers: ['addressbar.h', 'completer.h', 'urllineedit.h'],
4 4
     ui_files: ['addressbar.ui'],
5 5
     dependencies: dep_qt5
@@ -11,6 +11,5 @@ addressbar_lib = static_library('addressbar', ['addressbar.cpp', 'completer.cpp'
11 11
 
12 12
 dep_addressbar = declare_dependency(
13 13
     include_directories: addressbar_inc,
14
-    link_with: addressbar_lib,
15
-    sources: ['addressbar.cpp', 'completer.cpp', 'urllineedit.cpp', addressbar_moc]
14
+    link_with: addressbar_lib
16 15
 )

+ 1
- 1
lib/bookmarks/meson.build View File

@@ -1,5 +1,5 @@
1 1
 bookmarks_inc = include_directories('.')
2
-bookmarks_moc = qt5.preprocess(
2
+bookmarks_moc = mod_qt5.preprocess(
3 3
     moc_headers: ['bookmarkswidget.h', 'model/bookmarkmodel.h', 'forms/editbookmarkdialog.h'],
4 4
     ui_files: ['bookmarksform.ui', 'forms/editbookmarkdialog.ui'],
5 5
     dependencies: dep_qt5

+ 1
- 1
lib/configuration/meson.build View File

@@ -1,5 +1,5 @@
1 1
 configuration_inc = include_directories('.')
2
-configuration_moc = qt5.preprocess(
2
+configuration_moc = mod_qt5.preprocess(
3 3
     moc_headers: ['configuration.h'],
4 4
     dependencies: dep_qt5
5 5
 )

+ 1
- 1
lib/downloads/meson.build View File

@@ -1,5 +1,5 @@
1 1
 downloads_inc = include_directories('.')
2
-downloads_moc = qt5.preprocess(
2
+downloads_moc = mod_qt5.preprocess(
3 3
     moc_headers: ['downloadswidget.h', 'widgets/downloaditemwidget.h', 'widgets/elidedlabel.h'],
4 4
     ui_files: ['downloadsform.ui', 'widgets/downloaditemform.ui'],
5 5
     dependencies: dep_qt5

+ 1
- 1
lib/webprofile/meson.build View File

@@ -1,6 +1,6 @@
1 1
 webprofile_lib = static_library('webprofile', 
2 2
     ['webprofilemanager.cpp', 'webprofile.cpp', interfaces_moc,
3
-    qt5.preprocess(moc_headers: ['webprofilemanager.h', 'webprofile.h'], dependencies: dep_qt5)],
3
+    mod_qt5.preprocess(moc_headers: ['webprofilemanager.h', 'webprofile.h'], dependencies: dep_qt5)],
4 4
     dependencies: dep_qt5,
5 5
     include_directories: [include]
6 6
 )

+ 25
- 26
meson.build View File

@@ -1,7 +1,9 @@
1 1
 project('smolbote', 'cpp',
2 2
     version: 'master',
3 3
     default_options: ['cpp_std=c++17', 'strip=true', 'warning_level=3'],
4
-    license: 'GPL3')
4
+    license: 'GPL3',
5
+    meson_version: '>=0.49.0'
6
+)
5 7
 
6 8
 # autogenerate qtcreator project files
7 9
 # add_postconf_script(script_name, arg1, arg2, ...)
@@ -11,47 +13,46 @@ project('smolbote', 'cpp',
11 13
 
12 14
 # add -DQT_NO_DEBUG to non-debug builds
13 15
 if not get_option('debug')
14
-    add_global_arguments('-DQT_NO_DEBUG', language: 'cpp')
16
+    add_project_arguments('-DQT_NO_DEBUG', language: 'cpp')
15 17
 endif
16 18
 
17
-# Qt 5
18
-qt5 = import('qt5')
19
-dep_qt5 = dependency('qt5', modules: ['Core', 'Network', 'Widgets', 'WebEngineWidgets', 'Concurrent', 'Test'])
19
+mod_qt5 = import('qt5')
20
+dep_qt5 = dependency('qt5', modules: ['Core', 'Network', 'Widgets', 'WebEngineWidgets', 'Concurrent'])
21
+
22
+mod_python = import('python')
23
+python3 = mod_python.find_installation('python3')
20 24
 
21
-# Boost
22 25
 dep_boost = dependency('boost', modules: ['program_options'])
23 26
 
24
-# spdlog
25 27
 dep_spdlog = dependency('spdlog', fallback: ['spdlog', 'spdlog_dep'], version: '>=1.3.1')
26 28
 
27
-# Breakpad
29
+optional_deps = []
30
+
28 31
 if get_option('Breakpad').enabled()
29
-dep_breakpad = declare_dependency(
30
-    compile_args: '-DBREAKPAD',
31
-    dependencies: [dependency('breakpad-client'),
32
-                   dependency('threads')]
32
+optional_deps += declare_dependency(compile_args: '-DBREAKPAD',
33
+    dependencies: [dependency('breakpad-client'), dependency('threads')]
33 34
 )
34
-else
35
-    dep_breakpad = declare_dependency()
36 35
 endif
37 36
 
38
-# KDE
39 37
 if get_option('Plasma').enabled()
40
-dep_plasma = declare_dependency(
41
-    compile_args: '-DPLASMA',
42
-    dependencies: [ dependency('KF5WindowSystem', method: 'cmake'),
43
-                    dependency('KF5Wallet', method: 'cmake')]
38
+optional_deps += declare_dependency(compile_args: '-DPLASMA',
39
+    dependencies: [ dependency('KF5WindowSystem', method: 'cmake'), dependency('KF5Wallet', method: 'cmake')]
44 40
 )
45
-else
46
-    dep_plasma = declare_dependency()
47 41
 endif
48 42
 
43
+if get_option('Python').enabled()
44
+optional_deps += declare_dependency(compile_args: '-DPYTHON',
45
+    dependencies: [ meson.get_compiler('cpp').find_library('linenoise'),
46
+                    python3.dependency('python', version: '>=3.0.0')])
47
+    subdir('src/cli')
48
+endif
49
+
50
+dep_gtest = dependency('gtest', required: get_option('testing'))
51
+
49 52
 # Generate config header
50 53
 include = include_directories('include')
51 54
 
52 55
 git = find_program('git').path()
53
-pymod = import('python')
54
-python3 = pymod.find_installation('python3')
55 56
 
56 57
 dep_genheaders = declare_dependency(
57 58
     include_directories: include_directories('.'),
@@ -70,13 +71,11 @@ dep_genheaders = declare_dependency(
70 71
     )]
71 72
 )
72 73
 
73
-interfaces_moc = qt5.preprocess(
74
+interfaces_moc = mod_qt5.preprocess(
74 75
     moc_headers: 'include/profileinterface.h',
75 76
     dependencies: dep_qt5
76 77
 )
77 78
 
78
-dep_gtest = dependency('gtest', required: get_option('testing'))
79
-
80 79
 subdir('lib/about')
81 80
 subdir('lib/addressbar')
82 81
 subdir('lib/bookmarks')

+ 1
- 0
meson_options.txt View File

@@ -9,5 +9,6 @@ option('translations', description: 'Generate and install translations', type: '
9 9
 # Feature options
10 10
 option('Breakpad', description: 'Enable breakpad crash reporting', type: 'feature', value: 'auto')
11 11
 option('Plasma',   description: 'Enable KDE plasma integration',   type: 'feature', value: 'auto')
12
+option('Python',   description: 'Enable Python interpreter',       type: 'feature', value: 'auto')
12 13
 option('testing',  description: 'Build tests (requires gtest)',    type: 'feature', value: 'auto')
13 14
 

+ 1
- 1
plugins/ConfigurationEditor/meson.build View File

@@ -1,4 +1,4 @@
1
-ConfigurationEditorPlugin_moc = qt5.preprocess(
1
+ConfigurationEditorPlugin_moc = mod_qt5.preprocess(
2 2
     include_directories: include,
3 3
     moc_headers: ['configurationeditorplugin.h', 'forms/configurationdialog.h'],
4 4
     ui_files: ['forms/configurationdialog.ui'],

+ 1
- 1
plugins/ProfileEditor/meson.build View File

@@ -1,4 +1,4 @@
1
-ProfileEditorPlugin_moc = qt5.preprocess(
1
+ProfileEditorPlugin_moc = mod_qt5.preprocess(
2 2
     include_directories: include,
3 3
     moc_headers: ['profileeditorplugin.h', 'forms/profilemanagerdialog.h', 'forms/profileview.h', 'forms/newprofiledialog.h', 'forms/newhttpheaderdialog.h'],
4 4
     ui_files: ['forms/profilemanagerdialog.ui', 'forms/profileview.ui', 'forms/newprofiledialog.ui', 'forms/newhttpheaderdialog.ui'],

+ 51
- 0
src/cli/cli.cpp View File

@@ -0,0 +1,51 @@
1
+#include <stdio.h>
2
+#include <stdlib.h>
3
+//#include <string.h>
4
+#include <linenoise.h>
5
+#include <Python.h>
6
+
7
+int main(int argc, char** argv)
8
+{
9
+    printf("cli test application\n");
10
+
11
+    wchar_t *program = Py_DecodeLocale(argv[0], NULL);
12
+    if (program == NULL) {
13
+        fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
14
+        exit(1);
15
+    }
16
+
17
+    // inform the interpreter about paths to run-time libraries
18
+    Py_SetProgramName(program);  /* optional but recommended */
19
+
20
+
21
+    // Initialize the python interpreter
22
+    Py_Initialize();
23
+
24
+    PyRun_SimpleString("print('Python interpreter ready')\n");
25
+
26
+    const char* prompt = "poi> ";
27
+
28
+    while(true) {
29
+        char *cmd = linenoise(prompt);
30
+
31
+        if(cmd == nullptr || *cmd == '\0') {
32
+            printf("break\n");
33
+            free(cmd);
34
+            break;
35
+        }
36
+
37
+        //printf("echo(%i):'%s'\n", strlen(cmd), cmd);
38
+        PyRun_SimpleString(cmd);
39
+        free(cmd);
40
+    }
41
+
42
+    // finalize the interpreter
43
+    if (Py_FinalizeEx() < 0) {
44
+        exit(120);
45
+    }
46
+
47
+    //
48
+    PyMem_RawFree(program);
49
+
50
+    return 0;
51
+}

+ 4
- 0
src/cli/meson.build View File

@@ -0,0 +1,4 @@
1
+cli_demo = executable('cli', install: false, dependencies: [ optional_deps ],
2
+    sources: [ 'cli.cpp' ]
3
+)
4
+

+ 2
- 2
src/meson.build View File

@@ -1,5 +1,5 @@
1 1
 # poi
2
-poi_moc = qt5.preprocess(
2
+poi_moc = mod_qt5.preprocess(
3 3
     moc_headers: ['browser.h',
4 4
         'mainwindow/mainwindow.h', 'mainwindow/menubar.h', 'mainwindow/widgets/dockwidget.h', 'mainwindow/widgets/menusearch.h', 'mainwindow/widgets/navigationbar.h', 'mainwindow/widgets/searchform.h',
5 5
         'session/savesessiondialog.h', 'session/sessiondialog.h', 'session/sessionform.h',
@@ -13,7 +13,7 @@ poi_moc = qt5.preprocess(
13 13
 
14 14
 poi = executable(get_option('poiName'), install: true,
15 15
     cpp_args: ['-DQAPPLICATION_CLASS=QApplication'],
16
-    dependencies: [dep_qt5, dep_boost, dep_SingleApplication, dep_genheaders, dep_breakpad, dep_plasma, dep_spdlog,
16
+    dependencies: [dep_qt5, dep_boost, dep_spdlog, dep_SingleApplication, dep_genheaders, optional_deps,
17 17
         dep_about, dep_addressbar, dep_bookmarks, dep_configuration, dep_downloads, dep_urlfilter, dep_webprofile],
18 18
     include_directories: [include],
19 19
     sources: ['main.cpp', 'builtins.cpp', 'crashhandler.cpp', poi_moc,

Loading…
Cancel
Save