Make a AutoBuild System with Git Server 转载

本文详细阐述了如何构建一个自动化构建与测试系统,包括设置Git服务器、编写post-receive钩子脚本,实现自动拉取最新提交、构建、运行单元测试,并通过邮件通知结果。此外,介绍了如何在每次提交后自动清理旧的构建环境,确保系统高效稳定运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


转载:

  一个autobuild系统, 如果您和我有同样的需求, 不妨跟随我一起搭建一个这样的系统, easy and simple, have fun :)

Why:

  事情是这样开始的, 我自己的项目放置在github上, 这是一个linux项目, 然而我所用来开发的机器是mac, 它不能用来编译所有的模块, 每次我都需要push提交之后, 再去server上pull下来, 然后编译看看结果, 这个过程我持续了一阵子之后再也忍受不了了, 我想要一个这样的系统:

1. 当我push提交之后, 他能实时的反馈给我编译的结果, 就像本地编译一样,

2. 运行test unit, 并将结果实时反馈给我

3. 随后发送一封邮件到我的邮箱内, 包含编译结果以及test unit运行结果

4. 而这次的提交仅仅是为了测试集成的效果, 而不影响真正的版本库主干


How:

  目的明确后, 我想到了git hook, 这里面的hook有一个可以满足我的需求-- post-receive, 这是一个server端的hook(shell脚本), 每当接收到applypatch后都会调用一次并将输出结果反馈给client, 接下来我们将开始利用这个hook搭建这套系统.

  首先我们来看一下工作流程(如下图):

  

图1 WorkFlow


  简单的描述一下这个流程, 相对还算清晰简洁, 找一台可以用作build的机器, 建立一个git bare repo 用于接受提交, a clone repo for update & build, 当你向这个repo push后, server收到commit会自动调用post-receive hook, 接下来你需要让这个hook脚本做4件事:

  1. 定位到clone repo 目录中进行pull, 更新最后一次提交

  2. 在build目录中执行make

  3. 执行TestUnit

  4. 将刚才输出的信息发送到指定邮箱


  这个脚本完成上述4个步骤, 也就完成了我们制定的目标. 现在所有重点都在这个hook脚本内, 不过你是否有一个疑惑, 这些执行中的信息如何才能反馈给提交的client? 这个也是我最先想问的, 查了git hook的资料后, 发现post-receive执行时, 标准输出(stdout)和标准错误输出(stderr)都会被git-send-back给当前client, 所以这个传输问题我们可以不用担心,  我们只需要关心哪些信息我们需要收集, 哪些需要丢弃即可.


ToDo:

  目标清楚了, 原理也清楚了, 接下来我会展示如何搭建一个git server ,以及如何编写这个git hook(post-receive),  到最后测试结果演示.

  1. Git server:

    搭建server很多文章中都有描述, 我稍微提炼一下, 做一个最精简的. 首先我们找一台机器(要有root or sudo权限)

   1). mkdir -p git_repo/autobuild   ( git_repo为git server的根目录, autobuild为旗下的其中一个repo )

   2). cd git_repo && git --bare init

   3). sudo git daemon --verbose --export-all --base-path=gir_repo --enable=upload-pack --enable=upload-archive --enable=receive-pack    (这个可以做成一个shell 也可以把git daemon注册成service, 这个就不再这里过多讨论了 各有喜好)

   完成上述3步后, 一个简单的git server就搭好了, 现在我们需要将其clone出来到一个目录中用于接下来做autobuild环境. (今后每次receive commit后我们都会到这个目录做一次git pull更新最后一次提交, 并进行后续操作)

  比如 我们将其clone到一个名为"/test_env"的目录下: 

  git clone git://127.0.0.1/autobuild test_env


  好了到此, 搭建git server并准备autobuild环境目录已经完成, 接下来我们开始编写post-receive hook了.

  2. Post-receive Hook:

    刚刚也提到了, 这个脚本就是我们今天的主角, 那么我们先回到git_repo/autobuild目录来, 在这里面, 我们可以看到hooks目录, 进去之后我们可以找到post-receive.sample 这个模板, 将其rename为post-receive, 并添加我们需要的工作流程:

    一个简洁的例子, 内容如下:

  1. mailfile='autobuild.txt'  
  2. email='xxx@xx.com'  
  3.   
  4. unset GIT_DIR   
  5.   
  6. # 1. git pull  
  7. cd /git_repo/autobuild  
  8. git pull > $mailfile  
  9.   
  10. # 2. build  
  11. make clean  
  12. make --no-print-directory 2>> $mailfile  
  13.   
  14. # 3. run test unit  
  15. make run_test --no-print-directory >> $mailfile  
  16.   
  17. # 4. output to stdout for echo back  
  18. cat $mailfile  
  19.   
  20. # 5. send a email to yourself  
  21. mail -s "Autobuild `date`" $email < $mailfile  
mailfile='autobuild.txt'
email='xxx@xx.com'

unset GIT_DIR 

# 1. git pull
cd /git_repo/autobuild
git pull > $mailfile

# 2. build
make clean
make --no-print-directory 2>> $mailfile

# 3. run test unit
make run_test --no-print-directory >> $mailfile

# 4. output to stdout for echo back
cat $mailfile

# 5. send a email to yourself
mail -s "Autobuild `date`" $email < $mailfile

  上面的例子仅仅完成了我们工作流程中的目标, 并没有进行任何排版工作, 为了使邮件的格式更加清晰, 你可以在其中放置更多的echo, 比如打上一些横线作为分割, 写上一些提示语句, 这个就看大家自己的喜好了, 我就不在这里赘赘的描述了 :), 接下来, 你需要将这个repo加入到你本地的git remote列表中(使用remote add命令添加), 每当你想要autobuild的时候, 就将当前branch push到这个remote repo中, 你会在push执行时得到上述我们提到的所有反馈(build info, run test unit, receive a email for backup). That's All.

   最后, 附上一个我的邮件信息格式, 以供参考:

  1. 2011年 11月 27日 星期日 23:04:46 EST  
  2. hi, This is a Autobuild message, please don't reply!  
  3. ------------------------Update Info-------------------------------  
  4. Merge made by recursive.  
  5.  ftu/Makefile |    2 +-  
  6.  1 files changed, 1 insertions(+), 1 deletions(-)  
  7.   
  8. ------------------------Build Result------------------------------  
  9. No errors  
  10.   
  11. ------------------------Test Result-----------------------------------  
  12. ( test -d test && cd test && make run_test )  
  13. (cd ../final_libraries/bin && ./test )  
  14. FINAL TEST UNIT START...  
  15.   
  16.  <<<<<<< CASE NAME:test_list DESCRIBE:for test flist >>>>>>>  
  17. [ALL ASSERT PASSED -- 11/11]  
  18.   
  19.  <<<<<<< CASE NAME:test_hash DESCRIBE:for test fhash set and get >>>>>>>  
  20. 0--2717/2775  
  21. 1--3238/4163  
  22. 2--2769/2775  
  23. 3--3272/4163  
  24. 4--2742/2775  
  25. 5--3284/4163  
  26. 6--2751/2775  
  27. 7--3260/4163  
  28. 8--2741/2775  
  29. 9--3226/4163  
  30. total count = 30000 max_size = 34690(cost 589730 byte) use ratio=1.00 avg len=3000  
  31. hash iter totoal=30000  
  32. hashforeach totoal=30000  
  33. [ALL ASSERT PASSED -- 30003/30003]  
  34.   
  35.  <<<<<<< CASE NAME:test_hash_del DESCRIBE:for test hash_del method >>>>>>>  
  36. hash del complete  
  37. [ALL ASSERT PASSED -- 20000/20000]  
  38.   
  39.  <<<<<<< CASE NAME:test_mem DESCRIBE:for test mempool alloc and free >>>>>>>  
  40. main tid=47601252718336  
  41. tid=47601254823680  
  42. tid=47601256924928  
  43. mempool init complete tid=47601254823680  
  44. tid=47601254823680 size=4 diff_time:155540usec | 155ms  
  45. tid=47601256924928 size=4 diff_time:183863usec | 183ms  
  46. tid=47601254823680 size=12 diff_time:153841usec | 153ms  
  47. tid=47601256924928 size=12 diff_time:146459usec | 146ms  
  48. tid=47601256924928 size=20 diff_time:146551usec | 146ms  
  49. tid=47601254823680 size=20 diff_time:170322usec | 170ms  
  50. tid=47601256924928 size=30 diff_time:144495usec | 144ms  
  51. tid=47601254823680 size=30 diff_time:152498usec | 152ms  
  52. tid=47601256924928 size=36 diff_time:148525usec | 148ms  
  53. tid=47601254823680 size=36 diff_time:152242usec | 152ms  
  54. tid=47601256924928 size=60 diff_time:136363usec | 136ms  
  55. tid=47601254823680 size=60 diff_time:136486usec | 136ms  
  56. tid=47601256924928 size=100 diff_time:139143usec | 139ms  
  57. tid=47601254823680 size=100 diff_time:148458usec | 148ms  
  58. tid=47601256924928 size=180 diff_time:155570usec | 155ms  
  59. tid=47601254823680 size=180 diff_time:137590usec | 137ms  
  60. tid=47601254823680 size=300 diff_time:147943usec | 147ms  
  61. tid=47601256924928 size=300 diff_time:154894usec | 154ms  
  62. tid=47601254823680 size=600 diff_time:147344usec | 147ms  
  63. tid=47601256924928 size=600 diff_time:155993usec | 155ms  
  64. tid=47601254823680 size=1000 diff_time:149958usec | 149ms  
  65. tid=47601256924928 size=1000 diff_time:146590usec | 146ms  
  66. tid=47601254823680 size=1200 diff_time:140344usec | 140ms  
  67. tid=47601256924928 size=1200 diff_time:157028usec | 157ms  
  68. tid=47601254823680 size=3000 diff_time:154509usec | 154ms  
  69. tid=47601256924928 size=3000 diff_time:159357usec | 159ms  
  70. tid=47601254823680 size=5000 diff_time:148422usec | 148ms  
  71. tid=47601256924928 size=5000 diff_time:147129usec | 147ms  
  72. tid=47601254823680 size=8202 diff_time:151623usec | 151ms  
  73. tid=47601256924928 size=8202 diff_time:153929usec | 153ms  
  74. tid=47601254823680 size=16394 diff_time:146452usec | 146ms  
  75. tid=47601256924928 size=16394 diff_time:141301usec | 141ms  
  76. tid=47601254823680 size=51200 diff_time:257559usec | 257ms  
  77. tid=47601254823680 total diff_time:2651372usec | 2651ms avg=155ms  
  78. tid=47601256924928 size=51200 diff_time:243754usec | 243ms  
  79. tid=47601256924928 total diff_time:2661121usec | 2661ms avg=156ms  
  80. [ALL ASSERT PASSED -- 52094510/52094510]  
  81.   
  82.  <<<<<<< CASE NAME:test_realloc DESCRIBE:for test mempool realloc >>>>>>>  
  83. [ALL ASSERT PASSED -- 8/8]  
  84.   
  85.  <<<<<<< CASE NAME:test_log DESCRIBE:for test log system >>>>>>>  
  86. log work thread start  
  87. read log info:[2011-11-27 23:04:55][debug]:log test final  
  88.   
  89. find ptr=0x7fff5036ce2d  
  90. [ALL ASSERT PASSED -- 3/3]  
  91.   
  92.  <<<<<<< CASE NAME:test_mbuf DESCRIBE:for test mbuf of mbuf_seek & rewind & realloc >>>>>>>  
  93. [ALL ASSERT PASSED -- 31/31]  
  94.   
  95.  <<<<<<< CASE NAME:test_mbuf1 DESCRIBE:for test mbuf of mbuf_push & mbuf_pop >>>>>>>  
  96. [ALL ASSERT PASSED -- 90/90]  
  97.   
  98.  <<<<<<< CASE NAME:test_timer DESCRIBE:for test ftimerfd >>>>>>>  
  99. [ALL ASSERT PASSED -- 4/4]  
  100.   
  101.  <<<<<<< CASE NAME:test_fev DESCRIBE:for test fev for create register add del methods >>>>>>>  
  102. [ALL ASSERT PASSED -- 18/18]  
  103.   
  104.  <<<<<<< CASE NAME:test_fev_listener DESCRIBE:for test fev listener >>>>>>>  
  105. test listener thread startup  
  106. wait for poll  
  107. net_conn:connect sucess fd = 6  
  108. [ALL ASSERT PASSED -- 5/5]  
  109.   
  110.  <<<<<<< CASE NAME:test_fev_buff DESCRIBE:for test fev buff >>>>>>>  
  111. wait for poll  
  112. net_conn:connect sucess fd = 6  
  113. read size=12, read_str=hello final  
  114. main recv str=hi final  
  115. evbuff error  
  116. error happened haha  
  117. [ALL ASSERT PASSED -- 22/22]  
  118.   
  119.  <<<<<<< CASE NAME:test_fev_conn DESCRIBE:for test fev asynchronous connect >>>>>>>  
  120. main tid=47601252718336  
  121. wait for poll  
  122. accept sucessful  
  123. tid=47601256924928  
  124. [ALL ASSERT PASSED -- 2/2]  
  125.   
  126. --------------------------------------  
  127. TOTAL CASE 13, PASS 13, FAILED 0  
  128.   
  129. Best Regards! Final Autobuild Team  
2011年 11月 27日 星期日 23:04:46 EST
hi, This is a Autobuild message, please don't reply!
------------------------Update Info-------------------------------
Merge made by recursive.
 ftu/Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

------------------------Build Result------------------------------
No errors

------------------------Test Result-----------------------------------
( test -d test && cd test && make run_test )
(cd ../final_libraries/bin && ./test )
FINAL TEST UNIT START...

 <<<<<<< CASE NAME:test_list DESCRIBE:for test flist >>>>>>>
[ALL ASSERT PASSED -- 11/11]

 <<<<<<< CASE NAME:test_hash DESCRIBE:for test fhash set and get >>>>>>>
0--2717/2775
1--3238/4163
2--2769/2775
3--3272/4163
4--2742/2775
5--3284/4163
6--2751/2775
7--3260/4163
8--2741/2775
9--3226/4163
total count = 30000 max_size = 34690(cost 589730 byte) use ratio=1.00 avg len=3000
hash iter totoal=30000
hashforeach totoal=30000
[ALL ASSERT PASSED -- 30003/30003]

 <<<<<<< CASE NAME:test_hash_del DESCRIBE:for test hash_del method >>>>>>>
hash del complete
[ALL ASSERT PASSED -- 20000/20000]

 <<<<<<< CASE NAME:test_mem DESCRIBE:for test mempool alloc and free >>>>>>>
main tid=47601252718336
tid=47601254823680
tid=47601256924928
mempool init complete tid=47601254823680
tid=47601254823680 size=4 diff_time:155540usec | 155ms
tid=47601256924928 size=4 diff_time:183863usec | 183ms
tid=47601254823680 size=12 diff_time:153841usec | 153ms
tid=47601256924928 size=12 diff_time:146459usec | 146ms
tid=47601256924928 size=20 diff_time:146551usec | 146ms
tid=47601254823680 size=20 diff_time:170322usec | 170ms
tid=47601256924928 size=30 diff_time:144495usec | 144ms
tid=47601254823680 size=30 diff_time:152498usec | 152ms
tid=47601256924928 size=36 diff_time:148525usec | 148ms
tid=47601254823680 size=36 diff_time:152242usec | 152ms
tid=47601256924928 size=60 diff_time:136363usec | 136ms
tid=47601254823680 size=60 diff_time:136486usec | 136ms
tid=47601256924928 size=100 diff_time:139143usec | 139ms
tid=47601254823680 size=100 diff_time:148458usec | 148ms
tid=47601256924928 size=180 diff_time:155570usec | 155ms
tid=47601254823680 size=180 diff_time:137590usec | 137ms
tid=47601254823680 size=300 diff_time:147943usec | 147ms
tid=47601256924928 size=300 diff_time:154894usec | 154ms
tid=47601254823680 size=600 diff_time:147344usec | 147ms
tid=47601256924928 size=600 diff_time:155993usec | 155ms
tid=47601254823680 size=1000 diff_time:149958usec | 149ms
tid=47601256924928 size=1000 diff_time:146590usec | 146ms
tid=47601254823680 size=1200 diff_time:140344usec | 140ms
tid=47601256924928 size=1200 diff_time:157028usec | 157ms
tid=47601254823680 size=3000 diff_time:154509usec | 154ms
tid=47601256924928 size=3000 diff_time:159357usec | 159ms
tid=47601254823680 size=5000 diff_time:148422usec | 148ms
tid=47601256924928 size=5000 diff_time:147129usec | 147ms
tid=47601254823680 size=8202 diff_time:151623usec | 151ms
tid=47601256924928 size=8202 diff_time:153929usec | 153ms
tid=47601254823680 size=16394 diff_time:146452usec | 146ms
tid=47601256924928 size=16394 diff_time:141301usec | 141ms
tid=47601254823680 size=51200 diff_time:257559usec | 257ms
tid=47601254823680 total diff_time:2651372usec | 2651ms avg=155ms
tid=47601256924928 size=51200 diff_time:243754usec | 243ms
tid=47601256924928 total diff_time:2661121usec | 2661ms avg=156ms
[ALL ASSERT PASSED -- 52094510/52094510]

 <<<<<<< CASE NAME:test_realloc DESCRIBE:for test mempool realloc >>>>>>>
[ALL ASSERT PASSED -- 8/8]

 <<<<<<< CASE NAME:test_log DESCRIBE:for test log system >>>>>>>
log work thread start
read log info:[2011-11-27 23:04:55][debug]:log test final

find ptr=0x7fff5036ce2d
[ALL ASSERT PASSED -- 3/3]

 <<<<<<< CASE NAME:test_mbuf DESCRIBE:for test mbuf of mbuf_seek & rewind & realloc >>>>>>>
[ALL ASSERT PASSED -- 31/31]

 <<<<<<< CASE NAME:test_mbuf1 DESCRIBE:for test mbuf of mbuf_push & mbuf_pop >>>>>>>
[ALL ASSERT PASSED -- 90/90]

 <<<<<<< CASE NAME:test_timer DESCRIBE:for test ftimerfd >>>>>>>
[ALL ASSERT PASSED -- 4/4]

 <<<<<<< CASE NAME:test_fev DESCRIBE:for test fev for create register add del methods >>>>>>>
[ALL ASSERT PASSED -- 18/18]

 <<<<<<< CASE NAME:test_fev_listener DESCRIBE:for test fev listener >>>>>>>
test listener thread startup
wait for poll
net_conn:connect sucess fd = 6
[ALL ASSERT PASSED -- 5/5]

 <<<<<<< CASE NAME:test_fev_buff DESCRIBE:for test fev buff >>>>>>>
wait for poll
net_conn:connect sucess fd = 6
read size=12, read_str=hello final
main recv str=hi final
evbuff error
error happened haha
[ALL ASSERT PASSED -- 22/22]

 <<<<<<< CASE NAME:test_fev_conn DESCRIBE:for test fev asynchronous connect >>>>>>>
main tid=47601252718336
wait for poll
accept sucessful
tid=47601256924928
[ALL ASSERT PASSED -- 2/2]

--------------------------------------
TOTAL CASE 13, PASS 13, FAILED 0

///////
 
这套方案进行一次进化, 主要是改进了一些在提交版本时冲突的问题.

  1. 编写好code并commit到local branch
  2. push到autobuild server一个对应的branch上, server会将新code pull到指定的目录下
  3. compile & run unit test ... 
  4. 观看实时结果, 并收到一封email

  OK, 流程上很简单清晰, 但是这里有一个问题, 如果我们写好的code与server上的code已经存在了冲突, 那第二步将会失败, 导致无法继续, 作为用户, 自然不希望看到这一点, 所以我们来着手改进它.

  目的明确就好办了, 下面谈谈我是如何改进的. 首先我们需要解决一旦发生了push后新代码与当前build环境的code有冲突的情况, 我们该做些什么事情, 删除分支? 可以. 换新分支继续push, 也可以, 不过这样会导致用户体验不好. 所以可以集中精力在删除分支上. 想要做到让用户没有感觉, 那么这个过程需要放在server端处理. 简单的做法,  如果我们删除了分支, 自然build环境中的code也就没有存在的价值, 因为这和用户需要build的代码可能差异很大, 我们可以先删除整个build目录, 然后重新checkout一份新的出来. OK, 简单的列一下:

  1. user编写code并commit到local branch
  2. push到autobuild server一个branch上
  3. autobuild server删除之前的build环境, 并重新checkout一份新的仓库代码
  4. 切换到对应branch上, compile & run unit test ...
  5. autobuild server删除对应branch的index
  6. user 观查实时反馈, 并最终收到一份邮件

  这里面我需要解释一下: 

  • 第3步, 为什么是在每次接收到commit才去删除之前的build环境? -- 这主要是方便debug, 比如发现了coredump, 或者程序逻辑不正确需要上去debug, 这至少为我们留下了现场可供参考, 不至于什么都没有了.
  • 第5步, 为什么删除的index, 而不是通过一条git指令比如 git push repository :branch_name 去删除? -- 这会导致我们的post-receive脚本被重新触发并执行, 容易出现错误.
  好了, 来张图可能就更清楚了:

  接下来再来看看我们调整过后的脚本:

   

  1. <SPAN style="FONT-SIZE: 14px">  
  2. mailfile='autobuild.txt'  
  3. email='xxx@xx.com'  
  4.   
  5. unset GIT_DIR   
  6.   
  7. # 1. get branch name   
  8. while read oldrev newrev ref  
  9. do  
  10.     echo "found pushed branch name:$ref"  
  11.     echo "oldrev=$oldrev newrev=$newrev"  
  12.     old_rev=$oldrev  
  13.     new_rev=$newrev  
  14.     refs=$ref  
  15. done  
  16. branch_name=`echo $refs | awk -F "/" {'print $3'}`  
  17.   
  18. # 2. cleanup build environment   
  19. top_dir='xxx'  
  20. test_dir='xxx'   
  21. cd $top_dir  
  22. rm -rf $test_dir  
  23.   
  24. # 3. checkout repository   
  25. git clone git://127.0.0.1/your_repository   
  26.   
  27. # 4. switch to branch   
  28. git checkout -b $branch_name -t origin/$branch_name  
  29.   
  30. # 5. build   
  31. make --no-print-directory 2>> $mailfile  
  32.   
  33. # 6. run test unit   
  34. make run_test --no-print-directory >> $mailfile  
  35.   
  36. # 7. output to stdout for echo back   
  37. cat $mailfile  
  38.   
  39. # 8. remove branch head index   
  40. rm -f /gitrepo_directory/refs/heads/$branch_name  
  41.   
  42. # 9. send a email to yourself   
  43. mail -s "Autobuild `date`" $email < $mailfile</SPAN>  
#! /bin/bash function ascend_git_mm_init { echo "0:Main Branch(Default, Onetrack, br_hisi_trunk_ai)" echo "1:David Kernel Version 6.6" echo "2:David Kernel Version 5.10" echo "3:David Chip BVersion" echo "4:David Chip BVersion 510" echo "5:David Chip BVersion 600" echo "6:David Chip BVersion 610" echo "7:New Main Branch(Chip BVersion 610: br_bbit_torino_v100r001c10_protype_20240410)" echo "8:David Chip BVersion 630" echo "9:David Chip BVersion 632" echo "10:David Chip BVersion 800" #echo "default: Ascend Solution Main Branch" read -p "Please Select Branch: " br if [[ "I$br" == "I1" ]] then #echo "git mm Init David Kernel 6.6 Branch" git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_bbit_torino_v100r001c15_1982_kernel_switch -g all -p auto git mm sync open_source/libjpeg-turbo repohooks elif [[ "I$br" == "I2" ]] then #echo "git mm Init David Kernel 5.10 Branch" git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_bbit_torino_v100r001c10_1982_chip_verify -g all -p auto git mm sync open_source/libjpeg-turbo repohooks elif [[ "I$br" == "I3" ]] then #echo "git mm Init David Kernel 6.6 & UB Branch" git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_bbit_torino_v00r100c10_esl310_0515 -g all -p auto git mm sync open_source/libjpeg-turbo repohooks elif [[ "I$br" == "I4" ]] then git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_bbit_torino_v00r100c10_esl510_0510 -g all -p auto git mm sync open_source/libjpeg-turbo repohooks elif [[ "I$br" == "I5" ]] then git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_bbit_torino_v00r100c10_eslb600_0606 -g all -p auto git mm sync open_source/libjpeg-turbo repohooks elif [[ "I$br" == "I6" ]] then git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_bbit_torino_v00r100c10_eslb610_0706 -g all -p auto git mm sync open_source/libjpeg-turbo repohooks elif [[ "I$br" == "I7" ]] then git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_bbit_torino_v100r001c10_protype_20240410 -g all -p auto git mm sync open_source/libjpeg-turbo repohooks elif [[ "I$br" == "I8" ]] then git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_bbit_torino_v00r100c10_esl630_0826 -g all -p auto git mm sync open_source/libjpeg-turbo repohooks elif [[ "I$br" == "I9" ]] then git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_bbit_torino_v100r001c10_b632_20241219 -g all -p auto git mm sync open_source/libjpeg-turbo repohooks elif [[ "I$br" == "I10" ]] then git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_release_torino_v100r001c10b600_soc_abl -g all -p auto git mm sync open_source/libjpeg-turbo repohooks else #echo "git mm Init Main Branch" git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_hisi_trunk_ai -g all -p auto git mm sync open_source/libjpeg-turbo repohooks fi #git mm info -a } function ascend_pull_toolchain { #echo $ost $cpua if [[ "${ost}" == "openeuler" ]] then git mm sync \ hisi/bin/toolchain/"${cpua}"/euleros/ccec_libs_url \ hisi/bin/toolchain/"${cpua}"/euleros/hcc_libs_url \ hisi/bin/toolchain/"${cpua}"/euleros/llvm_libs_url \ -j$((`nproc` - 1)) else git mm sync \ hisi/bin/toolchain/"${cpua}"/"${osdst}"/ccec_libs_url \ hisi/bin/toolchain/"${cpua}"/"${osdst}"/hcc_libs_url \ hisi/bin/toolchain/"${cpua}"/"${osdst}"/llvm_libs_url \ -j$((`nproc` - 1)) fi if [[ "${ost}" == "ubuntu" || "${ost}" == "centos" ]] && [[ "${cpua}" == "x86" ]] then git mm sync hisi/bin/toolchain/x86/ubuntu/hcc_r52_libs_url -j$((`nproc` - 1)) fi } function ascend_pull_comsrc { if [[ -d cmake ]] then cd cmake git checkout . cd "${rootdir}" fi if [[ -d tests/kernel ]] then rm -rf tests/kernel fi #aisdk-product/driver/aisdk_bsp \ #hisi/bios \ #hisi/bootloader/xloader \ #hisi/drivers/network \ #hisi/bootloader/onchiprom_flash \ git mm sync \ hisi/cmake \ hisi/customize \ hisi/build/bin/os/aos_lite_libs_url \ OpenSourceCenter/openEuler/kernel \ hisi/tests/kernel/linux-6.6 \ open_source/kernel-6.6 \ hisi/kernel/vendor \ hisi/libc_sec \ -j$((`nproc` - 1)) } function pull_codes { read -p "Need Pull Turing Solution Codes Y/y or N/n: " rp rp=${rp^^} if [[ "I${rp}" != "IY" ]] then return fi if [[ ! -d .mm ]] then # echo git mm init "${prds}"_git_mm_init fi git mm sync open_source/libjpeg-turbo repohooks ascend_pull_toolchain if [[ ("${prds}" == "ascend" || "${prds}" == "pegasus") ]] then "${prds}"_pull_comsrc else common_pull_comsrc fi #git mm info -a } function pegasus_git_mm_init { echo "0:Main Branch(Default, Onetrack, br_hisi_trunk_ai)" echo "1:Hi1952V100 Kernel Version 5.10" #echo "default: Ascend Solution Main Branch" read -p "Please Select Branch: " br if [[ "I$br" == "I1" ]] then #git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_feature_pegasus_v200r001c10_chipout_test_1126 -g all -p auto git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_bbit_pegasus_v200r001c10_protype_20241018 -g all -p auto else #echo "git mm Init Main Branch" git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_hisi_trunk_ai -g all -p auto fi #git mm info -a } function pegasus_pull_comsrc { # peguas build need # $rootdir/build/bin/os 下AOS目录存在,AOS的压缩包解压会报错,未知原因 if [[ -d build/bin/os ]] then sudo rm -rf build/bin/os* fi git mm sync \ hisi/cmake \ hisi/customize \ hisi/build/bin/os/aos_lite_libs_url \ OpenSourceCenter/openEuler/kernel \ hisi/libc_sec \ -j$((`nproc` - 1)) #Godel_VOS/release/VOS \ #git mm info -a } function solomon_git_mm_init { echo "0:Main Branch(Default, Onetrack, Solomon Chip BVersion 500)" echo "1:Solomon Chip BVersion 500" #echo "default: Ascend Solution Main Branch" read -p "Please Select Branch: " br if [[ "I$br" == "I1" ]] then git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_bbit_torino_v100r001c10_b632_20241219 -g all -p auto git mm sync open_source/libjpeg-turbo repohooks else #echo "git mm Init Main Branch" git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_bbit_torino_v100r001c10_b632_20241219 -g all -p auto git mm sync open_source/libjpeg-turbo repohooks fi #git mm info -a } function DavidV121_git_mm_init { echo "0:Main Branch(Default, Onetrack)" echo "1:DavidV121 Chip BVersion 800" #echo "default: Ascend Solution Main Branch" read -p "Please Select Branch: " br if [[ "I$br" == "I1" ]] then git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_release_torino_v100r001c10b530 -g all -p auto git mm sync open_source/libjpeg-turbo repohooks else #echo "git mm Init Main Branch" git mm init -u ssh://git@szv-cr-y.codehub.huawei.com:2222/Turing_Solution/platform/manifest.git -b br_release_torino_v100r001c10b530 -g all -p auto git mm sync open_source/libjpeg-turbo repohooks fi #git mm info -a } function common_pull_comsrc { # peguas build need # $rootdir/build/bin/os 下AOS目录存在,AOS的压缩包解压会报错,未知原因 if [[ -d build/bin/os ]] then sudo rm -rf build/bin/os* fi git mm sync \ hisi/cmake \ hisi/customize \ hisi/build/bin/os/aos_lite_libs_url \ OpenSourceCenter/openEuler/kernel \ hisi/tests/kernel/linux-6.6 \ open_source/kernel-6.6 \ hisi/kernel/vendor \ hisi/libc_sec \ -j$((`nproc` - 1)) #Godel_VOS/release/VOS \ #git mm info -a } function pull_monalisa { cdir="${rootdir}"/tests/chipveri mdir="${cdir}"/monalisa mkdir -p tests "${cdir}" read -p "Need Pull monalisa code now, Y/y or N/n: " rp rp=${rp^^} if [[ "I${rp}" != "IY" ]] then return fi read -p "Input Checkout Branch name: " cbrm # $(()) only for digital #$(("Y${cbrm}" == "Y" ? cbrm="" : cbrm="-b ${cbrm}")) #[[ "Y${cbrm}" == "Y" ]] && gcbrm="" || gcbrm="-b ${cbrm}" if [[ -d ${mdir} ]] then cd "${mdir}" if [[ -d .git ]] then git checkout "${cbrm}" cd "${rootdir}" return fi rm -rf * .g* cd "${rootdir}" fi if [[ "Y${cbrm}" != "Y" ]] then cd "${cdir}" echo `git clone https://codehub-dg-y.huawei.com/ICT_bringup/monalisa/monalisa.git -b ${cbrm}` cd - else return fi read -p "Need Create Monalisa Branch, Y/y or N/n: " cbrm cbrm=${cbrm^^} if [[ "I${cbrm}" == "IY" ]] then cd "${mdir}" read -p "Input Branch name: " cbrm git branch ${cbrm} git checkout ${cbrm} read -p "Need Push Branch To remote now, Y/y or N/n: " pb pb="${pb^^}" if [[ "I${pb}" == "IY" ]] then git push origin "${cbrm}" fi fi cd "${rootdir}" } function code_init { sudo rm -rf a* b* c* d* C* D* H* i* M* o* p* r* tee tools v* .mm pull_monalisa pull_codes } function get_osinfo { cpua=`arch` ost=`lsb_release -a | grep "Distributor ID" | awk -F":" '{print $2}' | sed 's/^[ \t]*//g'` osdst=${ost,,} if [[ "${osdst}" != "ubuntu" ]] && [[ "${osdst}" != "centos" ]] && [[ "${osdst}" != "euleros" ]] && [[ "${osdst}" != "openeuler" ]] then echo "UnSupport OS Type!" exit 1 fi if [[ "${cpua}" == "x86_64" ]] then cpua="x86" else cpua="arm64" fi echo "OS Distr: "$osdst"CPU Arch:"$cpua } function git_install { # install git lfs curl -k https://cmc-szver-artifactory.cmc.tools.huawei.com/artifactory/cmc-software-release/CodeHub/git-lfs/release.v2/git_lfs_autoinstall.sh | sudo sh - && (git lfs uninstall; git lfs install) # 设置git默认编辑器 if [ -e "/usr/bin/vim" ]; then git config --global core.editor vim else git config --global core.editor vi fi echo "git install succ" } function dtc_build { dtcp=`which dtc` if [[ $dtcp != '' ]] then return fi git clone https://codehub-dg-y.huawei.com/ICT_bringup/tools/dtc.git cd dtc make all sudo make install cd - rm -rf dtc } function python_install { pypath=`which python3` # force python link to python3 sudo ln -sf $pypath /usr/bin/python # install pip3 for python3 pippath=`which pip3` if [[ $pippath == '' ]] then sudo apt install python3-pip fi sudo pip3 install Gitdb -i http://cmc-cd-mirror.rnd.huawei.com/pypi/simple/ --trusted-host cmc-cd-mirror.rnd.huawei.com sudo pip3 install GitPython -i http://cmc-cd-mirror.rnd.huawei.com/pypi/simple/ --trusted-host cmc-cd-mirror.rnd.huawei.com sudo pip3 install PyYAML -i http://cmc-cd-mirror.rnd.huawei.com/pypi/simple/ --trusted-host cmc-cd-mirror.rnd.huawei.com sudo pip3 install ruamel.yaml -i http://cmc-cd-mirror.rnd.huawei.com/pypi/simple/ --trusted-host cmc-cd-mirror.rnd.huawei.com sudo pip3 install ruamel.yaml.clib -i http://cmc-cd-mirror.rnd.huawei.com/pypi/simple/ --trusted-host cmc-cd-mirror.rnd.huawei.com sudo pip3 install rich -i http://cmc-cd-mirror.rnd.huawei.com/pypi/simple/ --trusted-host cmc-cd-mirror.rnd.huawei.com sudo pip3 install pytest -i http://cmc-cd-mirror.rnd.huawei.com/pypi/simple/ --trusted-host cmc-cd-mirror.rnd.huawei.com sudo pip3 install toml -i http://cmc-cd-mirror.rnd.huawei.com/pypi/simple/ --trusted-host cmc-cd-mirror.rnd.huawei.com # sudo pip3 install textual-dev -i http://cmc-cd-mirror.rnd.huawei.com/pypi/simple/ --trusted-host cmc-cd-mirror.rnd.huawei.com sudo pip3 install httpx -i http://cmc-cd-mirror.rnd.huawei.com/pypi/simple/ --trusted-host cmc-cd-mirror.rnd.huawei.com sudo pip3 install openpyxl -i http://cmc-cd-mirror.rnd.huawei.com/pypi/simple/ --trusted-host cmc-cd-mirror.rnd.huawei.com sudo chmod 755 -R /usr/local/lib/python3* sudo chmod 755 -R /usr/local/lib64/python3* echo "Python install succ" } function ascend_modsig_init { #curl -s -o `pwd`/signature-jenkins-slave-5.1.19-RELEASE.zip https://cmc-szver-artifactory.cmc.tools.huawei.com/artifactory/cmc-builtools-prod/SignatureClient/0599A7L5/toolVersion/0599AC25/20221119162112511/Software/signature-jenkins-slave-5.1.19-RELEASE.zip wget --no-check-certificate -P `pwd`/ https://cmc-szver-artifactory.cmc.tools.huawei.com/artifactory/cmc-builtools-prod/SignatureClient/0599A7L5/toolVersion/0599AC25/20221119162112511/Software/signature-jenkins-slave-5.1.19-RELEASE.zip #curl -s -o `pwd`/jre-8u392-linux-x64.tar.gz https://cmc-hgh-artifactory.cmc.tools.huawei.com/artifactory/cmc-software-release/Huawei%20JDK/Huawei%20JDK%20V100R001/Huawei%20JDK%20V100R001C00SPC390B003/jre-8u392-linux-x64.tar.gz wget --no-check-certificate -P `pwd`/ https://cmc-hgh-artifactory.cmc.tools.huawei.com/artifactory/cmc-software-release/Huawei%20JDK/Huawei%20JDK%20V100R001/Huawei%20JDK%20V100R001C00SPC390B003/jre-8u392-linux-x64.tar.gz sudo unzip signature-jenkins-slave-5.1.19-RELEASE.zip -d /usr/local/ rm -f /usr/local/signature-jenkins-slave-5.1.19-RELEASE/sslcerts/root.jks sudo rm -f /usr/local/signature-jenkins-slave-5.1.19-RELEASE/sslcerts/client.jks sudo rm -f /usr/local/signature-jenkins-slave-5.1.19-RELEASE/sslcerts/ssl.properties sudo rm -f /usr/local/signature-jenkins-slave-5.1.19-RELEASE/sslcerts/trustcerts/root.crt sudo wget -P /usr/local/signature-jenkins-slave-5.1.19-RELEASE/sslcerts/ http://nexus.turing-ci.hisilicon.com/repository/files/turing-ci/root.jks sudo wget -P /usr/local/signature-jenkins-slave-5.1.19-RELEASE/sslcerts/ http://nexus.turing-ci.hisilicon.com/repository/files/turing-ci/newcert/client.jks sudo wget -P /usr/local/signature-jenkins-slave-5.1.19-RELEASE/sslcerts/ http://nexus.turing-ci.hisilicon.com/repository/files/turing-ci/newcert/ssl.properties sudo wget -P /usr/local/signature-jenkins-slave-5.1.19-RELEASE/sslcerts/trustcerts/ http://nexus.turing-ci.hisilicon.com/repository/files/turing-ci/newcert/root.crt sudo wget -P /usr/local/signature-jenkins-slave-5.1.19-RELEASE/certs/ http://nexus.turing-ci.hisilicon.com/repository/files/turing-ci/G2RootCATest.cer sudo cp /usr/local/signature-jenkins-slave-5.1.19-RELEASE/signature.jar /usr/local/signature-jenkins-slave-5.1.19-RELEASE/lib sudo cp jre-8u392-linux-x64.tar.gz /usr/local/signature-jenkins-slave-5.1.19-RELEASE/ sudo chmod -R 755 /usr/local/signature-jenkins-slave-5.1.19-RELEASE/ #unzip signature-jenkins-slave-5.1.19-RELEASE.zip #mv jre-8u392-linux-x64.tar.gz signature-jenkins-slave-5.1.19-RELEASE/ } function ascend_env_init { # 修改PATH变量,使得~/bin里的可执行文件能被找到 if [[ `cat ~/.bashrc | grep "PATH=~/bin"` == '' ]] then echo "export PATH=~/bin:$PATH" >> ~/.bashrc fi # 临时去掉代理, 保证获取的git mm工具是正确的 if [[ `cat ~/.bashrc | grep "export no_proxy"` == '' ]] then echo "export no_proxy+=,10.141.107.107,.hisilicon.com,.huawei.com" >> ~/.bashrc fi source ~/.bashrc dtc_build #${prds}_modsig_init } function euleros_init { sudo yum install -y \ autoconf automake autogen bc bison bzip2-devel \ cmake elfutils-libelf-devel flex \ gcc gcc-c++ gettext git libffi-devel libtool make \ ncurses openssl-devel openssl pkgconfig python3 python3-devel \ readline readline-devel rpm rpm-build \ samba sqlite-devel tcl tcsh texinfo tk unzip \ xz xz-devel zip zlib-devel sudo yum update } function ubuntu_init { sudo apt update sudo apt install lcov ntp expect unzip curl ntpdate \ lrzsz autoconf libtool nfs-common default-jre \ openssl git libssl-dev bison flex bc libncurses5 \ rpm2cpio build-essential ncurses-dev \ xz-utils libelf-dev cppcheck git gcc python3.8 \ fakeroot pkg-config libglib2.0-dev dos2unix \ libyaml-dev lsb-core automake texinfo gettext unrar zip \ checkinstall libgtk-3-dev \ libexpat1-dev zlib1g-dev libcurl4-gnutls-dev \ libncurses5-dev libreadline-dev help2man \ libncurses-dev apt-file rpm cmake libbz2-dev \ uuid-dev libtinfo-dev libtinfo5 cppcheck-gui \ ubuntu-restricted-extras #sudo apt install linux-headers-5.4.0-42-generic sudo apt upgrade } function tools_init { sudo ln -sf /usr/bin/bash /usr/bin/sh get_osinfo ${osdst}_init git_install python_install ascend_env_init } #echo $# if [[ $# < 2 ]] then echo "Usage: ./monalisa_init.sh operation product" echo " eg: ./monalisa_init.sh init ascend" echo " or: ./monalisa_init.sh update ascend /data/workdir/hi1982" exit 1 fi prds=$2 user_name="" user_email="" rootdir=`pwd` cpua="" osdst="" tools_init if [[ $1 == "init" ]] then code_init if [[ ("${prds}" == "ascend" || "${prds}" == "solomon" || "${prds}" == "DavidV121") && "${osdst}" == "euleros" ]] then echo "====================install numa=======================" sudo yum install numactl-devel sudo yum install numactl-libs cp /usr/lib64/libnuma.so* \ build/bin/toolchain/arm64/euleros/hcc_libs/hcc_glibc_trusted_arm64_euleros_2_12_adk/do_arm64le_native/sysroot/usr/lib64/ cp /usr/lib64/libnl-genl-3.so.200.26.0 build/bin/toolchain/arm64/euleros/hcc_libs/hcc_glibc_trusted_arm64_euleros_2_12_adk/do_arm64le_native/sysroot/usr/lib64/ cp /usr/lib64/libnl-3.so build/bin/toolchain/arm64/euleros/hcc_libs/hcc_glibc_trusted_arm64_euleros_2_12_adk/do_arm64le_native/sysroot/usr/lib64/ cp /usr/lib64/libnl-genl-3.so build/bin/toolchain/arm64/euleros/hcc_libs/hcc_glibc_trusted_arm64_euleros_2_12_adk/do_arm64le_native/sysroot/usr/lib64/ cp /usr/lib64/libnl-genl-3.so.200 build/bin/toolchain/arm64/euleros/hcc_libs/hcc_glibc_trusted_arm64_euleros_2_12_adk/do_arm64le_native/sysroot/usr/lib64/ cp /usr/lib64/libnl-3.so.200 build/bin/toolchain/arm64/euleros/hcc_libs/hcc_glibc_trusted_arm64_euleros_2_12_adk/do_arm64le_native/sysroot/usr/lib64/ cp /usr/lib64/libnl-3.so.200.26.0 build/bin/toolchain/arm64/euleros/hcc_libs/hcc_glibc_trusted_arm64_euleros_2_12_adk/do_arm64le_native/sysroot/usr/lib64/ fi if [[ "${prds}" == "solomon" ]] && [[ "I$br" == "I1" ]] && [[ "${osdst}" == "euleros" ]] then cd $rootdir/tests/kernel/linux-6.6/ git reset --hard bbd3e15c40570df1b4a66f9ac402a07710b7c7ed elif [[ "${prds}" == "DavidV121" ]] then cd $rootdir/open_source/kernel-6.6/ git reset --hard 21636d939ed4956cec36b4eba2fb18b8ad68efab cd $rootdir/drivers/kernel/ git reset --hard 0305b56317cd785db15e2f10cced6916bdba1abc fi exit 0 else pull_codes exit 0 fi
07-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值