Re: Proposal: an addition to glib for getting the absolute path of the current binary.



Enrico Weigelt wrote:
Well, perhaps we should better talk about a generic config and
location management API, maybe as library libgconfig, etc.

Finally we have something to agree on. :)

I talked to a KDE developer. He told me that KDE apps do not use hardcoded paths directly. You won't things like these in KDE apps:
KImage *image = new KImage(DATADIR "/foo.png");

KDE apps use KStandardDirs: http://developer.kde.org/documentation/library/cvs-api/kdecore/html/classKStandardDirs.html
It's a general API for locating files using a list of search paths.

So I'm thinking about this:
Create a set of GSearchDir "class", based on KStandardDirs.
Every application and library will create a new instance of this "class" and register two search paths: 1. The prefix, as dynamically detected at runtime. This is only done for platforms which supports it, like Linux and Win32. This function is called g_search_dir_add_self_prefix() or something. 2. Hardcoded paths, as defined in configure and Makefile.am. g_search_dir_add("data", DATADIR) or something like that.

The values of certain environment variables are automatically added to GSearchDir. I'm thinking about the Freedesktop Basedir environment variables.

This allows apps to locate their own prefix at runtime on platforms which support it, which makes them relocatable. On platforms that do not support it, apps will gracefully fall back to hardcoded paths as defined by configure and Makefile.am at compile time. Also, when the user did something like ./configure --datadir=/somewhere/else, GSearchDir will also fallback to hardcoded paths.


This isn't completely thought out but it should provide a good base for further discussion. What do you think? Is something similar like this a good solution?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]