Tidy ci scripts

This commit is contained in:
halx99 2021-12-30 20:15:42 +08:00
parent afe3865921
commit f9d2c3cb7d
6 changed files with 188 additions and 3 deletions

View File

@ -33,4 +33,4 @@ jobs:
arch: ${{ env.BUILD_ARCH }}
- name: Build
run: tools\windows-ci\genbindings.ps1
run: tools\win-ci\genbindings.ps1

View File

@ -29,7 +29,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
- name: Build
run: tools\windows-ci\build.ps1 $env:BUILD_ARCH
run: tools\win-ci\build.ps1 $env:BUILD_ARCH
build-linux:
name: build-linux

View File

@ -44,4 +44,4 @@ jobs:
arch: ${{ env.BUILD_ARCH }}
- name: Build
run: tools\windows-ci\build.ps1 $env:BUILD_ARCH
run: tools\win-ci\build.ps1 $env:BUILD_ARCH

View File

@ -0,0 +1,148 @@
#!/usr/bin/env python
'''
aaa
'''
import os
import urllib
import zipfile
import platform
import sys
import subprocess
import tempfile
import argparse
import ssl
try:
ssl._create_default_https_context = ssl._create_unverified_context
print("==> setup_android.py set ssl context ok")
except Exception:
pass
from retry import retry
if(sys.version_info.major >= 3):
import urllib.request
DIR_PATH = os.path.dirname(os.path.realpath(__file__))
COCOS2D_X = os.path.abspath(os.path.join(DIR_PATH, "../.."))
# ROOT_DIR/cocos2d-x
ROOT_DIR = os.path.abspath(os.path.join(COCOS2D_X, ".."))
NDK_VER = "19.2.5345600" # "r19c"
# ANDROID_NDK = os.path.join(ROOT_DIR, "android-ndk-" + NDK_VER)
ANDROID_SDK = os.path.join(ROOT_DIR, "android-sdk")
ANDROID_NDK = os.path.join(ANDROID_SDK, "ndk/" + NDK_VER)
SDK_MANAGER = os.path.join(ROOT_DIR, "cmdline-tools/bin/sdkmanager")
SYSTEM = platform.system().lower()
if SYSTEM == "windows":
SDK_MANAGER = SDK_MANAGER + ".bat"
def run(command):
print("=" * 80)
print(command)
subprocess.check_call(command.split())
def run_with_yes(command):
print("=" * 80)
print("yes|" + command)
f = tempfile.TemporaryFile("w")
repeat_yes = 50
f.write("y\n" * repeat_yes)
f.seek(0)
subprocess.check_call(command.split(), stdin=f)
def unzip(zip_file, directory):
print("=" * 80)
print("Unzip: " + zip_file + " to " + directory)
if SYSTEM == "windows":
zipfile.ZipFile(zip_file).extractall(directory)
else:
# module zipfile ignore priviliges i.e. +x
cmd = "unzip -d " + directory + " " + zip_file
subprocess.check_output(cmd.split())
def download(url, zip_file):
print("=" * 80)
print("Download: " + url + ", file: " + zip_file)
try:
os.remove(zip_file)
except OSError:
pass
if(sys.version_info.major >= 3):
urllib.request.urlretrieve(url, zip_file)
else:
urllib.urlretrieve(url, zip_file)
@retry(Exception, tries=5, delay=1, backoff=1)
def install_android_ndk():
file_name = "android-ndk-" + NDK_VER + "-" + SYSTEM + "-x86_64.zip"
url = "https://dl.google.com/android/repository/" + file_name
zip_file = os.path.abspath(os.path.join(ROOT_DIR, file_name))
download(url, zip_file)
unzip(zip_file, ROOT_DIR)
@retry(Exception, tries=5, delay=1, backoff=1)
def install_android_cmdline_tools():
file_plat = platform.system().lower()
if file_plat == "darwin":
file_plat = "mac"
file_name = "commandlinetools-{system}-7302050_latest.zip".format(system=file_plat)
url = "https://dl.google.com/android/repository/" + file_name
zip_file = os.path.abspath(os.path.join(ROOT_DIR, file_name)) # folder is cmdline-tools
download(url, zip_file)
unzip(zip_file, os.path.join(ROOT_DIR, ""))
@retry(Exception, tries=5, delay=1, backoff=1)
def install_android_sdk():
# list packages
# run_with_yes(SDK_MANAGER + " --list --sdk_root=" + ANDROID_SDK)
switches = " --verbose --sdk_root=" + ANDROID_SDK + " "
cmd_base = SDK_MANAGER + switches
packages = [
'platform-tools',
'cmdline-tools;latest',
'platforms;android-28',
'build-tools;29.0.2',
'ndk;' + NDK_VER
]
run_with_yes(cmd_base + " ".join(packages))
# run_with_yes(cmd_base + " --install ndk;" + NDK_VER)
def export_environment(ndk_only):
with open(os.path.join(ROOT_DIR, "environment.sh"), "a") as myfile:
if not ndk_only:
myfile.write("export ANDROID_HOME=" + ANDROID_SDK + "\n")
myfile.write("export ANDROID_SDK_ROOT=" + ANDROID_SDK + "\n")
myfile.write("export ANDROID_NDK_HOME=" + ANDROID_NDK + "\n")
myfile.write("export ANDROID_NDK=" + ANDROID_NDK + "\n")
with open(os.path.join(ROOT_DIR, "environment.ps1"), "a") as myfile:
if not ndk_only:
myfile.write("$env:ANDROID_HOME=\"" + ANDROID_SDK + "\"\n")
myfile.write("$env:ANDROID_SDK_ROOT=\"" + ANDROID_SDK + "\"\n")
myfile.write("$env:ANDROID_NDK_HOME=\"" + ANDROID_NDK + "\"\n")
myfile.write("$env:ANDROID_NDK=\"" + ANDROID_NDK + "\"\n")
def main(ndk_only):
# if not ndk_only:
install_android_cmdline_tools()
install_android_sdk()
# install_android_ndk()
export_environment(ndk_only)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Install android sdk/ndk')
parser.add_argument("--ndk_only", help="Install ndk only", action="store_true")
args = parser.parse_args()
main(args.ndk_only)

View File

@ -0,0 +1,37 @@
## Installing pyenv
mkdir $HOME/.pyenv/
mkdir pyenv
curl -L "https://github.com/pyenv-win/pyenv-win/archive/master.zip" -o "pyenv-win.zip"
Expand-Archive -Path pyenv-win.zip -DestinationPath .\
$pyenv_root="$HOME\.pyenv"
move "pyenv-win-master\pyenv-win" "$pyenv_root\"
$pyenv_bin="$pyenv_root\pyenv-win\bin"
$env:Path = "$pyenv_bin;$env:Path"
## Installing python-2.7.18-win32 and install packages
pyenv install -l
pyenv install 2.7.18-win32
$python_root="$pyenv_root\pyenv-win\versions\2.7.18-win32"
$env:Path = "$python_root\Scripts\;$python_root\;$env:Path"
(Get-Command python.exe).Path
python -V
pip install PyYAML Cheetah
## download ndk
curl -L "https://dl.google.com/android/repository/android-ndk-r19c-windows-x86_64.zip" -o "android-ndk-r19c-windows-x86_64.zip"
Expand-Archive -Path android-ndk-r19c-windows-x86_64.zip -DestinationPath .\
ls
$ndk_root=(Resolve-Path .\android-ndk-r19c).Path
$env:ANDROID_NDK=$ndk_root
## run genbindings.py
pwd
cd tools/tolua
python genbindings.py