-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBazel.targets
77 lines (69 loc) · 3.65 KB
/
Bazel.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
<Project>
<!-- DO NOT import this project when bazel is building. use Condition="$(BazelBuild) == ''" when importing. -->
<PropertyGroup>
<!-- Configurations for Bazel.targets -->
<!--
If we include Publish in the list here, we'd have to include BazelBuild in the BeforeTargets list of
BazelPublish, which would always set the suffix to publish, we don't want that.
-->
<_BazelTargetsCore>
Restore;
Build;
Rebuild
</_BazelTargetsCore>
<BazelifyBeforeTargets>$(_BazelTargetsCore);Publish;Clean</BazelifyBeforeTargets>
<BazelBuildAfterTargets>$(_BazelTargetsCore);BazelPublish</BazelBuildAfterTargets>
</PropertyGroup>
<Target
Name="Bazelify"
BeforeTargets="$(BazelifyBeforeTargets)">
<ItemGroup>
<!-- This needs to be in a Target because in a solution build, ProjectReference items aren't populated until execution time -->
<_BazelProject Condition="$(BazelProjectUseSolutionItems) == 'true'" Include="@(ProjectReference)"/>
<!--
We can't override the Solution's targets in MSBuild so generate a no-op for any
MSBuild tasks that get invoked with the list of Project References.
-->
<ProjectReference Condition="$(BazelProjectUseSolutionItems) == 'true'" Remove="@(ProjectReference)"/>
<!-- Individual project file case -->
<_BazelProject Condition="$(BazelProjectUseSolutionItems) == ''" Include="$(MSBuildProjectFullPath)"/>
</ItemGroup>
<ItemGroup>
<!-- We can't update metadata for a list of items inside a Target, so we have to use _BazelProject first -->
<BazelProject Include="@(_BazelProject)">
<!-- \foo\bar\workspace\a\b.csproj => a\b\ => a/b/ => a/b => //a/b:b -->
<!-- \foo\bar\workspace\a.csproj => '..\workspace\' => '\' => '' => '//:a' -->
<BazelLabel>//$([MSBuild]::MakeRelative($(BazelWorkspacePath), %(RootDir)%(Directory))
.TrimStart('../'$(BazelWorkspace))
.Replace('\','/')
.Trim('/')):%(Filename)</BazelLabel>
</BazelProject>
</ItemGroup>
</Target>
<!-- Generate No-ops for msubild targets. We'll call bazel build after these.
These target definitions only affect project files, they are ignored in the solution metaproject, because that
defines these targets directly -->
<Target Name="Build" />
<Target Name="Rebuild" />
<Target Name="Clean">
<Error Text="Refusing to clean project. Cleaning an individual project is not possible with bazel. If you need to do a clean, clean the entire solution."/>
</Target>
<!-- Microsoft.NET.Publish.targets is imported after Directory.Build.targets, so unfortunately we can't do much for that here.
<Target Name="Publish" /> -->
<Target Name="Restore">
<!-- We are always able to override this target because it is defined by NuGet.targets, not the top level project,
for both the generated solution metaproj and a normal project file -->
<PropertyGroup>
<BazelTargetSuffix>_restore</BazelTargetSuffix>
</PropertyGroup>
</Target>
<Target Name="BazelPublish"
AfterTargets="Publish">
<PropertyGroup>
<BazelTargetSuffix>_publish</BazelTargetSuffix>
</PropertyGroup>
</Target>
<Target Name="BazelBuild" AfterTargets="$(BazelBuildAfterTargets)">
<Exec Command="bazel build @(BazelProject->'%(BazelLabel)$(BazelTargetSuffix)', ' ')"/>
</Target>
</Project>