From bc5303f6f20b9d0a1440d6dc152d6aa412447d95 Mon Sep 17 00:00:00 2001 From: heliclei Date: Mon, 6 Jan 2014 20:58:00 +0800 Subject: [PATCH] build all android targets --- tools/jenkins-scripts/create-job.py | 30 +++++++++++++++++++ tools/jenkins-scripts/ghprb.py | 45 +++++++++++++++++++++-------- 2 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 tools/jenkins-scripts/create-job.py diff --git a/tools/jenkins-scripts/create-job.py b/tools/jenkins-scripts/create-job.py new file mode 100644 index 0000000000..ec161ae67b --- /dev/null +++ b/tools/jenkins-scripts/create-job.py @@ -0,0 +1,30 @@ +#create ghprb job by pr number + +import os +import sys +import json +import requests + +#get pr number from cmd +pr_num = sys.argv[1] + +#get github access token +access_token = os.environ['GITHUB_ACCESS_TOKEN'] + +#get pr data via github api + +api_get_pr = "https://api.github.com/repos/cocos2d/cocos2d-x/pulls/"+str(pr_num)+"?access_token="+access_token + +r = requests.get(api_get_pr) +pr = r.json() + +#forge a payload +payload = {"action":"open","number":"","pull_request":""} +payload['number']=pr_num +payload['pull_request']=pr + +jenkins_trigger_url="http://ci.cocos2d-x.org:8000/job/cocos-2dx-pull-request-build/buildWithParameters?token="+access_token + +#send trigger and payload +post_data = "payload:"+json.dumps(payload +requests.post(jenkins_trigger_url, data=post_data) diff --git a/tools/jenkins-scripts/ghprb.py b/tools/jenkins-scripts/ghprb.py index b0d3669997..360986f40a 100755 --- a/tools/jenkins-scripts/ghprb.py +++ b/tools/jenkins-scripts/ghprb.py @@ -9,12 +9,13 @@ import base64 import requests import sys import traceback +import platform #set Jenkins build description using submitDescription to mock browser behavior #TODO: need to set parent build description -def set_description(desc): +def set_description(desc, url): req_data = urllib.urlencode({'description': desc}) - req = urllib2.Request(os.environ['BUILD_URL'] + 'submitDescription', req_data) + req = urllib2.Request(url + 'submitDescription', req_data) #print(os.environ['BUILD_URL']) req.add_header('Content-Type', 'application/x-www-form-urlencoded') base64string = base64.encodestring(os.environ['JENKINS_ADMIN']+ ":" + os.environ['JENKINS_ADMIN_PW']).replace('\n', '') @@ -36,16 +37,15 @@ def main(): #build for pull request action 'open' and 'synchronize', skip 'close' action = payload['action'] print 'action: ' + action - if((action != 'opened') and (action != 'synchronize')): - print 'pull request #' + str(pr_num) + ' is closed, no build triggered' - exit(0) + pr = payload['pull_request'] url = pr['html_url'] print "url:" + url - pr_desc = '

pr#' + str(pr_num) + '

' - set_description(pr_desc) + pr_desc = '

pr#' + str(pr_num) + ' is '+ action +'

' + + #get statuses url statuses_url = pr['statuses_url'] @@ -55,6 +55,13 @@ def main(): #set commit status to pending target_url = os.environ['BUILD_URL'] + + set_description(pr_desc, target_url) + + if((action != 'opened') and (action != 'synchronize')): + print 'pull request #' + str(pr_num) + ' is '+action+', no build triggered' + return(0) + data = {"state":"pending", "target_url":target_url} access_token = os.environ['GITHUB_ACCESS_TOKEN'] Headers = {"Authorization":"token " + access_token} @@ -78,7 +85,18 @@ def main(): #update submodule git_update_submodule = "git submodule update --init --force" os.system(git_update_submodule) - + + #add symbol link + PROJECTS=["Cpp/HelloCpp","Cpp/TestCpp","Cpp/SimpleGame","Cpp/AssetsManagerTest", + "Javascript/TestJavascript","Javascript/CocosDragonJS","Javascript/CrystalCraze", + "Javascript/MoonWarriors","Javascript/WatermelonWithMe","Lua/HelloLua","Lua/TestLua"] + if(platform.system == 'Darwin'): + for item in PROJECTS: + os.System("ln -s "+os.environ['WORKSPACE']+"/android_build_objs " + os.environ['WORKSPACE']+"/samples/"+item+"/proj.android/obj") + elif(platform.system == 'Windows'): + for item in PROJECTS: + os.System("mklink /J "+os.environ['WORKSPACE']+os.sep+"samples"+os.sep +item+os.sep+"proj.android/obj " + os.environ['WORKSPACE']+os.sep+"android_build_objs") + #build #TODO: support android-mac build currently #TODO: add android-windows7 build @@ -87,7 +105,7 @@ def main(): #TODO: add mac build #TODO: add win32 build if(branch == 'develop'): - ret = os.system("python build/android-build.py -n -j5 testcpp") + ret = os.system("python build/android-build.py -n -j10 all") elif(branch == 'master'): ret = os.system("samples/Cpp/TestCpp/proj.android/build_native.sh") @@ -113,12 +131,15 @@ def main(): os.system("git checkout develop") os.system("git branch -D pull" + str(pr_num)) - exit(exit_code) + return(exit_code) # -------------- main -------------- if __name__ == '__main__': + sys_ret = 0 try: - main() + sys_ret = main() except: traceback.print_exc() - exit(1) + sys_ret = 1 + finally: + sys.exit(sys_ret)