@@ -40,57 +40,85 @@ endmacro()
4040# To facilitate this, the ARG_GENERATED_FILES is actually just the underlying ARG_MSG and ARG_SRV
4141# files which we feed the commands as DEPENDS to trigger their execution.
4242macro (_generate_module_java ARG_PKG ARG_GEN_OUTPUT_DIR ARG_GENERATED_FILES)
43-
4443 # ###############################
4544 # Gradle Subproject
4645 # ###############################
4746 set (GRADLE_BUILD_DIR " ${CMAKE_CURRENT_BINARY_DIR}/java" )
4847 set (GRADLE_BUILD_FILE " ${GRADLE_BUILD_DIR}/${ARG_PKG}/build.gradle" )
4948 list (APPEND ALL_GEN_OUTPUT_FILES_java ${GRADLE_BUILD_FILE})
50-
49+ # a marker for the compiling script later to discover
50+ # this command will only get run when an underlying dependency changes, whereas the compiling
51+ # add_custom_target always runs (this was so we can ensure compile time dependencies are ok).
52+ # So we leave this dropping to inform it when gradle needs to run so that we can skip by
53+ # without the huge latency whenever we don't.
54+ set (DROPPINGS_FILE " ${GRADLE_BUILD_DIR}/${ARG_PKG}/droppings" )
5155 add_custom_command (OUTPUT ${GRADLE_BUILD_FILE}
52- DEPENDS ${GENJAVA_BIN}
56+ DEPENDS ${GENJAVA_BIN} ${ARG_GENERATED_FILES}
5357 COMMAND ${CATKIN_ENV} ${PYTHON_EXECUTABLE} ${GENJAVA_BIN}
5458 - o ${GRADLE_BUILD_DIR}
5559 - p ${ARG_PKG}
60+ COMMAND touch ${DROPPINGS_FILE}
5661 COMMENT " Generating Java gradle project from ${ARG_PKG}"
5762 )
5863
5964 # ###############################
6065 # Compile Gradle Subproject
6166 # ###############################
67+ # Push the compile back to the last thing that gets done before the generate messages
68+ # is done for this package (see the PRE_LINK coupled with the TARGET option below). This
69+ # is different to genpy, gencpp since it's a compile step. If you don't force it to be
70+ # the last thing, then it may be trying to compile while dependencies are still getting
71+ # themselves ready for ${ARG_PKG}_generate_messages in parallel.
72+ # (i.e. beware of sequencing add_custom_command, it usually has to compete)
6273 set (ROS_GRADLE_VERBOSE $ENV{ROS_GRADLE_VERBOSE})
6374 if (ROS_GRADLE_VERBOSE)
64- set (GRADLE_CMD " ./gradlew " )
75+ set (verbosity " --verbosity " )
6576 else ()
66- set (GRADLE_CMD " ./gradlew;-q " )
77+ set (verbosity " " )
6778 endif ()
68- set (GEN_OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/ generated_java_messages .flag )
6979
70- add_custom_command (OUTPUT ${GEN_OUTPUT_FILE}
80+ add_custom_target (${ARG_PKG}_generate_messages_java_gradle
81+ COMMAND ${CATKIN_ENV} ${PYTHON_EXECUTABLE} ${GENJAVA_BIN}
82+ ${verbosity}
83+ -- compile
84+ - o ${GRADLE_BUILD_DIR}
85+ - p ${ARG_PKG}
7186 DEPENDS ${GRADLE_BUILD_FILE} ${ARG_GENERATED_FILES}
72- COMMAND ${CATKIN_ENV} ${GRADLE_CMD}
73- COMMAND touch ${GEN_OUTPUT_FILE}
7487 WORKING_DIRECTORY ${GRADLE_BUILD_DIR}/ ${ARG_PKG}
75- COMMENT " Generating Java code for ${ARG_PKG}" )
76- list (APPEND ALL_GEN_OUTPUT_FILES_java ${GEN_OUTPUT_FILE})
77-
78- # ###############################
79- # Debugging
80- # ###############################
81- # foreach(gen_output_file ${ALL_GEN_OUTPUT_FILES_java})
82- # message(STATUS "ALL_GEN_OUTPUT_FILES_java..........${gen_output_file}")
83- # endforeach()
88+ COMMENT " Compiling Java code for ${ARG_PKG}"
89+ )
90+ add_dependencies (${ARG_PKG}_generate_messages ${ARG_PKG}_generate_messages_java_gradle)
8491
8592 # ###############################
8693 # Dependent Targets
8794 # ###############################
95+ # This is a bad hack that needs to disappear. e.g.
96+ # - topic_tools and roscpp are both packages with a couple of msgs
97+ # - topic tools messages doesn't actually depend on roscpp messages
98+ # this is guarded, so it's not doubling up on work when called from catkin_package (roscpp does this too)
99+ # and we need it to get access to the build_depends list just in case people called generate_messages before catkin_package()
100+ if (NOT DEFINED ${ARG_PKG}_BUILD_DEPENDS)
101+ catkin_package_xml (DIRECTORY ${PROJECT_SOURCE_DIR})
102+ endif ()
103+ foreach (depends ${${ARG_PKG}_BUILD_DEPENDS})
104+ if (TARGET ${depends}_generate_messages_java_gradle)
105+ message (STATUS " Adding dependency.....${depends}_generate_messages -> ${ARG_PKG}_generate_messages" )
106+ add_dependencies (${ARG_PKG}_generate_messages_java_gradle ${depends}_generate_messages_java_gradle)
107+ endif ()
108+ endforeach ()
88109 # Make sure we have built gradle-rosjava_bootstrap if it is in the source workspace
89110 # (otherwise package.xml will make sure it has installed via rosdep/deb.
90111 # if(TARGET gradle-rosjava_bootstrap)
91112 # Preference would be to add it to ${ARG_PKG}_generate_messages_java but that
92113 # is not defined till after this module is parsed, so add it all
93114 # add_dependencies(${ARG_PKG}_generate_messages gradle-rosjava_bootstrap)
94115 # endif()
116+
117+ # ###############################
118+ # Debugging
119+ # ###############################
120+ # foreach(gen_output_file ${ALL_GEN_OUTPUT_FILES_java})
121+ # message(STATUS "ALL_GEN_OUTPUT_FILES_java..........${gen_output_file}")
122+ # endforeach()
95123endmacro ()
96124
0 commit comments