Welcome to mirror list, hosted at ThFree Co, Russian Federation.

load-corefx-testhost.ps1 « HttpStress « StressTests « tests « System.Net.Http « libraries « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 16e80572cd0ea7d503c482c5266f3ac39772d96c (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the MIT license.
# See the LICENSE file in the project root for more information.

# Helper script used for pointing the current powershell environment 
# to the testhost sdk built by the corefx build script.

[CmdletBinding(PositionalBinding=$false)]
Param(
  [string][Alias('f')]$framework = "netcoreapp",
  [string][Alias('c')]$configuration = "Debug",
  [string][Alias('a')]$arch = "x64",
  [string][Alias('o')]$os = "",
  [switch][Alias('b')]$copyAspNetBits
)

# script needs to be sourced, detect if running standalone
if ($MyInvocation.InvocationName -ne ".")
{
    write-output "Script must be sourced"
    write-output "USAGE: . $($MyInvocation.InvocationName) <args>"
    exit
}

# find corefx root, assuming script lives in the git repo
$SOURCE_DIR="$(split-path -Parent $MyInvocation.MyCommand.Definition)"
$COREFX_ROOT_DIR=$(git -C "$SOURCE_DIR" rev-parse --show-toplevel)

function Find-Os()
{
    if (!$(test-path variable:IsWindows) -or $IsWindows)
    {
        return "Windows_NT"
    } 
    else
    {
        switch -Wildcard ($(uname -s))
        {
            "Linux*" { return "Linux" }
            "Darwin*" { return "MacOS" }
            "*" { return "Unix" }
        }
    }
}

if ($os -eq "")
{
    $os=$(Find-Os)
}

# the corefx testhost does not bundle AspNetCore runtime bits;
# fix up by copying from the bootstrap sdk 
function Copy-Aspnetcore-Bits([string] $testhost_path)
{
    function find-bootstrap-sdk()
    {
        if (test-path -PathType container "$COREFX_ROOT_DIR/.dotnet")
        {
            "$COREFX_ROOT_DIR/.dotnet"
        }
        else
        {
            $dotnet_path = $(get-command dotnet).Source

            try
            {
                # follow any symlinks if unix
                $dotnet_path = $(readlink -f $dotnet_path)
            }
            catch [System.Management.Automation.CommandNotFoundException]
            {

            }

            split-path -Path $dotnet_path
        }
    }

    $netfx_bits_folder="Microsoft.NETCore.App"
    $aspnet_bits_folder="Microsoft.AspNetCore.App"

    if (!(test-path -PathType container "$testhost_path/shared/$aspnet_bits_folder"))
    {
        $bootstrap_sdk=$(find-bootstrap-sdk)

        function get-most-recent-version($path)
        {
            (Get-ChildItem -Directory "$path" `
            | Select-Object -ExpandProperty Fullname `
            | Split-Path -Leaf `
            | ForEach-Object{[System.Version]$_} `
            | Sort-Object -Descending `
            | Select-Object -First 1).ToString()
        }
        
        $netfx_runtime_version=$(get-most-recent-version "$testhost_path/shared/$netfx_bits_folder")
        $aspnet_runtime_version=$(get-most-recent-version "$bootstrap_sdk/shared/$aspnet_bits_folder")

        # copy the bits
        mkdir -p "$testhost_path/shared/$aspnet_bits_folder/" > $null
        copy-item -R "$bootstrap_sdk/shared/$aspnet_bits_folder/$aspnet_runtime_version" "$testhost_path/shared/$aspnet_bits_folder/$netfx_runtime_version"
        if (!$?)
        {
            write-host "failed to copy aspnetcore bits"
            return
        }

        $aspNetRuntimeConfig="$testhost_path/shared/$aspnet_bits_folder/$netfx_runtime_version/$aspnet_bits_folder.runtimeconfig.json"
        if (test-path -PathType leaf "$aspNetRuntimeConfig")
        {
            # point aspnetcore runtimeconfig.json to current netfx version
            # would prefer jq here but missing in many distros by default
            $updated_content = $(get-content "$aspNetRuntimeConfig") -replace '"version"\s*:\s*"[^"]*"', "`"version`":`"$netfx_runtime_version`""
            write-output $updated_content | Out-File -FilePath "$aspNetRuntimeConfig" -Encoding utf8
        }

        write-host "Copied Microsoft.AspNetCore.App runtime bits from $bootstrap_sdk"
    }
}

function Set-Sdk-Environment()
{
    $candidate_path=$([IO.Path]::Combine($COREFX_ROOT_DIR, 'artifacts', 'bin', 'testhost', "$FRAMEWORK-$OS-$CONFIGURATION-$ARCH"))

    if (!$(test-path -PathType container $candidate_path))
    {
        write-output "Could not locate testhost sdk path $candidate_path" 
        return
    }
    elseif (!$(test-path -PathType leaf "$candidate_path/dotnet") -and 
            !$(test-path -PathType leaf "$candidate_path/dotnet.exe"))
    {
        write-output "Could not find dotnet executable in testhost sdk path $candidate_path"
        return
    }

    if($copyAspNetBits)
    {
        Copy-Aspnetcore-Bits $candidate_path
    }

    $pathSeparator=if($os -eq "Windows_NT") { ";" } else { ":" }
    
    $env:DOTNET_ROOT=$candidate_path
    $env:DOTNET_CLI_HOME=$candidate_path
    $env:PATH=($candidate_path + $pathSeparator + $env:PATH)
    $env:DOTNET_MULTILEVEL_LOOKUP=0
    $env:DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2
}


Set-Sdk-Environment