Skip to content

Commit

Permalink
Merge pull request #748 from YuriSizov/jekyll-override-download-configs
Browse files Browse the repository at this point in the history
Add support for download config overrides
  • Loading branch information
YuriSizov authored Nov 8, 2023
2 parents 56eb995 + 405220f commit 83d0f43
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 4 deletions.
50 changes: 50 additions & 0 deletions _data/download_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defaults:
android.apk: android_editor.apk
linux.64: linux.x86_64.zip
linux.32: linux.x86_32.zip
linux.arm64: linux.arm64.zip
linux.arm32: linux.arm32.zip
macos.universal: macos.universal.zip
windows.64: win64.exe.zip
windows.32: win32.exe.zip
Expand All @@ -17,6 +19,8 @@ defaults:
editor:
linux.64: mono_linux_x86_64.zip
linux.32: mono_linux_x86_32.zip
linux.arm64: mono_linux_arm64.zip
linux.arm32: mono_linux_arm32.zip
macos.universal: mono_macos.universal.zip
windows.64: mono_win64.zip
windows.32: mono_win32.zip
Expand Down Expand Up @@ -68,3 +72,49 @@ defaults:
windows.64: win64.exe.zip
windows.32: win32.exe.zip
linux_server.64: linux_server.64.zip

overrides:
# Mono version of Godot 4 was only introduced in 4.0 alpha 17.
- version: 4
range:
- "4.0-alpha1"
- "4.0-alpha16"
config:
templates: export_templates.tpz
editor:
android.apk: android_editor.apk
linux.64: linux.x86_64.zip
linux.32: linux.x86_32.zip
macos.universal: macos.universal.zip
windows.64: win64.exe.zip
windows.32: win32.exe.zip
web: web_editor.zip
extras:
aar_library: template_release.aar

# Godot 4.2 beta 5 introduced Linux ARM builds.
- version: 4
range:
- "4.0-alpha17"
- "4.2-beta4"
config:
templates: export_templates.tpz
editor:
android.apk: android_editor.apk
linux.64: linux.x86_64.zip
linux.32: linux.x86_32.zip
macos.universal: macos.universal.zip
windows.64: win64.exe.zip
windows.32: win32.exe.zip
web: web_editor.zip
extras:
aar_library: template_release.aar

mono:
templates: mono_export_templates.tpz
editor:
linux.64: mono_linux_x86_64.zip
linux.32: mono_linux_x86_32.zip
macos.universal: mono_macos.universal.zip
windows.64: mono_win64.zip
windows.32: mono_win32.zip
14 changes: 14 additions & 0 deletions _data/download_platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@
tags:
- 64 bit

- name: "linux.arm32"
title: "Linux"
caption: "Standard (ARM32)"
tags:
- ARM32
- 32 bit

- name: "linux.arm64"
title: "Linux"
caption: "Standard (ARM64)"
tags:
- ARM64
- 64 bit

- name: "linux_server.64"
title: "Linux Server"
caption: "Standard (x86_64)"
Expand Down
119 changes: 115 additions & 4 deletions _plugins/make_download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
HOST_GITHUB = "https://github.com/godotengine/godot/releases/download"
HOST_GITHUB_BUILDS = "https://github.com/godotengine/godot-builds/releases/download"

FLAVOR_MATRIX = {
"dev" => 1,
"alpha" => 2,
"beta" => 3,
"rc" => 4,
"stable" => 10
}

module MakeDownloadFilter
# Input should be a value from versions.yml or the output of make_release_version().
def get_download_platforms(input, mono = false)
Expand Down Expand Up @@ -157,6 +165,92 @@ def get_version_name(input)
return input.key?("release_version") ? input["release_version"] : input["name"]
end

def parse_version_string(version_string)
string_bits = version_string.split("-")

version_bits = parse_version_name(string_bits[0])
flavor_bits = parse_version_flavor(string_bits[1])

return [ version_bits, flavor_bits ]
end

def parse_version_name(version_name)
parsed_version = [ 0, 0, 0, 0 ]
version_bits = version_name.split(".")

parsed_version.each_with_index do |value, index|
if version_bits[index] != nil
parsed_version[index] = version_bits[index].to_i
end
end

return parsed_version
end

def parse_version_flavor(version_flavor)
flavor_name = version_flavor
flavor_number = 0

match = /([0-9]+)$/.match(version_flavor)
if match != nil
match_offset = match.offset(0)

flavor_name = version_flavor[0, match_offset[0]]
flavor_number = version_flavor[match_offset[0], match_offset[1] - match_offset[0]].to_i
end

return [ flavor_name, flavor_number ]
end

def get_version_bits_hash(version_bits)
hash = 0

# We assume no part of the Godot version string can be above 99,
# but we also assume that values above 9 are possible.
version_bits.each_with_index do |bit, index|
pow_index = version_bits.size - index
pow_value = 100 ** pow_index

hash += pow_value * bit
end

return hash
end

def get_flavor_bits_hash(flavor_bits)
hash = 0

if FLAVOR_MATRIX.key?(flavor_bits[0])
hash += FLAVOR_MATRIX[flavor_bits[0]] * 10000
end

hash += flavor_bits[1]

return hash
end

def is_in_version_range(version_bits_hash, flavor_bits_hash, version_range)
range_from = parse_version_string(version_range[0])
range_to = parse_version_string(version_range[1])

from_version_hash = get_version_bits_hash(range_from[0])
to_version_hash = get_version_bits_hash(range_to[0])

if version_bits_hash < from_version_hash or version_bits_hash > to_version_hash
return false
end

if version_bits_hash == from_version_hash and flavor_bits_hash < get_flavor_bits_hash(range_from[1])
return false
end

if version_bits_hash == to_version_hash and flavor_bits_hash > get_flavor_bits_hash(range_to[1])
return false
end

return true
end

# Input should be a value from versions.yml or the output of make_release_version().
def get_download_slugs(input, mono = false)
version_name = get_version_name(input)
Expand All @@ -170,17 +264,34 @@ def get_download_slugs(input, mono = false)
if not download_configs["defaults"].key?(version_major)
return nil
end
slugs_data = download_configs["defaults"][version_major]

# Consider potential overrides.
if download_configs.key?("overrides")
version_bits_hash = get_version_bits_hash(parse_version_name(version_name))
flavor_bits_hash = get_flavor_bits_hash(parse_version_flavor(input["flavor"]))

for override_data in download_configs["overrides"] do
if override_data["version"] != version_major
next
end

if is_in_version_range(version_bits_hash, flavor_bits_hash, override_data["range"])
slugs_data = override_data["config"]
break
end
end
end

slugs_defaults = download_configs["defaults"][version_major]
if mono
# Requesting mono, but there is no config for mono, abort.
if not slugs_defaults.key?("mono")
if not slugs_data.key?("mono")
return nil
end
slugs_defaults = slugs_defaults["mono"]
slugs_data = slugs_data["mono"]
end

return slugs_defaults
return slugs_data
end

end
Expand Down

0 comments on commit 83d0f43

Please sign in to comment.