From e718d2544f6c719bc6e31f569400f44d54de3a34 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Tue, 17 Jul 2018 18:47:05 -0400 Subject: MM-11366: support a plugin bundle with multiple executables (#9121) This avoids the need to distribute multiple plugins per architecture. --- model/manifest.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'model/manifest.go') diff --git a/model/manifest.go b/model/manifest.go index d494df466..6a3b0bfad 100644 --- a/model/manifest.go +++ b/model/manifest.go @@ -120,13 +120,30 @@ type Manifest struct { } type ManifestBackend struct { - // The path to your executable binary. This should be relative to the root of your bundle and the - // location of the manifest file. + // Executables are the paths to your executable binaries, specifying multiple entry points + // for different platforms when bundled together in a single plugin. + Executables *ManifestExecutables `json:"executables,omitempty" yaml:"executables,omitempty"` + + // Executable is the path to your executable binary. This should be relative to the root + // of your bundle and the location of the manifest file. // // On Windows, this file must have a ".exe" extension. + // + // If your plugin is compiled for multiple platforms, consider bundling them together + // and using the Executables field instead. Executable string `json:"executable" yaml:"executable"` } +type ManifestExecutables struct { + // LinuxAmd64 is the path to your executable binary for the corresponding platform + LinuxAmd64 string `json:"linux-amd64,omitempty" yaml:"linux-amd64,omitempty"` + // DarwinAmd64 is the path to your executable binary for the corresponding platform + DarwinAmd64 string `json:"darwin-amd64,omitempty" yaml:"darwin-amd64,omitempty"` + // WindowsAmd64 is the path to your executable binary for the corresponding platform + // This file must have a ".exe" extension + WindowsAmd64 string `json:"windows-amd64,omitempty" yaml:"windows-amd64,omitempty"` +} + type ManifestWebapp struct { // The path to your webapp bundle. This should be relative to the root of your bundle and the // location of the manifest file. @@ -173,6 +190,34 @@ func (m *Manifest) ClientManifest() *Manifest { return cm } +// GetExecutableForRuntime returns the path to the executable for the given runtime architecture. +// +// If the manifest defines multiple executables, but none match, or if only a single executable +// is defined, the Executable field will be returned. This method does not guarantee that the +// resulting binary can actually execute on the given platform. +func (m *Manifest) GetExecutableForRuntime(goOs, goArch string) string { + if m.Backend == nil { + return "" + } + + var executable string + if m.Backend.Executables != nil { + if goOs == "linux" && goArch == "amd64" { + executable = m.Backend.Executables.LinuxAmd64 + } else if goOs == "darwin" && goArch == "amd64" { + executable = m.Backend.Executables.DarwinAmd64 + } else if goOs == "windows" && goArch == "amd64" { + executable = m.Backend.Executables.WindowsAmd64 + } + } + + if executable == "" { + executable = m.Backend.Executable + } + + return executable +} + // FindManifest will find and parse the manifest in a given directory. // // In all cases other than a does-not-exist error, path is set to the path of the manifest file that was -- cgit v1.2.3-1-g7c22