Finding asset files, when developing & when installed (C++/Python, primarily on Linux) -
my project has global asset directory (/usr/share/openage
) contains various files (graphics, texts, ...) , user-specific asset directory (~/.openage
) allows user overwrite of global assets/add own.
it understanding when building, pass install prefix build scheme (e.g. ./configure --install-prefix=/usr
), in turn generate file (e.g. configure.h
) makes install prefix available code (e.g. #define install_prefix="/usr"
). code assets in install_prefix "share/openage"
. far, good.
however, when project hasn't been installed yet (which true in 99.9% of cases me developer), directory /usr/share/openage
doesn't exist yet; instead, want utilize ./assets
in current directory. worse, if installed directory exists (e.g. independent, before install), might info incompatible current dev version.
similarily, if running installed project, i'd want utilize user's home directory (~/.openage
) user asset directory, while in "devmode", should utilize directory "./userassets".
it gets worse when thinking non-posix platforms. on windows, install_prefix
useless since programs can installed anywhere (do programs utilize current working directory or asset directory?), , don't have slightest thought how mac handles this.
so question is: there accepted "best way this"? surely, hundreds of projects (basically every single project has asset directory) have dealt problem 1 way or on other.
unfortunately, don't know google for. don't know how tag question. current ideas (and associated issues) include:
looking fileopenage_version
, exists in source directory, in cwd
. if exists, assume project uninstalled. issue: in "development mode", cwd
might not project root directory. checking whether readlink("/proc/self/exe")
starts install_prefix
issue: platform-specific issue: theoretically, project root directory in /usr/myweirdhomedirectory/git/openage
forcing developers specify argument --not-installed
, or set environment variable, openage_installed=0
issue: inconvenient issue: forgetting specify argument lead confusion when wrong asset directory used during development, phone call ./configure
different install_prefix
issue: when project built installing, recommended make test
run tests while project not installed a combination of first 2 options: checking dirname(readlink("proc/self/exe")) + "/openage_version"
issue: more platform-specific this seems robust alternative far
the solution chose decision in python part of application.
there python module, buildsystem.setup
, not installed during make install
.
using fact, can simply
def is_in_devmode(): try: import ..buildsystem.setup homecoming true except importerror: homecoming false
python c++ installation assets search-path
No comments:
Post a Comment