feat(plugin): support REIMS_GO_PLATFORM override for cross-platform market checks

This commit is contained in:
千川白浪 committed 2026-12-02 08:16:22 -07:00
1 parent 61c358bd9f
commit cdd45a3ad8
2 files changed
+22

No files matched your search

+9
View File
@@ -519,6 +519,9 @@ func parseLocaleMessagesJSON(raw []byte) (map[string]string, error) {
}
func currentPlatformTag() string {
if override := strings.TrimSpace(os.Getenv("REIMS_GO_PLATFORM")); override != "" {
return strings.ToLower(strings.ReplaceAll(override, "/", "-"))
}
arch := runtime.GOARCH
if arch == "amd64" {
arch = "x64"
@@ -692,6 +695,12 @@ func matchesCurrentPlatform(platforms []string) bool {
}
curTag := currentPlatformTag()
curPair := runtime.GOOS + "/" + runtime.GOARCH
if override := strings.TrimSpace(os.Getenv("REIMS_GO_PLATFORM")); override != "" {
curPair = strings.ToLower(strings.ReplaceAll(override, "-", "/"))
if curPair == "windows/x64" {
curPair = "windows/amd64"
}
}
for _, p := range platforms {
p = strings.TrimSpace(p)
if p == "*" || strings.EqualFold(p, "any") || strings.EqualFold(p, curTag) || strings.EqualFold(p, curPair) {
+13
View File
@@ -0,0 +1,13 @@
package plugin
import "testing"
func TestPlatformOverrideEnv(t *testing.T) {
t.Setenv("REIMS_GO_PLATFORM", "windows-x64")
if !matchesCurrentPlatform([]string{"windows-x64"}) || !matchesCurrentPlatform([]string{"windows/amd64"}) {
t.Fatal("expected windows-x64 override to match windows-x64 and windows/amd64")
}
if matchesCurrentPlatform([]string{"linux-x64"}) {
t.Fatal("expected windows-x64 override to reject linux-x64")
}
}