Commit 12742b8c authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Ming Rui Zhang

win32: add python build script

Change-Id: I464d2f29173d2bcfdf6ddea5e26ed9e0192e98ae
parent f4314dbe
:: Ring - native Windows fetch and build
@echo off
@setlocal
if "%1" == "/?" goto Usage
if "%~1" == "" goto Usage
set doFetch=N
set doBuildContrib=N
set doBuildDaemon=N
set targetContrib=""
set SCRIPTNAME=%~nx0
if "%1"=="fetch" (
set doFetch=Y
) else if "%1"=="contrib" (
set doBuildContrib=Y
) else if "%1"=="daemon" (
set doBuildDaemon=Y
) else (
goto Usage
)
set BUILD.x86=N
set BUILD.x64=Y
set BUILD.uwp=N
set BUILD.win32=Y
shift
:ParseArgs
if "%1" == "" goto FinishedArgs
if /I "%1"=="x86" (
set BUILD.x86=Y
) else if /I "%1"=="x64" (
set BUILD.x64=Y
) else if /I "%1"=="uwp" (
set BUILD.uwp=Y
) else if /I "%1"=="win32" (
set BUILD.win32=Y
) else if /I "%1" neq "" (
if "%doBuildContrib%" neq "N" (
set targetContrib=%1
) else if "%doFetch%" neq "N" (
set targetContrib=%1
)
) else (
goto Usage
)
shift
goto ParseArgs
:FinishedArgs
set CONTRIB_DIR=%~dp0../contrib
set platform=N
set arch=N
if "%BUILD.x86%"=="Y" (
set arch=x86
) else if "%BUILD.x64%"=="Y" (
set arch=x64
)
if "%BUILD.uwp%"=="Y" (
set platform=uwp
if "%arch%"=="x86" (
set DAEMON_MSBUILD_ARGS=/nologo /p:useenv=true /p:Configuration=ReleaseLib /p:Platform=Win32 /verbosity:normal /maxcpucount:%NUMBER_OF_PROCESSORS%
) else if "%arch%"=="x64" (
set DAEMON_MSBUILD_ARGS=/nologo /p:useenv=true /p:Configuration=ReleaseLib /p:Platform=x64 /verbosity:normal /maxcpucount:%NUMBER_OF_PROCESSORS%
)
) else if "%BUILD.win32%"=="Y" (
set platform=win32
if "%arch%"=="x86" (
set DAEMON_MSBUILD_ARGS=/nologo /p:useenv=true /p:Configuration=ReleaseLib_win32 /p:Platform=Win32 /verbosity:normal /maxcpucount:%NUMBER_OF_PROCESSORS%
) else if "%arch%"=="x64" (
set DAEMON_MSBUILD_ARGS=/nologo /p:useenv=true /p:Configuration=ReleaseLib_win32 /p:Platform=x64 /verbosity:normal /maxcpucount:%NUMBER_OF_PROCESSORS%
)
)
if "%arch%" neq "N" (
if "%platform%" neq "N" (
if "%doFetch%" neq "N" (
call %CONTRIB_DIR%\src\fetch_all.bat %platform% %arch% %targetContrib%
) else if "%doBuildContrib%" neq "N" (
call %CONTRIB_DIR%\build_all.bat %platform% %arch% %targetContrib%
) else if "%doBuildDaemon%" neq "N" (
goto buildDaemon
)
goto :eof
)
)
goto Usage
:buildDaemon
@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 (
if "%platform%"=="uwp" (
set Comp_x86=x86 uwp 10.0.15063.0
set Comp_x64=x86_amd64 uwp 10.0.15063.0
) else (
set Comp_x86=x86 10.0.15063.0
set Comp_x64=x86_amd64 10.0.15063.0
)
) else (
if "%platform%"=="uwp" (
set Comp_x86=amd64_x86 uwp 10.0.15063.0
set Comp_x64=amd64 uwp 10.0.15063.0
) else (
set Comp_x86=amd64_x86 10.0.15063.0
set Comp_x64=amd64 10.0.15063.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%
)
::build the daemon
echo "building daemon..."
msbuild ring-daemon.vcxproj %DAEMON_MSBUILD_ARGS%
goto :eof
@endlocal
:Usage
echo:
echo The correct usage is:
echo:
echo %0 [action] [target platform] [architecture]
echo:
echo where
echo:
echo [action] is: fetch ^| build
echo [target platform] is: uwp ^| win32
echo [architecture] is: x86 ^| x64
echo:
echo For example:
echo %SCRIPTNAME% fetch win32 x86 - fetch contrib for a win32/x86 build
echo %SCRIPTNAME% contrib uwp x64 - build uwp(win10)/x64 contrib
echo %SCRIPTNAME% daemon uwp x64 - build uwp(win10)/x64 daemon
echo:
goto :eof
@endlocal
\ No newline at end of file
{
"name": "daemon",
"deps": [
"asio",
"ffmpeg",
"natpmp",
"opendht",
"pjproject",
"portaudio",
"secp256k1",
"upnp",
"yaml-cpp"
],
"configuration": "ReleaseLib_win32",
"project_paths": ["ring-daemon.vcxproj"]
}
\ No newline at end of file
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2026
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ring-daemon", "ring-daemon.vcxproj", "{79F8DE42-595D-49D9-A66F-55244FD9DCC3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
DebugLib_win32|x64 = DebugLib_win32|x64
DebugLib_win32|x86 = DebugLib_win32|x86
DebugLib|x64 = DebugLib|x64
DebugLib|x86 = DebugLib|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
ReleaseLib_win32|x64 = ReleaseLib_win32|x64
ReleaseLib_win32|x86 = ReleaseLib_win32|x86
ReleaseLib|x64 = ReleaseLib|x64
ReleaseLib|x86 = ReleaseLib|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.Debug|x64.ActiveCfg = Debug|x64
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.Debug|x64.Build.0 = Debug|x64
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.Debug|x86.ActiveCfg = Debug|Win32
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.Debug|x86.Build.0 = Debug|Win32
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.DebugLib_win32|x64.ActiveCfg = DebugLib_win32|x64
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.DebugLib_win32|x64.Build.0 = DebugLib_win32|x64
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.DebugLib_win32|x86.ActiveCfg = DebugLib_win32|Win32
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.DebugLib_win32|x86.Build.0 = DebugLib_win32|Win32
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.DebugLib|x64.ActiveCfg = DebugLib|x64
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.DebugLib|x64.Build.0 = DebugLib|x64
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.DebugLib|x86.ActiveCfg = DebugLib|Win32
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.DebugLib|x86.Build.0 = DebugLib|Win32
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.Release|x64.ActiveCfg = Release|x64
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.Release|x64.Build.0 = Release|x64
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.Release|x86.ActiveCfg = Release|Win32
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.Release|x86.Build.0 = Release|Win32
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.ReleaseLib_win32|x64.ActiveCfg = ReleaseLib_win32|x64
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.ReleaseLib_win32|x64.Build.0 = ReleaseLib_win32|x64
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.ReleaseLib_win32|x86.ActiveCfg = ReleaseLib_win32|Win32
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.ReleaseLib_win32|x86.Build.0 = ReleaseLib_win32|Win32
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.ReleaseLib|x64.ActiveCfg = ReleaseLib|x64
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.ReleaseLib|x64.Build.0 = ReleaseLib|x64
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.ReleaseLib|x86.ActiveCfg = ReleaseLib|Win32
{79F8DE42-595D-49D9-A66F-55244FD9DCC3}.ReleaseLib|x86.Build.0 = ReleaseLib|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7505C3ED-E07A-48C4-BE60-8BD5A00CC85C}
EndGlobalSection
EndGlobal
......@@ -53,70 +53,70 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{79F8DE42-595D-49D9-A66F-55244FD9DCC3}</ProjectGuid>
<RootNamespace>ringdaemon</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugLib|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugLib_win32|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLib|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLib_win32|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugLib|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugLib_win32|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<WindowsAppContainer>false</WindowsAppContainer>
......@@ -124,14 +124,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLib|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLib_win32|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
......
import sys
import os
import subprocess
import platform
import argparse
import json
import re
import zipfile
import tarfile
import multiprocessing
import shutil
import shlex
import glob
import time
from datetime import timedelta
import struct
import importlib
import logging
import traceback
import re
import fileinput
root_logger = logging.getLogger(__name__)
log = None
# project paths
daemon_msvc_dir = os.path.dirname(os.path.realpath(__file__))
daemon_dir = os.path.dirname(daemon_msvc_dir)
contrib_src_dir = daemon_dir + r'\contrib\src'
contrib_build_dir = daemon_dir + r'\contrib\build'
contrib_tmp_dir = daemon_dir + r'\contrib\tarballs'
# SCM
wget_args = [
'--no-check-certificate', '--retry-connrefused',
'--waitretry=1', '--read-timeout=20',
'--timeout=15', '--tries=4']
git_apply_args = ['apply', '--reject',
'--ignore-whitespace', '--whitespace=fix']
patch_args = ['-flp1', '-i']
# 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')]
python_is_64bit = (False, True)[8 * struct.calcsize("P") == 64]
def shellquote(s, windows=False):
if not windows:
return "'" + s.replace("'", "'\''") + "'"
else:
return '\"' + s + '\"'
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 make_daemon(pkg_info, force, sdk_version, toolset):
for dep in pkg_info.get('deps', []):
resolve(dep, False, sdk_version, toolset)
root_logger.warning(
"Building daemon with preferred sdk version %s and toolset %s", sdk_version, toolset)
env_set = 'false' if pkg_info.get('with_env', '') == '' else 'true'
sdk_to_use = sdk_version if env_set == 'false' else pkg_info.get('with_env', '')
build('daemon', daemon_msvc_dir,
pkg_info.get('project_paths', []),
pkg_info.get('custom_scripts', {}),
env_set,
sdk_to_use,
toolset,
conf=pkg_info.get('configuration', 'Release'))
def make(pkg_info, force, sdk_version, toolset):
pkg_name = pkg_info.get('name')
if pkg_name == 'daemon':
return make_daemon(pkg_info, force, sdk_version, toolset)
version = pkg_info.get('version')
pkg_build_uptodate = False
pkg_ver_uptodate = False
# attempt to get the current built version
current_version = ''
# check build file for current version
build_file = contrib_build_dir + r'\\.' + pkg_name
if os.path.exists(build_file):
if force:
os.remove(build_file)
else:
pkg_build_uptodate = is_build_uptodate(pkg_name, build_file)
with open(build_file, 'r+') as f:
current_version = f.read()
if current_version == version:
pkg_ver_uptodate = True
for dep in pkg_info.get('deps', []):
dep_build_dep = resolve(dep, False, sdk_version, toolset)
if dep_build_dep:
pkg_build_uptodate = False
pkg_up_to_date = pkg_build_uptodate & pkg_ver_uptodate
if not pkg_up_to_date or current_version is None or force:
if not current_version is '':
log.debug(pkg_name + ' currently @: ' + current_version)
if force:
log.debug('Forcing fetch/patch/build for ' + pkg_name)
should_fetch = not pkg_up_to_date
pkg_build_path = contrib_build_dir + '\\' + pkg_name
should_fetch &= not os.path.exists(pkg_build_path)
if not pkg_up_to_date or force:
if not force and not current_version is None:
log.warning(pkg_name + ' is not up to date')
if (should_fetch or force) and fetch_pkg(pkg_name, version, pkg_info['url'], force):
apply(pkg_name, pkg_info.get('patches', []),
pkg_info.get('win_patches', []))
env_set = 'false' if pkg_info.get('with_env', '') != '' else 'true'
sdk_to_use = sdk_version if env_set == 'false' else pkg_info.get('with_env', '')
if build(pkg_name,
contrib_build_dir + '\\' + pkg_name,
pkg_info.get('project_paths', []),
pkg_info.get('custom_scripts', {}),
env_set,
sdk_to_use,
toolset):
track_build(pkg_name, version)
else:
log.error("Couldn't build contrib " + pkg_name)
exit(1)
log.info(pkg_name + ' up to date')
return True
# did not need build
log.info(pkg_name + ' already up to date')
return False
def fetch_pkg(pkg_name, version, url, force):
version_replace = re.compile(re.escape('__VERSION__'))
full_url = version_replace.sub(version, url)
if not full_url:
log.error(pkg_name + ' missing url in package configuration')
return False
archive_name = full_url[full_url.rfind("/") + 1:]
archive_path = contrib_tmp_dir + '\\' + archive_name
if not os.path.exists(archive_path):
log.debug('Fetching ' + pkg_name + ' from: ' + full_url)
args = [full_url, '-P', contrib_tmp_dir]
args.extend(wget_args)
dl_result = getSHrunner().exec_batch('wget', args)
if dl_result[0] is not 0:
log.warning(
'wget failure. Using powershell Invoke-WebRequest instead')
args = ['-Uri', full_url, '-OutFile', archive_path]
dl_result = getSHrunner().exec_ps1('Invoke-WebRequest', args)
return extract_archive(pkg_name, archive_name, archive_path)
else:
log.warning(archive_name +
' already exists in the tarball/archive directory')
decomp_result = extract_archive(pkg_name, archive_name, archive_path)
if not decomp_result and force:
log.debug('Removing old tarball for ' + archive_name)
getSHrunner().exec_batch('del', ['/s', '/q', archive_name])
return fetch_pkg(pkg_name, version, url, False)
else:
return True
return False
def remove_archive_if_needed(pkg_build_path, dirty_path):
if os.path.exists(pkg_build_path):
log.debug('Removing old package ' + pkg_build_path)
getSHrunner().exec_batch('rmdir', ['/s', '/q', pkg_build_path])
elif os.path.exists(dirty_path):
log.debug('Removing partial decompression ' + dirty_path)
getSHrunner().exec_batch('rmdir', ['/s', '/q', dirty_path])
def extract_tar(pkg_build_path, name, path):
with tarfile.open(path, 'r') as tarball:
tar_common_prefix = os.path.commonprefix(tarball.getnames())
dirty_path = contrib_build_dir + '\\' + tar_common_prefix
remove_archive_if_needed(pkg_build_path, dirty_path)
log.debug('Decompressing ' + name + ' to ' + pkg_build_path)
tarball.extractall(contrib_build_dir)
os.rename(contrib_build_dir + '\\' + tar_common_prefix,
pkg_build_path)
return True
return False
def extract_zip(pkg_build_path, name, path):
with zipfile.ZipFile(path, 'r') as ziparchive:
zip_common_prefix = os.path.commonprefix(ziparchive.namelist())
dirty_path = contrib_build_dir + '\\' + zip_common_prefix
remove_archive_if_needed(pkg_build_path, dirty_path)
log.debug('Decompressing ' + name + ' to ' + pkg_build_path)
ziparchive.extractall(contrib_build_dir)
os.rename(contrib_build_dir + '\\' + zip_common_prefix,
pkg_build_path)
return True
return False
def extract_archive(pkg_name, name, path):
pkg_build_path = contrib_build_dir + '\\' + pkg_name
if tarfile.is_tarfile(path):
return extract_tar(pkg_build_path, name, path)
elif zipfile.is_zipfile(path):
return extract_zip(pkg_build_path, name, path)
def apply_linux(patch_path):
log.debug('applying linux patch ' + patch_path)
args = []
args.extend(patch_args)
args.append(patch_path)
return getSHrunner().exec_sh('patch', args)
def apply_windows(patch_path):
log.debug('applying windows patch ' + patch_path)
args = []
args.extend(git_apply_args)
args.append(patch_path)
return getSHrunner().exec_batch('git', args)
def apply(pkg_name, patches, win_patches):
log.debug('patching ' + pkg_name + '...')
tmp_dir = os.getcwd()
pkg_build_path = contrib_build_dir + '\\' + pkg_name
if not os.path.exists(pkg_build_path):
os.makedirs(pkg_build_path)
os.chdir(pkg_build_path)
base_sh_src_path = get_sh_path(contrib_src_dir)
# 1. git patches (LF)
for p in patches:
patch_path = base_sh_src_path + '/' + pkg_name + '/' + p
result = apply_linux(patch_path)
if result[0]:
log.error('Couldn\'t apply patch: ' + patch_path)
exit(1)
# 2. windows git patches (CR/LF)
for wp in win_patches:
patch_path = contrib_src_dir + '\\' + pkg_name + '\\' + wp
result = apply_windows(patch_path)
if result[0]:
log.error('Couldn\'t apply patch: ' + patch_path)
exit(1)
os.chdir(tmp_dir)
def get_pkg_file(pkg_name):
if pkg_name == 'daemon':
pkg_location = daemon_msvc_dir
else:
pkg_location = daemon_dir + r'\contrib\src\\' + pkg_name
pkg_json_file = pkg_location + r"\\package.json"
if not os.path.exists(pkg_json_file):
log.error("No package info for " + pkg_name)
sys.exit(1)
return pkg_json_file
def resolve(pkg_name, force=False, sdk_version='', toolset=''):
pkg_json_file = get_pkg_file(pkg_name)
with open(pkg_json_file) as json_file:
log.info('Resolving: ' + pkg_name)
pkg_info = json.load(json_file)
try:
return make(pkg_info, force, sdk_version, toolset)
except Exception as e:
print(e)
log.error('Make ' + pkg_name + ' failed!')
sys.exit(1)
def track_build(pkg_name, version):
build_file = contrib_build_dir + '\\.' + pkg_name
f = open(build_file, "w+")
f.write(version)
f.close()
def build(pkg_name, pkg_dir, project_paths, custom_scripts, with_env, sdk,
toolset, arch='x64', conf='Release'):
getMSbuilder().set_msbuild_configuration(with_env, arch, conf, toolset)
getMSbuilder().setup_vs_env(sdk)
success = True
build_operations = 0
tmp_dir = os.getcwd()
os.chdir(pkg_dir)
# pre_build custom step (CMake...)
pre_build_scripts = custom_scripts.get("pre_build", [])
if pre_build_scripts:
log.debug('Pre_build phase')
for script in pre_build_scripts:
result = getSHrunner().exec_batch(script)
success &= not result[0]