-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathMicrosoft.WSL.Containers.common.targets
More file actions
127 lines (105 loc) · 5.8 KB
/
Microsoft.WSL.Containers.common.targets
File metadata and controls
127 lines (105 loc) · 5.8 KB
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
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="WSLCSDK_ErrorNoPlatform" BeforeTargets="PrepareForBuild" Condition="'$(WSLCSDK_Platform)' == ''">
<Error Text="wslcsdk.dll could not be copied because the AnyCPU platform is being used. Please specify a platform to copy this file, using either RuntimeIdentifier, an architecture specific Platform, or explicitly with WSLCSDK_Platform." />
</Target>
<ItemGroup>
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\runtimes\win-$(WSLCSDK_Platform)\wslcsdk.dll" />
</ItemGroup>
<!-- ================================================================== -->
<!-- Container Image Build Targets -->
<!-- ================================================================== -->
<!-- Default properties -->
<PropertyGroup>
<WslcImageOutputDir Condition="'$(WslcImageOutputDir)' == ''">$(OutDir)</WslcImageOutputDir>
<WslcCliPath Condition="'$(WslcCliPath)' == '' AND Exists('$(ProgramW6432)\WSL\wslc.exe')">$(ProgramW6432)\WSL\wslc.exe</WslcCliPath>
<WslcCliPath Condition="'$(WslcCliPath)' == ''">wslc</WslcCliPath>
</PropertyGroup>
<!-- Default metadata for WslcImage items -->
<ItemDefinitionGroup>
<WslcImage>
<Tag>latest</Tag>
<OutputDir>$(WslcImageOutputDir)</OutputDir>
</WslcImage>
</ItemDefinitionGroup>
<!-- Auto-detection fallback: if no WslcImage declared, detect container/Dockerfile -->
<ItemGroup Condition="'@(WslcImage)' == '' AND Exists('$(ProjectDir)container\Dockerfile')">
<WslcImage Include="$(MSBuildProjectName)"
Dockerfile="$(ProjectDir)container\Dockerfile"
Context="$(ProjectDir)container"
Sources="$(ProjectDir)container" />
</ItemGroup>
<ItemGroup Condition="'@(WslcImage)' == '' AND Exists('$(ProjectDir)docker\Dockerfile')">
<WslcImage Include="$(MSBuildProjectName)"
Dockerfile="$(ProjectDir)docker\Dockerfile"
Context="$(ProjectDir)docker"
Sources="$(ProjectDir)docker" />
</ItemGroup>
<!-- Check that wslc CLI is installed -->
<Target Name="WslcCheckDependencies"
BeforeTargets="WslcBuildAllImages"
Condition="'@(WslcImage)' != ''">
<Exec Command=""$(WslcCliPath)" --version"
IgnoreExitCode="true"
ConsoleToMSBuild="true"
StandardOutputImportance="low"
StandardErrorImportance="low">
<Output TaskParameter="ExitCode" PropertyName="_WslcExitCode" />
</Exec>
<Error Condition="'$(_WslcExitCode)' != '0'"
Code="WSLC0001"
Text="The WSLC runtime was not found. Install WSL by running: wsl --install --no-distribution" />
</Target>
<!-- Outer target: dispatch each WslcImage to inner target via MSBuild task -->
<Target Name="WslcBuildAllImages"
AfterTargets="Build"
DependsOnTargets="WslcCheckDependencies"
Condition="'@(WslcImage)' != ''">
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="_WslcBuildSingleImage"
Properties="Configuration=$(Configuration);Platform=$(Platform);_WslcName=%(WslcImage.Identity);_WslcTag=%(WslcImage.Tag);_WslcDockerfile=%(WslcImage.Dockerfile);_WslcContext=%(WslcImage.Context);_WslcSourceDir=%(WslcImage.Sources);_WslcOutput=%(WslcImage.OutputDir)" />
</Target>
<!--
Collect source files for incremental check.
Wildcards are expanded here in ItemGroup Include (not in Inputs attribute or MSBuild task Properties,
where they get escaped). Sources can be semicolon separated directory paths;
each is expanded with **\* to collect all files recursively.
-->
<Target Name="_WslcCollectSources" BeforeTargets="_WslcBuildSingleImage">
<ItemGroup>
<_WslcSourceDirs Include="$(_WslcSourceDir.Split(';'))" />
<_WslcSourceFiles Include="$(_WslcDockerfile)" />
<_WslcSourceFiles Include="%(_WslcSourceDirs.Identity)\**\*" Condition="'%(_WslcSourceDirs.Identity)' != ''" />
</ItemGroup>
</Target>
<!-- Inner target: build a single image with incremental check -->
<Target Name="_WslcBuildSingleImage"
DependsOnTargets="_WslcCollectSources"
Inputs="@(_WslcSourceFiles)"
Outputs="$(IntDir)wslc_$(_WslcName).marker">
<MakeDir Directories="$(IntDir)" />
<Message Importance="high"
Text="WSLC: Building image '$(_WslcName):$(_WslcTag)'..." />
<Exec Command=""$(WslcCliPath)" image build -t "$(_WslcName):$(_WslcTag)" -f "$(_WslcDockerfile)" "$(_WslcContext)""
ConsoleToMSBuild="true" />
<!--
Uncomment when wslc image save is available:
<MakeDir Directories="$(_WslcOutput)" />
<Exec Command=""$(WslcCliPath)" image save -o "$(_WslcOutput)\$(_WslcName).tar" "$(_WslcName):$(_WslcTag)""
ConsoleToMSBuild="true" />
-->
<Touch Files="$(IntDir)wslc_$(_WslcName).marker" AlwaysCreate="true" />
<Message Importance="high"
Text="WSLC: [$(_WslcName)] Image '$(_WslcName):$(_WslcTag)' built successfully." />
</Target>
<!-- Clean container artifacts -->
<Target Name="WslcClean"
AfterTargets="Clean"
Condition="'@(WslcImage)' != ''">
<Delete Files="$(IntDir)wslc_%(WslcImage.Identity).marker" />
<!--
Uncomment when wslc image save is available:
<Delete Files="%(WslcImage.OutputDir)\%(WslcImage.Identity).tar" />
-->
</Target>
</Project>