Skip to content

Commit

Permalink
feat(build_tools): add build version print in shared lib
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai committed Mar 20, 2020
1 parent 9d71f4c commit d14e394
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
7 changes: 4 additions & 3 deletions build_tools/build_iOS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function create_cmake_config(){
}
#build to ffmpeg
function build_shared_framework(){
if [ -z "${LIB_NAME}" ];then
if [[ -z "${LIB_NAME}" ]];then
export LIB_NAME=ffmpeg
fi
SRC_LIBRARIES="$(cd ./install/ffmpeg/iOS/fat/lib; ls)"
Expand All @@ -84,7 +84,7 @@ function build_shared_framework(){
fi
done

if [ -d "${DAV1D_EXTERNAL_DIR}/iOS/fat" ];then
if [[ -d "${DAV1D_EXTERNAL_DIR}/iOS/fat" ]];then
SRC_LIBRARIES_DIR="$SRC_LIBRARIES_DIR ${DAV1D_EXTERNAL_DIR}/iOS/fat/lib"
SRC_LIBRARIES="$SRC_LIBRARIES dav1d"
fi
Expand All @@ -98,7 +98,8 @@ function build_shared_framework(){

create_cmake_config

touch dummy.c
cp ${BUILD_TOOLS_DIR}/src/build_version.cpp ./
sh ${BUILD_TOOLS_DIR}/gen_build_version.sh > version.h
rm -rf Xcode/
mkdir -p Xcode/OS
cd Xcode/OS
Expand Down
3 changes: 2 additions & 1 deletion build_tools/build_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ function build_shared_framework(){

create_cmake_config

touch dummy.c
cp ${BUILD_TOOLS_DIR}/src/build_version.cpp ./
sh ${BUILD_TOOLS_DIR}/gen_build_version.sh > version.h
rm -rf Xcode/
mkdir -p Xcode
cd Xcode
Expand Down
8 changes: 7 additions & 1 deletion build_tools/common_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,14 @@ function link_shared_lib_Android(){
ldflags="$ldflags -lx264 -L${X264_INSTALL_DIR}/lib/"
fi

${CROSS_COMPILE}-gcc -lm -lz -shared --sysroot=${SYSTEM_ROOT} -Wl,--no-undefined -Wl,-z,noexecstack ${CPU_LD_FLAGS} -landroid -llog -Wl,-soname,lib${LIB_NAME}.so \
cp ${BUILD_TOOLS_DIR}/src/build_version.cpp ./
sh ${BUILD_TOOLS_DIR}/gen_build_version.sh > version.h

${CROSS_COMPILE}-gcc build_version.cpp -lm -lz -shared --sysroot=${SYSTEM_ROOT} \
-Wl,--no-undefined -Wl,-z,noexecstack ${CPU_LD_FLAGS} -landroid -llog -Wl,-soname,lib${LIB_NAME}.so \
${objs} \
-o ${install_dir}/lib${LIB_NAME}.so \
-Wl,--whole-archive ${ldflags} -Wl,--no-whole-archive

rm build_version.cpp version.h
}
6 changes: 6 additions & 0 deletions build_tools/gen_build_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
git_v=$(git describe --always)
time_v=$(date "+%Y%m%d_%H:%M:%S")

out="#define build_version \"${time_v}_${git_v}\""
echo "$out"
2 changes: 1 addition & 1 deletion build_tools/iOS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(LIBRARYS ${SRC_LIBRARIES})

link_directories(${SRC_LIBRARIES_DIR})
add_library(${LIB_NAME} SHARED
dummy.c
build_version.cpp
)
if (IOS)
set_target_properties(${LIB_NAME} PROPERTIES
Expand Down
23 changes: 23 additions & 0 deletions build_tools/src/build_version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Created by moqi on 2020/3/20.
//
#include <stdio.h>
#include "version.h"
#ifdef __ANDROID__
#include <android/log.h>
#endif

static const char *get_external_build_version();

static const char *v = get_external_build_version();

static const char *get_external_build_version()
{
#ifdef __ANDROID__
__android_log_print(ANDROID_LOG_VERBOSE, "version", "external version is %s\n", build_version);
#else
printf("external version is %s\n", build_version);
#endif
return build_version;
}

0 comments on commit d14e394

Please sign in to comment.