vmlinux, vmlinux.bin, bzImage; cmake的find_package(Clang)新增了哪些变量( 比较两次记录的所有变量差异)

发布时间:2024年01月07日

vmlinux, vmlinux.bin, bzImage

cd  /bal/linux-stable/
file  vmlinux
#vmlinux: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, BuildID[sha1]=b99bbd9dda1ec2751da246d4a7ae4e6fcf7d789b, not stripped
#文件大小 20MB, 19940148B

file arch/x86/boot/compressed/vmlinux.bin
#arch/x86/boot/compressed/vmlinux.bin: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, BuildID[sha1]=b99bbd9dda1ec2751da246d4a7ae4e6fcf7d789b, stripped
#文件大小 14MB, 13706624B

file  arch/x86/boot/vmlinux.bin
#arch/x86/boot/vmlinux.bin: data
#文件大小 6.5MB, 6752568B

file  arch/x86/boot/bzImage 
#arch/x86/boot/bzImage: Linux kernel x86 boot executable bzImage, version 4.14.332+ (z@shinelon) #1 SMP Sat Jan 6 19:26:05 CST 2024, RO-rootFS, swap_dev 0X6, Normal VGA
#文件大小 6.5MB , 6767424B

cmake 比较两次记录的所有变量差异

运行效果:

find_package(Clang REQUIRED CONFIG)一共新增了约79个cmake变量,如下:

保存cmake当前变量们并与上次变量们比较,第【64】行,退出码:【0】, 标准输出: 【比较命令:‘diff /tmp/cmake_vars_1200 /tmp/cmake_vars_1201’ , 差异行数:79 /tmp/cmake_vars_diff_1200_1201】, 错误输出:【】

在这里插入图片描述

例子 文件 CMakeLists.txt

#文件名: CMakeLists.txt
#...
save_cmake_vars__cur_diff_prev(${CMAKE_CURRENT_LIST_LINE})
find_package(Clang REQUIRED CONFIG)
save_cmake_vars__cur_diff_prev(${CMAKE_CURRENT_LIST_LINE})  #此为第64行
#...

文件名: diff2f.sh

#文件名:  diff2f.sh
#!/usr/bin/env bash

# me.sh  ${_OutFPathPrefix} ${_prevVarsFIdx} ${gVarsFIdx}
#若参数少于3个,则退出(退出码为55)
[ $# -lt 3 ] && exit 55

_OutFPathPrefix=$1
_prevVarsFIdx=$2
gVarsFIdx=$3
_prevOutFPath="${_OutFPathPrefix}${_prevVarsFIdx}"
outFPath="${_OutFPathPrefix}${gVarsFIdx}"
resultF="${_OutFPathPrefix}diff_${_prevVarsFIdx}_${gVarsFIdx}"

echo -n "比较命令:‘diff ${_prevOutFPath} ${outFPath}’ , "
echo -n "差异行数:"
diff --side-by-side --suppress-common-lines ${_prevOutFPath} ${outFPath} > $resultF ;
wc -l $resultF |  perl -pe 'chomp if eof'
#用命令 “ perl -pe 'chomp if eof'  ” 删除wc输出的换行符号

文件名: save_vars__cur_diff_prev.cmake

#文件名: save_vars__cur_diff_prev.cmake
set(_Text_gVarsFIdxDesc "变量描述: 'cmake CACHE (INTERNAL)' 即 cmake全局(同级)变量")
set(_OutFPathPrefix "/tmp/cmake_vars_")

#如果从没有定义过全局变量gVarsFIdx 则定义该全局变量
if(NOT DEFINED gVarsFIdx)
    set(gVarsFIdx 0 CACHE INTERNAL  ${_Text_gVarsFIdxDesc})
    # 'CACHE INTERNAL'变量gVarsFIdx 写入在文件  ./cmake-build-debug/CMakeCache.txt :
    #gVarsFIdx:INTERNAL=数值

    message(STATUS "初始化 gVarsFIdx=${gVarsFIdx}")
endif()

function(save_cmake_vars__cur_diff_prev _CMAKE_CURRENT_LIST_LINE)
#    message(STATUS "函数进入 gVarsFIdx=${gVarsFIdx}")
    MATH(EXPR _prevVarsFIdx "${gVarsFIdx} - 1")
#    set(_prevOutFPath "${_OutFPathPrefix}${_prevVarsFIdx}")

    set(_curVarsFIdx "${gVarsFIdx}")

    # 获取 cmake变量们
    get_cmake_property(_varNames VARIABLES)

    # cmake变量们写入文件
    set(_curOutFPath "${_OutFPathPrefix}${gVarsFIdx}")
    file(WRITE ${_curOutFPath} "")
    foreach(_varName ${_varNames})
        if (_varName MATCHES "^_"  #忽略_开头的变量名
                OR _varName STREQUAL "gVarsFIdx") #忽略此脚本用到的变量名gVarsFIdx
#            message(STATUS "忽略变量名【${_varName}】")
            continue()
        endif()

        #向文件中写入一行
        file(APPEND ${_curOutFPath} "${_varName}=${${_varName}}\n")
    endforeach()

    #文件名下标 自增1
    MATH(EXPR _nextVarsFIdx "${gVarsFIdx} + 1")
    set(gVarsFIdx ${_nextVarsFIdx} CACHE INTERNAL  ${_Text_gVarsFIdxDesc})
#####
# 执行 diff 命令
execute_process(
#        COMMAND   bash -x  ...
        COMMAND   bash  /bal/clang-add-funcIdAsm/cmake_script/save_vars__cur_diff_prev/diff2f.sh ${_OutFPathPrefix} ${_prevVarsFIdx} ${_curVarsFIdx}
        RESULT_VARIABLE shExitCode
        OUTPUT_VARIABLE shStdOut
        ERROR_VARIABLE shStdErr
)

message(STATUS "保存cmake当前变量们并与上次变量们比较,第【${_CMAKE_CURRENT_LIST_LINE}】行,退出码:【${shExitCode}】, 标准输出: 【${shStdOut}】, 错误输出:【${shStdErr}】")
#message(STATUS "函数出来 gVarsFIdx=${gVarsFIdx}")

endfunction()

# 调用函数保存所有变量
#save_cmake_vars__cur_diff_prev()
文章来源:https://blog.csdn.net/hfcaoguilin/article/details/135431185
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。