github.com/hashicorp/go-plugin@v1.6.0/internal/cmdrunner/notes_windows.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  //go:build windows
     5  // +build windows
     6  
     7  package cmdrunner
     8  
     9  import (
    10  	"debug/elf"
    11  	"debug/macho"
    12  	"debug/pe"
    13  	"fmt"
    14  	"os"
    15  	"runtime"
    16  )
    17  
    18  // additionalNotesAboutCommand tries to get additional information about a command that might help diagnose
    19  // why it won't run correctly. It runs as a best effort only.
    20  func additionalNotesAboutCommand(path string) string {
    21  	notes := ""
    22  	stat, err := os.Stat(path)
    23  	if err != nil {
    24  		return notes
    25  	}
    26  
    27  	notes += "\nAdditional notes about plugin:\n"
    28  	notes += fmt.Sprintf("  Path: %s\n", path)
    29  	notes += fmt.Sprintf("  Mode: %s\n", stat.Mode())
    30  
    31  	if elfFile, err := elf.Open(path); err == nil {
    32  		defer elfFile.Close()
    33  		notes += fmt.Sprintf("  ELF architecture: %s (current architecture: %s)\n", elfFile.Machine, runtime.GOARCH)
    34  	} else if machoFile, err := macho.Open(path); err == nil {
    35  		defer machoFile.Close()
    36  		notes += fmt.Sprintf("  MachO architecture: %s (current architecture: %s)\n", machoFile.Cpu, runtime.GOARCH)
    37  	} else if peFile, err := pe.Open(path); err == nil {
    38  		defer peFile.Close()
    39  		machine, ok := peTypes[peFile.Machine]
    40  		if !ok {
    41  			machine = "unknown"
    42  		}
    43  		notes += fmt.Sprintf("  PE architecture: %s (current architecture: %s)\n", machine, runtime.GOARCH)
    44  	}
    45  	return notes
    46  }