From 0bd91ad4058c006bb67b48801e1877e8a893ef4d Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Wed, 8 Jun 2016 13:48:30 -0400 Subject: [PATCH] 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. --- Modules/UseJava.cmake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake index 6644bd4cc..cf9c2d723 100644 --- a/Modules/UseJava.cmake +++ b/Modules/UseJava.cmake @@ -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