-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.bat
118 lines (79 loc) · 3.37 KB
/
build.bat
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
@echo off
if [%VisualStudioVersion%]==[] (
echo Please launch this build script from a Visual Studio command prompt
exit /b 1
)
if [%1]==[] goto USAGE
set CERT_THUMBPRINT=%1
set TIMESTAMP_SERVER=http://timestamp.digicert.com
set CAB_ARCH=%VSCMD_ARG_TGT_ARCH%
if "%CAB_ARCH%"=="x64" (
set CAB_ARCH=amd64
)
set INF2CAT_OS=10_%VSCMD_ARG_TGT_ARCH%
if "%VSCMD_ARG_TGT_ARCH%"=="arm64" (
set INF2CAT_OS=10_VB_%VSCMD_ARG_TGT_ARCH%
)
set ROOT=%~dp0
:: Force complete rebuild
rmdir /s /q %ROOT%bin
:: Build driver but do not sign it
:: It's not possible to control all arguments to signtool through msbuild
msbuild.exe %ROOT%src\mullvad-split-tunnel.vcxproj /p:Configuration=Release /p:Platform=%VSCMD_ARG_TGT_ARCH% /p:SignMode=Off
IF %ERRORLEVEL% NEQ 0 goto ERROR
:: Sign driver
signtool sign /tr %TIMESTAMP_SERVER% /td sha256 /fd sha256 /sha1 "%CERT_THUMBPRINT%" /v %ROOT%bin\%VSCMD_ARG_TGT_ARCH%-Release\mullvad-split-tunnel\mullvad-split-tunnel.sys
IF %ERRORLEVEL% NEQ 0 goto ERROR
:: Re-generate catalog file now that driver binary has changed
del %ROOT%bin\%VSCMD_ARG_TGT_ARCH%-Release\mullvad-split-tunnel\mullvad-split-tunnel.cat
"%WindowsSdkVerBinPath%x86\inf2cat.exe" /driver:%ROOT%bin\%VSCMD_ARG_TGT_ARCH%-Release\mullvad-split-tunnel /os:"%INF2CAT_OS%" /verbose
IF %ERRORLEVEL% NEQ 0 goto ERROR
:: Sign catalog
signtool sign /tr %TIMESTAMP_SERVER% /td sha256 /fd sha256 /sha1 "%CERT_THUMBPRINT%" /v %ROOT%bin\%VSCMD_ARG_TGT_ARCH%-Release\mullvad-split-tunnel\mullvad-split-tunnel.cat
IF %ERRORLEVEL% NEQ 0 goto ERROR
:: Build a CAB file for submission to the MS Hardware Dev Center
mkdir %ROOT%bin\temp\cab
>"%ROOT%bin\temp\cab\mullvad-split-tunnel-%CAB_ARCH%.ddf" (
echo .OPTION EXPLICIT ; Generate errors
echo .Set CabinetFileCountThreshold=0
echo .Set FolderFileCountThreshold=0
echo .Set FolderSizeThreshold=0
echo .Set MaxCabinetSize=0
echo .Set MaxDiskFileCount=0
echo .Set MaxDiskSize=0
echo .Set CompressionType=MSZIP
echo .Set Cabinet=on
echo .Set Compress=on
echo .Set CabinetNameTemplate=mullvad-split-tunnel-%CAB_ARCH%.cab
echo .Set DestinationDir=Package
echo .Set DiskDirectoryTemplate=%ROOT%bin\temp\cab
echo %ROOT%bin\%VSCMD_ARG_TGT_ARCH%-Release\mullvad-split-tunnel\mullvad-split-tunnel.cat
echo %ROOT%bin\%VSCMD_ARG_TGT_ARCH%-Release\mullvad-split-tunnel\mullvad-split-tunnel.inf
echo %ROOT%bin\%VSCMD_ARG_TGT_ARCH%-Release\mullvad-split-tunnel\mullvad-split-tunnel.sys
echo %ROOT%bin\%VSCMD_ARG_TGT_ARCH%-Release\mullvad-split-tunnel\mullvad-split-tunnel.pdb
)
:: makecab produces several garbage files
:: Force current working directory to prevent spreading them out
pushd %ROOT%bin\temp\cab
makecab /f "%ROOT%bin\temp\cab\mullvad-split-tunnel-%CAB_ARCH%.ddf"
popd
IF %ERRORLEVEL% NEQ 0 goto ERROR
signtool sign /tr %TIMESTAMP_SERVER% /td sha256 /fd sha256 /sha1 "%CERT_THUMBPRINT%" /v %ROOT%bin\temp\cab\mullvad-split-tunnel-%CAB_ARCH%.cab
IF %ERRORLEVEL% NEQ 0 goto ERROR
:: Collect artifacts
mkdir %ROOT%bin\dist
copy /b %ROOT%bin\%VSCMD_ARG_TGT_ARCH%-Release\mullvad-split-tunnel\mullvad-split-tunnel.pdb %ROOT%bin\dist\
copy /b %ROOT%bin\temp\cab\mullvad-split-tunnel-%CAB_ARCH%.cab %ROOT%bin\dist\
echo;
echo BUILD COMPLETED SUCCESSFULLY
echo ARTIFACTS ARE IN --^> bin/dist/ ^<--
echo;
exit /b 0
:USAGE
echo Usage: %0 ^<cert_sha1_hash^>
exit /b 1
:ERROR
echo;
echo !!! BUILD FAILED !!!
echo;
exit /b 1