Worker: check BLENDER_CMD environment variable (for multi-GPU Eevee rendering) #104193
@ -50,6 +50,11 @@ func FileAssociation() (string, error) {
|
||||
return fileAssociation()
|
||||
}
|
||||
|
||||
// EnvironmentVariable returns the content of the BLENDER_CMD environment variable.
|
||||
func EnvironmentVariable() string {
|
||||
return os.Getenv("BLENDER_CMD")
|
||||
}
|
||||
|
||||
func CheckBlender(ctx context.Context, exename string) (CheckBlenderResult, error) {
|
||||
if exename == "" {
|
||||
// exename is not given, see if we can use .blend file association.
|
||||
|
@ -5,6 +5,7 @@ package find_blender
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
@ -41,3 +42,20 @@ func TestGetBlenderVersion(t *testing.T) {
|
||||
assert.ErrorIs(t, err, exec.ErrNotFound)
|
||||
assert.Empty(t, version)
|
||||
}
|
||||
|
||||
func TestGetBlenderCommandFromEnvironment(t *testing.T) {
|
||||
|
||||
// Without environment variable, we expect an empty string
|
||||
path := EnvironmentVariable()
|
||||
assert.Equal(t, "", path)
|
||||
|
||||
// Try finding the blender path in the BLENDER_CMD environment variable
|
||||
err := os.Setenv("BLENDER_CMD", "/path/specified/in/env/to/blender")
|
||||
if err != nil {
|
||||
t.Fatal("Could not set BLENDER_CMD environment variable")
|
||||
}
|
||||
|
||||
path = EnvironmentVariable()
|
||||
assert.Equal(t, "/path/specified/in/env/to/blender", path)
|
||||
|
||||
}
|
||||
|
@ -85,9 +85,12 @@ func (ce *CommandExecutor) cmdBlenderRenderCommand(
|
||||
}
|
||||
|
||||
if crosspath.Dir(parameters.exe) == "." {
|
||||
// No directory path given. Check that the executable can be found on the
|
||||
// path.
|
||||
if _, err := exec.LookPath(parameters.exe); err != nil {
|
||||
// No directory path given. Check that the executable can be found in the
|
||||
// environment variable BLENDER_CMD or on the path.
|
||||
if path := find_blender.EnvironmentVariable(); path != "" {
|
||||
logger.Info().Str("path", path).Msg("found Blender in environment")
|
||||
parameters.exe = path
|
||||
} else if _, err := exec.LookPath(parameters.exe); err != nil {
|
||||
// Attempt a platform-specific way to find which Blender executable to
|
||||
// use. If Blender cannot not be found, just use the configured command
|
||||
// and let the OS produce the errors.
|
||||
|
@ -2,6 +2,7 @@ package worker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
@ -79,6 +80,41 @@ func TestCmdBlenderCliArgsInExeParameter(t *testing.T) {
|
||||
assert.Equal(t, ErrNoExecCmd, err, "nil *exec.Cmd should result in ErrNoExecCmd")
|
||||
}
|
||||
|
||||
func TestCmdBlenderFromEnvironment(t *testing.T) {
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
ce, mocks := testCommandExecutor(t, mockCtrl)
|
||||
|
||||
envExe := `D:\Blender_3.2_stable\blender.exe`
|
||||
|
||||
// This should use blender.exe from the BLENDER_CMD environment variable
|
||||
err := os.Setenv("BLENDER_CMD", envExe)
|
||||
if err != nil {
|
||||
t.Fatal("Could not set BLENDER_CMD environment variable")
|
||||
}
|
||||
|
||||
taskID := "c5dfdfab-4492-4ab1-9b38-8ca4cbd84a17"
|
||||
cmd := api.Command{
|
||||
Name: "blender",
|
||||
Parameters: map[string]interface{}{
|
||||
// Passing "blender", the environment path should override this
|
||||
"exe": "blender",
|
||||
"argsBefore": []string{},
|
||||
"blendfile": "file.blend",
|
||||
"args": []string{},
|
||||
},
|
||||
}
|
||||
|
||||
mocks.cli.EXPECT().CommandContext(gomock.Any(),
|
||||
envExe, // from environment variable
|
||||
"file.blend", // from 'blendfile'
|
||||
).Return(nil)
|
||||
|
||||
err = ce.cmdBlenderRender(context.Background(), zerolog.Nop(), taskID, cmd)
|
||||
assert.Equal(t, ErrNoExecCmd, err, "nil *exec.Cmd should result in ErrNoExecCmd")
|
||||
}
|
||||
|
||||
func TestProcessLineBlender(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockCtrl := gomock.NewController(t)
|
||||
|
Loading…
Reference in New Issue
Block a user