diff --git a/import-utils.go b/import-utils.go index 78e464b..5755ae5 100644 --- a/import-utils.go +++ b/import-utils.go @@ -76,6 +76,12 @@ func isFile(filePath string) bool { func searchAmongPath(filename string, dirList []string) (filePath string) { var err error + + suffix := SHAREDLIBRARY_EXTENSION + if strings.HasSuffix(filename, ".debug") { + suffix += ".debug" + } + for _, dir := range dirList { if dir, err = ExpandPath(dir); err != nil { continue @@ -84,6 +90,12 @@ func searchAmongPath(filename string, dirList []string) (filePath string) { filePath = fullPath break } + + subdir := strings.TrimSuffix(filename, suffix) + if fullPath := path.Join(dir, subdir, filename); isFile(fullPath) { + filePath = fullPath + break + } } return } diff --git a/lib-ext-darwin.go b/lib-ext-darwin.go new file mode 100644 index 0000000..dcf4bd8 --- /dev/null +++ b/lib-ext-darwin.go @@ -0,0 +1,9 @@ +//go:build darwin + +// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com). +// All rights reserved. + +// lib-ext-darwin.go +package expr + +const SHAREDLIBRARY_EXTENSION = ".dylib" diff --git a/lib-ext-linux.go b/lib-ext-linux.go new file mode 100644 index 0000000..3249a98 --- /dev/null +++ b/lib-ext-linux.go @@ -0,0 +1,9 @@ +//go:build linux + +// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com). +// All rights reserved. + +// lib-ext-linux.go +package expr + +const SHAREDLIBRARY_EXTENSION = ".so" diff --git a/lib-ext-windows.go b/lib-ext-windows.go new file mode 100644 index 0000000..7415aec --- /dev/null +++ b/lib-ext-windows.go @@ -0,0 +1,9 @@ +//go:build windows + +// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com). +// All rights reserved. + +// lib-ext-windows.go +package expr + +const SHAREDLIBRARY_EXTENSION = ".dll" diff --git a/plugins.go b/plugins.go index 385da52..f7bf85d 100644 --- a/plugins.go +++ b/plugins.go @@ -31,11 +31,11 @@ func pluginExists(name string) (exists bool) { func makePluginName(name string) (decorated string) { var template string if execName, err := os.Executable(); err != nil || !strings.Contains(execName, "debug") { - template = "expr-%s-plugin.so" + template = "expr-%s-plugin%s" } else { - template = "expr-%s-plugin.so.debug" + template = "expr-%s-plugin%s.debug" } - decorated = fmt.Sprintf(template, name) + decorated = fmt.Sprintf(template, name, SHAREDLIBRARY_EXTENSION) return } diff --git a/t_plugin_test.go b/t_plugin_test.go index 18748c7..f622199 100644 --- a/t_plugin_test.go +++ b/t_plugin_test.go @@ -5,6 +5,7 @@ package expr import ( + "os" "testing" ) @@ -36,3 +37,23 @@ func TestMakePluginName(t *testing.T) { t.Errorf("makePluginName(%q) failed: Got: %q, Want: %q", name, got, want) } } + +func TestLoadPluginName(t *testing.T) { + name := "json" + // want := "expr-" + name + "-plugin.so" + want := 1 + + os.Setenv("PLUGINS", "${HOME}/go/src/git.portale-stac.it/go") + // os.Setenv("EXPR_PLUGIN_PATH", "${PLUGINS}/expr-json-plugin:${PLUGINS}/expr-csv-plugin") + os.Setenv("EXPR_PLUGIN_PATH", "${PLUGINS}") + got, err := importPluginFromSearchPath(name) + + if err != nil { + t.Errorf("importPluginFromSearchPath(%q) failed: %v", name, err) + return + } + + if got != want { + t.Errorf("importPluginFromSearchPath(%q) failed: Got: %q, Want: %q", name, got, want) + } +}