mirror of https://github.com/axmolengine/axmol.git
Migrate setup.py to setup.ps1
This commit is contained in:
parent
f98ecb2000
commit
e78ef2d885
|
@ -2,19 +2,23 @@
|
|||
|
||||
## Common Requirement [Python](https://www.python.org/downloads/)
|
||||
|
||||
- Python-3.7+
|
||||
- PowerShell if you want use the simply build script `tools/ci/build.ps1`
|
||||
- win7+, no needs install the system preinstalled PowerShell 5.0 should works
|
||||
- PowerShell-5.0+
|
||||
- Please install from:
|
||||
- https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.3
|
||||
- https://github.com/PowerShell/PowerShell/releases
|
||||
- win7+, no needs install, the system preinstalled PowerShell 5.0 should works
|
||||
- macos,linux or you want install latest powershell for windows, visit: https://github.com/PowerShell/PowerShell/releases
|
||||
|
||||
- Python-3.7+
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. Enter `axmol` root directory
|
||||
2. Run `python setup.py`, restart the console after it has finished for environment variables to take effect
|
||||
2. Run `pwsh setup.ps1`, restart the console after it has finished for environment variables to take effect
|
||||
|
||||
## Creating A New Project
|
||||
|
||||
Using a console window, an example of a command to generate a new project is as follows:
|
||||
Using a powershell console window, an example of a command to generate a new project is as follows:
|
||||
|
||||
```axmol new -p YOUR.UNIQUE.ID -d PROJECT_PATH -l [cpp|lua] [--portrait] PROJECT_NAME```
|
||||
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "This Shell Script will install dependencies for axmol"
|
||||
echo -n "Are you continue? (y/n) "
|
||||
read answer
|
||||
if echo "$answer" | grep -iq "^y" ;then
|
||||
echo "It will take few minutes"
|
||||
else
|
||||
exit
|
||||
fi
|
||||
|
||||
sudo apt update
|
||||
|
||||
# for vm, libxxf86vm-dev also required
|
||||
|
||||
DEPENDS=' libx11-dev'
|
||||
DEPENDS+=' automake'
|
||||
DEPENDS+=' libtool'
|
||||
DEPENDS+=' cmake'
|
||||
DEPENDS+=' libxmu-dev'
|
||||
DEPENDS+=' libglu1-mesa-dev'
|
||||
DEPENDS+=' libgl2ps-dev'
|
||||
DEPENDS+=' libxi-dev'
|
||||
DEPENDS+=' libzip-dev'
|
||||
DEPENDS+=' libpng-dev'
|
||||
DEPENDS+=' libfontconfig1-dev'
|
||||
DEPENDS+=' libgtk-3-dev'
|
||||
DEPENDS+=' binutils'
|
||||
DEPENDS+=' libbsd-dev'
|
||||
DEPENDS+=' libasound2-dev'
|
||||
DEPENDS+=' libxxf86vm-dev'
|
||||
DEPENDS+=' libvlc-dev libvlccore-dev vlc'
|
||||
|
||||
# if vlc encouter codec error, install
|
||||
# sudo apt install ubuntu-restricted-extras
|
||||
|
||||
sudo apt install --allow-unauthenticated --yes $DEPENDS > /dev/null
|
||||
|
||||
echo "Installing latest freetype for linux ..."
|
||||
mkdir buildsrc
|
||||
cd buildsrc
|
||||
git clone https://github.com/freetype/freetype.git
|
||||
cd freetype
|
||||
git checkout VER-2-13-0
|
||||
sh autogen.sh
|
||||
./configure --prefix=/usr --enable-freetype-config --disable-static
|
||||
sudo make install
|
||||
cd ..
|
||||
cd ..
|
|
@ -0,0 +1,121 @@
|
|||
$myRoot = $PSScriptRoot
|
||||
$AX_ROOT = $myRoot
|
||||
|
||||
$build1kPath = Join-Path $myRoot 'tools/ci/build1k.ps1'
|
||||
$prefix = Join-Path $myRoot 'tools/external'
|
||||
if (!(Test-Path $prefix -PathType Container)) {
|
||||
mkdir $prefix | Out-Null
|
||||
}
|
||||
|
||||
# setup toolchains: glslcc, cmake, ninja, ndk, jdk, ...
|
||||
. $build1kPath -setupOnly $true -prefix $prefix
|
||||
|
||||
$AX_CONSOLE_BIN = Join-Path $AX_ROOT 'tools/console/bin'
|
||||
|
||||
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables
|
||||
$IsWin = $IsWindows -or ("$env:OS" -eq 'Windows_NT')
|
||||
|
||||
if ($IsWin) {
|
||||
if ($env:AX_ROOT -ne $AX_ROOT) {
|
||||
[Environment]::SetEnvironmentVariable('AX_ROOT', $AX_ROOT, 'User')
|
||||
}
|
||||
|
||||
$pathList = [System.Collections.ArrayList]$env:PATH.Split(';')
|
||||
if (!$pathList.IndexOf($AX_CONSOLE_BIN) -eq -1) {
|
||||
$pathList = [Environment]::GetEnvironmentVariable('PATH', 'User').Split(';')
|
||||
$pathList.Insert(0, $AX_CONSOLE_BIN)
|
||||
$PATH = $pathList -join ';'
|
||||
[Environment]::SetEnvironmentVariable('PATH', $PATH, 'User')
|
||||
}
|
||||
}
|
||||
else {
|
||||
$PATH = [System.Collections.ArrayList]$env:PATH.Split(':')
|
||||
if (Test-Path $PROFILE -PathType Leaf) {
|
||||
$profileContent = Get-Content $PROFILE
|
||||
}
|
||||
else {
|
||||
$profileContent = ''
|
||||
}
|
||||
|
||||
if ($profileContent.IndexOf('$env:AX_ROOT = ') -eq -1) {
|
||||
$profileContent += '$env:AX_ROOT = "{0}"{1}' -f $AX_ROOT, "`n"
|
||||
}
|
||||
|
||||
if ($profileContent.IndexOf('$env:PATH = ') -eq -1) {
|
||||
$profileContent += '$env:PATH = "{0}:$env:PATH"' -f $AX_CONSOLE_BIN
|
||||
}
|
||||
|
||||
$profileDir = Split-Path $PROFILE -Parent
|
||||
if (!(Test-Path $profileDir -PathType Container)) {
|
||||
mkdir $profileDir | Out-Null
|
||||
}
|
||||
|
||||
Set-Content $PROFILE -Value $profileContent
|
||||
}
|
||||
|
||||
if ($IsLinux) {
|
||||
b1k_print "This Shell Script will install dependencies for axmol"
|
||||
Write-Host "Are you continue? (y/n) " -NoNewline
|
||||
$answer = Read-Host
|
||||
if ($answer -like 'y*') {
|
||||
b1k_print "It will take few minutes"
|
||||
sudo apt update
|
||||
# for vm, libxxf86vm-dev also required
|
||||
|
||||
DEPENDS = @()
|
||||
|
||||
DEPENDS = 'libx11-dev'
|
||||
DEPENDS += 'automake'
|
||||
DEPENDS += 'libtool'
|
||||
DEPENDS += 'cmake'
|
||||
DEPENDS += 'libxmu-dev'
|
||||
DEPENDS += 'libglu1-mesa-dev'
|
||||
DEPENDS += 'libgl2ps-dev'
|
||||
DEPENDS += 'libxi-dev'
|
||||
DEPENDS += 'libzip-dev'
|
||||
DEPENDS += 'libpng-dev'
|
||||
DEPENDS += 'libfontconfig1-dev'
|
||||
DEPENDS += 'libgtk-3-dev'
|
||||
DEPENDS += 'binutils'
|
||||
DEPENDS += 'libbsd-dev'
|
||||
DEPENDS += 'libasound2-dev'
|
||||
DEPENDS += 'libxxf86vm-dev'
|
||||
DEPENDS += @('libvlc-dev', 'libvlccore-dev', 'vlc')
|
||||
|
||||
# if vlc encouter codec error, install
|
||||
# sudo apt install ubuntu-restricted-extras
|
||||
|
||||
sudo apt install --allow-unauthenticated --yes $DEPENDS > /dev/null
|
||||
|
||||
b1k_print "Installing latest freetype for linux ..."
|
||||
mkdir buildsrc
|
||||
Set-Location buildsrc
|
||||
git clone 'https://github.com/freetype/freetype.git'
|
||||
Set-Location freetype
|
||||
git checkout 'VER-2-13-0'
|
||||
sh autogen.sh
|
||||
./configure '--prefix=/usr' '--enable-freetype-config' '--disable-static'
|
||||
sudo make install
|
||||
Set-Location ..
|
||||
Set-Location ..
|
||||
}
|
||||
}
|
||||
|
||||
if ($IsWin) {
|
||||
$myProcess = [System.Diagnostics.Process]::GetCurrentProcess()
|
||||
$parentProcess = $myProcess.Parent
|
||||
if (!$parentProcess) {
|
||||
$myPID = $myProcess.Id
|
||||
$instance = Get-WmiObject Win32_Process -Filter "ProcessId = $myPID"
|
||||
$parentProcess = Get-Process -Id $instance.ParentProcessID
|
||||
}
|
||||
$parentProcessName = $parentProcess.ProcessName
|
||||
}
|
||||
|
||||
if ("$parentProcessName" -like 'explorer') {
|
||||
b1k_print "setup successfully, press any key to exit."
|
||||
$null = Read-Host
|
||||
}
|
||||
else {
|
||||
b1k_print 'setup successfully.'
|
||||
}
|
727
setup.py
727
setup.py
|
@ -1,727 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
# coding=utf-8
|
||||
"""****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
Copyright (c) 2021-2022 Bytedance Inc.
|
||||
|
||||
https://axmolengine.github.io/axmol
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************"""
|
||||
|
||||
'''
|
||||
This script will install environment variables needed to by axmol. It will set these envrironment variables:
|
||||
* AX_CONSOLE_ROOT: used to run axmol console tools
|
||||
* ANDROID_HOME: used to generate applicatoin on Android through commands
|
||||
* AX_ROOT: path where axmol is installed
|
||||
|
||||
On Max OS X, when start a shell, it will read these files and execute commands in sequence:
|
||||
|
||||
~/.bash_profile
|
||||
~/.bash_login
|
||||
~/.profile
|
||||
|
||||
And it will read only one of them. So we will add environment variable in the same sequence.
|
||||
Which means that
|
||||
* add environment variables into ~/.bash_profile if it exists
|
||||
* otherwise it will the add environment variables into ~/.bash_login if it exists
|
||||
* otherwise it will the add environment variables into ~/.profile if it exists
|
||||
|
||||
Will create ~/.bash_profile when none of them exist, and add environment variables into it.
|
||||
'''
|
||||
|
||||
import os
|
||||
import sys
|
||||
import fileinput
|
||||
import shutil
|
||||
import subprocess
|
||||
import ssl
|
||||
try:
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
print("==> setup.py set ssl context ok")
|
||||
except Exception:
|
||||
pass
|
||||
from optparse import OptionParser
|
||||
from time import time
|
||||
from time import sleep
|
||||
from os.path import dirname
|
||||
|
||||
AX_ROOT = 'AX_ROOT'
|
||||
AX_CONSOLE_ROOT = 'AX_CONSOLE_ROOT'
|
||||
|
||||
ANDROID_HOME = 'ANDROID_HOME'
|
||||
|
||||
def _check_python_version():
|
||||
major_ver = sys.version_info[0]
|
||||
if major_ver < 2:
|
||||
print ("The python version is %d.%d. But python 2.x+ is required. (Version 2.7 is well tested)\n"
|
||||
"Download it here: https://www.python.org/" % (major_ver, sys.version_info[1]))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class SetEnvVar(object):
|
||||
|
||||
RESULT_UPDATE_FAILED = -2
|
||||
RESULT_ADD_FAILED = -1
|
||||
RESULT_DO_NOTHING = 0
|
||||
RESULT_UPDATED = 1
|
||||
RESULT_ADDED = 2
|
||||
|
||||
MAC_CHECK_FILES = ['.bash_profile', '.bash_login', '.profile']
|
||||
LINUX_CHECK_FILES = ['.bashrc']
|
||||
ZSH_CHECK_FILES = ['.zshrc']
|
||||
RE_FORMAT = r'^export[ \t]+%s=(.+)'
|
||||
|
||||
def __init__(self):
|
||||
self.need_backup = True
|
||||
self.backup_file = None
|
||||
self.current_absolute_path = os.path.dirname(
|
||||
os.path.realpath(__file__))
|
||||
self.file_used_for_setup = ''
|
||||
|
||||
def _isWindows(self):
|
||||
return sys.platform == 'win32'
|
||||
|
||||
def _isLinux(self):
|
||||
return sys.platform.startswith('linux')
|
||||
|
||||
def _is_mac(self):
|
||||
return sys.platform == 'darwin'
|
||||
|
||||
def _is_zsh(self):
|
||||
shellItem = os.environ.get('SHELL')
|
||||
if shellItem is not None:
|
||||
if len(shellItem) >= 3:
|
||||
return shellItem[-3:] == "zsh"
|
||||
return False
|
||||
|
||||
def _get_unix_file_list(self):
|
||||
file_list = None
|
||||
|
||||
if self._is_zsh():
|
||||
file_list = SetEnvVar.ZSH_CHECK_FILES
|
||||
elif self._isLinux():
|
||||
file_list = SetEnvVar.LINUX_CHECK_FILES
|
||||
elif self._is_mac():
|
||||
file_list = SetEnvVar.MAC_CHECK_FILES
|
||||
|
||||
return file_list
|
||||
|
||||
def _get_filepath_for_setup(self):
|
||||
file_list = self._get_unix_file_list()
|
||||
|
||||
file_to_write = None
|
||||
if file_list is None:
|
||||
return ''
|
||||
|
||||
home = os.path.expanduser('~')
|
||||
for file_name in file_list:
|
||||
file_path = os.path.join(home, file_name)
|
||||
if os.path.exists(file_path):
|
||||
file_to_write = file_path
|
||||
break
|
||||
|
||||
if file_to_write is None:
|
||||
self.need_backup = False
|
||||
file_to_write = os.path.join(home, file_list[0])
|
||||
file_obj = open(file_to_write, 'w')
|
||||
file_obj.close()
|
||||
|
||||
return file_to_write
|
||||
|
||||
# modify registry table to add an environment variable on windows
|
||||
def _set_environment_variable_win32(self, key, value):
|
||||
ret = False
|
||||
try:
|
||||
env = None
|
||||
env = _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER,
|
||||
'Environment',
|
||||
0,
|
||||
_winreg.KEY_SET_VALUE | _winreg.KEY_READ)
|
||||
_winreg.SetValueEx(env, key, 0, _winreg.REG_SZ, value)
|
||||
_winreg.FlushKey(env)
|
||||
_winreg.CloseKey(env)
|
||||
ret = True
|
||||
except Exception:
|
||||
if env:
|
||||
_winreg.CloseKey(env)
|
||||
ret = False
|
||||
|
||||
return ret
|
||||
|
||||
def _gen_backup_file(self):
|
||||
file_name = os.path.basename(self.file_used_for_setup)
|
||||
file_path = os.path.dirname(self.file_used_for_setup)
|
||||
backup_file_name = file_name + ".backup"
|
||||
path = os.path.join(file_path, backup_file_name)
|
||||
i = 1
|
||||
while os.path.exists(path):
|
||||
backup_file_name = file_name + ".backup%d" % i
|
||||
path = os.path.join(file_path, backup_file_name)
|
||||
i += 1
|
||||
|
||||
return path
|
||||
|
||||
def _set_environment_variable_unix(self, key, value):
|
||||
|
||||
if self.need_backup:
|
||||
# backup the environment file
|
||||
self.backup_file = self._gen_backup_file()
|
||||
shutil.copy(self.file_used_for_setup, self.backup_file)
|
||||
self.need_backup = False
|
||||
|
||||
file = open(self.file_used_for_setup, 'a')
|
||||
file.write('\n# Add environment variable %s for axmol\n' % key)
|
||||
file.write('export %s="%s"\n' % (key, value))
|
||||
file.write('export PATH=$%s:$PATH\n' % key)
|
||||
if key == ANDROID_HOME:
|
||||
file.write(
|
||||
'export PATH=$%s/tools:$%s/platform-tools:$PATH\n' % (key, key))
|
||||
file.close()
|
||||
return True
|
||||
|
||||
def _set_environment_variable(self, key, value):
|
||||
|
||||
print(" -> Add %s environment variable..." % key)
|
||||
ret = False
|
||||
if self._isWindows():
|
||||
ret = self._set_environment_variable_win32(key, value)
|
||||
else:
|
||||
ret = self._set_environment_variable_unix(key, value)
|
||||
|
||||
if ret:
|
||||
print(" ->Added %s=%s\n" % (key, value))
|
||||
else:
|
||||
print(" ->Add failed\n")
|
||||
|
||||
return ret
|
||||
|
||||
def _search_unix_variable(self, var_name, file_name):
|
||||
if not os.path.isfile(file_name):
|
||||
return None
|
||||
|
||||
import re
|
||||
str_re = SetEnvVar.RE_FORMAT % var_name
|
||||
patten = re.compile(str_re)
|
||||
ret = None
|
||||
for line in open(file_name):
|
||||
str1 = line.lstrip(' \t')
|
||||
match = patten.match(str1)
|
||||
if match is not None:
|
||||
ret = match.group(1)
|
||||
|
||||
return ret
|
||||
|
||||
def _find_environment_variable(self, var):
|
||||
print(" ->Search for environment variable %s..." % var)
|
||||
ret = None
|
||||
try:
|
||||
ret = os.environ[var]
|
||||
except Exception:
|
||||
if not self._isWindows():
|
||||
file_list = self._get_unix_file_list()
|
||||
|
||||
if file_list is not None:
|
||||
home = os.path.expanduser('~')
|
||||
for name in file_list:
|
||||
path = os.path.join(home, name)
|
||||
ret = self._search_unix_variable(var, path)
|
||||
if ret is not None:
|
||||
break
|
||||
else:
|
||||
try:
|
||||
env = None
|
||||
env = _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER,
|
||||
'Environment',
|
||||
0,
|
||||
_winreg.KEY_READ)
|
||||
|
||||
ret = _winreg.QueryValueEx(env, var)[0]
|
||||
_winreg.CloseKey(env)
|
||||
except Exception:
|
||||
if env:
|
||||
_winreg.CloseKey(env)
|
||||
ret = None
|
||||
|
||||
if ret is None:
|
||||
print(" ->%s not found\n" % var)
|
||||
else:
|
||||
print(" ->%s is found : %s\n" % (var, ret))
|
||||
|
||||
return ret
|
||||
|
||||
def _get_input_value(self, var_name):
|
||||
if sys.version_info.major >= 3:
|
||||
ret = input(
|
||||
' ->Please enter the path of %s (or press Enter to skip):' % var_name)
|
||||
else:
|
||||
ret = raw_input(
|
||||
' ->Please enter the path of %s (or press Enter to skip):' % var_name)
|
||||
ret.rstrip(" \t")
|
||||
return ret
|
||||
|
||||
|
||||
def _check_valid(self, var_name, value):
|
||||
ret = False
|
||||
if var_name == ANDROID_HOME:
|
||||
ret = self._is_android_sdk_root_valid(value)
|
||||
else:
|
||||
ret = False
|
||||
|
||||
if not ret:
|
||||
print(
|
||||
' ->Error: "%s" is not a valid path of %s. Ignoring it.' % (value, var_name))
|
||||
|
||||
return ret
|
||||
|
||||
def _is_android_sdk_root_valid(self, android_sdk_root):
|
||||
if not android_sdk_root:
|
||||
return False
|
||||
|
||||
if self._isWindows():
|
||||
android_path = os.path.join(
|
||||
android_sdk_root, 'tools', 'android.bat')
|
||||
else:
|
||||
android_path = os.path.join(android_sdk_root, 'tools', 'android')
|
||||
if os.path.isfile(android_path):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def remove_dir_from_win_path(self, remove_dir):
|
||||
try:
|
||||
env = None
|
||||
path = None
|
||||
env = _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER,
|
||||
'Environment',
|
||||
0,
|
||||
_winreg.KEY_SET_VALUE | _winreg.KEY_READ)
|
||||
path = _winreg.QueryValueEx(env, 'Path')[0]
|
||||
|
||||
path_lower = path.lower()
|
||||
remove_dir = remove_dir.replace('/', '\\')
|
||||
remove_dir_lower = remove_dir.lower()
|
||||
start_pos = path_lower.find(remove_dir_lower)
|
||||
if (start_pos >= 0):
|
||||
length = len(remove_dir_lower)
|
||||
need_remove = path[start_pos:(start_pos + length)]
|
||||
path = path.replace(need_remove, '')
|
||||
path = path.replace(';;', ';')
|
||||
_winreg.SetValueEx(env, 'Path', 0, _winreg.REG_SZ, path)
|
||||
_winreg.FlushKey(env)
|
||||
_winreg.CloseKey(env)
|
||||
|
||||
print(' ->Remove directory \"%s\" from PATH!\n' % remove_dir)
|
||||
except Exception:
|
||||
print(' ->Remove directory \"%s\" from PATH failed!\n' %
|
||||
remove_dir)
|
||||
|
||||
def set_windows_path(self, add_dir):
|
||||
ret = False
|
||||
try:
|
||||
env = None
|
||||
path = None
|
||||
env = _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER,
|
||||
'Environment',
|
||||
0,
|
||||
_winreg.KEY_SET_VALUE | _winreg.KEY_READ)
|
||||
path = _winreg.QueryValueEx(env, 'Path')[0]
|
||||
|
||||
# add variable if can't find it in PATH
|
||||
path_lower = path.lower()
|
||||
add_dir_lower = add_dir.lower()
|
||||
if (path_lower.find(add_dir_lower) == -1):
|
||||
path = add_dir + ';' + path
|
||||
_winreg.SetValueEx(env, 'Path', 0, _winreg.REG_SZ, path)
|
||||
_winreg.FlushKey(env)
|
||||
|
||||
_winreg.CloseKey(env)
|
||||
ret = True
|
||||
except Exception:
|
||||
if not path:
|
||||
path = add_dir
|
||||
_winreg.SetValueEx(env, 'Path', 0, _winreg.REG_SZ, path)
|
||||
_winreg.FlushKey(env)
|
||||
ret = True
|
||||
else:
|
||||
_winreg.SetValueEx(env, 'Path', 0, _winreg.REG_SZ, path)
|
||||
_winreg.FlushKey(env)
|
||||
ret = False
|
||||
|
||||
if env:
|
||||
_winreg.CloseKey(env)
|
||||
|
||||
if ret:
|
||||
print(" ->Add directory \"%s\" into PATH succeed!\n" % add_dir)
|
||||
else:
|
||||
print(" ->Add directory \"%s\" into PATH failed!\n" % add_dir)
|
||||
|
||||
def set_console_root(self):
|
||||
print("->Check environment variable %s" % AX_CONSOLE_ROOT)
|
||||
axmol_console_root = os.path.join(
|
||||
self.current_absolute_path, 'tools', 'console', 'bin')
|
||||
old_dir = self._find_environment_variable(AX_CONSOLE_ROOT)
|
||||
if old_dir is None:
|
||||
# add environment variable
|
||||
if self._isWindows():
|
||||
self.set_windows_path(axmol_console_root)
|
||||
|
||||
self._set_environment_variable(
|
||||
AX_CONSOLE_ROOT, axmol_console_root)
|
||||
else:
|
||||
if old_dir == axmol_console_root:
|
||||
# is same with before, nothing to do
|
||||
return
|
||||
|
||||
# update the environment variable
|
||||
if self._isWindows():
|
||||
self.remove_dir_from_win_path(old_dir)
|
||||
self.set_windows_path(axmol_console_root)
|
||||
|
||||
self._force_update_env(AX_CONSOLE_ROOT, axmol_console_root)
|
||||
|
||||
def set_axmol_root(self):
|
||||
print("->Check environment variable %s" % AX_ROOT)
|
||||
axmol_root = self.current_absolute_path
|
||||
old_dir = self._find_environment_variable(AX_ROOT)
|
||||
if old_dir is None:
|
||||
# add environment variable
|
||||
self._set_environment_variable(AX_ROOT, axmol_root)
|
||||
else:
|
||||
if old_dir == axmol_root:
|
||||
# is same with before, nothing to do
|
||||
return
|
||||
self._force_update_env(AX_ROOT, axmol_root)
|
||||
|
||||
def _force_update_unix_env(self, var_name, value):
|
||||
import re
|
||||
home = os.path.expanduser('~')
|
||||
str_re = SetEnvVar.RE_FORMAT % var_name
|
||||
patten = re.compile(str_re)
|
||||
replace_str = 'export %s=%s\n' % (var_name, value)
|
||||
|
||||
file_list = SetEnvVar.MAC_CHECK_FILES
|
||||
if self._isLinux():
|
||||
file_list = SetEnvVar.LINUX_CHECK_FILES
|
||||
|
||||
print(" ->Update variable %s in files %s" %
|
||||
(var_name, str(file_list)))
|
||||
variable_updated = False
|
||||
for file_name in file_list:
|
||||
path = os.path.join(home, file_name)
|
||||
if os.path.isfile(path):
|
||||
lines = []
|
||||
# read files
|
||||
need_over_write = False
|
||||
file_obj = open(path, 'r')
|
||||
for line in file_obj:
|
||||
str_temp = line.lstrip(' \t')
|
||||
match = patten.match(str_temp)
|
||||
if match is not None:
|
||||
variable_updated = True
|
||||
need_over_write = True
|
||||
lines.append(replace_str)
|
||||
else:
|
||||
lines.append(line)
|
||||
file_obj.close()
|
||||
|
||||
# rewrite file
|
||||
if need_over_write:
|
||||
file_obj = open(path, 'w')
|
||||
file_obj.writelines(lines)
|
||||
file_obj.close()
|
||||
print(" ->File %s updated!" % path)
|
||||
|
||||
# nothing updated, should add variable
|
||||
if not variable_updated:
|
||||
print("\n ->No files updated, add variable %s instead!" %
|
||||
var_name)
|
||||
ret = self._set_environment_variable(var_name, value)
|
||||
else:
|
||||
ret = True
|
||||
|
||||
return ret
|
||||
|
||||
def _force_update_env(self, var_name, value):
|
||||
ret = False
|
||||
if self._isWindows():
|
||||
print(" ->Force update environment variable %s" % var_name)
|
||||
ret = self._set_environment_variable_win32(var_name, value)
|
||||
if not ret:
|
||||
print(" ->Failed!")
|
||||
else:
|
||||
print(" ->Succeed : %s=%s" % (var_name, value))
|
||||
else:
|
||||
ret = self._force_update_unix_env(var_name, value)
|
||||
return ret
|
||||
|
||||
def _get_androidsdk_path(self):
|
||||
return self._get_sdkpath_for_cmd("android")
|
||||
|
||||
def _get_sdkpath_for_cmd(self, cmd, has_bin_folder=True):
|
||||
ret = None
|
||||
print(" ->Search for command " + cmd + " in system...")
|
||||
if not self._isWindows():
|
||||
if sys.version_info.major >= 3:
|
||||
import subprocess
|
||||
else:
|
||||
import commands as subprocess
|
||||
state, result = subprocess.getstatusoutput("which " + cmd)
|
||||
if state == 0:
|
||||
ret = os.path.realpath(result)
|
||||
ret = os.path.dirname(ret)
|
||||
# Use parent folder if has_bin_folder was set
|
||||
if has_bin_folder:
|
||||
ret = os.path.dirname(ret)
|
||||
|
||||
if ret is not None:
|
||||
print(" ->Path " + ret + " was found\n")
|
||||
else:
|
||||
print(" ->Command " + cmd + " not found\n")
|
||||
return ret
|
||||
|
||||
def _find_value_from_sys(self, var_name):
|
||||
if var_name == ANDROID_HOME:
|
||||
return self._get_androidsdk_path()
|
||||
else:
|
||||
return None
|
||||
|
||||
def set_variable(self, var_name, value):
|
||||
print("->Check environment variable %s" % var_name)
|
||||
find_value = self._find_environment_variable(var_name)
|
||||
var_found = (find_value is not None)
|
||||
action_none = 0
|
||||
action_add = 1
|
||||
action_update = 2
|
||||
|
||||
need_action = action_none
|
||||
if var_found:
|
||||
if value and self._check_valid(var_name, value):
|
||||
# should update
|
||||
need_action = action_update
|
||||
else:
|
||||
# do nothing
|
||||
need_action = action_none
|
||||
else:
|
||||
if not value:
|
||||
# find the command path in system
|
||||
value = self._find_value_from_sys(var_name)
|
||||
|
||||
if not value:
|
||||
value = self._get_input_value(var_name)
|
||||
|
||||
if value and self._check_valid(var_name, value):
|
||||
# should add variable
|
||||
need_action = action_add
|
||||
else:
|
||||
# do nothing
|
||||
need_action = action_none
|
||||
|
||||
if need_action == action_none:
|
||||
# do nothing
|
||||
return SetEnvVar.RESULT_DO_NOTHING
|
||||
elif need_action == action_add:
|
||||
# add variable
|
||||
if self._set_environment_variable(var_name, value):
|
||||
return SetEnvVar.RESULT_ADDED
|
||||
else:
|
||||
return SetEnvVar.RESULT_ADD_FAILED
|
||||
elif need_action == action_update:
|
||||
# update variable
|
||||
if self._force_update_env(var_name, value):
|
||||
# update succeed
|
||||
return SetEnvVar.RESULT_UPDATED
|
||||
else:
|
||||
# update failed
|
||||
return SetEnvVar.RESULT_UPDATE_FAILED
|
||||
else:
|
||||
return SetEnvVar.RESULT_DO_NOTHING
|
||||
|
||||
def set_environment_variables(self, android_sdk_root, quiet):
|
||||
|
||||
print('\nSetting up axmol...')
|
||||
|
||||
self.file_used_for_setup = self._get_filepath_for_setup()
|
||||
|
||||
self.set_axmol_root()
|
||||
self.set_console_root()
|
||||
|
||||
if self._isWindows():
|
||||
print(
|
||||
'->Configuration for Android platform only, you can also skip and manually edit your environment variables\n')
|
||||
else:
|
||||
print('->Configuration for Android platform only, you can also skip and manually edit "%s"\n' %
|
||||
self.file_used_for_setup)
|
||||
if(quiet) :
|
||||
sdk_ret = self.set_variable(ANDROID_HOME, android_sdk_root)
|
||||
|
||||
# tip the backup file
|
||||
if (self.backup_file is not None) and (os.path.exists(self.backup_file)):
|
||||
print('\nA backup file \"%s\" is created for \"%s\".' %
|
||||
(self.backup_file, self.file_used_for_setup))
|
||||
|
||||
if self._isWindows():
|
||||
print(
|
||||
'\nPlease restart the terminal or restart computer to make added system variables take effect\n')
|
||||
else:
|
||||
print('\nPlease execute command: "source %s" to make added system variables take effect\n' %
|
||||
self.file_used_for_setup)
|
||||
|
||||
class FileDownloader(object):
|
||||
def __init__(self):
|
||||
self.current_absolute_path = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
def download_file(self, url, filename):
|
||||
# remove file for retry
|
||||
try:
|
||||
os.remove(filename)
|
||||
except OSError:
|
||||
pass
|
||||
print("==> Ready to download '%s' from '%s'" % (filename, url))
|
||||
if(sys.version_info.major >= 3):
|
||||
import urllib.request as urllib2
|
||||
else:
|
||||
import urllib2
|
||||
try:
|
||||
u = urllib2.urlopen(url)
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 404:
|
||||
print("==> Error: Could not find the file from url: '%s'" % (url))
|
||||
print("==> Http request failed, error code: " + str(e.code) + ", reason: " + e.read())
|
||||
sys.exit(1)
|
||||
|
||||
f = open(filename, 'wb')
|
||||
content_len = 0
|
||||
if(sys.version_info.major >= 3):
|
||||
content_len = u.getheader("Content-Length")
|
||||
else:
|
||||
content_len = u.info().getheaders("Content-Length")
|
||||
if content_len and len(content_len) > 0:
|
||||
content_len = content_len[0]
|
||||
file_size = 0
|
||||
if content_len:
|
||||
file_size = int(content_len)
|
||||
else:
|
||||
print("==> WARNING: Couldn't grab the file size from remote")
|
||||
return
|
||||
|
||||
print("==> Start to download, please wait ...")
|
||||
|
||||
file_size_dl = 0
|
||||
block_sz = 8192
|
||||
block_size_per_second = 0
|
||||
old_time = time()
|
||||
|
||||
status = ""
|
||||
while True:
|
||||
buffer = u.read(block_sz)
|
||||
if not buffer:
|
||||
print("%s%s" % (" " * len(status), "\r")),
|
||||
break
|
||||
|
||||
file_size_dl += len(buffer)
|
||||
block_size_per_second += len(buffer)
|
||||
f.write(buffer)
|
||||
new_time = time()
|
||||
if (new_time - old_time) > 1:
|
||||
speed = block_size_per_second / (new_time - old_time) / 1000.0
|
||||
if file_size != 0:
|
||||
percent = file_size_dl * 100. / file_size
|
||||
status = r"Downloaded: %6dK / Total: %dK, Percent: %3.2f%%, Speed: %6.2f KB/S " % (file_size_dl / 1000, file_size / 1000, percent, speed)
|
||||
else:
|
||||
status = r"Downloaded: %6dK, Speed: %6.2f KB/S " % (file_size_dl / 1000, speed)
|
||||
print(status),
|
||||
sys.stdout.flush()
|
||||
print("\r"),
|
||||
block_size_per_second = 0
|
||||
old_time = new_time
|
||||
|
||||
print("==> Downloading finished!")
|
||||
f.close()
|
||||
|
||||
def ensure_directory(self, target):
|
||||
if not os.path.exists(target):
|
||||
os.mkdir(target)
|
||||
|
||||
def download_file_with_retry(self, url, filename, times, delay):
|
||||
if(sys.version_info.major >= 3):
|
||||
import urllib.request as urllib2
|
||||
else:
|
||||
import urllib2
|
||||
|
||||
output_path = dirname(filename)
|
||||
downloader.ensure_directory(output_path)
|
||||
|
||||
times_count = 0
|
||||
while(times_count < times):
|
||||
times_count += 1
|
||||
try:
|
||||
if(times_count > 1):
|
||||
print("==> Download file retry " + str(times_count))
|
||||
self.download_file(url, filename)
|
||||
return
|
||||
except Exception as err:
|
||||
if(times_count >= times):
|
||||
raise err
|
||||
sleep(delay)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if not _check_python_version():
|
||||
exit()
|
||||
|
||||
parser = OptionParser()
|
||||
parser.add_option('-a', '--androidsdkroot',
|
||||
dest='android_sdk_root', help='directory of android sdk root')
|
||||
parser.add_option(
|
||||
'-q', '--quiet', dest='quiet',action="store_false", default = True, help='setup without setting SDK')
|
||||
opts, args = parser.parse_args()
|
||||
|
||||
# set environment variables
|
||||
env = SetEnvVar()
|
||||
if env._isWindows():
|
||||
if(sys.version_info.major >= 3):
|
||||
import winreg as _winreg
|
||||
else:
|
||||
import _winreg
|
||||
|
||||
env.set_environment_variables(opts.android_sdk_root, opts.quiet)
|
||||
|
||||
if env._isWindows():
|
||||
import ctypes
|
||||
HWND_BROADCAST = 0xFFFF
|
||||
WM_SETTINGCHANGE = 0x1A
|
||||
SMTO_ABORTIFHUNG = 0x0002
|
||||
result = ctypes.c_long()
|
||||
SendMessageTimeoutW = ctypes.windll.user32.SendMessageTimeoutW
|
||||
SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
|
||||
u'Environment', SMTO_ABORTIFHUNG, 5000, ctypes.byref(result))
|
||||
|
||||
current_absolute_path = os.path.dirname(os.path.realpath(__file__))
|
||||
external_tools_path = os.path.join(current_absolute_path, 'tools', 'external')
|
||||
if not os.path.exists(external_tools_path):
|
||||
os.mkdir(external_tools_path)
|
||||
|
||||
downloader = FileDownloader()
|
||||
if env._isWindows():
|
||||
file_path = os.path.join(external_tools_path, 'nuget', 'nuget.exe')
|
||||
|
||||
if not os.path.isfile(file_path):
|
||||
downloader.download_file_with_retry('https://dist.nuget.org/win-x86-commandline/latest/nuget.exe', file_path, 5, 3)
|
|
@ -41,6 +41,7 @@
|
|||
# -xb: cross build tool build options: i.e. -xb '--config','Release'
|
||||
# -prefix: the install location for missing tools in system, default is "$HOME/build1k"
|
||||
# -winsdk: specific windows sdk version, i.e. -winsdk '10.0.19041.0', leave empty, cmake will auto choose latest avaiable
|
||||
# -setupOnly: whether setup only: true, false
|
||||
# support matrix
|
||||
# | OS | Build targets | C/C++ compiler toolchain | Cross Build tool |
|
||||
# +----------+----------------------+---------------------------+------------------|
|
||||
|
@ -62,6 +63,7 @@ $manifest = @{
|
|||
gcc = '9.0.0+';
|
||||
cmake = '3.26.4+';
|
||||
nuget = '*'; # any
|
||||
glslcc = '1.7.6+';
|
||||
ninja = '1.11.1+';
|
||||
jdk = '11.0.19+';
|
||||
cmdlinetools = '7.0+'; # android cmdlinetools
|
||||
|
@ -74,7 +76,19 @@ function b1k_print($msg) {
|
|||
Write-Host "build1k: $msg"
|
||||
}
|
||||
|
||||
$options = @{p = $null; a = 'x64'; d = $null; cc = $null; xt = 'cmake'; prefix = $null; xc = @(); xb = @(); winsdk = $null; dll = $false }
|
||||
$options = @{
|
||||
p = $null;
|
||||
a = 'x64';
|
||||
d = $null;
|
||||
cc = $null;
|
||||
xt = 'cmake';
|
||||
prefix = $null;
|
||||
xc = @();
|
||||
xb = @();
|
||||
winsdk = $null;
|
||||
dll = $false;
|
||||
setupOnly = $false
|
||||
}
|
||||
|
||||
$optName = $null
|
||||
foreach ($arg in $args) {
|
||||
|
@ -97,7 +111,10 @@ foreach ($arg in $args) {
|
|||
$pwsh_ver = $PSVersionTable.PSVersion.ToString()
|
||||
|
||||
b1k_print "PowerShell $pwsh_ver"
|
||||
b1k_print $(Out-String -InputObject $options)
|
||||
|
||||
if (!$options.setupOnly) {
|
||||
b1k_print $(Out-String -InputObject $options)
|
||||
}
|
||||
|
||||
$myRoot = $PSScriptRoot
|
||||
|
||||
|
@ -106,7 +123,8 @@ $HOST_LINUX = 1 # targets: linux,android
|
|||
$HOST_MAC = 2 # targets: android,ios,osx(macos),tvos,watchos
|
||||
|
||||
# 0: windows, 1: linux, 2: macos
|
||||
if ($IsWindows -or ("$env:OS" -eq 'Windows_NT')) {
|
||||
$IsWin = $IsWindows -or ("$env:OS" -eq 'Windows_NT')
|
||||
if ($IsWin) {
|
||||
$HOST_OS = $HOST_WIN
|
||||
$envPathSep = ';'
|
||||
}
|
||||
|
@ -123,8 +141,6 @@ else {
|
|||
}
|
||||
}
|
||||
|
||||
$IsWin = $HOST_OS -eq $HOST_WIN
|
||||
|
||||
$exeSuffix = if ($HOST_OS -eq 0) { '.exe' } else { '' }
|
||||
|
||||
$CONFIG_DEFAULT_OPTIONS = @()
|
||||
|
@ -165,24 +181,22 @@ if (!$TOOLCHAIN_VER) {
|
|||
$TOOLCHAIN_NAME = $TOOLCHAIN
|
||||
}
|
||||
|
||||
# determine build script workspace
|
||||
|
||||
$stored_cwd = $(Get-Location).Path
|
||||
if ($options.d) {
|
||||
Set-Location $options.d
|
||||
$prefix = if ($options.prefix) { $options.prefix } else { Join-Path $HOME 'build1k' }
|
||||
if (!(Test-Path "$prefix" -PathType Container)) {
|
||||
mkdir $prefix | Out-Null
|
||||
}
|
||||
|
||||
$tools_dir = if ($options.prefix) { $options.prefix } else { Join-Path $HOME 'build1k' }
|
||||
if (!(Test-Path "$tools_dir" -PathType Container)) {
|
||||
mkdir $tools_dir | Out-Null
|
||||
}
|
||||
b1k_print "proj_dir=$((Get-Location).Path), prefix=$prefix"
|
||||
|
||||
b1k_print "proj_dir=$((Get-Location).Path), tools_dir=$tools_dir"
|
||||
|
||||
function find_prog($name, $path = $null, $cmd = $null, $param = $null, $silent = $false) {
|
||||
function find_prog($name, $path = $null, $mode = 'ONLY', $cmd = $null, $param = $null, $silent = $false) {
|
||||
if ($path) {
|
||||
$storedPATH = $env:PATH
|
||||
$env:PATH = $path
|
||||
if ($mode -eq 'ONLY') {
|
||||
$env:PATH = $path
|
||||
}
|
||||
elseif ($mode -eq 'BOTH') {
|
||||
$env:PATH = "$path$envPathSep$env:PATH"
|
||||
}
|
||||
}
|
||||
if (!$cmd) { $cmd = $name }
|
||||
|
||||
|
@ -236,16 +250,16 @@ function find_prog($name, $path = $null, $cmd = $null, $param = $null, $silent =
|
|||
if ($checkVerCond) {
|
||||
$matched = Invoke-Expression $checkVerCond
|
||||
if ($matched) {
|
||||
if (!$silent) { b1k_print "Found suitable installed $name, version: $foundVer" }
|
||||
if (!$silent) { b1k_print "Found suitable installed ${name}: $prog_path, version: $foundVer" }
|
||||
$found_rets = $prog_path, $foundVer
|
||||
}
|
||||
else {
|
||||
if (!$silent) { b1k_print "The installed $name=$foundVer not match $requiredVer" }
|
||||
if (!$silent) { b1k_print "The installed ${name}: $prog_path, version: $foundVer not match required: $requiredVer" }
|
||||
$found_rets = $null, $preferredVer
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!$silent) { b1k_print "Found installed $name, version: $foundVer" }
|
||||
if (!$silent) { b1k_print "Found installed ${name}: $prog_path, version: $foundVer" }
|
||||
$found_rets = $prog_path, $foundVer
|
||||
}
|
||||
}
|
||||
|
@ -291,11 +305,9 @@ function download_file($url, $out) {
|
|||
function setup_cmake() {
|
||||
$cmake_prog, $cmake_ver = find_prog -name 'cmake'
|
||||
if ($cmake_prog) {
|
||||
b1k_print "Using installed cmake $cmake_prog, version: $cmake_ver"
|
||||
return $cmake_prog
|
||||
}
|
||||
else {
|
||||
b1k_print "Installing cmake $cmake_ver ..."
|
||||
|
||||
$cmake_suffix = @(".zip", ".sh", ".tar.gz").Get($HOST_OS)
|
||||
if ($HOST_OS -ne $HOST_MAC) {
|
||||
$cmake_dir = "cmake-$cmake_ver-$HOST_OS_NAME-x86_64"
|
||||
|
@ -303,7 +315,7 @@ function setup_cmake() {
|
|||
else {
|
||||
$cmake_dir = "cmake-$cmake_ver-$HOST_OS_NAME-universal"
|
||||
}
|
||||
$cmake_root = $(Join-Path $tools_dir $cmake_dir)
|
||||
$cmake_root = $(Join-Path $prefix $cmake_dir)
|
||||
$cmake_pkg_name = "$cmake_dir$cmake_suffix"
|
||||
$cmake_pkg_path = "$cmake_root$cmake_suffix"
|
||||
if (!(Test-Path $cmake_root -PathType Container)) {
|
||||
|
@ -314,7 +326,7 @@ function setup_cmake() {
|
|||
}
|
||||
|
||||
if ($HOST_OS -eq $HOST_WIN) {
|
||||
Expand-Archive -Path $cmake_pkg_path -DestinationPath $tools_dir\
|
||||
Expand-Archive -Path $cmake_pkg_path -DestinationPath $prefix\
|
||||
}
|
||||
elseif ($HOST_OS -eq $HOST_LINUX) {
|
||||
chmod 'u+x' "$cmake_pkg_path"
|
||||
|
@ -322,7 +334,7 @@ function setup_cmake() {
|
|||
& "$cmake_pkg_path" '--skip-license' '--exclude-subdir' "--prefix=$cmake_root"
|
||||
}
|
||||
elseif ($HOST_OS -eq $HOST_MAC) {
|
||||
tar xvf "$cmake_root.tar.gz" -C "$tools_dir/"
|
||||
tar xvf "$cmake_root.tar.gz" -C "$prefix/"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,7 +351,8 @@ function setup_cmake() {
|
|||
if (($null -ne $cmake_bin) -and ($env:PATH.IndexOf($cmake_bin) -eq -1)) {
|
||||
$env:PATH = "$cmake_bin$envPathSep$env:PATH"
|
||||
}
|
||||
b1k_print "Install cmake $cmake_ver succeed"
|
||||
b1k_print "Using cmake: $cmake_prog, version: $cmake_ver"
|
||||
return $cmake_prog
|
||||
}
|
||||
else {
|
||||
throw "Install cmake $cmake_ver fail"
|
||||
|
@ -349,27 +362,21 @@ function setup_cmake() {
|
|||
|
||||
# setup nuget
|
||||
function setup_nuget() {
|
||||
$nuget_prog, $nuget_ver = find_prog -name 'nuget'
|
||||
$nuget_bin = Join-Path $prefix 'nuget'
|
||||
$nuget_prog, $nuget_ver = find_prog -name 'nuget' -path $nuget_bin -mode 'BOTH'
|
||||
if ($nuget_prog) {
|
||||
b1k_print "Using installed nuget: $nuget_prog"
|
||||
return $nuget_prog
|
||||
}
|
||||
|
||||
$nuget_prog = Join-Path $tools_dir 'nuget'
|
||||
if (!(Test-Path -Path $nuget_prog -PathType Container)) {
|
||||
mkdir $nuget_prog
|
||||
if (!(Test-Path -Path $nuget_bin -PathType Container)) {
|
||||
mkdir $nuget_bin | Out-Null
|
||||
}
|
||||
|
||||
$nuget_prog = Join-Path $nuget_prog 'nuget.exe'
|
||||
|
||||
if (Test-Path -Path $nuget_prog -PathType Leaf) {
|
||||
b1k_print "Using installed nuget: $nuget_prog"
|
||||
return $nuget_prog
|
||||
}
|
||||
$nuget_prog = Join-Path $nuget_bin 'nuget.exe'
|
||||
download_file "https://dist.nuget.org/win-x86-commandline/$nuget_ver/nuget.exe" $nuget_prog
|
||||
|
||||
if (Test-Path -Path $nuget_prog -PathType Leaf) {
|
||||
b1k_print "The nuget was successfully installed to: $nuget_prog"
|
||||
b1k_print "Using nuget: $nuget_prog, version: $nuget_ver"
|
||||
return $nuget_prog
|
||||
}
|
||||
else {
|
||||
|
@ -380,31 +387,29 @@ function setup_nuget() {
|
|||
function setup_jdk() {
|
||||
$javac_prog, $jdk_ver = find_prog -name 'jdk' -cmd 'javac'
|
||||
if ($javac_prog) {
|
||||
b1k_print "Using installed jdk: $javac_prog, version: $jdk_ver"
|
||||
return $javac_prog
|
||||
}
|
||||
|
||||
b1k_print "Installing jdk $jdk_ver ..."
|
||||
$suffix = $('windows-x64.zip', 'linux-x64.tar.gz', 'macOS-x64.tar.gz').Get($HOST_OS)
|
||||
$java_home = Join-Path $tools_dir "jdk-$jdk_ver"
|
||||
$java_home = Join-Path $prefix "jdk-$jdk_ver"
|
||||
if (!(Test-Path $java_home -PathType Container)) {
|
||||
# refer to https://learn.microsoft.com/en-us/java/openjdk/download
|
||||
if (!(Test-Path "$tools_dir/microsoft-jdk-$jdk_ver-$suffix" -PathType Leaf)) {
|
||||
download_file "https://aka.ms/download-jdk/microsoft-jdk-$jdk_ver-$suffix" "$tools_dir/microsoft-jdk-$jdk_ver-$suffix"
|
||||
if (!(Test-Path "$prefix/microsoft-jdk-$jdk_ver-$suffix" -PathType Leaf)) {
|
||||
download_file "https://aka.ms/download-jdk/microsoft-jdk-$jdk_ver-$suffix" "$prefix/microsoft-jdk-$jdk_ver-$suffix"
|
||||
}
|
||||
|
||||
# uncompress
|
||||
if ($IsWin) {
|
||||
Expand-Archive -Path "$tools_dir/microsoft-jdk-$jdk_ver-$suffix" -DestinationPath "$tools_dir/"
|
||||
Expand-Archive -Path "$prefix/microsoft-jdk-$jdk_ver-$suffix" -DestinationPath "$prefix/"
|
||||
}
|
||||
else {
|
||||
tar xvf "$tools_dir/microsoft-jdk-$jdk_ver-$suffix" -C "$tools_dir/"
|
||||
tar xvf "$prefix/microsoft-jdk-$jdk_ver-$suffix" -C "$prefix/"
|
||||
}
|
||||
|
||||
# move to plain folder name
|
||||
$folderName = (Get-ChildItem -Path $tools_dir -Filter "jdk-$jdk_ver+*").Name
|
||||
$folderName = (Get-ChildItem -Path $prefix -Filter "jdk-$jdk_ver+*").Name
|
||||
if ($folderName) {
|
||||
Move-Item "$tools_dir/$folderName" $java_home
|
||||
Move-Item "$prefix/$folderName" $java_home
|
||||
}
|
||||
}
|
||||
$env:JAVA_HOME = $java_home
|
||||
|
@ -418,29 +423,61 @@ function setup_jdk() {
|
|||
throw "Install jdk $jdk_ver fail"
|
||||
}
|
||||
|
||||
b1k_print "Using jdk: $javac_prog, version: $jdk_ver"
|
||||
|
||||
return $javac_prog
|
||||
}
|
||||
|
||||
function setup_glslcc() {
|
||||
$glslcc_bin = Join-Path $prefix 'glslcc'
|
||||
$glslcc_prog, $glslcc_ver = find_prog -name 'glslcc' -path $glslcc_bin -mode 'BOTH'
|
||||
if ($glslcc_prog) {
|
||||
return $glslcc_prog
|
||||
}
|
||||
|
||||
$suffix = $('win64.zip', 'linux.tar.gz', 'osx.tar.gz').Get($HOST_OS)
|
||||
if (!(Test-Path $glslcc_bin -PathType Container)) {
|
||||
$glslcc_pkg = "$prefix/glslcc-$suffix"
|
||||
if (!(Test-Path $glslcc_pkg -PathType Leaf)) {
|
||||
download_file "https://github.com/septag/glslcc/releases/download/v$glslcc_ver/glslcc-$glslcc_ver-$suffix" "$glslcc_pkg"
|
||||
}
|
||||
if ($IsWin) {
|
||||
Expand-Archive -Path $glslcc_pkg -DestinationPath $glslcc_bin
|
||||
}
|
||||
else {
|
||||
mkdir -p $glslcc_bin | Out-Null
|
||||
tar xvf "$glslcc_pkg" -C $glslcc_bin
|
||||
}
|
||||
}
|
||||
if ($env:PATH.IndexOf($glslcc_bin) -eq -1) {
|
||||
$env:PATH = "$glslcc_bin$envPathSep$env:PATH"
|
||||
}
|
||||
$glslcc_prog = (Join-Path $glslcc_bin "glslcc$exeSuffix")
|
||||
|
||||
b1k_print "Using glslcc: $glslcc_prog, version: $glslcc_ver"
|
||||
|
||||
return $glslcc_prog
|
||||
}
|
||||
|
||||
function setup_ninja() {
|
||||
$ninja_prog, $ninja_ver = find_prog -name 'ninja'
|
||||
if ($ninja_prog) {
|
||||
b1k_print "Using installed ninja: $ninja_prog, version: $(ninja --version)"
|
||||
return $ninja_prog
|
||||
}
|
||||
|
||||
b1k_print "Installing ninja $ninja_ver ..."
|
||||
|
||||
$suffix = $('win', 'linux', 'mac').Get($HOST_OS)
|
||||
$ninja_bin = (Resolve-Path "$tools_dir/ninja-$suffix" -ErrorAction SilentlyContinue).Path
|
||||
$ninja_bin = (Resolve-Path "$prefix/ninja-$suffix" -ErrorAction SilentlyContinue).Path
|
||||
if (!$ninja_bin) {
|
||||
download_file "https://github.com/ninja-build/ninja/releases/download/v$ninja_ver/ninja-$suffix.zip" "$tools_dir/ninja-$suffix.zip"
|
||||
Expand-Archive -Path $tools_dir/ninja-$suffix.zip -DestinationPath "$tools_dir/ninja-$suffix/"
|
||||
$ninja_bin = (Resolve-Path "$tools_dir/ninja-$suffix" -ErrorAction SilentlyContinue).Path
|
||||
download_file "https://github.com/ninja-build/ninja/releases/download/v$ninja_ver/ninja-$suffix.zip" "$prefix/ninja-$suffix.zip"
|
||||
Expand-Archive -Path $prefix/ninja-$suffix.zip -DestinationPath "$prefix/ninja-$suffix/"
|
||||
$ninja_bin = (Resolve-Path "$prefix/ninja-$suffix" -ErrorAction SilentlyContinue).Path
|
||||
}
|
||||
if ($env:PATH.IndexOf($ninja_bin) -eq -1) {
|
||||
$env:PATH = "$ninja_bin$envPathSep$env:PATH"
|
||||
}
|
||||
$ninja_prog = (Join-Path $ninja_bin "ninja$exeSuffix")
|
||||
|
||||
b1k_print "Using ninja: $ninja_prog, version: $ninja_ver"
|
||||
return $ninja_prog
|
||||
}
|
||||
|
||||
|
@ -511,24 +548,24 @@ function setup_android_sdk() {
|
|||
$sdkmanager_prog, $sdkmanager_ver = (find_prog -name 'cmdlinetools' -cmd 'sdkmanager' -path "$sdk_root/cmdline-tools/latest/bin" -param "--sdk_root=$sdk_root")
|
||||
}
|
||||
else {
|
||||
$sdk_root = Join-Path $tools_dir 'adt/sdk'
|
||||
$sdk_root = Join-Path $prefix 'adt/sdk'
|
||||
if (!(Test-Path -Path $sdk_root -PathType Container)) {
|
||||
mkdir $sdk_root
|
||||
}
|
||||
}
|
||||
|
||||
if (!$sdkmanager_prog) {
|
||||
$sdkmanager_prog, $sdkmanager_ver = (find_prog -name 'cmdlinetools' -cmd 'sdkmanager' -path "$tools_dir/cmdline-tools/bin" -param "--sdk_root=$sdk_root")
|
||||
$sdkmanager_prog, $sdkmanager_ver = (find_prog -name 'cmdlinetools' -cmd 'sdkmanager' -path "$prefix/cmdline-tools/bin" -param "--sdk_root=$sdk_root")
|
||||
$suffix = $('win', 'linux', 'mac').Get($HOST_OS)
|
||||
if (!$sdkmanager_prog) {
|
||||
b1k_print "Installing cmdlinetools version: $sdkmanager_ver ..."
|
||||
|
||||
$cmdlinetools_pkg_name = "commandlinetools-$suffix-$($cmdlinetools_rev)_latest.zip"
|
||||
$cmdlinetools_pkg_path = Join-Path $tools_dir $cmdlinetools_pkg_name
|
||||
$cmdlinetools_pkg_path = Join-Path $prefix $cmdlinetools_pkg_name
|
||||
$cmdlinetools_url = "https://dl.google.com/android/repository/$cmdlinetools_pkg_name"
|
||||
download_file $cmdlinetools_url $cmdlinetools_pkg_path
|
||||
Expand-Archive -Path $cmdlinetools_pkg_path -DestinationPath "$tools_dir/"
|
||||
$sdkmanager_prog, $_ = (find_prog -name 'cmdlinetools' -cmd 'sdkmanager' -path "$tools_dir/cmdline-tools/bin" -param "--sdk_root=$sdk_root" -silent $True)
|
||||
Expand-Archive -Path $cmdlinetools_pkg_path -DestinationPath "$prefix/"
|
||||
$sdkmanager_prog, $_ = (find_prog -name 'cmdlinetools' -cmd 'sdkmanager' -path "$prefix/cmdline-tools/bin" -param "--sdk_root=$sdk_root" -silent $True)
|
||||
if (!$sdkmanager_prog) {
|
||||
throw "Install cmdlinetools version: $sdkmanager_ver fail"
|
||||
}
|
||||
|
@ -567,12 +604,9 @@ function setup_android_sdk() {
|
|||
return $sdk_root, $ndk_root
|
||||
}
|
||||
|
||||
function setup_clang(){
|
||||
function setup_clang() {
|
||||
$clang_prog, $clang_ver = find_prog -name 'clang'
|
||||
if ($clang_prog) {
|
||||
b1k_print "Using installed clang: $clang_prog, version: $clang_ver"
|
||||
}
|
||||
else {
|
||||
if (!$clang_prog) {
|
||||
throw 'required clang $clang_ver not installed, please install it from: https://github.com/llvm/llvm-project/releases'
|
||||
}
|
||||
}
|
||||
|
@ -764,6 +798,8 @@ validHostAndToolchain
|
|||
|
||||
########## setup build tools if not installed #######
|
||||
|
||||
$null = setup_glslcc
|
||||
|
||||
$cmake_prog = setup_cmake
|
||||
|
||||
if ($BUILD_TARGET -eq 'win32') {
|
||||
|
@ -787,86 +823,93 @@ elseif ($BUILD_TARGET -eq 'android') {
|
|||
}
|
||||
}
|
||||
|
||||
# enter building steps
|
||||
b1k_print "Building target $BUILD_TARGET on $HOST_OS_NAME with toolchain $TOOLCHAIN ..."
|
||||
if (!$options.setupOnly) {
|
||||
$stored_cwd = $(Get-Location).Path
|
||||
if ($options.d) {
|
||||
Set-Location $options.d
|
||||
}
|
||||
|
||||
# step1. preprocess cross make options
|
||||
$CONFIG_ALL_OPTIONS = [array]$(& $proprocessTable[$BUILD_TARGET] -inputOptions $CONFIG_DEFAULT_OPTIONS)
|
||||
# enter building steps
|
||||
b1k_print "Building target $BUILD_TARGET on $HOST_OS_NAME with toolchain $TOOLCHAIN ..."
|
||||
|
||||
if (!$CONFIG_ALL_OPTIONS) {
|
||||
$CONFIG_ALL_OPTIONS = @()
|
||||
}
|
||||
# step1. preprocess cross make options
|
||||
$CONFIG_ALL_OPTIONS = [array]$(& $proprocessTable[$BUILD_TARGET] -inputOptions $CONFIG_DEFAULT_OPTIONS)
|
||||
|
||||
# step2. apply additional cross make options
|
||||
$xopts = [array]$options.xc
|
||||
if ($xopts.Count -gt 0) {
|
||||
b1k_print ("Apply additional cross make options: $($xopts), Count={0}" -f $xopts.Count)
|
||||
$CONFIG_ALL_OPTIONS += $xopts
|
||||
}
|
||||
if ("$($xopts)".IndexOf('-B') -eq -1) {
|
||||
$BUILD_DIR = "build_$($options.a)"
|
||||
}
|
||||
else {
|
||||
foreach ($opt in $xopts) {
|
||||
if ($opt.StartsWith('-B')) {
|
||||
$BUILD_DIR = $opt.Substring(2).Trim()
|
||||
if (!$CONFIG_ALL_OPTIONS) {
|
||||
$CONFIG_ALL_OPTIONS = @()
|
||||
}
|
||||
|
||||
# step2. apply additional cross make options
|
||||
$xopts = [array]$options.xc
|
||||
if ($xopts.Count -gt 0) {
|
||||
b1k_print ("Apply additional cross make options: $($xopts), Count={0}" -f $xopts.Count)
|
||||
$CONFIG_ALL_OPTIONS += $xopts
|
||||
}
|
||||
if ("$($xopts)".IndexOf('-B') -eq -1) {
|
||||
$BUILD_DIR = "build_$($options.a)"
|
||||
}
|
||||
else {
|
||||
foreach ($opt in $xopts) {
|
||||
if ($opt.StartsWith('-B')) {
|
||||
$BUILD_DIR = $opt.Substring(2).Trim()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
b1k_print ("CONFIG_ALL_OPTIONS=$CONFIG_ALL_OPTIONS, Count={0}" -f $CONFIG_ALL_OPTIONS.Count)
|
||||
|
||||
# parsing build optimize flag from build_options
|
||||
$buildOptions = [array]$options.xb
|
||||
$nopts = $buildOptions.Count
|
||||
$optimize_flag = $null
|
||||
for ($i = 0; $i -lt $nopts; ++$i) {
|
||||
$optv = $buildOptions[$i]
|
||||
if ($optv -eq '--config') {
|
||||
if ($i -lt ($nopts - 1)) {
|
||||
$optimize_flag = $buildOptions[$i + 1]
|
||||
++$i
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
b1k_print ("CONFIG_ALL_OPTIONS=$CONFIG_ALL_OPTIONS, Count={0}" -f $CONFIG_ALL_OPTIONS.Count)
|
||||
|
||||
# parsing build optimize flag from build_options
|
||||
$buildOptions = [array]$options.xb
|
||||
$nopts = $buildOptions.Count
|
||||
$optimize_flag = $null
|
||||
for ($i = 0; $i -lt $nopts; ++$i) {
|
||||
$optv = $buildOptions[$i]
|
||||
if($optv -eq '--config') {
|
||||
if ($i -lt ($nopts - 1)) {
|
||||
$optimize_flag = $buildOptions[$i + 1]
|
||||
++$i
|
||||
if (($BUILD_TARGET -eq 'android') -and ($options.xt -eq 'gradle')) {
|
||||
if ($optimize_flag -eq 'Debug') {
|
||||
./gradlew assembleDebug $CONFIG_ALL_OPTIONS | Out-Host
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (($BUILD_TARGET -eq 'android') -and ($options.xt -eq 'gradle')) {
|
||||
if ($optimize_flag -eq 'Debug') {
|
||||
./gradlew assembleDebug $CONFIG_ALL_OPTIONS | Out-Host
|
||||
}
|
||||
else {
|
||||
./gradlew assembleRelease $CONFIG_ALL_OPTIONS | Out-Host
|
||||
}
|
||||
}
|
||||
else {
|
||||
./gradlew assembleRelease $CONFIG_ALL_OPTIONS | Out-Host
|
||||
}
|
||||
}
|
||||
else {
|
||||
# step3. configure
|
||||
cmake -B $BUILD_DIR $CONFIG_ALL_OPTIONS | Out-Host
|
||||
# step3. configure
|
||||
cmake -B $BUILD_DIR $CONFIG_ALL_OPTIONS | Out-Host
|
||||
|
||||
# step4. build
|
||||
# apply additional build options
|
||||
$BUILD_ALL_OPTIONS = @()
|
||||
$BUILD_ALL_OPTIONS += $buildOptions
|
||||
if (!$optimize_flag) {
|
||||
$BUILD_ALL_OPTIONS += '--config', 'Release'
|
||||
# step4. build
|
||||
# apply additional build options
|
||||
$BUILD_ALL_OPTIONS = @()
|
||||
$BUILD_ALL_OPTIONS += $buildOptions
|
||||
if (!$optimize_flag) {
|
||||
$BUILD_ALL_OPTIONS += '--config', 'Release'
|
||||
}
|
||||
|
||||
$BUILD_ALL_OPTIONS += "--parallel"
|
||||
if ($BUILD_TARGET -eq 'linux') {
|
||||
$BUILD_ALL_OPTIONS += "$(nproc)"
|
||||
}
|
||||
if ($TOOLCHAIN_NAME -eq 'xcode') {
|
||||
$BUILD_ALL_OPTIONS += '--', '-quiet'
|
||||
}
|
||||
b1k_print ("BUILD_ALL_OPTIONS=$BUILD_ALL_OPTIONS, Count={0}" -f $BUILD_ALL_OPTIONS.Count)
|
||||
|
||||
cmake --build $BUILD_DIR $BUILD_ALL_OPTIONS | Out-Host
|
||||
}
|
||||
|
||||
$BUILD_ALL_OPTIONS += "--parallel"
|
||||
if ($BUILD_TARGET -eq 'linux') {
|
||||
$BUILD_ALL_OPTIONS += "$(nproc)"
|
||||
$env:buildResult = ConvertTo-Json @{
|
||||
buildDir = $BUILD_DIR;
|
||||
targetOS = $BUILD_TARGET;
|
||||
compilerID = $TOOLCHAIN_NAME;
|
||||
}
|
||||
if ($TOOLCHAIN_NAME -eq 'xcode') {
|
||||
$BUILD_ALL_OPTIONS += '--', '-quiet'
|
||||
}
|
||||
b1k_print ("BUILD_ALL_OPTIONS=$BUILD_ALL_OPTIONS, Count={0}" -f $BUILD_ALL_OPTIONS.Count)
|
||||
|
||||
cmake --build $BUILD_DIR $BUILD_ALL_OPTIONS | Out-Host
|
||||
}
|
||||
|
||||
Set-Location $stored_cwd
|
||||
|
||||
$env:buildResult = ConvertTo-Json @{
|
||||
buildDir = $BUILD_DIR;
|
||||
targetOS = $BUILD_TARGET;
|
||||
compilerID = $TOOLCHAIN_NAME;
|
||||
Set-Location $stored_cwd
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue