Fix javah for strict javah & ordering. * javah on some JDKs is strict about sourcing, and no classpath entry referencing the jar was present for the javah command, either as an argument or in the environment. * javah was chained as a post-build of the jar creation. This caused breakage if src/java/*.cc tried to use the javah-generated .h file before it was generated. Fixes: https://tickets.puppetlabs.com/browse/FACT-1541 Fixes: https://bugs.gentoo.org/show_bug.cgi?id=600942 Signed-off-by: Robin H. Johnson diff -Nuar facter-9999.orig/lib/CMakeLists.txt facter-9999/lib/CMakeLists.txt --- facter-9999.orig/lib/CMakeLists.txt 2016-11-28 22:18:29.366271544 -0800 +++ facter-9999/lib/CMakeLists.txt 2016-11-28 22:28:36.244894899 -0800 @@ -267,7 +267,15 @@ include(UseJava) - add_jar(facter-jruby "${CMAKE_BINARY_DIR}/lib/com/puppetlabs/Facter.java" OUTPUT_NAME facter OUTPUT_DIR "${CMAKE_BINARY_DIR}/lib" ENTRY_POINT com/puppetlabs/Facter) + add_jar(facter-jruby-jar "${CMAKE_BINARY_DIR}/lib/com/puppetlabs/Facter.java" OUTPUT_NAME facter OUTPUT_DIR "${CMAKE_BINARY_DIR}/lib" ENTRY_POINT com/puppetlabs/Facter) - add_custom_command(TARGET facter-jruby POST_BUILD COMMAND javah ARGS -d "${CMAKE_CURRENT_LIST_DIR}/src/java" com.puppetlabs.Facter WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/lib") + # javah does not atomically write the header file, so parallel builds can + # read it before it finishes writing if not careful. + add_custom_command(OUTPUT "${CMAKE_CURRENT_LIST_DIR}/src/java/com_puppetlabs_Facter.h" + COMMAND javah ARGS -classpath facter.jar -d "${CMAKE_CURRENT_LIST_DIR}/src/java" com.puppetlabs.Facter + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + DEPENDS facter-jruby-jar) + # Anything that depends on facter-jruby wants both the jar AND the completely written header. + add_custom_target(facter-jruby DEPENDS facter-jruby-jar "${CMAKE_CURRENT_LIST_DIR}/src/java/com_puppetlabs_Facter.h") + set(LIBFACTER_COMMON_SOURCES ${LIBFACTER_COMMON_SOURCES} src/java/com_puppetlabs_Facter.h) endif() # Set include directories