From fa79b81d5b62fcac0035c05bbb60a0460231a310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 26 Jul 2022 17:25:31 +0200 Subject: [PATCH] Blender Finder: support multi-line output of `blender --version` When compiled without OpenColorIO, Blender will first complain "Color management: Error could not find role data role." before showing the actual version number. This is now handled by looking for a "Blender " prefix instead of just returning the first line of output. This has as a side-effect that when no such line can be found, we know it's not Blender, and thus an error can be returned (instead of the version of whatever binary was being run). --- internal/find_blender/find_blender.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/find_blender/find_blender.go b/internal/find_blender/find_blender.go index 2d8d141a..3f92667a 100644 --- a/internal/find_blender/find_blender.go +++ b/internal/find_blender/find_blender.go @@ -15,7 +15,10 @@ import ( "github.com/rs/zerolog/log" ) -var ErrNotAvailable = errors.New("not available on this platform") +var ( + ErrNotAvailable = errors.New("not available on this platform") + ErrNotBlender = errors.New("not a Blender executable") +) // blenderVersionTimeout is how long `blender --version` is allowed to take, // before timing out. This can be much slower than expected, when loading @@ -104,10 +107,12 @@ func getBlenderVersion(ctx context.Context, commandline string) (string, error) } version := string(stdoutStderr) - lines := strings.SplitN(version, "\n", 2) - if len(lines) > 0 { - version = lines[0] + lines := strings.Split(version, "\n") + for idx := range lines { + line := strings.TrimSpace(lines[idx]) + if strings.HasPrefix(line, "Blender ") { + return line, nil + } } - - return strings.TrimSpace(version), nil + return "", fmt.Errorf("%s: %w", commandline, ErrNotBlender) }