SoFunction
Updated on 2025-03-11

linphone-sdk-android version number generation analysis

Preface

Haven't written it for a long timelinphone-sdk-androidRelated articles are recorded in this article.linphone-sdkThe process of version number generation.

analyze

Note: The following source code is based on linphone-sdk-android 4.5.26.

Completely modifiedlinphone-sdkThe source code of the source code is always to be compiled. After compiling, we can get a version numberaarPackage, so where does this version number come from?

Compile products

First, let's see after the compilation is completedbuildThere are two products in the cataloguegradleScript file:and,OpenThe script file, the following code is found in it:println("AAR artefact group is: " + artefactGroupId + ", SDK version 4.5.27"),in4.5.27that islinphone-sdkversion number.

According to the analysis of the previous article, the compiled products are generally automatically generated, so the author islinphone-sdkSearch in the directoryfind . -name '**'

 ./cmake/Android/gradle/
 ./build/

Sure enough, the second line is the file I just opened. I found and opened the file on line 1., compared with the file on line 2, it was found that the former is the template file of the latter,Found in the file:println("AAR artefact group is: " + artefactGroupId + ", SDK version @LINPHONESDK_VERSION@"),in@LINPHONESDK_VERSION@that islinphone-sdkThe version number is now. Because this file suffix is.cmake, then Lenovo@LINPHONESDK_VERSION@It should be a cmake parameter.

Nextlinphone-sdkSearch in the directory includesLINPHONESDK_VERSIONDocuments with words:find . -type f | xargs grep 'LINPHONESDK_VERSION', There are many results for this search, so I won't post it. After the author's comparison and analysis, the last line of results was locked:./:bc_compute_full_version(LINPHONESDK_VERSION)

CMake

Open./, you can find the following code in the first few lines:

 include(bctoolbox/cmake/)
 bc_compute_full_version(LINPHONESDK_VERSION)

Line 2 of the codebc_compute_full_versionJust calculatelinphone-sdkThe version number function, defined in line 1 codeIn, openFile and findbc_compute_full_versionfunction:

 function(bc_compute_full_version OUTPUT_VERSION)
     # Find Git Programs     find_program(GIT_EXECUTABLE git NAMES Git CMAKE_FIND_ROOT_PATH_BOTH)
     # If the Git program is found     if(GIT_EXECUTABLE)
         # Execute the git describe command         execute_process(
             COMMAND "${GIT_EXECUTABLE}" "describe"
             OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
             OUTPUT_STRIP_TRAILING_WHITESPACE
             ERROR_QUIET
             WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
         )
         # parse git describe version
         # Analyze the return value of git describe as the version number, and parse it through grouping matching of regular expressions: 4.5.26-alpha-9-gb342a93         # If it is not parsed, the error message is output         if (NOT (GIT_DESCRIBE_VERSION MATCHES "^([0-9]+)[.]([0-9]+)[.]([0-9]+)(-alpha|-beta)?(-[0-9]+)?(-g[0-9a-f]+)?$"))
             message(FATAL_ERROR "invalid git describe version: '${GIT_DESCRIBE_VERSION}'")
         endif()
         # Set Group 1 as the main version: ([0-9]+) -> 4         set(version_major ${CMAKE_MATCH_1})
         # Set Group 2 as a minor version: ([0-9]+) -> 5         set(version_minor ${CMAKE_MATCH_2})
         # Set Group 3 as patch version: ([0-9]+) -> 26         set(version_patch ${CMAKE_MATCH_3})
         # If parsed to group 4: (-alpha|-beta)? -> -alpha, remove the previous ‘-’, get the subsequent ‘alpha|beta’, and assign it to version_prerelease         if (CMAKE_MATCH_4)
             string(SUBSTRING "${CMAKE_MATCH_4}" 1 -1 version_prerelease)
         endif()
         # If parsed to group 5: (-[0-9]+)? -> -9, then remove the previous ‘-’ and get the following ‘9’ and assign it to version_commit         if (CMAKE_MATCH_5)
             string(SUBSTRING "${CMAKE_MATCH_5}" 1 -1 version_commit)
         endif()
         # If parsing to group 6: (-g[0-9a-f]+)? -> -gb342a93, remove the previous ‘-g’ and get the subsequent ‘b342a93’ and assign it to version_hash         if (CMAKE_MATCH_6)
             string(SUBSTRING "${CMAKE_MATCH_6}" 2 -1 version_hash)
         endif()
         # interpret untagged hotfixes as pre-releases of the next "patch" release
         # If there is no version_prerelease, but version_commit, it is considered that this patch is the pre-release version of the next patch version, and the patch version number will be +1         # and set version_prerelease to "pre"         if (NOT version_prerelease AND version_commit)
             math(EXPR version_patch "${version_patch} + 1")
             set(version_prerelease "pre")
         endif()
         # format full version
         # Splice the primary, secondary, and patch version numbers         set(full_version "${version_major}.${version_minor}.${version_patch}")
         # If there is version_prerelease         if (version_prerelease)
             # Add "-pre" to the version number             string(APPEND full_version "-${version_prerelease}")
             # If there is version_commit             if (version_commit)
                 # Append ".9+b342a93" to version number                 string(APPEND full_version ".${version_commit}+${version_hash}")
             endif()
         endif()
         # Omit other check logic         # Set the version number to CMake cache parameters, full version number: 4.5.27-pre.9+b342a93         set(${OUTPUT_VERSION} "${full_version}" CACHE STRING "" FORCE)
     endif()
 endfunction()

The following is an analysisbc_compute_full_versionFunction is here.

First look upGitProgram, if foundGitThe function will continue only if it is done, otherwise the version number cannot be calculated.

turn upGitThe program will be executed afterwardsgit describeCommand, this command will give a human-readable name based on the currently available ref.

  • If there is a TAG on the current latest commit, and the TAG must have description information or have-- tagsParameter, this command returns this TAG name: 4.5.26,
  • Otherwise, return the name of the closest TAG to the current + the number of commits after this TAG + the first 7 digits of the current commit hash value: 4.5.26-9-gb342a93, where 'g' means yesGit

For details, please viewgit-describe

Assumptionsgit describeThe command returns:4.5.26-alpha-9-gb342a93, and then parse the returned result through grouping match of the regular expression.

Regular expression:

^([0-9]+)[.]([0-9]+)[.]([0-9]+)(-alpha|-beta)?(-[0-9]+)?(-g[0-9a-f]+)?$,

It is divided into the following 6 groups:

  • ([0-9]+)For the first groupCMAKE_MATCH_1, corresponding to 4,
  • ([0-9]+)For the second groupCMAKE_MATCH_2, corresponding to 5,
  • ([0-9]+)For the third groupCMAKE_MATCH_3, corresponding to 26,
  • (-alpha|-beta)?For the fourth groupCMAKE_MATCH_4, can be empty, corresponding to -alpha,
  • (-[0-9]+)?For the fifth groupCMAKE_MATCH_5, can be empty, corresponding to -9,
  • (-g[0-9a-f]+)?For the sixth groupCMAKE_MATCH_6, can be empty, corresponding to gb342a93,

Group 1, Group 2 and Group 3 are the main version, minor version and patch version respectively: 4.5.26.

If parsed to group four:-alpha, remove the previous one-, get the followingalphaand assign a value toversion_prereleaseVariable; if parsed into group five:-9, remove the previous one-, get the following9and assign a value toversion_commitVariable; if parsed into grouping six:-gb342a93, remove the previous one-g, get the followingb342a93and assign a value toversion_hashvariable.

If notversion_prereleaseVariable, but there areversion_commitvariable, this patch is considered to be the pre-release version of the next patch version, that is, add a version of the patch version number and assign a value.version_prereleaseThe variable ispre

The main version, minor version and patch version are:4.5.27and assign a value tofull_versionvariable.

If there isversion_prereleasevariable, thenfull_versionVariable append-pre, the version number is:4.5.27-pre; If there isversion_commitVariable, then the version number is addedversion_commitandversion_hashValue of variable.9+b342a93, get the version number:4.5.27-pre.9+b342a93

Finally gotlinphone-sdkVersion number:4.5.27-pre.9+b342a93

Summarize

This article records the author's searchlinphone-sdkThe process of generating the version number is analyzed at the same time.linphone-sdkGetGitSubmit record and TAG to generate version number:

  • implementgit describeCommands to get readableGitSubmit information,
  • Obtained through grouping configuration mode analysis of regular expressionsGitSubmit information,
  • Finally, the complete version number is corrected and spliced ​​according to the grouping information.

useGitWe may be able to refer to this method of submitting information to generate version numbers when writing SDK.

The above is the detailed content of the generation and analysis of linphone-sdk-android version number. For more information about linphone sdk android version number, please follow my other related articles!