Move CoreCLR to the modern build tools and dnx
[platform/upstream/coreclr.git] / tests / dir.targets
1 <?xml version="1.0" encoding="utf-8"?>
2 <Project ToolsVersion="12.0" InitialTargets="_RestoreBuildToolsWrapper" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
4   <!-- Inline task to bootstrap the build to enable downloading nuget.exe -->
5   <UsingTask TaskName="DownloadFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
6     <ParameterGroup>
7       <Address ParameterType="System.String" Required="true" />
8       <FileName ParameterType="System.String" Required="true" />
9     </ParameterGroup>
10     <Task>
11       <Reference Include="System" />
12       <Reference Include="System.IO" />
13       <Code Type="Fragment" Language="cs">
14         <![CDATA[
15             var directory = System.IO.Path.GetDirectoryName(FileName);
16             Directory.CreateDirectory(directory);
17
18             var tempFile = Path.Combine(directory, Path.GetRandomFileName());
19             var client = new System.Net.WebClient();
20             client.Proxy = System.Net.WebRequest.DefaultWebProxy;
21             if (client.Proxy != null) client.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
22             var tryCount = 1;
23             var maxTries = 3;
24
25             while (tryCount <= maxTries)
26             {
27                 try
28                 {
29                     Log.LogMessage("Attempting to download {0}...", Address);
30                     client.DownloadFile(Address, tempFile);
31                     break;
32                 }
33                 catch (System.Net.WebException e)
34                 {
35                     tryCount++;
36                     if (tryCount > maxTries)
37                     {
38                         throw;
39                     }
40                     else
41                     {
42                         Log.LogMessage(MessageImportance.High, "Download failed, retrying: {0}", e.Message);
43                     }
44                 }
45             }
46
47             try
48             {
49                 if (!File.Exists(FileName))
50                     File.Move(tempFile, FileName);
51             }
52             finally
53             {
54                 if (File.Exists(tempFile))
55                     File.Delete(tempFile);
56             }
57         ]]>
58       </Code>
59     </Task>
60   </UsingTask>
61
62   <!--
63     Needed to avoid the IntialTargets from having an Output which ends up getting
64     added to the output references when you have a project to project reference.
65   -->
66   <Target Name="_RestoreBuildToolsWrapper" DependsOnTargets="_RestoreBuildTools" />
67
68   <Target Name="_RestoreBuildTools"
69           Inputs="$(MSBuildThisFileDirectory)dir.props;$(SourceDir).nuget/packages.$(OsEnvironment).config"
70           Outputs="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll;$(NugetToolPath);$(DnuToolPath)">
71     <Message Importance="High" Text="Restoring build tools..." />
72
73     <Copy Condition="Exists('$(NuGetCachedPath)')" SourceFiles="$(NuGetCachedPath)" DestinationFiles="$(NuGetToolPath)" SkipUnchangedFiles="true" />
74
75     <!-- Download latest nuget.exe -->
76     <DownloadFile FileName="$(NuGetToolPath)"
77                   Address="https://www.nuget.org/nuget.exe"
78                   Condition="!Exists('$(NuGetToolPath)') and '$(OsEnvironment)'=='Windows_NT'" />
79
80     <Exec Command="curl -sSL --create-dirs -o $(NuGetToolPath) https://api.nuget.org/downloads/nuget.exe"
81           Condition="!Exists('$(NuGetToolPath)') and '$(OsEnvironment)'=='Unix'" />
82
83     <PropertyGroup>
84       <_RestoreBuildToolsCommand>$(NugetRestoreCommand) "$(SourceDir).nuget/packages.$(OsEnvironment).config"</_RestoreBuildToolsCommand>
85     </PropertyGroup>
86
87     <!-- Restore build tools -->
88     <Exec Command="$(_RestoreBuildToolsCommand)" StandardOutputImportance="Low" />
89
90     <!-- currently DNU doesn't support -ConfigFile: https://github.com/aspnet/dnx/issues/1693
91          Our DnuRestoreCommand doesn't force a config file  and we rely on the
92          directory probing for it to find nuget.config.  This works for restore from source,
93          but not restore from PackagesDir as happens for test project restore since PackagesDir
94          will not be under src.  To workaround, copy our nuget.config to packages. -->
95     <Copy Condition="Exists('$(NuGetConfigFile)')" SourceFiles="$(NuGetConfigFile)" DestinationFolder="$(PackagesDir)" SkipUnchangedFiles="true" />
96     <!-- <Copy Condition="Exists('$(NuGetConfigFile)')" SourceFiles="$(NuGetConfigFile)" DestinationFolder="$(IntermediateOutputRootPath)" SkipUnchangedFiles="true" /> -->
97
98     <!-- Add DNU and Roslyn tool execute rights -->
99     <Exec Condition="'$(OsEnvironment)'=='Unix'"
100           Command="chmod a+x &quot;$(DnxPackageDir)/bin/dnu&quot;" />
101     <Exec Condition="'$(OsEnvironment)'=='Unix'"
102           Command="chmod a+x &quot;$(DnxPackageDir)/bin/dnx&quot;" />
103     <Exec Condition="'$(OsEnvironment)'=='Unix'"
104           Command="find '$(RoslynPackageDir)tools' -name &quot;*.exe&quot; -exec chmod &quot;+x&quot; '{}' ';'" />
105
106     <Error Condition="'$(ErrorIfBuildToolsRestoredFromIndividualProject)'=='true'"
107            Text="The build tools package was just restored and so we cannot continue the build of an individual project because targets from the build tools package were not able to be imported. Please retry the build the individual project again." />
108
109     <!--
110       There are cases where the inputs could be newer than the outputs but the
111       download or restore may not need to update. In such cases we need to touch
112       these files otherwise we continually run this target over and over for
113       every project until these files are cleaned (if the are ever cleaned).
114     -->
115     <Touch Files="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll;$(NugetToolPath);$(DnuToolPath)" />
116   </Target>
117
118   <!-- Provide default empty targets for BuildAndTest and Test which can be hooked onto or overridden as necessary -->
119   <Target Name="BuildAndTest" DependsOnTargets="Build;Test" />
120
121   <Target Name="Test" />
122 </Project>