Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying all patches inside patches directory #79

Merged
merged 4 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions android.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
return()
endif(ANDROID_NDK_TOOLCHAIN_INCLUDED)
include($ENV{ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake)

# Debug and release flags.
list(REMOVE_ITEM ANDROID_COMPILER_FLAGS -g)
list(APPEND ANDROID_COMPILER_FLAGS_DEBUG -g)
list(APPEND ANDROID_COMPILER_FLAGS_RELWITHDEBINFO -g ${ANDROID_COMPILER_FLAGS_RELEASE})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not sufficient to change ANDROID_COMPILER_FLAGS_*. The values have already been copied into CMAKE_C_FLAGS_*, CMAKE_CXX_FLAGS_*,CMAKE_ASM_FLAGS_* further down in the included toolchain file and are not applied directly. So the replacements have to be applied to all of those variables:

## Build without debug symbols in Release mode and add RelWithDebInfo mode
foreach(_var ANDROID_COMPILER_FLAGS CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_ASM_FLAGS)
  string(REPLACE "-g " "" ${_var} "${${_var}}")
  set(${_var}_DEBUG "-g ${${_var}_DEBUG}")
  set(${_var}_RELWITHDEBINFO "-g ${${_var}_RELEASE}")
endforeach()
unset(_var)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the observation; I'll open a PR with the modification.


if(ANDROID_TOOLCHAIN STREQUAL clang)
list(APPEND ANDROID_COMPILER_FLAGS_RELWITHDEBINFO -fno-limit-debug-info)
endif()

# Toolchain ABI specific flags.
string(REPLACE ";" " " ANDROID_COMPILER_FLAGS_RELWITHDEBINFO "${ANDROID_COMPILER_FLAGS_RELWITHDEBINFO}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO ""
CACHE STRING "Flags used by the compiler during relwithdebinfo builds.")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO ""
CACHE STRING "Flags used by the compiler during relwithdebinfo builds.")
set(CMAKE_ASM_FLAGS_RELWITHDEBINFO ""
CACHE STRING "Flags used by the compiler during relwithdebinfo builds.")

set(CMAKE_C_FLAGS_RELWITHDEBINFO "${ANDROID_COMPILER_FLAGS_RELWITHDEBINFO} ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${ANDROID_COMPILER_FLAGS_RELWITHDEBINFO} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
set(CMAKE_ASM_FLAGS_RELWITHDEBINFO "${ANDROID_COMPILER_FLAGS_RELWITHDEBINFO} ${CMAKE_ASM_FLAGS_RELWITHDEBINFO}")
25 changes: 25 additions & 0 deletions apply_patches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Abort script on any failures
set -e

my_loc="$(cd "$(dirname $0)" && pwd)"
source $my_loc/config.sh
source $my_loc/utils.sh

if [ $# != 2 ] || [ $1 == '-h' ] || [ $1 == '--help' ]; then
echo "Usage: $0 patch_prefix output_prefix"
echo " example: $0 /home/user/ros_android/patches /home/user/my_workspace/output"
exit 1
fi

patch_prefix=$1
output_prefix=$2

echo
echo -e '\e[34mApplying patches.\e[39m'
echo

for patch_file in $patch_prefix/*.patch; do
apply_patch $patch_file -d $output_prefix
done
4 changes: 0 additions & 4 deletions config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ export ANDROID_PLATFORM=android-24
# Enable this value for debug build
#CMAKE_BUILD_TYPE=Debug
CMAKE_BUILD_TYPE=Release

# Enable this if you need to use pluginlib in Android.
# The plugins will be statically linked
use_pluginlib=1
213 changes: 21 additions & 192 deletions do_everything.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,7 @@ mkdir -p $prefix/libs
export TARGET_DIR=$prefix/target
[ -d $TARGET_DIR ] || mkdir -p $TARGET_DIR

# Get the android ndk build helper script
# If file doesn't exist, then download and patch it
#if ! [ -e $prefix/android.toolchain.cmake ]; then
# cd $prefix
# download 'https://raw.githubusercontent.com/taka-no-me/android-cmake/556cc14296c226f753a3778d99d8b60778b7df4f/android.toolchain.cmake'
# patch -p0 -N -d $prefix < $my_loc/patches/android.toolchain.cmake.patch
# cat $my_loc/files/android.toolchain.cmake.addendum >> $prefix/android.toolchain.cmake
#fi

export RBA_TOOLCHAIN=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake
apply_patch $my_loc/patches/android.toolchain.cmake.patch -d $ANDROID_NDK_HOME/build/cmake
export RBA_TOOLCHAIN=$my_loc/android.toolchain.cmake

# Get all library dependencies.
run_cmd get_system_dependencies $my_loc/system_deps.rosinstall $prefix/libs $my_loc/files
Expand All @@ -123,193 +113,32 @@ echo
if [[ $skip -ne 1 ]] ; then
run_cmd get_catkin_packages $prefix

echo
echo -e '\e[34mApplying patches.\e[39m'
echo

# patch CMakeLists.txt for lz4 library - Build as a library
apply_patch $my_loc/patches/lz4.patch

# patch rosbag_storage - Fix static linking due to missing BZIP2 dependency
apply_patch $my_loc/patches/rosbag_storage.patch

# Patch collada - Build as static lib
apply_patch $my_loc/patches/collada_dom.patch

# Patch assimp - Build as static lib
apply_patch $my_loc/patches/assimp.patch

# Patch console_bridge - Disable unit tests (unsatisfied dependencies)
apply_patch $my_loc/patches/console_bridge.patch

# Patch urdfdom - Build as static lib
apply_patch $my_loc/patches/urdfdom.patch

# Patch qhull - Don't install shared libraries
# TODO: Remove shared libraries to avoid hack in parse_libs.py
# apply_patch /opt/roscpp_android/patches/qhull.patch

# Patch bfl - Build as static lib
apply_patch $my_loc/patches/bfl.patch

# Patch orocos_kdl - Build as static lib
apply_patch $my_loc/patches/orocos_kdl.patch

# Patch PCL - Disable optionals.
apply_patch $my_loc/patches/pcl-1.8.1.patch

# Patch uuid - Avoiding stdlib.h include
apply_patch $my_loc/patches/uuid.patch

# Patch yaml - Avoid building tests
apply_patch $my_loc/patches/yaml-cpp.patch

# Patch bullet - Avoid building examples
apply_patch $my_loc/patches/bullet.patch

## ROS patches

# Patch rosconsole - Add android backend
apply_patch $my_loc/patches/rosconsole.patch

# Patch catkin - Fix transitive linking of interface libraries for static builds
apply_patch $my_loc/patches/catkin.patch

# Patch map_server - Fix find yaml
apply_patch $my_loc/patches/map_server.patch

# Patch bondcpp - Fix transitive linking problems
apply_patch $my_loc/patches/bondcpp.patch

# Patch image_publisher - Fix linking problems, transitive linking,
# and changed shared to static library building.
apply_patch $my_loc/patches/image_publisher.patch

# Patch image_rotate - Fix find opencv and transitive linking problem
apply_patch $my_loc/patches/image_rotate.patch

# Patch opencv - Fix installation path
apply_patch $my_loc/patches/opencv.patch

# Patch actionlib - problems with Boost changes.
apply_patch $my_loc/patches/actionlib.patch

# Patch rospack - problems with Boost changes
# Also emptied some unnecessary functions to avoid problems related to including Python.
apply_patch $my_loc/patches/rospack.patch

# Patch xmlrpcpp - problems with Boost changes.
apply_patch $my_loc/patches/xmlrpcpp.patch

# Patch roslib - weird issue with rospack.
# TODO: Need to look further (only on catkin_make_isolated)
# apply_patch /opt/roscpp_android/patches/roslib.patch

# Patch collada_parser - cmake detects mkstemps even though Android does not support it
# TODO: investigate how to prevent cmake to detect system mkstemps
# apply_patch $my_loc/patches/collada_parser.patch

# Patch laser_assembler - Remove testing for Android
# TODO: It seems like there may be a better way to handle the test issues
# http://stackoverflow.com/questions/22055741/googletest-for-android-ndk
# apply_patch $my_loc/patches/laser_assembler.patch

# Patch laser_filters - Remove testing for Android
# TODO: It seems like there may be a better way to handle the test issues
# http://stackoverflow.com/questions/22055741/googletest-for-android-ndk
# https://source.android.com/reference/com/android/tradefed/testtype/GTest.html
# apply_patch $my_loc/patches/laser_filters.patch

# Patch camera_info_manager - remove testing for Android
# TODO: It seems like there may be a better way to handle the test issues
# http://stackoverflow.com/questions/22055741/googletest-for-android-ndk
# https://source.android.com/reference/com/android/tradefed/testtype/GTest.html
apply_patch $my_loc/patches/camera_info_manager.patch

# Patch camera_calibration_parsers - deleted python things and solved problem finding Boost.
apply_patch $my_loc/patches/camera_calibration_parsers.patch

# Patch cv_bridge - fix transitive linking in cv_bridge-extras.cmake
apply_patch $my_loc/patches/cv_bridge.patch

# Patch theora_image_transport - fix transitive linking
apply_patch $my_loc/patches/theora_image_transport.patch

# Patch robot_pose_ekf - Add bfl library cmake variables, also, remove tests
# TODO: The correct way to handle this would be to create .cmake files for bfl and do a findpackage(orocos-bfl)
# apply_patch $my_loc/patches/robot_pose_ekf.patch

# Patch robot_state_publisher - Add ARCHIVE DESTINATION
# TODO: Create PR to add ARCHIVE DESTINATION
apply_patch $my_loc/patches/robot_state_publisher.patch

# Patch moveit_core - Add fcl library cmake variables
# TODO: The correct way to handle this would be to create .cmake files for fcl and do a findpackage(fcl)
#apply_patch $my_loc/patches/moveit_core.patch

# Patch moveit_core plugins - Add ARCHIVE DESTINATION
# TODO: PR merged: https://github.com/ros-planning/moveit_core/pull/251
# Wait for next release to remove (current 0.6.15)
#apply_patch $my_loc/patches/moveit_core_plugins.patch

# Patch camera_calibration_parsers - Fix yaml-cpp dependency
# TODO: PR created: https://github.com/ros-perception/image_common/pull/36
# apply_patch $my_loc/patches/camera_calibration_parsers.patch

# Patch image_view - Solved YAML linking problems, and transitive linking.
apply_patch $my_loc/patches/image_view.patch

# Patch depth_image_proc - Solved transitive linking problems
apply_patch $my_loc/patches/depth_image_proc.patch

# Patch urdf - Fixed linking with pluginlib and dependencies in downstream packages
apply_patch $my_loc/patches/urdf.patch

# Patch global_planner - Add angles dependency
# TODO: PR merged: https://github.com/ros-planning/navigation/pull/359
# Wait for next release to remove (current 1.12.4)
# apply_patch $my_loc/patches/global_planner.patch

#Patch Poco lib
apply_patch $my_loc/patches/poco.patch

# Plugin specific patches
if [ $use_pluginlib -ne 0 ]; then
# Patch pluginlib for static loading
apply_patch $my_loc/patches/pluginlib.patch
# apply_patch image_transport # to fix faulty export plugins
apply_patch $my_loc/patches/image_transport.patch
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This special case is not handled anymore. In combination with do_everything.sh:120ff if use_pluginlib is disabled in config.sh:12, applying the patches would break pluginlib.

The alternative would be to ignore package pluginlib and all its dependees when building with use_pluginlib=0, because the unpatched version would not work anyway on Android if I am not mistaken.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIU the unpatched version won't work; my rationale is that if you don't want pluginlib, applying a few extra packages doesn't add too much overhead, and you won't be able to use pluginlib anyway.

I agree that for correctness we should ignore pluginlib and deps, but on second thought I'd just drop the flag and build pluginlib support always, as it really doesn't add too much build time to the overall, and the flag just adds some more complexity to the scripts. WDYT?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always building with pluginlib support enabled would be fine for me.


## Demo Application specific patches

run_cmd apply_patches $my_loc/patches $prefix
fi

# Before build
# Search packages that depend on pluginlib and generate plugin loader.
if [ $use_pluginlib -ne 0 ]; then
echo
echo -e '\e[34mBuilding pluginlib support...\e[39m'
echo
echo
echo -e '\e[34mBuilding pluginlib support...\e[39m'
echo

pluginlib_helper_file=pluginlib_helper.cpp
$my_loc/files/pluginlib_helper/pluginlib_helper.py -scanroot $prefix/catkin_ws/src $user_workspace -cppout $my_loc/files/pluginlib_helper/$pluginlib_helper_file
cp $my_loc/files/pluginlib_helper/$pluginlib_helper_file $prefix/catkin_ws/src/pluginlib/src/
line="add_library(pluginlib STATIC src/pluginlib_helper.cpp)"
# temporally turn off error detection
set +e
grep "$line" $prefix/catkin_ws/src/pluginlib/CMakeLists.txt
# if line is not already added, then add it to the pluginlib cmake
if [ $? -ne 0 ]; then
# backup the file
cp $prefix/catkin_ws/src/pluginlib/CMakeLists.txt $prefix/catkin_ws/src/pluginlib/CMakeLists.txt.bak
sed -i '/INCLUDE_DIRS include/a LIBRARIES ${PROJECT_NAME}' $prefix/catkin_ws/src/pluginlib/CMakeLists.txt
echo -e "\n"$line >> $prefix/catkin_ws/src/pluginlib/CMakeLists.txt
echo 'install(TARGETS pluginlib RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})' >> $prefix/catkin_ws/src/pluginlib/CMakeLists.txt
fi
# turn error detection back on
set -e
pluginlib_helper_file=pluginlib_helper.cpp
$my_loc/files/pluginlib_helper/pluginlib_helper.py -scanroot $prefix/catkin_ws/src $user_workspace -cppout $my_loc/files/pluginlib_helper/$pluginlib_helper_file
cp $my_loc/files/pluginlib_helper/$pluginlib_helper_file $prefix/catkin_ws/src/pluginlib/src/
line="add_library(pluginlib STATIC src/pluginlib_helper.cpp)"
# temporally turn off error detection
set +e
grep "$line" $prefix/catkin_ws/src/pluginlib/CMakeLists.txt
# if line is not already added, then add it to the pluginlib cmake
if [ $? -ne 0 ]; then
# backup the file
cp $prefix/catkin_ws/src/pluginlib/CMakeLists.txt $prefix/catkin_ws/src/pluginlib/CMakeLists.txt.bak
sed -i '/INCLUDE_DIRS include/a LIBRARIES ${PROJECT_NAME}' $prefix/catkin_ws/src/pluginlib/CMakeLists.txt
echo -e "\n"$line >> $prefix/catkin_ws/src/pluginlib/CMakeLists.txt
echo 'install(TARGETS pluginlib RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})' >> $prefix/catkin_ws/src/pluginlib/CMakeLists.txt
fi
# turn error detection back on
set -e

echo
echo -e '\e[34mBuilding library dependencies.\e[39m'
Expand Down
68 changes: 0 additions & 68 deletions patches/android.toolchain.cmake.patch

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.