diff --git a/1k/build.ps1 b/1k/build.ps1 index 568fe55cf0be..28da89f68fe4 100644 --- a/1k/build.ps1 +++ b/1k/build.ps1 @@ -93,6 +93,9 @@ $exeSuffix = if ($HOST_OS -eq 0) { '.exe' } else { '' } $Script:cmake_generator = $null +# import VersionEx +. (Join-Path $PSScriptRoot 'versionex.ps1') + class build1k { [void] println($msg) { Write-Host "1kiss: $msg" @@ -249,7 +252,7 @@ if ($options.xb.GetType() -eq [string]) { } $pwsh_ver = $PSVersionTable.PSVersion.ToString() -if ([System.Version]$pwsh_ver -lt [System.Version]"7.0.0") { +if ([VersionEx]$pwsh_ver -lt [VersionEx]"7.0") { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } @@ -376,7 +379,7 @@ function version_eq($ver1, $ver2) { function version_ge($ver1, $ver2) { $validatedVer = [Regex]::Match($ver1, '(\d+\.)+(-)?(\*|\d+)') if ($validatedVer.Success) { - return [System.Version]$validatedVer.Value -ge [System.Version]$ver2 + return [VersionEx]$validatedVer.Value -ge [VersionEx]$ver2 } return $false } @@ -385,9 +388,9 @@ function version_ge($ver1, $ver2) { function version_in_range($ver1, $verMin, $verMax) { $validatedVer = [Regex]::Match($ver1, '(\d+\.)+(-)?(\*|\d+)') if ($validatedVer.Success) { - $typedVer1 = [System.Version]$validatedVer.Value - $typedVerMin = [System.Version]$verMin - $typedVerMax = [System.Version]$verMax + $typedVer1 = [VersionEx]$validatedVer.Value + $typedVerMin = [VersionEx]$verMin + $typedVerMax = [VersionEx]$verMax return $typedVer1 -ge $typedVerMin -and $typedVer1 -le $typedVerMax } return $false @@ -503,8 +506,8 @@ function find_prog($name, $path = $null, $mode = 'ONLY', $cmd = $null, $params = $verStr = "$($verInfo.Major).$($verInfo.Minor).$($verInfo.Build)" } - # full pattern: '(\d+\.)+(\*|\d+)(\-[a-z]+[0-9]*)?' can match x.y.z-rc3, but not require for us - $matchInfo = [Regex]::Match($verStr, '(\d+\.)+(\*|\d+)(\-[a-z]+[0-9]*)?') + # can match x.y.z-rc3 or x.y.z-65a239b + $matchInfo = [Regex]::Match($verStr, '(\d+\.)+(\*|\d+)(\-[a-z0-9]+)?') $foundVer = $matchInfo.Value } else { $foundVer = "$($cmd_info.Version)" @@ -672,11 +675,6 @@ function setup_cmake($skipOS = $false) { $b1k.rmdirs($cmake_root) $cmake_suffix = @(".zip", ".sh", ".tar.gz").Get($HOST_OS) - $cmake_dev_hash = $channels['cmake'] - if ($cmake_dev_hash) { - $cmake_ver = "$cmake_ver-$cmake_dev_hash" - } - if ($HOST_OS -ne $HOST_MAC) { $cmake_pkg_name = "cmake-$cmake_ver-$HOST_OS_NAME-x86_64" } @@ -686,11 +684,12 @@ function setup_cmake($skipOS = $false) { $cmake_pkg_path = Join-Path $external_prefix "$cmake_pkg_name$cmake_suffix" - if (!$cmake_dev_hash) { + $assemble_url = $channels['cmake'] + if (!$assemble_url) { $cmake_url = "https://github.com/Kitware/CMake/releases/download/v$cmake_ver/$cmake_pkg_name$cmake_suffix" } else { - $cmake_url = "https://cmake.org/files/dev/$cmake_pkg_name$cmake_suffix" + $cmake_url = & $assemble_url -FileName "$cmake_pkg_name$cmake_suffix" } $cmake_dir = Join-Path $external_prefix $cmake_pkg_name @@ -718,7 +717,7 @@ function setup_cmake($skipOS = $false) { } elseif ($IsLinux) { $b1k.mkdirs($cmake_root) - & "$cmake_pkg_path" '--skip-license' '--exclude-subdir' "--prefix=$cmake_root" + & "$cmake_pkg_path" '--skip-license' '--exclude-subdir' "--prefix=$cmake_root" 1>$null 2>$null } $cmake_prog, $_ = find_prog -name 'cmake' -path $cmake_bin -silent $true @@ -747,7 +746,7 @@ function ensure_cmake_ninja($cmake_prog, $ninja_prog) { if(!$? -and $IsWin) { # try runas admin again $mklink_args = "-Command ""& ""$myRoot\fsync.ps1"" -s '$ninja_prog' -d '$ninja_symlink_target' -l `$true 2>`$null""" Write-Host "mklink_args={$mklink_args}" - Start-Process powershell -ArgumentList $mklink_args -Verb runas -Wait + Start-Process powershell -ArgumentList $mklink_args -WindowStyle Hidden -Wait -Verb runas } } return $? @@ -1145,7 +1144,7 @@ $Global:VS_VERSION = $null $Global:VS_PATH = $null $Global:VS_INST = $null function find_vs_latest() { - $vs_version = [System.Version]'12.0.0.0' + $vs_version = [VersionEx]'12.0' if (!$Global:VS_INST) { $VSWHERE_EXE = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" $eap = $ErrorActionPreference @@ -1157,7 +1156,7 @@ function find_vs_latest() { if($vs_installs) { $vs_inst_latest = $null foreach($vs_inst in $vs_installs) { - $inst_ver = [System.Version]$vs_inst.installationVersion + $inst_ver = [VersionEx]$vs_inst.installationVersion if ($vs_version -lt $inst_ver) { $vs_version = $inst_ver $vs_inst_latest = $vs_inst @@ -1185,7 +1184,7 @@ function preprocess_win([string[]]$inputOptions) { $arch = if ($options.a -eq 'x86') { 'Win32' } else { $options.a } # arch - if ($VS_VERSION -ge [System.Version]'16.0.0.0') { + if ($VS_VERSION -ge [VersionEx]'16.0') { $outputOptions += '-A', $arch if ($TOOLCHAIN_VER) { $outputOptions += "-Tv$TOOLCHAIN_VER" @@ -1393,6 +1392,14 @@ if ($Global:is_win32) { } elseif ($Global:is_android) { $ninja_prog = setup_ninja + # ensure ninja in cmake_bin + if (!(ensure_cmake_ninja $cmake_prog $ninja_prog)) { + $cmake_prog = setup_cmake -Force + if (!(ensure_cmake_ninja $cmake_prog $ninja_prog)) { + $b1k.println("Ensure ninja in cmake bin directory fail") + } + } + $null = setup_jdk # setup android sdk cmdlinetools require jdk $sdk_root, $ndk_root = setup_android_sdk $env:ANDROID_HOME = $sdk_root @@ -1405,15 +1412,6 @@ elseif ($Global:is_android) { $ndk_host = @('windows', 'linux', 'darwin').Get($HOST_OS) $env:ANDROID_NDK_BIN = Join-Path $ndk_root "toolchains/llvm/prebuilt/$ndk_host-x86_64/bin" - - # ensure ninja in cmake_bin - if (!(ensure_cmake_ninja $cmake_prog $ninja_prog)) { - $cmake_prog = setup_cmake -Force - if (!(ensure_cmake_ninja $cmake_prog $ninja_prog)) { - $b1k.println("Ensure ninja in cmake bin directory fail") - } - } - function active_ndk_toolchain() { if ($env:PATH.IndexOf($env:ANDROID_NDK_BIN) -eq -1) { $env:PATH = "$env:ANDROID_NDK_BIN$ENV_PATH_SEP$env:PATH" @@ -1704,7 +1702,7 @@ if (!$setupOnly) { cmd /c "gn $gn_gen_args" } else { - if ([System.Version]$pwsh_ver -ge [System.Version]'7.3.0') { + if ([VersionEx]$pwsh_ver -ge [VersionEx]'7.3') { bash -c "gn $gn_gen_args" } else { gn $gn_gen_args diff --git a/1k/install-pwsh.sh b/1k/install-pwsh.sh index c135d3c1bffa..381069d9cc97 100755 --- a/1k/install-pwsh.sh +++ b/1k/install-pwsh.sh @@ -6,12 +6,12 @@ HOST_OS=$(uname) myRoot=$(dirname "$0") -$prefix = ~/.1kiss +prefix=~/.1kiss mkdir -p $prefix pwsh_ver=$1 if [ "$pwsh_ver" = "" ] ; then - pwsh_ver='7.4.0' + pwsh_ver='7.4.1' fi function check_pwsh { diff --git a/1k/manifest.ps1 b/1k/manifest.ps1 index 12a65f2ce02b..ecedd375b896 100644 --- a/1k/manifest.ps1 +++ b/1k/manifest.ps1 @@ -13,5 +13,3 @@ $manifest['glslcc'] = '1.9.4+' # android sdk tools $android_sdk_tools['build-tools'] = '34.0.0' # match with AGP, current 8.2.1 android studio 2023.1.1 $android_sdk_tools['platforms'] = 'android-34' - -# [void]$manifest diff --git a/1k/versionex.ps1 b/1k/versionex.ps1 new file mode 100644 index 000000000000..fea6e2cc416f --- /dev/null +++ b/1k/versionex.ps1 @@ -0,0 +1,206 @@ +# The System.Version compare not relex: [Version]'1.0' -eq [Version]'1.0.0' == false +# So provide a spec VersionEx make [VersionEx]'1.0' -eq [VersionEx]'1.0.0' == true available +if (-not ([System.Management.Automation.PSTypeName]'System.VersionEx').Type) { + + Add-Type -TypeDefinition @" + +namespace System +{ + public sealed class VersionEx : ICloneable, IComparable + { + int _Major = 0; + int _Minor = 0; + int _Build = 0; + int _Revision = 0; + + public int Minor { get { return _Major; } } + + public int Major { get { return _Minor; } } + + public int Build { get { return _Build; } } + + public int Revision { get { return _Revision; } } + + int DefaultFormatFieldCount { get { return (_Build > 0 || _Revision > 0) ? (_Revision > 0 ? 4 : 3) : 2; } } + + public VersionEx() { } + + public VersionEx(string version) + { + var v = Parse(version); + _Major = v.Major; + _Minor = v.Minor; + _Build = v.Build; + _Revision = v.Revision; + } + + public VersionEx(System.Version version) { + _Major = version.Major; + _Minor = version.Minor; + _Build = Math.Max(version.Build, 0); + _Revision = Math.Max(version.Revision, 0); + } + + public VersionEx(int major, int minor, int build, int revision) + { + _Major = major; + _Minor = minor; + _Build = build; + _Revision = revision; + } + + public static VersionEx Parse(string input) + { + var versionNums = input.Split('.'); + int major = 0; + int minor = 0; + int build = 0; + int revision = 0; + for (int i = 0; i < versionNums.Length; ++i) + { + switch (i) + { + case 0: + major = int.Parse(versionNums[i]); + break; + case 1: + minor = int.Parse(versionNums[i]); + break; + case 2: + build = int.Parse(versionNums[i]); + break; + case 3: + revision = int.Parse(versionNums[i]); + break; + } + } + return new VersionEx(major, minor, build, revision); + } + + public static bool TryParse(string input, out VersionEx result) + { + try + { + result = VersionEx.Parse(input); + return true; + } + catch (Exception) + { + result = null; + return false; + } + } + + public object Clone() + { + return new VersionEx(Major, Minor, Build, Revision); + } + + public int CompareTo(object obj) + { + if (obj is VersionEx) + { + return CompareTo((VersionEx)obj); + } + else if (obj is Version) + { + var rhs = (Version)obj; + return _Major != rhs.Major ? (_Major > rhs.Major ? 1 : -1) : + _Minor != rhs.Minor ? (_Minor > rhs.Minor ? 1 : -1) : + _Build != rhs.Build ? (_Build > rhs.Build ? 1 : -1) : + _Revision != rhs.Revision ? (_Revision > rhs.Revision ? 1 : -1) : + 0; + } + else return 1; + } + + public int CompareTo(VersionEx obj) + { + return + ReferenceEquals(obj, this) ? 0 : + ReferenceEquals(obj, null) ? 1 : + _Major != obj._Major ? (_Major > obj._Major ? 1 : -1) : + _Minor != obj._Minor ? (_Minor > obj._Minor ? 1 : -1) : + _Build != obj._Build ? (_Build > obj._Build ? 1 : -1) : + _Revision != obj._Revision ? (_Revision > obj._Revision ? 1 : -1) : + 0; + } + + public bool Equals(VersionEx obj) + { + return CompareTo(obj) == 0; + } + + public override bool Equals(object obj) + { + return CompareTo(obj) == 0; + } + + public override string ToString() + { + return ToString(DefaultFormatFieldCount); + } + + public string ToString(int fieldCount) + { + switch (fieldCount) + { + case 2: + return string.Format("{0}.{1}", _Major, _Minor); + case 3: + return string.Format("{0}.{1}.{2}", _Major, _Minor, _Build); + case 4: + return string.Format("{0}.{1}.{2}.{3}", _Major, _Minor, _Build, _Revision); + default: + return "0.0.0.0"; + } + } + + public override int GetHashCode() + { + // Let's assume that most version numbers will be pretty small and just + // OR some lower order bits together. + + int accumulator = 0; + + accumulator |= (_Major & 0x0000000F) << 28; + accumulator |= (_Minor & 0x000000FF) << 20; + accumulator |= (_Build & 0x000000FF) << 12; + accumulator |= (_Revision & 0x00000FFF); + + return accumulator; + } + + public static bool operator ==(VersionEx v1, VersionEx v2) + { + return v1.Equals(v2); + } + + public static bool operator !=(VersionEx v1, VersionEx v2) + { + return !v1.Equals(v2); + } + + public static bool operator <(VersionEx v1, VersionEx v2) + { + return v1.CompareTo(v2) < 0; + } + + public static bool operator >(VersionEx v1, VersionEx v2) + { + return v1.CompareTo(v2) > 0; + } + + public static bool operator <=(VersionEx v1, VersionEx v2) + { + return v1.CompareTo(v2) <= 0; + } + + public static bool operator >=(VersionEx v1, VersionEx v2) + { + return v1.CompareTo(v2) >= 0; + } + } +} +"@ +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 152d24e6bd71..9954b009c531 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# axmol-2.1.0 Jan.?? 2024 +# axmol-2.1.0 Jan.20 2024 ### Significant changes relative to 2.0.0: diff --git a/setup.ps1 b/setup.ps1 index 64d64eca9492..5d8c48cb8fc6 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -3,13 +3,16 @@ $myRoot = $PSScriptRoot $AX_ROOT = $myRoot -$pwsh_ver = $PSVersionTable.PSVersion.ToString() - Set-Alias println Write-Host +# import VersionEx +. (Join-Path $PSScriptRoot '1k/versionex.ps1') + +$pwsh_ver = [VersionEx]$PSVersionTable.PSVersion.ToString() + function mkdirs([string]$path) { if (!(Test-Path $path -PathType Container)) { - if ([System.Version]$pwsh_ver -ge [System.Version]'5.0.0.0') { + if ($pwsh_ver -ge [VersionEx]'5.0') { New-Item $path -ItemType Directory 1>$null } else { @@ -18,7 +21,7 @@ function mkdirs([string]$path) { } } -if ([System.Version]$pwsh_ver -lt [System.Version]'5.0.0.0') { +if ($pwsh_ver -lt [VersionEx]'5.0') { # try setup WMF5.1, require reboot, try run setup.ps1 several times Write-Host "Installing WMF5.1 ..." $osVer = [System.Environment]::OSVersion.Version @@ -146,7 +149,7 @@ if ($IsWin) { $execPolicy = powershell -Command 'Get-ExecutionPolicy' if ($execPolicy -ne 'Bypass') { println "axmol: Setting system installed powershell execution policy '$execPolicy'==>'Bypass', please click 'YES' on UAC dialog" - Start-Process powershell -ArgumentList '-Command "Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force"' -Wait -WindowStyle Hidden -Verb runas + Start-Process powershell -ArgumentList '-Command "Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force"' -WindowStyle Hidden -Wait -Verb runas } else { println "axmol: Great, the system installed powershell execution policy is '$execPolicy'" } diff --git a/tools/ci/make-pkg.ps1 b/tools/ci/make-pkg.ps1 index d6e142a3e5f9..997f23363d3f 100644 --- a/tools/ci/make-pkg.ps1 +++ b/tools/ci/make-pkg.ps1 @@ -89,8 +89,10 @@ function Compress-ArchiveEx() { Add-Type -AssemblyName System.IO.Compression.FileSystem } - $pwsh_ver = $PSVersionTable.PSVersion.ToString() - if (([System.Version]$pwsh_ver -ge [System.Version]'7.0.0.0') -and $IsWindows) { + # import VersionEx + . (Join-Path $AX_ROOT '1k/versionex.ps1') + + if (([VersionEx]$PSVersionTable.PSVersion.ToString() -ge [VersionEx]'7.0') -and $IsWindows) { if (-not ([System.Management.Automation.PSTypeName]'UnixFileStream').Type) { Add-Type -TypeDefinition @" diff --git a/tools/ci/update-prebuilts.ps1 b/tools/ci/update-prebuilts.ps1 index 52debfb46ad8..544c6b40d031 100644 --- a/tools/ci/update-prebuilts.ps1 +++ b/tools/ci/update-prebuilts.ps1 @@ -25,12 +25,7 @@ function download_file($url, $out, $force = $false) { Remove-Item $out } Write-Host "Downloading $url to $out ..." - if ([System.Version]$pwsh_ver -ge [System.Version]'7.0.0.0') { - curl -L $url -o $out - } - else { - Invoke-WebRequest -Uri $url -OutFile $out - } + Invoke-WebRequest -Uri $url -OutFile $out } function download_and_expand($url, $out, $dest) {