Browse Source

shell函数一样要声明在使用前,否则无法调用; rm -rf 排除文件时 括号要多文件时才有效,单个文件时不需要括号

Jeff 3 years ago
parent
commit
45fcb93d1b

+ 61 - 27
自动编译系统脚本标准化/41A-CompileScript.sh

@@ -4,7 +4,12 @@
 #////// 其他变量定义,全大写 //////#
 # 工作空间目录;
 WORK_DIR=$(pwd)
-echo "$WORK_DIR"
+# 重定向输出日志;
+REDIRECT_LOG=true
+# 日志文件;
+LOG_FILE=${WORK_DIR}/Target/build.log
+# 日期;
+CURR_TIME=$(date +"%Y-%m-%d %T")
 # Android目录;
 ANDROID_DIR=${WORK_DIR}"/kernel/android/R"
 # 配置文件;
@@ -19,10 +24,6 @@ KEY_OPTION=${ANDROID_DIR}"/device/tv051/R3/Releasekeys"
 IC_OTA=false
 # SVN路径;
 SCBC_APPS_SVN_SRC_APK=https://odm-design-center-hz.tclking.com/svn/scbc_apps/trunk/app/apk
-# 重定向输出日志;
-REDIRECT_LOG=false
-# 日志文件;
-LOG_FILE=${WORK_DIR}/Target/build.log
 # 是否编译中间件;
 export TV_MIDWARE_MAKE=false
 # 是否安装RTK的APP,即RTK公版;
@@ -142,18 +143,17 @@ manualArgument()
 # 初始化参数;
 initArgument()
 {
-    # 删除上一次的编译文件;
-    rm -rf ${WORK_DIR}/Target
-    mkdir ${WORK_DIR}/Target
-
-    # 当REDIRECT_LOG=true时,重定向输出;
-    if [ ${REDIRECT_LOG} = true ]; then
-        if [ -f ${LOG_FILE} ]; then
-            rm -f ${LOG_FILE}
+    if [ ! -d ${WORK_DIR}/Target ];then
+        mkdir ${WORK_DIR}/Target
+    else
+        cd ${WORK_DIR}/Target
+        if [ ${REDIRECT_LOG} = true ];then
+            # Linux没有创建时间,所以无法确定文件是旧是新;所以redirectLog应该在Init之前执行;
+            rm -rf !${LOG_FILE}
+        else
+            rm -rf *
         fi
-        # 重定向Log到文件中;
-        exec 1>>${LOG_FILE}
-        exec 2>>${LOG_FILE}
+        cd ${WORK_DIR}
     fi
 
     # 用户不给版本号,设置默认值;
@@ -162,27 +162,39 @@ initArgument()
     fi
 
     # 远场语音设置:用户选择n不开启,否则不选或y都为开启;
-    if [ x$Arg_FarfieldVoice = "xn" ]; then
-        Arg_FarfieldVoice=false
-    else
+    if [ x$Arg_FarfieldVoice = "xy" ]; then
         Arg_FarfieldVoice=true
+    elif [ x$Arg_FarfieldVoice = "xn" ]; then
+        Arg_FarfieldVoice=false
+    elif [ x$Arg_FarfieldVoice = "x" ]; then
+        Arg_FarfieldVoice=false
     fi
 
     # 用户不选择OTA编译,则默认为false;
-    if [ x$Arg_BuildOTA = "x" ]; then
+    if [ x$Arg_BuildOTA = "xy" ]; then
+        Arg_BuildOTA=true
+    elif [ x$Arg_BuildOTA = "xn" ]; then
+        Arg_BuildOTA=false
+    elif [ x$Arg_BuildOTA = "x" ]; then
         Arg_BuildOTA=false
     fi
 
     # Clean编译:用户手动选择,则true,否则不选或n都为关闭;
     if [ x$Arg_CleanBuild = "xy" ]; then
         Arg_CleanBuild=true
-    else
+    elif [ x$Arg_CleanBuild = "x" ];then
+        Arg_CleanBuild=false
+    elif [ x$Arg_CleanBuild = "xn" ];then
         Arg_CleanBuild=false
     fi
     
-    # 编译类型:用户不选择则默认user(CTS);
-    if [ x$Arg_BuildRelease = "x" ]; then
+    # 编译类型:用户不选择则默认Debug;
+    if [ x$Arg_BuildRelease = "xy" ]; then
         Arg_BuildRelease=1
+    elif [ x$Arg_BuildRelease = "xn" ]; then
+        Arg_BuildRelease=2
+    elif [ x$Arg_BuildRelease = "x" ]; then
+        Arg_BuildRelease=2
     fi
 
     # 将字串小写比较;
@@ -197,7 +209,9 @@ initArgument()
     # 编译中间件,默认false;
     if [ x$Arg_MakeTVMidware = "xy" ]; then
         Arg_MakeTVMidware=true
-    else
+    elif [ x$Arg_MakeTVMidware = "xn" ]; then
+        Arg_MakeTVMidware=false
+    elif [ x$Arg_MakeTVMidware = "x" ]; then
         Arg_MakeTVMidware=false
     fi
 
@@ -206,9 +220,9 @@ initArgument()
         Arg_InstallRTKAPK=true
         # RTK公版不能编译中间件;
         Arg_MakeTVMidware=false
-    fi
-    
-    if [ x$Arg_InstallRTKAPK = "xn" ]; then
+    elif [ x$Arg_InstallRTKAPK = "xn" ]; then
+        Arg_InstallRTKAPK=false
+    elif [ x$Arg_InstallRTKAPK = "x" ]; then
         Arg_InstallRTKAPK=false
     fi
 
@@ -539,8 +553,28 @@ compile()
     echo "$(date '+%Y-%m-%d %H:%S') compile finished"
 }
 
+redirectLog()
+{
+    if [ ${REDIRECT_LOG} = false ];then
+        echo -e "\n未开启日志重定向功能,无build.log生成!\n"
+    else
+        if [ ! -d ${WORK_DIR}/Target ];then
+            mkdir ${WORK_DIR}/Target
+        else
+            rm -f ${LOG_FILE}
+        fi
+
+        # 重定向Log到文件中;
+        exec 1>>${LOG_FILE}
+        exec 2>>${LOG_FILE}
+    fi
+}
+
 main()
 {
+    # 重定向日志;
+    redirectLog
+    echo "Start main:${CURR_TIME}"
     # 如果外部参数>0,解析参数;
     if [ $# -gt 0 ]; then
         parseArgument $@

+ 59 - 27
自动编译系统脚本标准化/51M-CompileScript.sh

@@ -2,10 +2,14 @@
 
 #/////////////////////////////////////////////////////////////////#
 #////// 其他变量定义,全大写 //////#
-CURR_TIME=$(date +"%Y-%m-%d %T")
 # 工作空间目录;
 WORK_DIR=$(pwd)
-echo "$WORK_DIR"
+# 重定向输出日志;
+REDIRECT_LOG=true
+# 日志文件;
+LOG_FILE=${WORK_DIR}/Target/build.log
+# 日期;
+CURR_TIME=$(date +"%Y-%m-%d %T")
 # Android目录;
 ANDROID_DIR=${WORK_DIR}"/kernel/android/R"
 # 配置文件;
@@ -20,10 +24,6 @@ KEY_OPTION=${ANDROID_DIR}"/device/tv051/R4/Releasekeys"
 IC_OTA=false
 # SVN路径;
 SCBC_APPS_SVN_SRC_APK=https://odm-design-center-hz.tclking.com/svn/scbc_apps/trunk/app/apk
-# 重定向输出日志;
-REDIRECT_LOG=false
-# 日志文件;
-LOG_FILE=${WORK_DIR}/Target/build.log
 # 是否编译中间件;
 export TV_MIDWARE_MAKE=false
 # 是否安装RTK的APP,即RTK公版;
@@ -137,18 +137,17 @@ manualArgument()
 # 初始化参数;
 initArgument()
 {
-    # 删除上一次的编译文件;
-    rm -rf ${WORK_DIR}/Target
-    mkdir ${WORK_DIR}/Target
-
-    # 当REDIRECT_LOG=true时,重定向输出;
-    if [ ${REDIRECT_LOG} = true ]; then
-        if [ -f ${LOG_FILE} ]; then
-            rm -f ${LOG_FILE}
+    if [ ! -d ${WORK_DIR}/Target ];then
+        mkdir ${WORK_DIR}/Target
+    else
+        cd ${WORK_DIR}/Target
+        if [ ${REDIRECT_LOG} = true ];then
+            # Linux没有创建时间,所以无法确定文件是旧是新;所以redirectLog应该在Init之前执行;
+            rm -rf !${LOG_FILE}
+        else
+            rm -rf *
         fi
-        # 重定向Log到文件中;
-        exec 1>>${LOG_FILE}
-        exec 2>>${LOG_FILE}
+        cd ${WORK_DIR}
     fi
 
     # 用户不给版本号,设置默认值;
@@ -157,14 +156,20 @@ initArgument()
     fi
 
     # 远场语音设置:用户选择n不开启,否则不选或y都为开启;
-    if [ x$Arg_FarfieldVoice = "xn" ]; then
-        Arg_FarfieldVoice=false
-    else
+    if [ x$Arg_FarfieldVoice = "xy" ]; then
         Arg_FarfieldVoice=true
+    elif [ x$Arg_FarfieldVoice = "xn" ]; then
+        Arg_FarfieldVoice=false
+    elif [ x$Arg_FarfieldVoice = "x" ]; then
+        Arg_FarfieldVoice=false
     fi
 
     # 用户不选择OTA编译,则默认为false;
-    if [ x$Arg_BuildOTA = "x" ]; then
+    if [ x$Arg_BuildOTA = "xy" ]; then
+        Arg_BuildOTA=true
+    elif [ x$Arg_BuildOTA = "xn" ]; then
+        Arg_BuildOTA=false
+    elif [ x$Arg_BuildOTA = "x" ]; then
         Arg_BuildOTA=false
     fi
 
@@ -177,9 +182,13 @@ initArgument()
         Arg_CleanBuild=false
     fi
     
-    # 编译类型:用户不选择则默认user(CTS);
-    if [ x$Arg_BuildRelease = "x" ]; then
+    # 编译类型:用户不选择则默认Debug;
+    if [ x$Arg_BuildRelease = "xy" ]; then
         Arg_BuildRelease=1
+    elif [ x$Arg_BuildRelease = "xn" ]; then
+        Arg_BuildRelease=2
+    elif [ x$Arg_BuildRelease = "x" ]; then
+        Arg_BuildRelease=2
     fi
 
     # 将字串小写比较;
@@ -194,7 +203,9 @@ initArgument()
     # 编译中间件,默认false;
     if [ x$Arg_MakeTVMidware = "xy" ]; then
         Arg_MakeTVMidware=true
-    else
+    elif [ x$Arg_MakeTVMidware = "xn" ]; then
+        Arg_MakeTVMidware=false
+    elif [ x$Arg_MakeTVMidware = "x" ]; then
         Arg_MakeTVMidware=false
     fi
 
@@ -203,9 +214,9 @@ initArgument()
         Arg_InstallRTKAPK=true
         # RTK公版不能编译中间件;
         Arg_MakeTVMidware=false
-    fi
-    
-    if [ x$Arg_InstallRTKAPK = "xn" ]; then
+    elif [ x$Arg_InstallRTKAPK = "xn" ]; then
+        Arg_InstallRTKAPK=false
+    elif [ x$Arg_InstallRTKAPK = "x" ]; then
         Arg_InstallRTKAPK=false
     fi
 
@@ -585,8 +596,28 @@ compile()
     echo "$(date '+%Y-%m-%d %H:%S') compile finished"
 }
 
+redirectLog()
+{
+    if [ ${REDIRECT_LOG} = false ];then
+        echo -e "\n未开启日志重定向功能,无build.log生成!\n"
+    else
+        if [ ! -d ${WORK_DIR}/Target ];then
+            mkdir ${WORK_DIR}/Target
+        else
+            rm -f ${LOG_FILE}
+        fi
+
+        # 重定向Log到文件中;
+        exec 1>>${LOG_FILE}
+        exec 2>>${LOG_FILE}
+    fi
+}
+
 main()
 {
+    # 重定向日志;
+    redirectLog
+    echo "Start main:${CURR_TIME}"
     # 如果外部参数>0,解析参数;
     if [ $# -gt 0 ]; then
         parseArgument $@
@@ -599,6 +630,7 @@ main()
 
     # 编译;
     compile
+    echo "$(date '+%Y-%m-%d %H:%S') compile finished"
 }
 
 main $@

+ 0 - 2
自动编译系统脚本标准化/builder.py

@@ -76,8 +76,6 @@ def loadJson():
 def cmdExecute2(cmd, dir=None):
     print(str.format("cmd start:%s, %s") % (cmd, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
     proc = subprocess.Popen(cmd, shell=True, cwd=dir)
-    # 等待完成;
-    proc.wait()
     print(str.format("cmd end:%s, %s") % (cmd, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))