Commit eda74b60 authored by Ming Rui Zhang's avatar Ming Rui Zhang

win32: use python build script

Change-Id: Ifba6fd1c3946fba13196bb2c1a51e1f0f43e80b1
parent 55c1b0a4
:: Jami - native Windows client project build script
@echo off
setlocal
if "%1" == "/?" goto Usage
if "%~1" == "" goto Usage
set doDeps=N
set doCompile=N
set doBuild=N
set doBuildBeta=N
set SCRIPTNAME=%~nx0
if "%1"=="compile" (
set doCompile=Y
) else if "%1"=="build" (
set doBuild=Y
) else if "%1"=="deps" (
set doDeps=Y
) else if "%1"=="beta" (
set doBuildBeta=Y
) else (
goto Usage
)
set arch=N
shift
:ParseArgs
if "%1" == "" goto FinishedArgs
if /I "%1"=="x86" (
set arch=x86
) else if /I "%1"=="x64" (
set arch=x64
) else (
goto Usage
)
shift
goto ParseArgs
:FinishedArgs
if "%arch%"=="x86" (
set MSBUILD_ARGS=/nologo /p:useenv=true /p:Platform=Win32 /maxcpucount:%NUMBER_OF_PROCESSORS%
) else if "%arch%"=="x64" (
set MSBUILD_ARGS=/nologo /p:useenv=true /p:Platform=x64 /maxcpucount:%NUMBER_OF_PROCESSORS%
)
@setlocal
set VSInstallerFolder="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer"
if %PROCESSOR_ARCHITECTURE%==x86 set VSInstallerFolder="%ProgramFiles%\Microsoft Visual Studio\Installer"
pushd %VSInstallerFolder%
for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
set VSLATESTDIR=%%i
)
popd
echo VS Installation folder: %VSLATESTDIR%
if not exist "%VSLATESTDIR%\VC\Auxiliary\Build\vcvarsall.bat" (
echo:
echo VSInstallDir not found or not installed correctly.
goto cleanup
)
if %PROCESSOR_ARCHITECTURE%==x86 (
set Comp_x86=x86 10.0.16299.0
set Comp_x64=x86_amd64 10.0.16299.0
) else (
set Comp_x86=amd64_x86 10.0.16299.0
set Comp_x64=amd64 10.0.16299.0
)
set path=%path:"=%
if "%arch%"=="x86" (
call "%VSLATESTDIR%"\\VC\\Auxiliary\\Build\\vcvarsall.bat %Comp_x86%
) else if "%arch%"=="x64" (
call "%VSLATESTDIR%"\\VC\\Auxiliary\\Build\\vcvarsall.bat %Comp_x64%
)
if "%arch%" neq "N" (
if "%doCompile%" neq "N" (
goto compileClient
) else if "%doBuild%" neq "N" (
goto buildClient
) else if "%doDeps%" neq "N" (
goto buildDeps
) else if "%doBuildBeta%" neq "N" (
goto buildBetaClient
)
goto :eof
)
goto Usage
:buildDeps
set TOBUILD=qrencode-win32\qrencode-win32\vc8\qrcodelib\qrcodelib.vcxproj
msbuild %TOBUILD% /verbosity:normal /p:Configuration=Release-Lib %MSBUILD_ARGS%
set WGET_CMD=wget --no-check-certificate --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 --tries=4
goto cleanup
:compileClient
msbuild ring-client-windows.vcxproj /verbosity:normal /p:Configuration=ReleaseCompile %MSBUILD_ARGS%
goto cleanup
:buildClient
msbuild ring-client-windows.vcxproj /verbosity:normal /p:Configuration=Release %MSBUILD_ARGS%
goto cleanup
:buildBetaClient
msbuild ring-client-windows.vcxproj /verbosity:normal /p:Configuration=Beta %MSBUILD_ARGS%
goto cleanup
@endlocal
:Usage
echo:
echo The correct usage is:
echo:
echo %0 [action] [architecture]
echo:
echo where
echo:
echo [action] is: compile ^| build
echo [architecture] is: x86 ^| x64
echo:
echo For example:
echo %0 compile x86 - compile only x86 (for CI)
echo %0 build x64 - build x64 client
echo:
goto :eof
:cleanup
endlocal
exit /B %ERRORLEVEL%
\ No newline at end of file
@echo off
setlocal EnableDelayedExpansion
set cloneSubmodules=N
if "%1" == "/c" (
set cloneSubmodules=Y
)
set WGET_CMD=wget --no-check-certificate --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 --tries=4
set APPLY_CMD=git apply --reject --ignore-whitespace --whitespace=fix
if exist qrencode-win32 (
rmdir qrencode-win32 /s /q
)
git clone https://github.com/BlueDragon747/qrencode-win32.git
cd qrencode-win32
git checkout d6495a2aa74d058d54ae0f1b9e9e545698de66ce
%APPLY_CMD% ..\qrencode-win32.patch
:cleanup
endlocal
@endlocal
exit /B %ERRORLEVEL%
:getTarballDepToFolder
%WGET_CMD% %1/archive/%2.tar.gz
7z -y x %2.tar.gz && 7z -y x %2.tar
del %2.tar && del %2.tar.gz && del pax_global_header
if exist %3 (
rmdir %3 /s /q
)
if exist %3-%2 (
rename %3-%2 %3
) else (
rename lib%3-%2 %3
)
\ No newline at end of file
echo Start generating changelog
start pandoc -f markdown -t html5 -o changelog.html changelog.md
echo Changelog generated successfully
\ No newline at end of file
import tempfile
import re
import sys
import os
import subprocess
import platform
import argparse
import multiprocessing
import fileinput
import re
# vs help
win_sdk_default = '10.0.16299.0'
win_toolset_default = 'v141'
vs_where_path = os.path.join(
os.environ['ProgramFiles(x86)'], 'Microsoft Visual Studio', 'Installer', 'vswhere.exe'
)
host_is_64bit = (False, True)[platform.machine().endswith('64')]
def execute_cmd(cmd, with_shell=False, env_vars={}):
if(bool(env_vars)):
p = subprocess.Popen(cmd, shell=with_shell,
stdout=sys.stdout,
env=env_vars)
else:
p = subprocess.Popen(cmd, shell=with_shell)
_, perr = p.communicate()
if perr:
return 1
return 0
def getLatestVSVersion():
args = [
'-latest',
'-products *',
'-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'-property installationVersion'
]
cmd = [vs_where_path] + args
output = subprocess.check_output(' '.join(cmd)).decode('utf-8')
if output:
return output.splitlines()[0].split('.')[0]
else:
return
def findVSLatestDir():
args = [
'-latest',
'-products *',
'-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'-property installationPath'
]
cmd = [vs_where_path] + args
output = subprocess.check_output(' '.join(cmd)).decode('utf-8')
if output:
return output.splitlines()[0]
else:
return
def findMSBuild():
filename = 'MSBuild.exe'
for root, _, files in os.walk(findVSLatestDir() + r'\\MSBuild'):
if filename in files:
return os.path.join(root, filename)
def getVSEnv(arch='x64', platform='', version=''):
env_cmd = 'set path=%path:"=% && ' + \
getVSEnvCmd(arch, platform, version) + ' && set'
p = subprocess.Popen(env_cmd,
shell=True,
stdout=subprocess.PIPE)
stdout, _ = p.communicate()
out = stdout.decode('utf-8').split("\r\n")[5:-1]
return dict(s.split('=', 1) for s in out)
def getCMakeGenerator(vs_version):
if vs_version == '15':
return '\"Visual Studio 15 2017 Win64\"'
else:
return '\"Visual Studio ' + vs_version + ' 2019\"'
def getVSEnvCmd(arch='x64', platform='', version=''):
vcEnvInit = [findVSLatestDir() + r'\VC\Auxiliary\Build\"vcvarsall.bat']
if platform != '':
args = [arch, platform, version]
else:
args = [arch, version]
if args:
vcEnvInit.extend(args)
vcEnvInit = 'call \"' + ' '.join(vcEnvInit)
return vcEnvInit
def build_project(msbuild, msbuild_args, proj, env_vars):
args = []
args.extend(msbuild_args)
args.append(proj)
cmd = [msbuild]
cmd.extend(args)
if (execute_cmd(cmd, True, env_vars)):
print("Build failed when building ", proj)
sys.exit(1)
def replace_vs_prop(filename, prop, val):
p = re.compile(r'(?s)<' + prop + r'\s?.*?>(.*?)<\/' + prop + r'>')
val = r'<' + prop + r'>' + val + r'</' + prop + r'>'
with fileinput.FileInput(filename, inplace=True) as file:
for line in file:
print(re.sub(p, val, line), end='')
def deps(arch, toolset):
print('Deps Qt Client Release|' + arch)
# Fetch QRencode
print('Generate QRencode')
apply_cmd = "git apply --reject --ignore-whitespace --whitespace=fix"
qrencode_path = 'qrencode-win32'
if (os.path.isdir(qrencode_path)):
os.system('rmdir qrencode-win32 /s /q')
execute_cmd("git clone https://github.com/BlueDragon747/qrencode-win32.git", True)
execute_cmd("cd qrencode-win32 && git checkout d6495a2aa74d058d54ae0f1b9e9e545698de66ce && " + apply_cmd + ' ..\\qrencode-win32.patch', True)
print('Building qrcodelib')
build(arch, '', '', 'Release-Lib', '\\qrencode-win32\\qrencode-win32\\vc8\\qrcodelib\\qrcodelib.vcxproj', False)
def build(arch, toolset, sdk_version, config_str, project_path_under_current_path, force_option=True):
print('Building projects in ' + config_str + '|' + arch)
vs_env_vars = {}
vs_env_vars.update(getVSEnv())
this_dir = os.path.dirname(os.path.realpath(__file__))
qt_client_proj_path = this_dir + project_path_under_current_path
msbuild = findMSBuild()
if not os.path.isfile(msbuild):
raise IOError('msbuild.exe not found. path=' + msbuild)
msbuild_args = [
'/nologo',
'/verbosity:minimal',
'/maxcpucount:' + str(multiprocessing.cpu_count()),
'/p:Platform=' + arch,
'/p:Configuration=' + config_str,
'/p:useenv=true']
if (toolset != ''):
msbuild_args.append('/p:PlatformToolset=' + toolset)
if (force_option):
# force toolset
replace_vs_prop(qt_client_proj_path,
'PlatformToolset',
toolset)
# force unicode
replace_vs_prop(qt_client_proj_path,
'CharacterSet',
'Unicode')
# force sdk_version
replace_vs_prop(qt_client_proj_path,
'WindowsTargetPlatformVersion',
sdk_version)
build_project(msbuild, msbuild_args, qt_client_proj_path, vs_env_vars)
def parse_args():
ap = argparse.ArgumentParser(description="Windows Jami-lrc build tool")
ap.add_argument(
'-b', '--build', action='store_true',
help='Build Qt Client')
ap.add_argument(
'-a', '--arch', default='x64',
help='Sets the build architecture')
ap.add_argument(
'-d', '--deps', action='store_true',
help='Build Deps for Qt Client')
ap.add_argument(
'-c', '--complie', action='store_true',
help='Release Complie for Qt Client')
ap.add_argument(
'-bt', '--beta', action='store_true',
help='Build Qt Client in Beta Config')
ap.add_argument(
'-s', '--sdk', default=win_sdk_default, type=str,
help='Use specified windows sdk version')
ap.add_argument(
'-t', '--toolset', default=win_toolset_default, type=str,
help='Use specified platform toolset version')
parsed_args = ap.parse_args()
return parsed_args
def main():
if not host_is_64bit:
print('These scripts will only run on a 64-bit Windows system for now!')
sys.exit(1)
if int(getLatestVSVersion()) < 15:
print('These scripts require at least Visual Studio v15 2017!')
sys.exit(1)
parsed_args = parse_args()
if parsed_args.deps:
deps(parsed_args.arch, parsed_args.toolset)
if parsed_args.build:
build(parsed_args.arch, parsed_args.toolset, parsed_args.sdk, 'Release', '\\ring-client-windows.vcxproj')
if parsed_args.beta:
build(parsed_args.arch, parsed_args.toolset, parsed_args.sdk, 'Beta', '\\ring-client-windows.vcxproj')
if parsed_args.complie:
build(parsed_args.arch, parsed_args.toolset, parsed_args.sdk, 'ReleaseCompile', '\\ring-client-windows.vcxproj')
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment