Skip to content

Commit

Permalink
fix(build): do not patch/rebuild tensorrt if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
fantes authored and mergify[bot] committed Jun 3, 2021
1 parent e726e94 commit bfd29ec
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,9 @@ if (USE_TENSORRT)
GIT_REPOSITORY https://github.com/NVIDIA/TensorRT.git
GIT_TAG ${TENSORRT_VERSION}
GIT_CONFIG advice.detachedHead=false
PATCH_COMMAND git reset --hard && git submodule foreach --recursive git reset --hard && git apply ${TRT_PATCHES}
BUILD_COMMAND test -f ${TENSORRT_COMPLETE} || cmake ${TRT_FLAGS}
PATCH_COMMAND sh ${CMAKE_SOURCE_DIR}/cmake/patch_external.sh TENSORRT ${CMAKE_BINARY_DIR}/tensorrt-oss/src/tensorrt-oss-stamp tensorrt-oss-download tensorrt-oss-patch ${CMAKE_BINARY_DIR}/tensorrt-oss/src/tensorrt-oss ${TRT_PATCHES}
CONFIGURE_COMMAND ""
BUILD_COMMAND sh ${CMAKE_SOURCE_DIR}/cmake/build_external.sh TENSORRT ${CMAKE_BINARY_DIR}/tensorrt-oss ${TENSORRT_COMPLETE} src/tensorrt-oss src/tensorrt-oss-build ${N} ${CMAKE_COMMAND} ${TRT_FLAGS}
INSTALL_COMMAND ""
)

Expand Down
20 changes: 20 additions & 0 deletions cmake/build_external.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
NAME=$1
PREFIX=$2
COMPLETION_STAMP=$3
SOURCE_POSTFIX=$4
BUILD_POSTFIX=$5
J=$6
CMAKE_COMMAND=$7
shift 7
ARGS=$@
[ -f "$COMPLETION_STAMP" ] && echo "$NAME" already built, not rebuilding && exit 0
echo "External build of : $NAME"
echo "with prefix : $PREFIX"
echo "completion stamp : $COMPLETION_STAMP"
echo "source postfix : $SOURCE_POSTFIX"
echo "build postfix : $BUILD_POSTFIX"
echo "-j : $J"
echo "CMAKE_COMMAND : $CMAKE_COMMAND"
echo "additional args : $ARGS"
$CMAKE_COMMAND -S $PREFIX/$SOURCE_POSTFIX -B $PREFIX/$BUILD_POSTFIX $ARGS
make -C $PREFIX/$BUILD_POSTFIX -j$J
16 changes: 16 additions & 0 deletions cmake/patch_external.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
NAME=$1
PREFIX=$2
DOWNLOAD_STAMP=$3
PATCH_STAMP=$4
SOURCE_LOCATION=$5
shift 5
PATCHES=$@
[ -f "$PREFIX/$DOWNLOAD_STAMP" ] && [ -f "$PREFIX//$PATCH_STAMP" ] && [ $(( $(stat -c %Y "$PREFIX/$PATCH_STAMP") - $(stat -c %Y "$PREFIX/$DOWNLOAD_STAMP") )) -ge 0 ] && echo "$NAME" already patched, skipping && exit 0
echo "External patch of : $NAME"
echo "with prefix : $PREFIX"
echo "download stamp : $DOWNLOAD_STAMP"
echo "patch stamp : $PATCH_STAMP"
echo "source location : $SOURCE_LOCATION"
echo "patches : $PATCHES"
cd $SOURCE_LOCATION
git apply $PATCHES

0 comments on commit bfd29ec

Please sign in to comment.