aboutsummaryrefslogtreecommitdiff
path: root/vcpkg/ports/vulkan-sdk-components/get-vulkan-sdk-components-info.ps1
blob: dd341713f8824185388da67e6ee23a936875f201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function Get-GlslangVersion {
    param(
        [string]$SdkVersion,
        [string]$TempWorkDir
    )

    [string]$_GitDir = Join-Path $TempWorkDir "glslang"
    [string]$_GitUrl = 'https://github.com/KhronosGroup/glslang.git'
    [string]$_GitTag = 'vulkan-sdk-' + $SdkVersion

    # The port glslang releases two version for a revision commit,
    # like fa9c3de released with 14.3.0 and vulkan-sdk-1.3.290.0.
    # The version of glslang is the one which is not the SDK version.
    # `--branch` to set cloned HEAD to the commit which should be referenced by 2 tags
    # `--depth=1` to avoid fetching history
    # `--filter=tree:0` and `--no-checkout` to avoid fetching files
    & git clone $_GitUrl $_GitDir `
        "--branch=$_GitTag" `
        "--depth=1" `
        "--filter=tree:0" "--no-checkout" "-q"
    # Get the tag list
    $_VersionCandidates = & git -C $_GitDir tag -l
    Remove-Item -Recurse -Force -Path $_GitDir

    # Check the tag list
    if ($null -eq $_VersionCandidates) { throw 'No VersionCandidates detected.' }
    if (2 -ne $_VersionCandidates.Length) { throw 'VersionCandidates must 2.' }
    if ($_GitTag -notin $_VersionCandidates) { throw 'VersionCandidates must contain SDK.' }
    [string]$_GlslangVersion = $_VersionCandidates | Where-Object { $_ -notmatch $_GitTag }
    if ([version]$_GlslangVersion -lt [version]'0.0.0') { throw 'Failed to determine version' }

    return $_GlslangVersion
}

function Get-VulkanSdkComponentsInfo {
    param(
        [string]$ScriptDir,
        [string]$TempWorkDir
    )

    $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop

    if ($PSVersionTable.PSVersion.Major -lt 7) {
        Write-Error 'This script requires PowerShell 7 or later.'
    }

    if ('vulkan-sdk-components' -ne (Split-Path -Leaf $ScriptDir)) {
        throw 'This script must be run from `vulkan-sdk-components` directory.'
    }

    [string]$VulkanPortDir = $ScriptDir

    [string]$SdkVersion = Join-Path -Resolve $VulkanPortDir 'vcpkg.json'
    | Get-ChildItem | Get-Content -Raw | ConvertFrom-Json -Depth 5
    | Select-Object -ExpandProperty version

    return @{
        'glslang' = Get-GlslangVersion -SdkVersion:$SdkVersion -TempWorkDir:$TempWorkDir
    }

}

$Param = @{
    ScriptDir   = $PSScriptRoot
    TempWorkDir = (New-Item -ItemType Directory Temp:/$(New-Guid)).FullName
}

Get-VulkanSdkComponentsInfo @Param | Format-Table