GNOME Bugzilla – Bug 667937
allow creating schema source from resource
Last modified: 2018-05-24 13:40:49 UTC
It should be possible to put a gschemas.compiled into a resource and use that to create a schema source.
Created attachment 205280 [details] [review] settings: Plug resources into schema settings Add g_settings_schema_source_new_from_resource(). Bug #667937.
this is potentially evil due to the fact that it breaks the tools (editor, commandline)
IMHO that's not a blocker, since it would still be allowed to install the schema files to the usual paths for the tools to find, or those tools could just gain an option to take a executable and a resource path, and load the resources from it.
I can see how this could be usable. However, i think we need to make sure we know the full story of resources vs gsettings schemas before we put this in. BTW. Its not *impossible* for e.g. dconf to access the build in schema file, at least on Linux. For instance you can use: objcopy -j .gresource._gtk -Obinary libgtk-3.so gtk.gresource To extract the gtk resources from the elf section, and you can then load the binary using g_resource_load() and access the schema. In fact, with some minimal elf support you could probably mmap the library file, look up the .gresource.* section size and offsets in the elf header, and then directly g_resource_new_from_data() that region. If this was supported then one could add a file in $datadir/glib-2.0/schemas/ pointing out the .so and the resource section name and the resource path.
Created attachment 205436 [details] Example code to read resources from elf files Here is an example of how to extract resources from an ELF file. Compile it with: gcc `pkg-config --libs --cflags gio-2.0` -lelf dump-elf-resource.c -o dump-elf-resource Then you can do e.g: ./dump-elf-resource libgtk-3.so _gtk /org/gtk/libgtk/gtk-default.css to print the default gtk+ css
Note, we should probably strip any initial underscores from the c_name when generating the resource name.
Pushed a fix for the initial underscore to glib, so with that you need to use ./dump-elf-resource libgtk-3.so gtk /org/gtk/libgtk/gtk-default.css instead.
Ryan: how about a g_settings_schema_source_new_from_data() then that just takes the raw data instead of the resource path? I can implement the new_from_resource as a tiny wrapper around that, but I can't do a new_from_data outside glib because I don't have access to gvdb from outside.
Created attachment 205975 [details] [review] settings: Plug resources into schema settings Add g_settings_schema_source_new_from_data(). This will allow to uses resources to create the schema source. Bug #667937.
I actually prefer the one that works from the resource. I'd like to make sure that we first have a complete story about accessing schemas from resources inside of other people's binaries (for the sake of the gsettings commandline tool and dconf-editor).
Since the 'complete story' is unlikely to spontaneously emerge after > 4 years of this bug, can we just have the tiny function from attachment 205280 [details] [review] ? It'd be really useful to be able to embed the schema into the executable, no more asserts from mismatch with the installed schema (on key additions, for example). IMHO the 'complete story' is just corner cases (lockdown, overrides), and not that important (to me at least).
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/499.