-
Notifications
You must be signed in to change notification settings - Fork 850
Expand file tree
/
Copy pathinit.cmd
More file actions
298 lines (255 loc) · 8.86 KB
/
Copy pathinit.cmd
File metadata and controls
298 lines (255 loc) · 8.86 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
@echo off
rem Scripts cannot set enviroment variables because of an older handler in the agent that is not compatible with some pipeline containers
rem Hence to set enviroment variables, use SetEnviromentVariable
if not "%winui_echo%" == "" @echo on
goto :begin
rem This function is used to set enviroment variables in Azure Pipelines
rem It will call task.setVariable on top of the regular "set" command if /pipeline is passed in.
rem See comment at top of file for reasoning
:SetEnviromentVariable
set _varName=%~1
set _varValue=%~2
set %_varName%=%_varValue%
if not "%Pipeline%"=="true" (
set _varName=
set _varValue=
exit /b 0
)
echo ##vso[task.setVariable variable=%_varName%]%_varValue%
set _varName=
set _varValue=
exit /b 0
:AddPathIfExists
set _ToAdd=%~1
if not exist "%_ToAdd%" (
goto :PathNotFound
)
set PATH=%_ToAdd%;%PATH%
set _ToAdd=
exit /b 0
:PathNotFound
echo Could not find path: %~1
exit /b 4
:begin
set RepoRoot=%~dp0
rem Remove the trailing backslash
set RepoRoot=%RepoRoot:~0,-1%
set EnvOnly=
set EnvCheck=
set Verbose=
set NoTitle=
set Pipeline=
rem In case we run init.cmd multiple times, we don't want to keep our additions to PATH around.
rem We'll save the original value of PATH and restore it on future calls to init.cmd.
rem Given that PATH can get super long, we'll split this into multiple statements since having both "set"
rem statements on the same line can cause cmd to complain the command is too large.
if "%_OriginalPathBeforeInit%" neq "" goto :OriginalPathSet
set _OriginalPathBeforeInit=%PATH%
goto :DoneSettingPath
:OriginalPathSet
set PATH=%_OriginalPathBeforeInit%
:DoneSettingPath
set x86=
set amd64=
set ARM64=
set ARM64EC=
set fre=
set chk=
set _BuildArch=
set _BuildType=
set _DotNetMoniker=net8.0
set _archIsSet=
set _noPgo=
:parseArgs
if /i "%1"=="" (
goto:doneParsingArgs
) else if /i "%1"=="/envonly" (
set EnvOnly=true
) else if /i "%1"=="/envcheck" (
set EnvOnly=true
set EnvCheck=true
)else if /i "%1"=="/pipeline" (
set EnvOnly=true
set Pipeline=true
) else if /i "%1"=="/verbose" (
set Verbose=-Verbosity normal
) else if /i "%1"=="/notitle" (
set NoTitle=1
) else if /i "%1"=="x86chk" (
set x86=1
set chk=1
set _archIsSet=1
) else if /i "%1"=="x86fre" (
set x86=1
set fre=1
set _archIsSet=1
) else if /i "%1"=="x64fre" (
set amd64=1
set fre=1
set _archIsSet=1
) else if /i "%1"=="x64chk" (
set amd64=1
set chk=1
set _archIsSet=1
) else if /i "%1"=="amd64fre" (
set amd64=1
set fre=1
set _archIsSet=1
) else if /i "%1"=="amd64chk" (
set amd64=1
set chk=1
set _archIsSet=1
) else if /i "%1"=="arm64fre" (
set ARM64=1
set fre=1
set _archIsSet=1
) else if /i "%1"=="arm64chk" (
set ARM64=1
set chk=1
set _archIsSet=1
) else if /i "%1"=="arm64ecfre" (
set ARM64EC=1
set fre=1
set _archIsSet=1
) else if /i "%1"=="arm64ecchk" (
set ARM64EC=1
set chk=1
set _archIsSet=1
) else if /i "%1"=="net6" (
set _DotNetMoniker=net6.0
) else if /i "%1"=="net7" (
set _DotNetMoniker=net7.0
) else if /i "%1"=="net8" (
set _DotNetMoniker=net8.0
) else if /i "%1"=="/nopgo" (
set _noPgo=1
) else (
echo Syntax: %0 ^<arch^>^<flavor^> [^<options^>] [^<toolset^>]
echo.
echo ^<arch^> : x86 ^| ^(x64^|amd64^) ^| arm64 ^| arm64ec
echo ^<flavor^> : chk ^| fre
echo ^<options^> : /verbose, /envonly, /envcheck, /notitle, /nopgo
exit /b 1
)
rem To set enviroment variables, use SetEnviromentVariable
rem See top of file for reasoning
call :SetEnviromentVariable _DotNetMoniker %_DotNetMoniker%
call :SetEnviromentVariable RepoRoot "%RepoRoot%"
shift
goto:parseArgs
:doneParsingArgs
rem If /envcheck is specified, verify that a full init has been run at least once.
rem Without a prior full init, required tools and NuGet packages won't be available.
if "%EnvCheck%"=="true" (
if not exist "%RepoRoot%\packages" (
echo ERROR: Cannot use /envcheck because a full init has not been run yet.
echo Required tools and NuGet packages are missing.
echo.
echo Run a full init first: init.cmd [flavor]
echo Example: init.cmd amd64chk
exit /b 1
)
if not exist "%RepoRoot%\.tools" (
echo ERROR: Cannot use /envcheck because a full init has not been run yet.
echo Required tools and NuGet packages are missing.
echo.
echo Run a full init first: init.cmd [flavor]
echo Example: init.cmd amd64chk
exit /b 1
)
)
if "%_archIsSet%"=="" (
set amd64=1
set chk=1
)
set _archIsSet=
if "%x86%"=="1" (
call :SetEnviromentVariable _BuildArch x86
call :SetEnviromentVariable Platform Win32
)
if "%amd64%"=="1" (
call :SetEnviromentVariable _BuildArch amd64
call :SetEnviromentVariable Platform x64
)
if "%ARM64%"=="1" (
call :SetEnviromentVariable _BuildArch ARM64
call :SetEnviromentVariable Platform ARM64
)
if "%ARM64EC%"=="1" (
call :SetEnviromentVariable _BuildArch ARM64EC
call :SetEnviromentVariable Platform ARM64EC
)
if not "%Pipeline%"=="true" (
call :SetEnviromentVariable BUILDPLATFORM %Platform%
if "%x86%"=="1" (
call :SetEnviromentVariable BUILDPLATFORM x86
)
)
if "%fre%"=="1" (
call :SetEnviromentVariable _BuildType fre
call :SetEnviromentVariable Configuration Release
)
if "%chk%"=="1" (
call :SetEnviromentVariable _BuildType chk
call :SetEnviromentVariable Configuration Debug
)
rem Enable PGO optimization by default for release (fre) builds.
rem Developers can opt out by passing /nopgo to init.
rem ARM64EC is excluded because no PGO training data exists for that architecture.
rem Reset to Off so switching to chk or passing /nopgo disables PGO.
rem Using "Off" instead of empty so Invoke-CmdScript (init.ps1) propagates the value.
call:SetEnviromentVariable PGOBuildMode Off
if "%fre%"=="1" if not "%_noPgo%"=="1" if not "%ARM64EC%"=="1" (
call:SetEnviromentVariable PGOBuildMode Optimize
)
set _noPgo=
if "%DevEnvDir%" == "" goto :NeedDevCmd
where msbuild >nul 2>&1
if errorlevel 1 goto :NeedDevCmd
goto :SkipDevCmd
:NeedDevCmd
echo DevEnvDir environment variable not set or msbuild unavailable. Running DevCmd.cmd to get a developer command prompt...
if "%ARM64EC%"=="1" (
call %RepoRoot%\DevCmd.cmd /PreserveContext /prerelease -arch=amd64 -host_arch=amd64
) else if "%ARM64%"=="1" (
call %RepoRoot%\DevCmd.cmd /PreserveContext /prerelease -arch=arm64 -host_arch=amd64
) else (
call %RepoRoot%\DevCmd.cmd /PreserveContext /prerelease -arch=%_BuildArch% -host_arch=amd64
)
if errorlevel 1 (echo Could not set up a developer command prompt && exit /b %ERRORLEVEL%)
:SkipDevCmd
if "%VisualStudioVersion%" == "16.0" (echo Visual Studio 2019 is not supported. && exit /b /1)
set PATH=%RepoRoot%\.buildtools\MSBuild\Current\Bin\amd64;%RepoRoot%\.tools;%RepoRoot%\.tools\VSS.NuGet.AuthHelper;%RepoRoot%\tools;%RepoRoot%\dxaml\scripts;%PATH%
rem If we have init'd from a VS developer command prompt, we should use its tooling instead of the VS build tools installed with the repo
call :AddPathIfExists "%VSINSTALLDIR%\MSBuild\Current\Bin\amd64"
call :SetEnviromentVariable BuildArtifactsDir "%RepoRoot%\BuildOutput"
call :SetEnviromentVariable BinRoot "%BuildArtifactsDir%\Bin"
call :SetEnviromentVariable BuildOutputRoot "%BuildArtifactsDir%\Obj"
call :SetEnviromentVariable TEMP "%BuildArtifactsDir%\Temp\%_BuildArch%%_BuildType%"
call :SetEnviromentVariable TMP "%TEMP%"
if not exist "%TEMP%" mkdir "%TEMP%"
call :SetEnviromentVariable DOTNET_ROOT "%RepoRoot%\.dotnet"
call :SetEnviromentVariable DOTNET_ROOT_x86 "%RepoRoot%\.dotnet\x86"
call :SetEnviromentVariable DOTNET_INSTALL_DIR "%RepoRoot%\.dotnet"
call :SetEnviromentVariable DOTNET_MULTILEVEL_LOOKUP 0
set PATH=%DOTNET_ROOT%;%DOTNET_ROOT_x86%;%PATH%
call %RepoRoot%\scripts\init\SetupDotNetFiles.cmd %RepoRoot%
powershell -ExecutionPolicy Bypass -NoProfile %RepoRoot%\scripts\GenerateTestPfx.ps1 %RepoRoot%\build\WinUITest.pfx
if "%EnvOnly%"=="" (
rem For pipeline builds, submodules are checked out with authentication elsewhere
rem For dev builds, ensure that submodules are populated with latest commits
git submodule update --init --recursive
powershell -ExecutionPolicy Bypass -NoProfile -File %RepoRoot%\scripts\init\Initialize-Restore.ps1 -RepoRoot %RepoRoot% %Verbose%
)
if "%ARM64EC%"=="1" (
if exist %RepoRoot%\scripts\MockArm64ECFolder.ps1 (
powershell -ExecutionPolicy Bypass -NoProfile -File %RepoRoot%\scripts\MockArm64ECFolder.ps1
)
)
xcopy /d /y %RepoRoot%\scripts\winui.natvis "%USERPROFILE%\My Documents\Visual Studio 2022\Visualizers\" >nul 2>&1
set EnvironmentInitialized=1
if "%NoTitle%"=="" (
title DCPP %RepoRoot% - %_BuildArch%%_BuildType%
)
doskey /macrofile=%RepoRoot%\scripts\aliases
exit /b 0