/
Microsoft.Orleans.CodeGenerator.MSBuild.targets
141 lines (118 loc) · 7.41 KB
/
Microsoft.Orleans.CodeGenerator.MSBuild.targets
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
<Project TreatAsLocalProperty="
Orleans_ArgsFile;
Orleans_CodeGenDirectory;
Orleans_CodeGeneratorEnabled;
Orleans_CoreAssembly;
Orleans_DotNetHost;
Orleans_GeneratorAssembly;
Orleans_MSBuildIsCore;
Orleans_OutputFileName;
Orleans_TargetIsCore;
Orleans_TaskAssembly;">
<PropertyGroup>
<Orleans_DotNetHost Condition="'$(DotNetFromPath)' == 'true'">dotnet</Orleans_DotNetHost>
<Orleans_CoreAssembly Condition="'$(OrleansCodeGenCoreAssembly)' != ''">$(OrleansCodeGenCoreAssembly)</Orleans_CoreAssembly>
<Orleans_CoreAssembly Condition="'$(Orleans_CoreAssembly)' == ''">$(MSBuildThisFileDirectory)..\tasks\Orleans.CodeGenerator.MSBuild.dll</Orleans_CoreAssembly>
<!-- Specify the assembly containing the MSBuild tasks. -->
<Orleans_MSBuildIsCore Condition="'$(MSBuildRuntimeType)' == 'Core' or '$(OS)' != 'Windows_NT'">true</Orleans_MSBuildIsCore>
<Orleans_TaskAssembly Condition="'$(OrleansCodeGenTasksAssembly)' != ''">$(OrleansCodeGenTasksAssembly)</Orleans_TaskAssembly>
<Orleans_TaskAssembly Condition="'$(Orleans_TaskAssembly)' == '' and '$(Orleans_MSBuildIsCore)' == 'true'">$(MSBuildThisFileDirectory)..\tasks\Orleans.CodeGenerator.MSBuild.Tasks.dll</Orleans_TaskAssembly>
<!-- When the MSBuild host is full-framework, we defer to PATH for dotnet -->
<Orleans_DotNetHost Condition="'$(Orleans_MSBuildIsCore)' != 'true'">dotnet</Orleans_DotNetHost>
<Orleans_DotNetHost Condition="'$(DotNetHost)' != ''">$(DotNetHost)</Orleans_DotNetHost>
<!-- Specify the assembly containing the code generator. -->
<Orleans_GeneratorAssembly Condition="'$(Orleans_GeneratorAssembly)' == ''">$(Orleans_CoreAssembly)</Orleans_GeneratorAssembly>
</PropertyGroup>
<PropertyGroup>
<OrleansCodeGenLogLevel Condition="'$(OrleansCodeGenLogLevel)' == ''">Warning</OrleansCodeGenLogLevel>
<Orleans_CodeGenDirectory Condition="'$([System.IO.Path]::IsPathRooted($(IntermediateOutputPath)))' == 'true'">$(IntermediateOutputPath)</Orleans_CodeGenDirectory>
<Orleans_CodeGenDirectory Condition="'$(Orleans_CodeGenDirectory)' == ''">$(ProjectDir)$(IntermediateOutputPath)</Orleans_CodeGenDirectory>
<Orleans_OutputFileName>$(Orleans_CodeGenDirectory)$(TargetName).orleans.g.cs</Orleans_OutputFileName>
<Orleans_CodeGeneratorEnabled Condition=" '$(DesignTimeBuild)' != 'true'">true</Orleans_CodeGeneratorEnabled>
<Orleans_ArgsFile>$(Orleans_CodeGenDirectory)$(TargetName).orleans.g.args.txt</Orleans_ArgsFile>
</PropertyGroup>
<UsingTask
TaskName="Orleans.CodeGenerator.MSBuild.Tasks.GetDotNetHost"
AssemblyFile="$(Orleans_TaskAssembly)"
Condition="'$(Orleans_CodeGeneratorEnabled)' == 'true' and '$(Orleans_DotNetHost)' == '' and '$(Orleans_MSBuildIsCore)' == 'true'" />
<!--
Input to the code generator should not include its output.
-->
<ItemGroup>
<Orleans_CodeGenInputs Include="@(Compile);@(ReferencePath)" />
<Orleans_CodeGenInputs Remove="$(Orleans_OutputFileName)" />
</ItemGroup>
<PropertyGroup>
<ResolveReferencesDependsOn>$(ResolveReferencesDependsOn);OrleansCodeGenCollectInputArgs;OrleansGenerateCode</ResolveReferencesDependsOn>
</PropertyGroup>
<!--
Update the file which captures the total set of all inputs to the code generator.
This is loosely based on the _GenerateCompileDependencyCache target from the .NET project system.
-->
<Target Name="OrleansCodeGenCollectInputArgs"
DependsOnTargets="ResolveAssemblyReferences"
Condition="'$(Orleans_CodeGeneratorEnabled)' == 'true'">
<ItemGroup>
<Orleans_CodeGenArgs Include="WaitForDebugger" Condition="'$(OrleansCodeGenWaitForDebugger)' != ''" />
<Orleans_CodeGenArgs Include="LogLevel:$(OrleansCodeGenLogLevel)" />
<Orleans_CodeGenArgs Include="DebuggerStepThrough:true" Condition="'$(OrleansCodeGenDebuggerStepThrough)' == 'true'" />
<Orleans_CodeGenArgs Include="ProjectPath:$(MSBuildProjectFullPath)"/>
<Orleans_CodeGenArgs Include="ProjectGuid:$(ProjectGuid)"/>
<Orleans_CodeGenArgs Include="AssemblyName:$(AssemblyName)"/>
<Orleans_CodeGenArgs Include="OutputType:$(OutputType)"/>
<Orleans_CodeGenArgs Include="TargetPath:$(TargetPath)"/>
<Orleans_CodeGenArgs Include="CodeGenOutputFile:$(Orleans_OutputFileName)"/>
<Orleans_CodeGenArgs Include="@(Compile -> 'Compile:%(FullPath)')"/>
<Orleans_CodeGenArgs Include="@(ReferencePath -> 'Reference:%(FullPath)')"/>
<Orleans_CodeGenArgs Include="DefineConstants:$(DefineConstants.Replace(';',','))"/>
</ItemGroup>
<Message Text="[Orleans.CodeGenerator] - CodeGen arguments=@(Orleans_CodeGenArgs -> '%(Identity)')" Importance="Low"/>
<Message Text="[Orleans.CodeGenerator] - CodeGen arguments file=$(Orleans_ArgsFile)" Importance="Low"/>
<!--
In order to detect when the set of input files itself has changed, or some property values have changed,
these values are hashed into the arguments file. Any changes will trigger a file write and hence the code
generator will be re-executed.
-->
<Hash ItemsToHash="@(Orleans_CodeGenInputs);@(Orleans_CodeGenArgs)">
<Output TaskParameter="HashResult" PropertyName="Orleans_UpdatedInputCacheContents" />
</Hash>
<!-- Add the hash of inputs to the codegen arguments and write the arguments file if it has changed -->
<ItemGroup>
<Orleans_CodeGenArgs Include="InputHash:$(Orleans_UpdatedInputCacheContents)"/>
</ItemGroup>
<WriteLinesToFile
Overwrite="true"
File="$(Orleans_ArgsFile)"
Lines="@(Orleans_CodeGenArgs)"
WriteOnlyWhenDifferent="True"/>
<ItemGroup>
<FileWrites Include="$(Orleans_ArgsFile)" Condition="Exists('$(Orleans_ArgsFile)')" />
</ItemGroup>
</Target>
<Target Name="OrleansGenerateCode"
AfterTargets="OrleansCodeGenCollectInputArgs;ResolveAssemblyReferences"
BeforeTargets="AssignTargetPaths"
Inputs="@(Orleans_CodeGenInputs);$(Orleans_ArgsFile)"
Outputs="$(Orleans_OutputFileName)"
Condition="'$(Orleans_CodeGeneratorEnabled)' == 'true'">
<Message Text="[Orleans.CodeGenerator] - CodeGen executable=$(Orleans_GeneratorAssembly)" Importance="Low" />
<Orleans.CodeGenerator.MSBuild.Tasks.GetDotNetHost Condition="'$(Orleans_DotNetHost)' == '' and '$(Orleans_MSBuildIsCore)' == 'true' ">
<Output TaskParameter="DotNetHost" PropertyName="Orleans_DotNetHost" />
</Orleans.CodeGenerator.MSBuild.Tasks.GetDotNetHost>
<!-- Use dotnet to execute the process. -->
<Exec Command=""$(Orleans_DotNetHost)" "$(Orleans_GeneratorAssembly)" SourceToSource "$(Orleans_ArgsFile)"" Outputs="$(Orleans_OutputFileName)" />
<Touch Files="$(Orleans_OutputFileName)" />
<ItemGroup>
<Compile Include="$(Orleans_OutputFileName)" Condition="Exists('$(Orleans_OutputFileName)')" />
<FileWrites Include="$(Orleans_OutputFileName)" Condition="Exists('$(Orleans_OutputFileName)')"/>
</ItemGroup>
</Target>
<Target Name="OrleansIncludeCodegenOutputDuringDesignTimeBuild"
BeforeTargets="AssignTargetPaths"
Condition="'$(Orleans_CodeGeneratorEnabled)' != 'true' and Exists('$(Orleans_OutputFileName)')">
<ItemGroup>
<Compile Include="$(Orleans_OutputFileName)" Condition="Exists('$(Orleans_OutputFileName)')" />
<FileWrites Include="$(Orleans_OutputFileName)" Condition="Exists('$(Orleans_OutputFileName)')" />
</ItemGroup>
</Target>
</Project>