summaryrefslogtreecommitdiff
path: root/.packages/microsoft.dotnet.arcade.sdk/1.0.0-beta.19461.7/tools/VisualStudio.AcquireOptimizationData.targets
blob: 66113c20b65bf9a280b17db2de9e7f3a906aa9b5 (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
<!-- 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. -->
<Project>
  <!-- 
    Properties:
      RepositoryName                   Current repository name (e.g. 'dotnet/roslyn').
      VisualStudioIbcSourceBranchName  The name of the branch of the repository that was used to produce the IBC data to be acquired (e.g. 'master').
      VisualStudioIbcDropId            The id of the drop. If specified, drop named 'OptimizationData/$(RepositoryName)/$(VisualStudioIbcSourceBranchName)/$(VisualStudioIbcDropId)' is used.
                                       Otherwise, the most recent drop of name that matches 'OptimizationData/$(RepositoryName)/$(VisualStudioIbcSourceBranchName)/*' is used.
  -->
  
  <PropertyGroup>
    <_VisualStudioBuildTasksAssembly>$(NuGetPackageRoot)microsoft.dotnet.build.tasks.visualstudio\$(MicrosoftDotNetBuildTasksVisualStudioVersion)\tools\net472\Microsoft.DotNet.Build.Tasks.VisualStudio.dll</_VisualStudioBuildTasksAssembly>
  </PropertyGroup>
  
  <UsingTask AssemblyFile="$(_VisualStudioBuildTasksAssembly)" TaskName="Microsoft.DotNet.Build.Tasks.VisualStudio.FindLatestDrop"/>

  <PropertyGroup>
    <!-- TODO: remove (https://github.com/dotnet/arcade/issues/2092) -->
    <EnablePartialNgenOptimization Condition="'$(EnablePartialNgenOptimization)' == '' and '$(Configuration)' == 'Release' and '$(OfficialBuild)' == 'true'">true</EnablePartialNgenOptimization>

    <EnableNgenOptimization Condition="'$(EnableNgenOptimization)' == ''">$(EnablePartialNgenOptimization)</EnableNgenOptimization>
  </PropertyGroup>
  
  <!--
    Acquire optimization data from VS drop, unless suppressed by setting EnableNgenOptimization to false.
    Find the latest optimization data drop and downloads it to IbcOptimizationDataDir directory.
  -->
  <Target Name="_AcquireVisualStudioOptimizationData"
          DependsOnTargets="_PrepareAcquireVisualStudioOptimizationData;_DownloadVisualStudioOptimizationDataOpt"
          AfterTargets="Restore"
          Condition="'$(EnableNgenOptimization)' == 'true'">
  </Target>
  
  <Target Name="_PrepareAcquireVisualStudioOptimizationData">
    <PropertyGroup>
      <_DropToolPath>$(NuGetPackageRoot)drop.app\$(DropAppVersion)\lib\net45\drop.exe</_DropToolPath>
      <_DropToolExists>false</_DropToolExists>
      <_DropToolExists Condition="Exists('$(_DropToolPath)')">true</_DropToolExists>
    </PropertyGroup>

    <!--
      Only report error when running in an official build.
      Allows to test optimization data operations locally by running 
      cibuild.cmd after manually restoring internal tools project.
    -->
    <Error Text='Internal tool not found: "$(_DropToolPath)". Run restore on "$(RepositoryEngineeringDir)common\internal\Tools.csproj".'
           Condition="'$(OfficialBuild)' == 'true' and !$(_DropToolExists)"/>
  </Target>

  <Target Name="_DownloadVisualStudioOptimizationDataOpt" Condition="$(_DropToolExists)">
    <Error Text="VisualStudioDropAccessToken property has to be specified when EnableNgenOptimization and OfficialBuild is true" Condition="'$(VisualStudioDropAccessToken)' == '' and '$(OfficialBuild)' == 'true'"/>
    <Error Text="RepositoryName property has to be specified when EnableNgenOptimization is true" Condition="'$(RepositoryName)' == ''"/>
    <Error Text="VisualStudioIbcSourceBranchName property has to be specified when EnableNgenOptimization is true" Condition="'$(VisualStudioIbcSourceBranchName)' == ''"/>

    <PropertyGroup>
      <_DropServiceUrl>https://devdiv.artifacts.visualstudio.com</_DropServiceUrl>
      <_PatAuthArg Condition="'$(VisualStudioDropAccessToken)' != ''">--patAuth "$(VisualStudioDropAccessToken)"</_PatAuthArg>
      <_DestArg>$(IbcOptimizationDataDir.TrimEnd('\'))</_DestArg>
      <_DropsJsonPath>$(ArtifactsLogDir)OptimizationDataDrops.json</_DropsJsonPath>
      <_DropsLogPath>$(ArtifactsLogDir)OptimizationDataAcquisition.log</_DropsLogPath>
      <_DropNamePrefix>OptimizationData/$(RepositoryName)/$(VisualStudioIbcSourceBranchName)</_DropNamePrefix>
      <_DropName>$(_DropNamePrefix)/$(VisualStudioIbcDropId)</_DropName>
    </PropertyGroup>

    <Message Text="Acquiring optimization data" Importance="high"/>

    <Exec Command='"$(_DropToolPath)" list --dropservice "$(_DropServiceUrl)" $(_PatAuthArg) --pathPrefixFilter "$(_DropNamePrefix)" --toJsonFile "$(_DropsJsonPath)" --traceto "$(_DropsLogPath)"' 
          Condition="'$(VisualStudioIbcDropId)' == ''"/>

    <FindLatestDrop DropListPath="$(_DropsJsonPath)" Condition="'$(VisualStudioIbcDropId)' == ''">
      <Output TaskParameter="DropName" PropertyName="_DropName"/>
    </FindLatestDrop>

    <Error Text="No drop matching given name found: $(_DropServiceUrl)/$(_DropNamePrefix)/*" Condition="'$(_DropName)' == ''"/>

    <MakeDir Directories="$(IbcOptimizationDataDir)" />

    <Message Text="Downloading optimization data from service $(_DropServiceUrl), drop $(_DropName)" Importance="high"/>
    <Exec Command='"$(_DropToolPath)" get --dropservice "$(_DropServiceUrl)" $(_PatAuthArg) --name "$(_DropName)" --dest "$(_DestArg)" --traceto "$(_DropsLogPath)"' />
  </Target>

</Project>