summaryrefslogtreecommitdiff
path: root/tests/helixperftasks.targets
blob: 62da5e4c32935f3463be5a711d4799cb2cb20d03 (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
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <UsingTask TaskName="RemoveDuplicateAssemblies" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
      <ParameterGroup>
        <DuplicateAssemblies ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
        <AssemblyPaths ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
        <UniqueAssemblyPaths ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" />
      </ParameterGroup>
      <Task>
        <Using Namespace="System"/>
        <Using Namespace="System.IO"/>
        <Using Namespace="System.Collections.Generic"/>
        <Code Type="Fragment" Language="cs">
          <![CDATA[
                  var uniqueAssemblyPathsList = new List<Microsoft.Build.Framework.ITaskItem>();
                  var dupeSet = new HashSet<string>();
                  foreach(var dupe in DuplicateAssemblies)
                  {
                    dupeSet.Add(dupe.GetMetadata("Identity"));
                  }
                  foreach(var assemPath in AssemblyPaths)
                  {
                    if((dupeSet.Contains(assemPath.GetMetadata("FileName")+assemPath.GetMetadata("Extension")) &&
                        !(assemPath.GetMetadata("Identity").StartsWith("runtime"))))
                    {
                      Log.LogMessage("Duplicate assembly filtered: {0}", assemPath.GetMetadata("Identity"));
                    }
                    else
                    {
                      uniqueAssemblyPathsList.Add(assemPath);
                    }

                  }
                  UniqueAssemblyPaths = uniqueAssemblyPathsList.ToArray();
          ]]>
        </Code>
      </Task>
    </UsingTask>


  <UsingTask TaskName="GetPerfTestAssemblies" AssemblyFile="$(ToolsDir)net45/Microsoft.DotNet.Build.CloudTestTasks.dll"/>
  <Import Project="$(ToolsDir)publishtest.targets" />
  <Import Project="$(ToolsDir)CloudTest.targets" />
  <Target Name="UploadPerfAssemblies">
    <Message Text="Searching for Perf tests in $(BinDir)" Importance = "High"/>
    <ItemGroup>
      <TestBinary Include="$(BinDir)**/*.dll" />
      <TestBinary Include="$(BinDir)**/*.exe" />
    </ItemGroup>
    <!-- Get full paths to each of the perf test directories -->
    <GetPerfTestAssemblies TestBinaries="@(TestBinary)" GetFullPaths="true">
      <Output TaskParameter="PerfTestAssemblies" ItemName="CoreCLRPerfTest" />
    </GetPerfTestAssemblies>

    <ItemGroup>
     <DnuSourceList Include="$(CORE_ROOT)\.nuget\pkg" />
    </ItemGroup>

    <!-- Restore the runtime dependencies -->
    <Exec Command="$(DnuRestoreCommand) &quot;$(TestRuntimeProjectJson)&quot;"
           StandardOutputImportance="Low"
           CustomErrorRegularExpression="^Unable to resolve .*"
           IgnoreExitCode="true"
           IgnoreStandardErrorWarningFormat="true" />

    <!-- For each perf test, generate assembly list, and zip up the workitem -->
    <MSBuild Projects="$(MSBuildProjectFile)" Properties="CurrPerfAssembly=%(CoreCLRPerfTest.Identity);TestRuntimeProjectLockJson=$(TestRuntimeProjectLockJson)" Targets="_zipSingleProject"/>

    <!-- After all workitems are packaged, call the CloudBuild Targets from Build Tools which upload these workitems and trigger a test run for these workitems -->
    <MSBuild Projects="$(MSBuildProjectFile)" Properties="BinDir=$(BinDir)../" Targets="CloudBuild" />

  </Target>

  <Target Name="RunTestsForProject">
    <Message Text="This is a dummy target to appease DependsOnTargets for ArchiveTestBuild in publishtest.targets" Importance="Low" />
  </Target>

  <!-- CoreCLR builds do not generate dependency lists yet, we need to archive the whole packages dir so that tests can find dependencies -->
  <!-- compress the required files from the packages dir in preparation for uploading -->
  <Target Name="CompressPackagesDir">
    <ItemGroup>
      <ExcludeFromArchive Include="nupkg$" />
      <ExcludeFromArchive Include="Microsoft.DotNet.BuildTools" />
      <ExcludeFromArchive Include="TestData" />
    </ItemGroup>
    <ZipFileCreateFromDirectory
        SourceDirectory="$(PackagesDir)"
        DestinationArchive="$(PackagesArchiveFile)"
        ExcludePatterns="@(ExcludeFromArchive)"
        OverwriteDestination="true" />
    <ItemGroup>
      <ForUpload Include="$(PackagesArchiveFile)">
        <RelativeBlobPath>$(Platform)$(ConfigurationGroup)/$(PackagesArchiveFilename)</RelativeBlobPath>
      </ForUpload>
    </ItemGroup>
  </Target>

  <Target Name="_zipSingleProject">
    <PropertyGroup>
      <OutDir>$([System.IO.Path]::GetDirectoryName($(CurrPerfAssembly)))/</OutDir>
      <TestArchiveDir>$(BaseOutputPath)\testStagingDir\</TestArchiveDir>
      <TestProjectName>$([System.IO.Path]::GetFileNameWithoutExtension($(CurrPerfAssembly)))</TestProjectName>
      <ProjectLockJson>$(OutDir)project.lock.json</ProjectLockJson>
    </PropertyGroup>

    <ItemGroup>
      <TestNugetProjectLockFile Include="$(ProjectLockJson)" Condition="Exists($(ProjectLockJson))"/>
      <TestNugetProjectLockFile Include="$(TestRuntimeProjectLockJson)" Condition="Exists($(TestRuntimeProjectLockJson))"/>
    </ItemGroup>

    <!-- Generate Assembly list based on the individual project's project.json as well as the common runtime dependencies generated by AddAssFilesToAssemblyList target -->
    <PrereleaseResolveNuGetPackageAssets
                               AllowFallbackOnTargetSelection="true"
                               IncludeFrameworkReferences="false"
                               NuGetPackagesDirectory="$(PackagesDir)"
                               RuntimeIdentifier="$(TestNugetRuntimeId)"
                               ProjectLanguage="C#"
                               ProjectLockFile="%(TestNugetProjectLockFile.FullPath)"
                               TargetMonikers="@(TestTargetFramework)">
      <Output TaskParameter="ResolvedCopyLocalItems" ItemName="RequiredAssemblies" />
    </PrereleaseResolveNuGetPackageAssets>


    <ItemGroup>
      <AssemblyPaths Include="$([MSBuild]::MakeRelative($(PackagesDir), %(RequiredAssemblies.FullPath)))" />
      <AssemblyFiles Include="@(RequiredAssemblies->'%(FileName)%(Extension)')"></AssemblyFiles>
      <DupeAssemblies Include="%(AssemblyFiles.Identity)" Condition="'@(AssemblyFiles->Count())' &gt; 1"> </DupeAssemblies>
    </ItemGroup>
    <!-- There are duplicate dependency assemblies calculated for some projects that we need to fix, this is check/fix to weed out duplicates -->
    <RemoveDuplicateAssemblies AssemblyPaths="@(AssemblyPaths)" DuplicateAssemblies="@(DupeAssemblies)">
      <Output TaskParameter="UniqueAssemblyPaths" ItemName="UniqueAssemblyPaths" />
    </RemoveDuplicateAssemblies>

    <WriteLinesToFile
      File="$(OutDir)/assemblylist.flat.txt"
      Lines="@(UniqueAssemblyPaths)"
      Overwrite="true"
      Encoding="Ascii" />

    <GenerateAssemblyList
      InputListLocation="$(OutDir)assemblylist.flat.txt"
      OutputListLocation="$(OutDir)assemblylist.txt"
     />

    <Message Text="Archiving Perf test assemblies for project: $(OutDir)" Importance="High" />
    <MSBuild Projects="$(MSBuildProjectFile)" Properties="OutDir=$(OutDir);TestArchiveDir=$(TestArchiveDir);TestProjectName=$(TestProjectName)" Targets="ArchiveTestBuild"/>
  </Target>
</Project>