Skip to content

Commit 4ac467b

Browse files
crazyhappygameminggo
authored andcommitted
Setup android builds: cpp_test, cpp_empty, cocos_new for appveyor (cocos2d#18624)
* Simlpify appveyor script, remove unused functions * Setup android builds: cpp_test, cpp_empty, cocos_new for appveyor * Use absolute path for download-deps.py * PushAppveyorArtifacts
1 parent eebf451 commit 4ac467b

File tree

4 files changed

+217
-24
lines changed

4 files changed

+217
-24
lines changed

.appveyor.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ environment:
77
PYTHON: "C:\\Python27"
88
PYTHON_VERSION: "2.7.13"
99
PYTHON_ARCH: "32"
10+
matrix:
11+
- build_type: android_cpp_empty_test
12+
- build_type: android_cpp_tests
13+
- build_type: android_cocos_new_test
14+
# - build_type: android_gen_libs
15+
- build_type: windows32
1016

1117
platform:
1218
- x86
1319

1420
configuration:
1521
- Release
1622

17-
before_build:
23+
before_build:
1824
- ps: ./tools/appveyor-scripts/before-build.ps1
1925

2026
build_script:
@@ -27,4 +33,6 @@ branches:
2733
- v4-develop
2834
- v3-doc
2935
- v3.11_backup
30-
- v35-for-tizen
36+
- v35-for-tizen
37+
38+
clone_depth: 50

tools/appveyor-scripts/before-build.ps1

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ function Download-Deps
88

99
function Download-NDK
1010
{
11-
$url = "https://dl.google.com/android/repository/android-ndk-r16-windows-x86.zip"
11+
$url = "https://dl.google.com/android/repository/android-ndk-r16-windows-x86.zip"
1212
$output = "$env:APPVEYOR_BUILD_FOLDER/../android-ndk-r16-windows-x86.zip"
1313
Write-Host "downloading $url"
14-
Start-FileDownload $url $output
15-
Write-Host "finish downloading $url"
14+
Start-FileDownload $url $output
15+
Write-Host "finish downloading $url"
1616

17-
Write-Host "installing NDK"
17+
Write-Host "installing NDK"
1818
Push-Location $env:APPVEYOR_BUILD_FOLDER/../
19-
$zipfile = $output
19+
$zipfile = $output
2020
Invoke-Expression "7z.exe x $zipfile"
21-
Write-Host "finish installing NDK"
21+
Write-Host "finish installing NDK"
2222
Pop-Location
2323
$env:NDK_ROOT = "$env:APPVEYOR_BUILD_FOLDER/../android-ndk-r16"
2424
Write-Host "set environment NDK_ROOT to $env:NDK_ROOT"
@@ -29,29 +29,38 @@ function Generate-Binding-Codes
2929

3030
# install python module
3131
& pip install PyYAML Cheetah
32-
Write-Host "generating binding codes"
32+
Write-Host "generating binding codes"
3333

3434
$env:PYTHON_BIN = $python
35-
Write-Host "set environment viriable PYTHON_BIN to $env:PYTHON_BIN"
35+
Write-Host "set environment viriable PYTHON_BIN to $env:PYTHON_BIN"
3636

37-
Push-Location $env:APPVEYOR_BUILD_FOLDER\tools\tolua
38-
& $python $env:APPVEYOR_BUILD_FOLDER\tools\tolua\genbindings.py
39-
Pop-Location
37+
Push-Location $env:APPVEYOR_BUILD_FOLDER\tools\tolua
38+
& $python $env:APPVEYOR_BUILD_FOLDER\tools\tolua\genbindings.py
39+
Pop-Location
4040

4141
Push-Location $env:APPVEYOR_BUILD_FOLDER\tools\tojs
42-
& $python $env:APPVEYOR_BUILD_FOLDER\tools\tojs\genbindings.py
43-
Pop-Location
42+
& $python $env:APPVEYOR_BUILD_FOLDER\tools\tojs\genbindings.py
43+
Pop-Location
4444
}
4545

4646
function Update-SubModule
4747
{
48-
Push-Location $env:APPVEYOR_BUILD_FOLDER
49-
& git submodule init
50-
& git submodule update --recursive
51-
Pop-Location
48+
Push-Location $env:APPVEYOR_BUILD_FOLDER
49+
& git submodule init
50+
& git submodule update --recursive
51+
Pop-Location
5252
}
5353

5454
Update-SubModule
55-
Download-Deps
56-
Download-NDK
57-
Generate-Binding-Codes
55+
56+
$python = "C:\\Python27\\python.exe"
57+
58+
If ($env:build_type -eq "windows32") {
59+
Download-Deps
60+
Download-NDK
61+
Generate-Binding-Codes
62+
}
63+
Else {
64+
& $python -u .\tools\appveyor-scripts\setup_android.py
65+
if ($lastexitcode -ne 0) {throw}
66+
}

tools/appveyor-scripts/build.ps1

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,55 @@
1-
& msbuild $env:APPVEYOR_BUILD_FOLDER\build\cocos2d-win32.sln /t:Build /p:Platform="Win32" /p:Configuration="Release" /m
2-
if ($lastexitcode -ne 0) {throw}
1+
$python = "C:\\Python27\\python.exe"
2+
3+
Write-Host "Set environment"
4+
# gradlew
5+
$env:ANDROID_HOME=$env:APPVEYOR_BUILD_FOLDER + "\..\android-sdk"
6+
$env:ANDROID_NDK_HOME=$env:APPVEYOR_BUILD_FOLDER + "\..\android-ndk-r16b"
7+
# gen-libs
8+
$env:ANDROID_SDK_ROOT=$env:APPVEYOR_BUILD_FOLDER + "\..\android-sdk"
9+
$env:NDK_ROOT=$env:APPVEYOR_BUILD_FOLDER + "\..\android-ndk-r16b"
10+
11+
function PushAndroidArtifacts
12+
{
13+
# https://www.appveyor.com/docs/packaging-artifacts/
14+
$root = Resolve-Path app\build\outputs\apk; [IO.Directory]::GetFiles($root.Path, '*.*', 'AllDirectories') | % { Push-AppveyorArtifact $_ -FileName $_.Substring($root.Path.Length + 1) -DeploymentName to-publish }
15+
}
16+
17+
18+
If ($env:build_type -eq "android_cpp_tests") {
19+
Write-Host "Build tests\cpp-tests"
20+
Push-Location $env:APPVEYOR_BUILD_FOLDER\tests\cpp-tests\proj.android\
21+
& ./gradlew build
22+
if ($lastexitcode -ne 0) {throw}
23+
PushAndroidArtifacts
24+
Pop-Location
25+
26+
} elseif ($env:build_type -eq "android_cpp_empty_test") {
27+
Write-Host "Build tests\cpp-empty-test"
28+
Push-Location $env:APPVEYOR_BUILD_FOLDER\tests\cpp-empty-test\proj.android\
29+
& ./gradlew build
30+
if ($lastexitcode -ne 0) {throw}
31+
PushAndroidArtifacts
32+
Pop-Location
33+
34+
} elseif ($env:build_type -eq "android_cocos_new_test") {
35+
Write-Host "Create new project cocos_new_test"
36+
& $python -u tools\cocos2d-console\bin\cocos.py --agreement n new -l cpp -p my.pack.qqqq cocos_new_test
37+
if ($lastexitcode -ne 0) {throw}
38+
39+
Write-Host "Build cocos_new_test"
40+
Push-Location $env:APPVEYOR_BUILD_FOLDER\cocos_new_test\proj.android\
41+
& ./gradlew build
42+
if ($lastexitcode -ne 0) {throw}
43+
PushAndroidArtifacts
44+
Pop-Location
45+
# TODO: uncomment when fixed
46+
# } elseif ($env:build_type -eq "android_gen_libs") {
47+
# Write-Host "Build cocos gen-libs"
48+
# & $python -u tools\cocos2d-console\bin\cocos.py gen-libs -p android -m release --ap android-15 --app-abi armeabi-v7a --agreement n
49+
# if ($lastexitcode -ne 0) {throw}
50+
51+
}
52+
Else {
53+
& msbuild $env:APPVEYOR_BUILD_FOLDER\build\cocos2d-win32.sln /t:Build /p:Platform="Win32" /p:Configuration="Release" /m
54+
if ($lastexitcode -ne 0) {throw}
55+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env python
2+
'''
3+
aaa
4+
'''
5+
import os
6+
import urllib
7+
import zipfile
8+
import platform
9+
import sys
10+
import subprocess
11+
import tempfile
12+
13+
DIR_PATH = os.path.dirname(os.path.realpath(__file__))
14+
15+
COCOS2D_X = os.path.abspath(os.path.join(DIR_PATH, "../.."))
16+
# ROOT_DIR/cocos2d-x
17+
ROOT_DIR = os.path.abspath(os.path.join(COCOS2D_X, ".."))
18+
19+
ANDROID_NDK = os.path.join(ROOT_DIR, "android-ndk-r16b")
20+
ANDROID_SDK = os.path.join(ROOT_DIR, "android-sdk")
21+
SDK_MANAGER = os.path.join(ROOT_DIR, "sdk_tools/tools/bin/sdkmanager")
22+
SYSTEM = platform.system().lower()
23+
if SYSTEM == "windows":
24+
SDK_MANAGER = SDK_MANAGER + ".bat"
25+
26+
27+
def run(command):
28+
print("=" * 80)
29+
print(command)
30+
subprocess.check_call(command.split())
31+
32+
33+
def run_with_yes(command):
34+
print("=" * 80)
35+
print("yes|" + command)
36+
f = tempfile.TemporaryFile("w")
37+
repeat_yes = 50
38+
f.write("y\n" * repeat_yes)
39+
f.seek(0)
40+
subprocess.check_call(command.split(), stdin=f)
41+
42+
43+
def unzip(zip_file, directory):
44+
print("=" * 80)
45+
print("Unzip: " + zip_file + " to " + directory)
46+
if SYSTEM == "windows":
47+
zipfile.ZipFile(zip_file).extractall(directory)
48+
else:
49+
# module zipfile ignore priviliges i.e. +x
50+
cmd = "unzip -d " + directory + " " + zip_file
51+
subprocess.check_output(cmd.split())
52+
53+
54+
def download(url, zip_file):
55+
print("=" * 80)
56+
print("Download: " + url + ", file: " + zip_file)
57+
urllib.urlretrieve(url, zip_file)
58+
59+
60+
def install_android_ndk():
61+
file_name = "android-ndk-r16b-" + SYSTEM + "-x86_64.zip"
62+
url = "https://dl.google.com/android/repository/" + file_name
63+
zip_file = os.path.abspath(os.path.join(ROOT_DIR, file_name))
64+
65+
download(url, zip_file)
66+
unzip(zip_file, ROOT_DIR)
67+
68+
69+
def install_android_sdk_tools():
70+
file_name = "sdk-tools-{system}-3859397.zip".format(
71+
system=platform.system().lower())
72+
url = "https://dl.google.com/android/repository/" + file_name
73+
zip_file = os.path.abspath(os.path.join(ROOT_DIR, file_name))
74+
75+
download(url, zip_file)
76+
unzip(zip_file, os.path.join(ROOT_DIR, "sdk_tools"))
77+
78+
79+
def install_android_sdk():
80+
switches = " --verbose --sdk_root=" + ANDROID_SDK + " "
81+
cmd1 = SDK_MANAGER + switches
82+
packages = [
83+
"platforms;android-15",
84+
"build-tools;25.0.0",
85+
"platform-tools",
86+
"tools"
87+
]
88+
89+
cmd = cmd1 + " ".join(packages)
90+
run_with_yes(cmd)
91+
92+
93+
def export_environment():
94+
# gradle
95+
# os.environ["ANDROID_HOME"] = ANDROID_SDK
96+
# os.environ["ANDROID_NDK_HOME"] = ANDROID_NDK
97+
# # cocos gen-libs
98+
# os.environ["ANDROID_SDK_ROOT"] = ANDROID_SDK
99+
# os.environ["NDK_ROOT"] = ANDROID_NDK
100+
101+
with open(os.path.join(ROOT_DIR, "environment.sh"), "a") as myfile:
102+
myfile.write("export ANDROID_HOME=" + ANDROID_SDK + "\n")
103+
myfile.write("export ANDROID_NDK_HOME=" + ANDROID_NDK + "\n")
104+
myfile.write("export ANDROID_SDK_ROOT=" + ANDROID_SDK + "\n")
105+
myfile.write("export NDK_ROOT=" + ANDROID_NDK + "\n")
106+
107+
with open(os.path.join(ROOT_DIR, "environment.ps1"), "a") as myfile:
108+
myfile.write("$env:ANDROID_HOME=\"" + ANDROID_SDK + "\"\n")
109+
myfile.write("$env:ANDROID_NDK_HOME=\"" + ANDROID_NDK + "\"\n")
110+
myfile.write("$env:ANDROID_SDK_ROOT=\"" + ANDROID_SDK + "\"\n")
111+
myfile.write("$env:NDK_ROOT=\"" + ANDROID_NDK + "\"\n")
112+
113+
114+
def main():
115+
run(sys.executable + " " + os.path.join(COCOS2D_X, "download-deps.py") + " --remove-download=False")
116+
install_android_ndk()
117+
install_android_sdk_tools()
118+
install_android_sdk()
119+
export_environment()
120+
121+
122+
if __name__ == '__main__':
123+
main()

0 commit comments

Comments
 (0)