Skip to content

Commit 09b1a97

Browse files
committed
Added new version helper class.
1 parent 594a7d0 commit 09b1a97

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

source/ice/core/version.moon

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Validation from require "ice.core.validation"
2+
3+
class Version
4+
@from_str: (str) =>
5+
major, minor, patch = str\gmatch "%d+.%d+.%d+"
6+
return nil unless major
7+
Version major, minor, patch
8+
9+
new: (@major, @minor, @patch) =>
10+
newer: (other) =>
11+
if (tonumber (@major or 0)) == (tonumber (other.major or 0))
12+
if (tonumber (@minor or 0)) == (tonumber (other.minor or 0))
13+
return (tonumber (@patch or 0)) > (tonumber (other.patch or 0))
14+
return (tonumber (@minor or 0)) > (tonumber (other.minor or 0))
15+
return (tonumber (@major or 0)) > (tonumber (other.major or 0))
16+
17+
{ :Version }

source/ice/platform/android.moon

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Path, Dir, File from require "ice.core.fs"
2+
import Version from require "ice.core.version"
23
import Exec, Where from require "ice.tools.exec"
34
import Zip from require "ice.tools.zip"
45
import Wget from require "ice.tools.wget"
@@ -149,11 +150,17 @@ class Android
149150
cmdline_tools_basepath = Path\join sdk_root, "cmdline-tools"
150151
cmdline_tools_version = (Setting\get "android.sdk.cmdline_tools_version") or "latest"
151152
if cmdline_tools_version == 'latest'
152-
cmdline_tools_version = '0.0'
153-
for path, m in Dir\list cmdline_tools_basepath, recursive:false
154-
if m == 'directory' and cmdline_tools_version < path
155-
cmdline_tools_version = path
156-
Log\verbose "Selecting new version for android command-line tools: #{cmdline_tools_version}"
153+
unless Dir\exists Path\join cmdline_tools_basepath, cmdline_tools_version
154+
cmdline_tools_version = Version\from_str '0.0'
155+
156+
-- Run over each path and compare versions
157+
for path, m in Dir\list cmdline_tools_basepath, recursive:false
158+
path_ver = Version\from_str path
159+
if path_ver and path_ver\newer cmdline_tools_version
160+
cmdline_tools_version = path_ver
161+
Log\verbose "Selecting new version for android command-line tools: #{cmdline_tools_version}"
162+
163+
Log\info "Selectied version for android command-line tools: #{cmdline_tools_version}"
157164

158165
possible_paths = {
159166
{ deprecated:true, source:'tools', location:Path\join sdk_root, "tools", "bin", "sdkmanager.bat" }

0 commit comments

Comments
 (0)