Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

packer: fix listing on windows with .exe ext #12981

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions command/plugins_required.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
9 changes: 7 additions & 2 deletions packer/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"log"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"runtime"
Expand Down Expand Up @@ -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{
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions packer/plugin_folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down