UseJava: Fix race condition creating java class list

Modify logic to unconditionally create an empty class list response file
to instead only create the empty file if no classes are being compiled.
Otherwise, the response file is created via a custom command that
generates the correct list.

This fixes a race condition on certain systems (e.g. HFS on OS X) where
the dependency for creating the "correct" list can have the "same" (due
to limited precision of the filesystem) timestamp as the empty file
created at configure time, resulting in an empty class list being
incorrectly used to invoke `jar` (resulting in `jar` being unhappy that
it was not given any input files). Although one would have some hope
that this doesn't affect "real" projects, it definitely does affect the
JavaExportImport unit test, causing the same to fail randomly when run
on an HFS partition.
This commit is contained in:
Matthew Woehlke 2016-06-08 13:48:30 -04:00 committed by Brad King
parent 89df91b938
commit 0bd91ad405
1 changed files with 5 additions and 5 deletions

View File

@ -609,11 +609,6 @@ function(add_jar _TARGET_NAME)
endif ()
endforeach()
# create an empty java_class_filelist
if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist)
file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "")
endif()
if (_JAVA_COMPILE_FILES OR _JAVA_COMPILE_FILELISTS)
set (_JAVA_SOURCES_FILELISTS)
@ -653,6 +648,11 @@ function(add_jar _TARGET_NAME)
DEPENDS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
else ()
# create an empty java_class_filelist
if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist)
file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "")
endif()
endif ()
# create the jar file