diff --git a/command/plugins_required.go b/command/plugins_required.go index 7ba301dcfcf..2fcaf60f384 100644 --- a/command/plugins_required.go +++ b/command/plugins_required.go @@ -83,11 +83,16 @@ func (c *PluginsRequiredCommand) RunContext(buildCtx context.Context, cla *Plugi return ret } + ext := "" + if runtime.GOOS == "windows" { + ext = ".exe" + } opts := plugingetter.ListInstallationsOptions{ PluginDirectory: c.Meta.CoreConfig.Components.PluginConfig.PluginDirectory, BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{ OS: runtime.GOOS, ARCH: runtime.GOARCH, + Ext: ext, APIVersionMajor: pluginsdk.APIVersionMajor, APIVersionMinor: pluginsdk.APIVersionMinor, Checksummers: []plugingetter.Checksummer{ diff --git a/packer/plugin.go b/packer/plugin.go index 72549a03d0b..5939d6aa6ab 100644 --- a/packer/plugin.go +++ b/packer/plugin.go @@ -9,7 +9,6 @@ import ( "log" "os" "os/exec" - "path" "path/filepath" "regexp" "runtime" @@ -75,11 +74,17 @@ func (c *PluginConfig) Discover() error { c.PluginDirectory, _ = PluginFolder() } + ext := "" + if runtime.GOOS == "windows" { + ext = ".exe" + } + installations, err := plugingetter.Requirement{}.ListInstallations(plugingetter.ListInstallationsOptions{ PluginDirectory: c.PluginDirectory, BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{ OS: runtime.GOOS, ARCH: runtime.GOARCH, + Ext: ext, APIVersionMajor: pluginsdk.APIVersionMajor, APIVersionMinor: pluginsdk.APIVersionMinor, Checksummers: []plugingetter.Checksummer{ @@ -97,7 +102,7 @@ func (c *PluginConfig) Discover() error { // We'll use that later to register the components for each plugin pluginMap := map[string]string{} for _, install := range installations { - pluginBasename := path.Base(install.BinaryPath) + pluginBasename := filepath.Base(install.BinaryPath) matches := extractPluginBasename.FindStringSubmatch(pluginBasename) if len(matches) != 2 { log.Printf("[INFO] - plugin %q could not have its name matched, ignoring", pluginBasename) diff --git a/packer/plugin_folders.go b/packer/plugin_folders.go index 09683d5f0bb..c7c1febd46c 100644 --- a/packer/plugin_folders.go +++ b/packer/plugin_folders.go @@ -13,13 +13,15 @@ import ( "github.com/hashicorp/packer-plugin-sdk/pathing" ) +var pathSep = fmt.Sprintf("%c", os.PathListSeparator) + // PluginFolder returns the known plugin folder based on system. func PluginFolder() (string, error) { if packerPluginPath := os.Getenv("PACKER_PLUGIN_PATH"); packerPluginPath != "" { - if strings.ContainsRune(packerPluginPath, os.PathListSeparator) { + if strings.Contains(packerPluginPath, pathSep) { return "", fmt.Errorf("Multiple paths are no longer supported for PACKER_PLUGIN_PATH.\n"+ "This should be defined as one of the following options for your environment:"+ - "\n* PACKER_PLUGIN_PATH=%v", strings.Join(strings.Split(packerPluginPath, ":"), "\n* PACKER_PLUGIN_PATH=")) + "\n* PACKER_PLUGIN_PATH=%v", strings.Join(strings.Split(packerPluginPath, pathSep), "\n* PACKER_PLUGIN_PATH=")) } return packerPluginPath, nil