Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/appdir.c')
-rw-r--r--source/blender/blenkernel/intern/appdir.c65
1 files changed, 40 insertions, 25 deletions
diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c
index c19afdb4fb8..f4dec0aecd7 100644
--- a/source/blender/blenkernel/intern/appdir.c
+++ b/source/blender/blenkernel/intern/appdir.c
@@ -374,7 +374,7 @@ static bool get_path_local_ex(char *targetpath,
/* Try `{g_app.program_dirname}/2.xx/{folder_name}` the default directory
* for a portable distribution. See `WITH_INSTALL_PORTABLE` build-option. */
const char *path_base = g_app.program_dirname;
-#ifdef __APPLE__
+#if defined(__APPLE__) && !defined(WITH_PYTHON_MODULE)
/* Due new code-sign situation in OSX > 10.9.5
* we must move the blender_version dir with contents to Resources. */
char osx_resourses[FILE_MAX];
@@ -782,6 +782,7 @@ const char *BKE_appdir_folder_id_version(const int folder_id,
* Access locations of Blender & Python.
* \{ */
+#ifndef WITH_PYTHON_MODULE
/**
* Checks if name is a fully qualified filename to an executable.
* If not it searches `$PATH` for the file. On Windows it also
@@ -794,11 +795,11 @@ const char *BKE_appdir_folder_id_version(const int folder_id,
* (must be #FILE_MAX minimum)
* \param name: The name of the executable (usually `argv[0]`) to be checked
*/
-static void where_am_i(char *fullname, const size_t maxlen, const char *name, const bool strict)
+static void where_am_i(char *fullname, const size_t maxlen, const char *name)
{
-#ifdef WITH_BINRELOC
+# ifdef WITH_BINRELOC
/* Linux uses `binreloc` since `argv[0]` is not reliable, call `br_init(NULL)` first. */
- if (!strict) {
+ {
const char *path = NULL;
path = br_find_exe(NULL);
if (path) {
@@ -807,10 +808,10 @@ static void where_am_i(char *fullname, const size_t maxlen, const char *name, co
return;
}
}
-#endif
+# endif
-#ifdef _WIN32
- if (!strict) {
+# ifdef _WIN32
+ {
wchar_t *fullname_16 = MEM_mallocN(maxlen * sizeof(wchar_t), "ProgramPath");
if (GetModuleFileNameW(0, fullname_16, maxlen)) {
conv_utf_16_to_8(fullname_16, fullname, maxlen);
@@ -825,7 +826,7 @@ static void where_am_i(char *fullname, const size_t maxlen, const char *name, co
MEM_freeN(fullname_16);
}
-#endif
+# endif
/* Unix and non Linux. */
if (name && name[0]) {
@@ -833,46 +834,60 @@ static void where_am_i(char *fullname, const size_t maxlen, const char *name, co
BLI_strncpy(fullname, name, maxlen);
if (name[0] == '.') {
BLI_path_abs_from_cwd(fullname, maxlen);
-#ifdef _WIN32
- if (!strict) {
- BLI_path_program_extensions_add_win32(fullname, maxlen);
- }
-#endif
+# ifdef _WIN32
+ BLI_path_program_extensions_add_win32(fullname, maxlen);
+# endif
}
else if (BLI_path_slash_rfind(name)) {
/* Full path. */
BLI_strncpy(fullname, name, maxlen);
-#ifdef _WIN32
- if (!strict) {
- BLI_path_program_extensions_add_win32(fullname, maxlen);
- }
-#endif
+# ifdef _WIN32
+ BLI_path_program_extensions_add_win32(fullname, maxlen);
+# endif
}
else {
- if (!strict) {
- BLI_path_program_search(fullname, maxlen, name);
- }
+ BLI_path_program_search(fullname, maxlen, name);
}
/* Remove "/./" and "/../" so string comparisons can be used on the path. */
BLI_path_normalize(NULL, fullname);
-#if defined(DEBUG)
+# if defined(DEBUG)
if (!STREQ(name, fullname)) {
CLOG_INFO(&LOG, 2, "guessing '%s' == '%s'", name, fullname);
}
-#endif
+# endif
}
}
+#endif /* WITH_PYTHON_MODULE */
-void BKE_appdir_program_path_init(const char *argv0, const bool strict)
+void BKE_appdir_program_path_init(const char *argv0)
{
- where_am_i(g_app.program_filepath, sizeof(g_app.program_filepath), argv0, strict);
+#ifdef WITH_PYTHON_MODULE
+ /* NOTE(@campbellbarton): Always use `argv[0]` as is, when building as a Python module.
+ * Otherwise other methods of detecting the binary that override this argument
+ * which must point to the Python module for data-files to be detected. */
+ STRNCPY(g_app.program_filepath, argv0);
+ BLI_path_abs_from_cwd(g_app.program_filepath, sizeof(g_app.program_filepath));
+ BLI_path_normalize(NULL, g_app.program_filepath);
+
+ if (g_app.program_dirname[0] == '\0') {
+ /* First time initializing, the file binary path isn't valid from a Python module.
+ * Calling again must set the `filepath` and leave the directory as-is. */
+ BLI_split_dir_part(
+ g_app.program_filepath, g_app.program_dirname, sizeof(g_app.program_dirname));
+ g_app.program_filepath[0] = '\0';
+ }
+#else
+ where_am_i(g_app.program_filepath, sizeof(g_app.program_filepath), argv0);
BLI_split_dir_part(g_app.program_filepath, g_app.program_dirname, sizeof(g_app.program_dirname));
+#endif
}
const char *BKE_appdir_program_path(void)
{
+#ifndef WITH_PYTHON_MODULE /* Default's to empty when building as as Python module. */
BLI_assert(g_app.program_filepath[0]);
+#endif
return g_app.program_filepath;
}