-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_scriptsource.cmd
168 lines (146 loc) · 5.28 KB
/
build_scriptsource.cmd
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
@ECHO OFF
REM Copyright (C) 2020-2024 v0lt
REM
REM SPDX-License-Identifier: LGPL-2.1-only
SETLOCAL
CD /D %~dp0
SET "TITLE=MPC Script Source"
SET "PROJECT=MpcScriptSource"
SET "MSBUILD_SWITCHES=/nologo /consoleloggerparameters:Verbosity=minimal /maxcpucount /nodeReuse:true"
SET "BUILDTYPE=Build"
SET "BUILDCFG=Release"
SET "SUFFIX="
SET "SIGN=False"
FOR %%A IN (%*) DO (
IF /I "%%A" == "Debug" (
SET "BUILDCFG=Debug"
SET "SUFFIX=_Debug"
)
IF /I "%%A" == "Sign" (
SET "SIGN=True"
)
)
IF /I "%SIGN%" == "True" (
IF NOT EXIST "%~dp0signinfo.txt" (
CALL :SubMsg "WARNING" "signinfo.txt not found."
SET "SIGN=False"
)
)
CALL :SubVSPath
SET "TOOLSET=%VS_PATH%\Common7\Tools\vsdevcmd"
SET "LOG_DIR=_bin\logs"
IF NOT EXIST "%LOG_DIR%" MD "%LOG_DIR%"
CALL "%TOOLSET%" -no_logo -arch=x86
REM again set the source directory (fix possible bug in VS2017)
CD /D %~dp0
CALL :SubCompiling x86
CALL "%TOOLSET%" -no_logo -arch=amd64
REM again set the source directory (fix possible bug in VS2017)
CD /D %~dp0
CALL :SubCompiling x64
IF /I "%SIGN%" == "True" (
SET FILES="%~dp0_bin\Filter_x86%SUFFIX%\%PROJECT%.ax" "%~dp0_bin\Filter_x64%SUFFIX%\%PROJECT%64.ax"
CALL "%~dp0\sign.cmd" %%FILES%%
IF %ERRORLEVEL% NEQ 0 (
CALL :SubMsg "ERROR" "Problem signing files."
) ELSE (
CALL :SubMsg "INFO" "Files signed successfully."
)
)
FOR /F "tokens=3,4 delims= " %%A IN (
'FINDSTR /I /L /C:"define VER_MAJOR" "Include\Version.h"') DO (SET "VERMAJOR=%%A")
FOR /F "tokens=3,4 delims= " %%A IN (
'FINDSTR /I /L /C:"define VER_MINOR" "Include\Version.h"') DO (SET "VERMINOR=%%A")
FOR /F "tokens=3,4 delims= " %%A IN (
'FINDSTR /I /L /C:"define VER_BUILD" "Include\Version.h"') DO (SET "VERBUILD=%%A")
FOR /F "tokens=3,4 delims= " %%A IN (
'FINDSTR /I /L /C:"define VER_RELEASE" "Include\Version.h"') DO (SET "VERRELEASE=%%A")
FOR /F "tokens=3,4 delims= " %%A IN (
'FINDSTR /I /L /C:"define REV_DATE" "revision.h"') DO (SET "REVDATE=%%A")
FOR /F "tokens=3,4 delims= " %%A IN (
'FINDSTR /I /L /C:"define REV_HASH" "revision.h"') DO (SET "REVHASH=%%A")
FOR /F "tokens=3,4 delims= " %%A IN (
'FINDSTR /I /L /C:"define REV_NUM" "revision.h"') DO (SET "REVNUM=%%A")
FOR /F "tokens=3,4 delims= " %%A IN (
'FINDSTR /I /L /C:"define REV_BRANCH" "revision.h"') DO (SET "REVBRANCH=%%A")
IF /I "%VERRELEASE%" == "1" (
SET "PCKG_NAME=%PROJECT%-%VERMAJOR%.%VERMINOR%.%VERBUILD%.%REVNUM%%SUFFIX%"
) ELSE (
IF /I "%REVBRANCH%" == "master" (
SET "PCKG_NAME=%PROJECT%-%VERMAJOR%.%VERMINOR%.%VERBUILD%.%REVNUM%_git%REVDATE%-%REVHASH%%SUFFIX%"
) ELSE (
SET "PCKG_NAME=%PROJECT%-%VERMAJOR%.%VERMINOR%.%VERBUILD%.%REVNUM%.%REVBRANCH%_git%REVDATE%-%REVHASH%%SUFFIX%"
)
)
CALL :SubDetectSevenzipPath
IF DEFINED SEVENZIP (
IF EXIST "_bin\%PCKG_NAME%.zip" DEL "_bin\%PCKG_NAME%.zip"
TITLE Creating archive %PCKG_NAME%.zip...
START "7z" /B /WAIT "%SEVENZIP%" a -tzip -mx9 "_bin\%PCKG_NAME%.zip" ^
.\_bin\Filter_x86%SUFFIX%\%PROJECT%.ax ^
.\_bin\Filter_x64%SUFFIX%\%PROJECT%64.ax ^
.\distrib\Install_MpcScriptSource_32.cmd ^
.\distrib\Install_MpcScriptSource_64.cmd ^
.\distrib\Uninstall_MpcScriptSource_32.cmd ^
.\distrib\Uninstall_MpcScriptSource_64.cmd ^
.\distrib\Reset_Settings.cmd ^
.\Readme.md ^
.\history.txt ^
.\LICENSE.txt
IF %ERRORLEVEL% NEQ 0 CALL :SubMsg "ERROR" "Unable to create %PCKG_NAME%.zip!"
CALL :SubMsg "INFO" "%PCKG_NAME%.zip successfully created"
)
TITLE Compiling %TITLE% [FINISHED]
TIMEOUT /T 3
ENDLOCAL
EXIT
:SubVSPath
FOR /f "delims=" %%A IN ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -property installationPath -latest -requires Microsoft.Component.MSBuild') DO SET VS_PATH=%%A
EXIT /B
:SubDetectSevenzipPath
FOR %%G IN (7z.exe) DO (SET "SEVENZIP_PATH=%%~$PATH:G")
IF EXIST "%SEVENZIP_PATH%" (SET "SEVENZIP=%SEVENZIP_PATH%" & EXIT /B)
FOR %%G IN (7za.exe) DO (SET "SEVENZIP_PATH=%%~$PATH:G")
IF EXIST "%SEVENZIP_PATH%" (SET "SEVENZIP=%SEVENZIP_PATH%" & EXIT /B)
FOR /F "tokens=2*" %%A IN (
'REG QUERY "HKLM\SOFTWARE\7-Zip" /v "Path" 2^>NUL ^| FIND "REG_SZ" ^|^|
REG QUERY "HKLM\SOFTWARE\Wow6432Node\7-Zip" /v "Path" 2^>NUL ^| FIND "REG_SZ"') DO SET "SEVENZIP=%%B\7z.exe"
EXIT /B
:SubCompiling
TITLE Compiling %TITLE% - %BUILDCFG%^|%1...
MSBuild.exe %PROJECT%.sln %MSBUILD_SWITCHES%^
/target:%BUILDTYPE% /p:Configuration="%BUILDCFG%" /p:Platform=%1^
/flp1:LogFile=%LOG_DIR%\errors_%BUILDCFG%_%1.log;errorsonly;Verbosity=diagnostic^
/flp2:LogFile=%LOG_DIR%\warnings_%BUILDCFG%_%1.log;warningsonly;Verbosity=diagnostic
IF %ERRORLEVEL% NEQ 0 (
CALL :SubMsg "ERROR" "%PROJECT%.sln %BUILDCFG% %1 - Compilation failed!"
) ELSE (
CALL :SubMsg "INFO" "%PROJECT%.sln %BUILDCFG% %1 compiled successfully"
)
EXIT /B
:SubMsg
ECHO. & ECHO ------------------------------
IF /I "%~1" == "ERROR" (
CALL :SubColorText "0C" "[%~1]" & ECHO %~2
) ELSE IF /I "%~1" == "INFO" (
CALL :SubColorText "0A" "[%~1]" & ECHO %~2
) ELSE IF /I "%~1" == "WARNING" (
CALL :SubColorText "0E" "[%~1]" & ECHO %~2
)
ECHO ------------------------------ & ECHO.
IF /I "%~1" == "ERROR" (
ECHO Press any key to close this window...
PAUSE >NUL
ENDLOCAL
EXIT
) ELSE (
EXIT /B
)
:SubColorText
FOR /F "tokens=1,2 delims=#" %%A IN (
'"PROMPT #$H#$E# & ECHO ON & FOR %%B IN (1) DO REM"') DO (
SET "DEL=%%A")
<NUL SET /p ".=%DEL%" > "%~2"
FINDSTR /v /a:%1 /R ".18" "%~2" NUL
DEL "%~2" > NUL 2>&1
EXIT /B