Swap priority of system path overrides for dev builds
authorJulian Eisel <eiseljulian@gmail.com>
Sun, 19 Nov 2017 11:24:12 +0000 (12:24 +0100)
committerJulian Eisel <eiseljulian@gmail.com>
Sun, 19 Nov 2017 12:13:37 +0000 (13:13 +0100)
Suggested by Campbell, thanks!

Also moved the exception into own function and improved comments.

Fixes T53008.

source/blender/blenkernel/intern/appdir.c

index 6dd852c78758f15a5f463ea64b5d726ae76e0ebc..8d4776dca0ee152481f9b991bc785a1e9b6f33ad 100644 (file)
@@ -289,6 +289,33 @@ static bool get_path_user(
        }
 }
 
+/**
+ * Special convenience exception for dev builds to allow overrides to the system path.
+ * With this, need for running 'make install' can be avoided, e.g. by symlinking SOURCE_DIR/release
+ * to EXECUTABLE_DIR/release, or by running Blender from source directory directly.
+ */
+static bool get_path_system_dev_build_exception(
+        char *targetpath, size_t targetpath_len, const char *relfolder)
+{
+       char cwd[FILE_MAX];
+
+       /* Try EXECUTABLE_DIR/release/folder_name. Allows symlinking release folder from source dir. */
+       if (test_path(targetpath, targetpath_len, bprogdir, "release", relfolder)) {
+               return true;
+       }
+       /* Try CWD/release/folder_name. Allows executing Blender from any directory
+        * (usually source dir), even without a release dir in bprogdir. */
+       if (BLI_current_working_dir(cwd, sizeof(cwd))) {
+               if (test_path(targetpath, targetpath_len, cwd, "release", relfolder)) {
+                       return true;
+               }
+       }
+       /* never use if not existing. */
+       targetpath[0] = '\0';
+
+       return false;
+}
+
 /**
  * Returns the path of a folder within the Blender installation directory.
  *
@@ -305,7 +332,6 @@ static bool get_path_system(
 {
        char system_path[FILE_MAX];
        const char *system_base_path;
-       char cwd[FILE_MAX];
        char relfolder[FILE_MAX];
 
        if (folder_name) {
@@ -320,25 +346,9 @@ static bool get_path_system(
                relfolder[0] = '\0';
        }
 
-       /* first allow developer only overrides to the system path
-        * these are only used when running blender from source */
-
-       /* try CWD/release/folder_name */
-       if (BLI_current_working_dir(cwd, sizeof(cwd))) {
-               if (test_path(targetpath, targetpath_len, cwd, "release", relfolder)) {
-                       return true;
-               }
-       }
-       /* try EXECUTABLE_DIR/release/folder_name */
-       if (test_path(targetpath, targetpath_len, bprogdir, "release", relfolder)) {
+       if (get_path_system_dev_build_exception(targetpath, targetpath_len, relfolder)) {
                return true;
        }
-       /* never use if not existing. */
-       targetpath[0] = '\0';
-
-       /* end developer overrides */
-
-
 
        system_path[0] = '\0';