diff options
| author | John Drinkwater <john@nextraweb.com> | 2016-08-01 17:00:00 +0100 |
|---|---|---|
| committer | Mark Young <marky@lunarg.com> | 2016-08-04 07:39:03 -0600 |
| commit | 3e58ec2944344cdbd90ef54cb9e2a2e83dc061a6 (patch) | |
| tree | df0f6a9ea10902bb7e2c060f69c139ddfde10743 /loader | |
| parent | 7adce38b9fdc72d67105554235faecc2ef075be3 (diff) | |
| download | usermoji-3e58ec2944344cdbd90ef54cb9e2a2e83dc061a6.tar.xz | |
loader: support manifests in XDG locations
Some users set the environment variable XDG_DATA_HOME to relocate
~/.local/share/ to a more friendly location and so it is not wise to
look solely at that location.
This change adds basic support for that env var without changing the
behaviour for typical users. If XDG_DATA_HOME is defined, the loader
checks XDG_DATA_HOME/vulkan/..., if HOME is defined the loader will
check HOME/.local/share/vulkan/..., and with neither it skips looking
for user manifests.
loader_get_manifest_files() now takes a relative location inside the
config path eg `/vulkan/implicit_layer.d` and appends that onto the
preferred location.
vk_loader_platform.h Linux defines got minor adjustments to support this
change, with an added bonus of being more readable.
Change-Id: I44e8a99f2a984f94dc33cdda122e6c417d3a3653
Diffstat (limited to 'loader')
| -rw-r--r-- | loader/loader.c | 58 | ||||
| -rw-r--r-- | loader/vk_loader_platform.h | 61 |
2 files changed, 71 insertions, 48 deletions
diff --git a/loader/loader.c b/loader/loader.c index d0cdc00b..6b228935 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -2492,8 +2492,9 @@ loader_add_layer_properties(const struct loader_instance *inst, * location is used to look for manifest files. The location * is interpreted as Registry path on Windows and a directory path(s) * on Linux. "home_location" is an additional directory in the users home - * directory to look at. It is exapanded into the dir path $HOME/home_location. - * This "home_location" is only used on Linux. + * directory to look at. It is expanded into the dir path + * $XDG_DATA_HOME/home_location or $HOME/.local/share/home_location depending + * on environment variables. This "home_location" is only used on Linux. * * \returns * VKResult @@ -2707,10 +2708,11 @@ static VkResult loader_get_manifest_files( #if !defined(_WIN32) if (home_location != NULL && (next_file == NULL || *next_file == '\0') && override == NULL) { - char *home = secure_getenv("HOME"); - if (home != NULL) { - size_t len; - char *home_loc = loader_stack_alloc(strlen(home) + 2 + + char *xdgdatahome = secure_getenv("XDG_DATA_HOME"); + size_t len; + if (xdgdatahome != NULL) { + + char *home_loc = loader_stack_alloc(strlen(xdgdatahome) + 2 + strlen(home_location)); if (home_loc == NULL) { loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, @@ -2718,7 +2720,7 @@ static VkResult loader_get_manifest_files( res = VK_ERROR_OUT_OF_HOST_MEMORY; goto out; } - strcpy(home_loc, home); + strcpy(home_loc, xdgdatahome); // Add directory separator if needed if (home_location[0] != DIRECTORY_SYMBOL) { len = strlen(home_loc); @@ -2732,9 +2734,49 @@ static VkResult loader_get_manifest_files( loader_log( inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, - "Searching the following paths for manifest files: %s\n", + "Searching the following path for manifest files: %s\n", home_loc); list_is_dirs = true; + + } else { + + char *home = secure_getenv("HOME"); + if (home != NULL) { + char *home_loc = loader_stack_alloc(strlen(home) + 16 + + strlen(home_location)); + if (home_loc == NULL) { + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, + "Out of memory can't get manifest files"); + res = VK_ERROR_OUT_OF_HOST_MEMORY; + goto out; + } + strcpy(home_loc, home); + + len = strlen(home); + if (home[len] != DIRECTORY_SYMBOL) { + home_loc[len] = DIRECTORY_SYMBOL; + home_loc[len + 1] = '\0'; + } + strcat(home_loc, ".local/share"); + + if (home_location[0] != DIRECTORY_SYMBOL) { + len = strlen(home_loc); + home_loc[len] = DIRECTORY_SYMBOL; + home_loc[len + 1] = '\0'; + } + strcat(home_loc, home_location); + file = home_loc; + next_file = loader_get_next_path(file); + home_location = NULL; + + loader_log( + inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, + "Searching the following path for manifest files: %s\n", + home_loc); + list_is_dirs = true; + } else { + // without knowing HOME, we just.. give up + } } } #endif diff --git a/loader/vk_loader_platform.h b/loader/vk_loader_platform.h index d1318539..3a026404 100644 --- a/loader/vk_loader_platform.h +++ b/loader/vk_loader_platform.h @@ -50,42 +50,23 @@ #define PATH_SEPERATOR ':' #define DIRECTORY_SYMBOL '/' -#define VULKAN_ICDCONF_DIR \ - "/" \ - "vulkan" \ - "/" \ - "icd.d" -#define VULKAN_ICD_DIR \ - "/" \ - "vulkan" \ - "/" \ - "icd" -#define VULKAN_ELAYERCONF_DIR \ - "/" \ - "vulkan" \ - "/" \ - "explicit_layer.d" -#define VULKAN_ILAYERCONF_DIR \ - "/" \ - "vulkan" \ - "/" \ - "implicit_layer.d" -#define VULKAN_LAYER_DIR \ - "/" \ - "vulkan" \ - "/" \ - "layer" +#define VULKAN_DIR "/vulkan/" +#define VULKAN_ICDCONF_DIR "icd.d" +#define VULKAN_ICD_DIR "icd" +#define VULKAN_ELAYERCONF_DIR "explicit_layer.d" +#define VULKAN_ILAYERCONF_DIR "implicit_layer.d" +#define VULKAN_LAYER_DIR "layer" #if defined(LOCALPREFIX) #define LOCAL_DRIVERS_INFO \ - LOCALPREFIX "/" SYSCONFDIR VULKAN_ICDCONF_DIR ":" LOCALPREFIX \ - "/" DATADIR VULKAN_ICDCONF_DIR ":" + LOCALPREFIX "/" SYSCONFDIR VULKAN_DIR VULKAN_ICDCONF_DIR ":" \ + LOCALPREFIX "/" DATADIR VULKAN_DIR VULKAN_ICDCONF_DIR ":" #define LOCAL_ELAYERS_INFO \ - LOCALPREFIX "/" SYSCONFDIR VULKAN_ELAYERCONF_DIR ":" LOCALPREFIX \ - "/" DATADIR VULKAN_ELAYERCONF_DIR ":" + LOCALPREFIX "/" SYSCONFDIR VULKAN_DIR VULKAN_ELAYERCONF_DIR ":" \ + LOCALPREFIX "/" DATADIR VULKAN_DIR VULKAN_ELAYERCONF_DIR ":" #define LOCAL_ILAYERS_INFO \ - LOCALPREFIX "/" SYSCONFDIR VULKAN_ILAYERCONF_DIR ":" LOCALPREFIX \ - "/" DATADIR VULKAN_ILAYERCONF_DIR ":" + LOCALPREFIX "/" SYSCONFDIR VULKAN_DIR VULKAN_ILAYERCONF_DIR ":" \ + LOCALPREFIX "/" DATADIR VULKAN_DIR VULKAN_ILAYERCONF_DIR ":" #else #define LOCAL_DRIVERS_INFO #define LOCAL_ELAYERS_INFO @@ -94,25 +75,25 @@ #define DEFAULT_VK_DRIVERS_INFO \ LOCAL_DRIVERS_INFO \ - "/" SYSCONFDIR VULKAN_ICDCONF_DIR ":" \ - "/usr/" DATADIR VULKAN_ICDCONF_DIR + "/" SYSCONFDIR VULKAN_DIR VULKAN_ICDCONF_DIR ":" \ + "/usr/" DATADIR VULKAN_DIR VULKAN_ICDCONF_DIR #define DEFAULT_VK_DRIVERS_PATH "" #define DEFAULT_VK_ELAYERS_INFO \ LOCAL_ELAYERS_INFO \ - "/" SYSCONFDIR VULKAN_ELAYERCONF_DIR ":" \ - "/usr/" DATADIR VULKAN_ELAYERCONF_DIR + "/" SYSCONFDIR VULKAN_DIR VULKAN_ELAYERCONF_DIR ":" \ + "/usr/" DATADIR VULKAN_DIR VULKAN_ELAYERCONF_DIR #define DEFAULT_VK_ILAYERS_INFO \ LOCAL_ILAYERS_INFO \ - "/" SYSCONFDIR VULKAN_ILAYERCONF_DIR ":" \ - "/usr/" DATADIR VULKAN_ILAYERCONF_DIR + "/" SYSCONFDIR VULKAN_DIR VULKAN_ILAYERCONF_DIR ":" \ + "/usr/" DATADIR VULKAN_DIR VULKAN_ILAYERCONF_DIR #define DEFAULT_VK_LAYERS_PATH "" #if !defined(LAYERS_SOURCE_PATH) #define LAYERS_SOURCE_PATH NULL #endif #define LAYERS_PATH_ENV "VK_LAYER_PATH" -#define HOME_VK_DRIVERS_INFO "/.local/share" VULKAN_ICDCONF_DIR -#define HOME_VK_ELAYERS_INFO "/.local/share" VULKAN_ELAYERCONF_DIR -#define HOME_VK_ILAYERS_INFO "/.local/share" VULKAN_ILAYERCONF_DIR +#define HOME_VK_DRIVERS_INFO VULKAN_DIR VULKAN_ICDCONF_DIR +#define HOME_VK_ELAYERS_INFO VULKAN_DIR VULKAN_ELAYERCONF_DIR +#define HOME_VK_ILAYERS_INFO VULKAN_DIR VULKAN_ILAYERCONF_DIR // C99: #define PRINTF_SIZE_T_SPECIFIER "%zu" |
