Skip to content

Commit c7420e4

Browse files
committed
add custom url config to support different url formats for different OSs
1 parent 8f52a24 commit c7420e4

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

plugins/runtime-utils.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@ func processRuntime(config RuntimeConfig, runtimesDir string) (*RuntimeInfo, err
4646
// Get the filename using the template
4747
fileName := GetFileName(pluginConfig.Download.FileNameTemplate, config.Version, mappedArch, runtime.GOOS)
4848

49+
customURLConfig, hasCustomURL := getCustomDownloadURL(pluginConfig.Download.CustomURLConfig, runtime.GOOS)
4950
// Get the download URL using the template
50-
downloadURL := GetDownloadURL(pluginConfig.Download.URLTemplate, fileName, config.Version, mappedArch, mappedOS, extension, pluginConfig.Download.ReleaseVersion)
51+
downloadURL := ""
52+
if hasCustomURL {
53+
downloadURL = GetDownloadURL(customURLConfig, fileName, config.Version, mappedArch, mappedOS, extension, pluginConfig.Download.ReleaseVersion)
54+
} else {
55+
downloadURL = GetDownloadURL(pluginConfig.Download.URLTemplate, fileName, config.Version, mappedArch, mappedOS, extension, pluginConfig.Download.ReleaseVersion)
56+
}
5157

5258
// For Python, we want to use a simpler directory structure
5359
var installDir string

plugins/runtimes/flutter/plugin.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ name: flutter
22
description: Dart Flutterruntime
33
default_version: "3.7.2"
44
download:
5-
url_template: "https://storage.googleapis.com/flutter_infra_release/releases/stable/{{.OS}}/flutter_{{.OS}}_{{.Version}}-stable.{{.Extension}}"
5+
url_template: "https://storage.googleapis.com/flutter_infra_release/releases/stable/{{.OS}}/flutter_{{.OS}}_{{.Arch}}_{{.Version}}-stable.{{.Extension}}"
6+
custom_url_config:
7+
linux: "https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_{{.OS}}_{{.Version}}-stable.{{.Extension}}"
8+
windows: "https://storage.googleapis.com/flutter_infra_release/releases/stable/windows/flutter_{{.OS}}_{{.Version}}-stable.{{.Extension}}"
69
file_name_template: "flutter"
710
extension:
811
linux: "tar.xz"
912
default: "zip"
1013
arch_mapping:
11-
"386": ""
12-
"amd64": ""
14+
"386": "ia32"
15+
"amd64": "x64"
1316
"arm": "arm"
1417
"arm64": "arm64"
1518
os_mapping:

plugins/shared.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@ type ExtensionConfig struct {
1313
Default string `yaml:"default"`
1414
}
1515

16+
type CustomURLConfig struct {
17+
Linux string `yaml:"linux"`
18+
Windows string `yaml:"windows"`
19+
MacOS string `yaml:"macos"`
20+
Default string `yaml:"default"`
21+
}
22+
1623
// DownloadConfig holds the download configuration from the plugin.yaml
1724
type DownloadConfig struct {
1825
URLTemplate string `yaml:"url_template"`
26+
CustomURLConfig CustomURLConfig `yaml:"custom_url_config,omitempty"`
1927
FileNameTemplate string `yaml:"file_name_template"`
2028
Extension ExtensionConfig `yaml:"extension"`
2129
ArchMapping map[string]string `yaml:"arch_mapping"`
@@ -87,6 +95,27 @@ func GetExtension(extension ExtensionConfig, goos string) string {
8795
return extension.Default
8896
}
8997

98+
func getCustomDownloadURL(customURLConfig CustomURLConfig, goos string) (string, bool) {
99+
switch goos {
100+
case "linux":
101+
if customURLConfig.Linux != "" {
102+
return customURLConfig.Linux, true
103+
}
104+
case "windows":
105+
if customURLConfig.Windows != "" {
106+
return customURLConfig.Windows, true
107+
}
108+
case "darwin":
109+
if customURLConfig.MacOS != "" {
110+
return customURLConfig.MacOS, true
111+
}
112+
}
113+
if customURLConfig.Default != "" {
114+
return customURLConfig.Default, true
115+
}
116+
return "", false
117+
}
118+
90119
// GetMajorVersion extracts the major version from a version string (e.g. "17.0.10" -> "17")
91120
func GetMajorVersion(version string) string {
92121
if idx := strings.Index(version, "."); idx != -1 {

0 commit comments

Comments
 (0)