-
Notifications
You must be signed in to change notification settings - Fork 321
/
Common.targets
146 lines (125 loc) · 7 KB
/
Common.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
142
143
144
145
146
<?xml version="1.0" encoding="utf-8"?>
<!--
* Consume .bond files and produce C# types
*
* (Dependencies are defined by Bond.CSharp.props. Be sure to import that first)
* Dependencies:
* $BOND_INCLUDE_PATH : Bond provided imports
* $BOND_COMPILER_PATH : Path to directory containing gbc.exe
*
* User-Defines:
* @BondCodegen : A bond idl file (usually with a .bond extension) to compile
* %Options : Any gbc options unique to this file (prefer $BondOptions than per-file)
* @BondImportDirectory : Directory for other schemas imported within a .bond file
* $BondOutputDirectory : Output directory for the generated files, by default IntermediateOutputPath
* $BondOptions : Additional options to pass to the gbc generator
* $BondCodegenMode : Code generation mode for gbc.exe to use (default c#)
*
-->
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- A set of properties that users of these targets can use to control whether proxies, services,
and types are included in compilation. The default for all is false, as including them via
these targets breaks ReSharper. -->
<PropertyGroup>
<BondOptions Condition=" '$(BondOptions)' == '' "></BondOptions>
<BondOutputDirectory Condition=" '$(BondOutputDirectory)' == '' ">$(IntermediateOutputPath)</BondOutputDirectory>
<BondCodegenMode Condition="'$(BondCodegenMode)' == ''">c#</BondCodegenMode>
</PropertyGroup>
<ItemDefinitionGroup>
<!-- Hide these from the VS project view -->
<BondImportDirectory>
<Visible>false</Visible>
</BondImportDirectory>
</ItemDefinitionGroup>
<!-- Let Visual Studio know about the BondCodegen item so it can display
it in the UI as a potential action for files. -->
<ItemGroup>
<AvailableItemName Include="BondCodegen" />
</ItemGroup>
<!-- Attempt to find gbc in a platform-agnostic way. -->
<PropertyGroup>
<_PreExistingBondExe></_PreExistingBondExe>
<_PreExistingBondExe Condition="Exists('$(BOND_COMPILER_PATH)\gbc.exe')">$(BOND_COMPILER_PATH)\gbc.exe</_PreExistingBondExe>
<_PreExistingBondExe Condition="Exists('$(BOND_COMPILER_PATH)\gbc')">$(BOND_COMPILER_PATH)\gbc</_PreExistingBondExe>
</PropertyGroup>
<!-- Some versions of Visual Studio have an additional up-to-date check
that is performed on a subset of files before invoking MSBuild. We
need to add gbc as an input to the Visual Studio up-to-date check as
well. -->
<ItemGroup>
<UpToDateCheckInput Include="$(_PreExistingBondExe)" />
</ItemGroup>
<!-- BondCodegenCs - transform .bond files into .cs files
If we were to use an output transform from BondCodegen to the
resulting .cs files we could get partial/minimal rebuilds on changes,
but this behavior doesn't reflect the internal import logic of Bond.
A change to common.bond would only rebuild common*cs, not all the
other files that import common.bond. Without a Bond parser prepass we
must rebuild all .bond files when any of them change. We force that
by putting a non-transform output (bondcodegen.done) in the list so
if any input changes, then all inputs rebuild since MSBuild can't
know what should create the unmapped output item and so can't be
selective.
NOTE: This still won't catch changes to files imported outside the
BondCodegen item. -->
<Target Name="BondCodegenCs"
Inputs="$(_PreExistingBondExe);@(BondCodegen)"
Outputs="$(BondOutputDirectory)\bondcodegen.done;@(BondCodegen -> '$(BondOutputDirectory)\%(FileName)_types.cs')"
BeforeTargets="CoreCompile"
Condition="'@(BondCodegen)' != ''">
<Error Text="Neither Bond.CSharp.props nor Bond.Compiler.CSharp.props was imported. Check that your NuGet package references are working properly."
Condition="'$(_bond_common_props_imported)' != 'true'" />
<MakeDir Directories="$(BondOutputDirectory)" />
<!-- just for a simpler commandline read -->
<PropertyGroup>
<_BondExe>gbc</_BondExe>
<_BondExe Condition="Exists('$(BOND_COMPILER_PATH)\gbc.exe')">$(BOND_COMPILER_PATH)\gbc.exe</_BondExe>
<_BondExe Condition="Exists('$(BOND_COMPILER_PATH)\gbc')">$(BOND_COMPILER_PATH)\gbc</_BondExe>
<_BondImportDirs>--import-dir="$(BOND_INCLUDE_PATH)" @(BondImportDirectory -> '--import-dir="%(Identity)\."',' ')</_BondImportDirs>
<_BondCommand>"$(_BondExe)" $(BondCodegenMode) $(_BondImportDirs) --jobs=-2 --namespace=bond=Bond --output-dir="$(BondOutputDirectory)\."</_BondCommand>
</PropertyGroup>
<!-- We'll optimize to generate in a single command where possible -->
<!-- Workaround for xbuild. It does not support ItemDefinitionGroup, so use Options only with MSBuild -->
<ItemGroup>
<_BondCodegenWithDefaultOptions Include="@(BondCodegen)" Condition="'%(BondCodegen.Options)' == ''" />
</ItemGroup>
<WriteLinesToFile File="$(BondOutputDirectory)\bonddefaultcodegen.in"
Lines="@(_BondCodegenWithDefaultOptions)"
Overwrite="true" />
<Exec Command="$(_BondCommand) $(BondOptions) @"$(BondOutputDirectory)\bonddefaultcodegen.in""
Condition="'@(_BondCodegenWithDefaultOptions)' != ''" />
<!-- And for any files needing custom options we'll have to generate one by one -->
<Exec Command="$(_BondCommand) %(BondCodegen.Options) "%(BondCodegen.Identity)""
Condition="'%(BondCodegen.Options)' != ''" />
<!-- Record all that we successfully ran codegen on all the files. -->
<WriteLinesToFile File="$(BondOutputDirectory)\bondcodegen.done"
Lines="#Ran codegen on the following files:;@(BondCodegen)"
Overwrite="true" />
</Target>
<!--
* BondCompileCs - whether or not we are rebuilding bond sources, we still need them compiled,
* so this target should always run.
-->
<Target Name="BondCompileCs"
BeforeTargets="CoreCompile"
Condition="'@(BondCodegen)' != ''">
<ItemGroup>
<_BondGeneratedFiles Include="@(BondCodegen -> '$(BondOutputDirectory)\%(FileName)_types.cs')">
<AutoGen>true</AutoGen>
<DependentUpon>%(BondCodegen.Identity)</DependentUpon>
</_BondGeneratedFiles>
<_BondGeneratedFileNames Include="@(_BondGeneratedFiles)"/>
<Compile Include="@(_BondGeneratedFileNames)" />
<!--
* MsBuild wants to keep track of all our outputs, to understand how to clean build. It seems it
* needs to know all of them regardless of what we actually produced THIS build, so adding always.
-->
<FileWrites Include="$(BondOutputDirectory)\bondcodegen.done;
$(BondOutputDirectory)\bonddefaultcodegen.in;
@(_BondGeneratedFileNames)" />
</ItemGroup>
</Target>
<PropertyGroup>
<_bond_common_targets_imported>true</_bond_common_targets_imported>
</PropertyGroup>
</Project>