aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-12-02 19:37:31 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-12-02 19:37:31 +0100
commit4c5294210a19e79d759b8f0ed7dcef9aafa4059f (patch)
treee0f069f75a505f1844b59741f8338f5b75a79b0c
parente180db41f514e3d769f3fa4af436d6a580487c2b (diff)
make auto plugin building work in dev builds
-rw-r--r--doc/plugins.md11
-rw-r--r--plugin.go31
2 files changed, 37 insertions, 5 deletions
diff --git a/doc/plugins.md b/doc/plugins.md
index d943ea0..2e9b2d2 100644
--- a/doc/plugins.md
+++ b/doc/plugins.md
@@ -38,8 +38,6 @@ To use this, clone the plugin repository, cd into it and run:
mt-build-plugin
```
-This tool won't work in development builds.
-
## Developing plugins
A plugin is simply a main package without a main function. Use the init
functions instead. Plugins can import
@@ -84,6 +82,9 @@ and copy everything excluding the `require `. Then append a new line:
`replace github.com/HimbeerserverDE/mt-multiserver-proxy SOMEVERSION => ../path/to/proxy/repo/`.
Now rebuild and install the plugin and it should be loaded.
-As of now there is no way to automate this, though the go toolchain
-provides everything needed to implement it.
-Expect this feature to be added soon.
+### Automatic development version management
+The `mt-build-plugin` tool as well as the proxy itself are capable of
+handling development versions, but the former only works if it's located
+in the same directory as the proxy executable. See
+[Automatic version management](https://github.com/HimbeerserverDE/mt-multiserver-proxy/blob/main/doc/plugins.md#automatic-version-management)
+for details.
diff --git a/plugin.go b/plugin.go
index f399a8f..aeb9b8d 100644
--- a/plugin.go
+++ b/plugin.go
@@ -16,6 +16,14 @@ func BuildPlugin() error {
return err
}
+ if version == "(devel)" {
+ return buildPluginDev(version)
+ }
+
+ return buildPlugin(version)
+}
+
+func buildPlugin(version string) error {
pathVer := "github.com/HimbeerserverDE/mt-multiserver-proxy@" + version
if err := goCmd("get", pathVer); err != nil {
@@ -33,6 +41,29 @@ func BuildPlugin() error {
return nil
}
+func buildPluginDev(version string) error {
+ replace := "-replace=github.com/HimbeerserverDE/mt-multiserver-proxy=" + Path()
+ const dropReplace = "-dropreplace=github.com/HimbeerserverDE/mt-multiserver-proxy"
+
+ if err := goCmd("mod", "edit", replace); err != nil {
+ return err
+ }
+
+ if err := goCmd("mod", "tidy"); err != nil {
+ return err
+ }
+
+ if err := goCmd("build", "-buildmode=plugin"); err != nil {
+ return err
+ }
+
+ if err := goCmd("mod", "edit", dropReplace); err != nil {
+ return err
+ }
+
+ return nil
+}
+
func loadPlugins() {
pluginsOnce.Do(openPlugins)
}