From 5bb6949bd62b39a0fffc034eafc30acda80567ad Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Wed, 16 Oct 2013 19:22:01 +0400 Subject: [PATCH] Fix running Java tests with run.py on everything other than Windows. Previously, run.py would assume that the opencv_java library is in the same directory as the tests, which is only true on Windows. The library path depends on the build configuration, which may not be known until the actual build (e.g. with the Visual Studio generators), so it can't be stored in the CMake cache for run.py to read. I didn't want to hardcode into run.py where the library is on each platform, either. So that's why I used the current scheme with the properties file. It also makes running the tests without run.py a little easier. --- modules/java/test/CMakeLists.txt | 26 ++++++++++++++++---------- modules/java/test/build.xml | 8 +++++--- modules/ts/misc/run.py | 5 ++++- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/modules/java/test/CMakeLists.txt b/modules/java/test/CMakeLists.txt index 122aae22a0..5479b42644 100644 --- a/modules/java/test/CMakeLists.txt +++ b/modules/java/test/CMakeLists.txt @@ -10,6 +10,9 @@ set(opencv_test_java_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/.build") set(android_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../android_test") set(java_source_dir ${CMAKE_CURRENT_SOURCE_DIR}) +# make sure the build directory exists +file(MAKE_DIRECTORY "${opencv_test_java_bin_dir}") + # get project sources file(GLOB_RECURSE opencv_test_java_files RELATIVE "${android_source_dir}" "${android_source_dir}/res/*" "${android_source_dir}/src/*.java") # These are the files that need to be updated for pure Java. @@ -58,14 +61,6 @@ add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/build.xml" COMMENT "Copying build.xml" ) -# Create a script for running the Java tests and place it in build/bin. -#if(WIN32) - #file(WRITE "${CMAKE_BINARY_DIR}/bin/opencv_test_java.cmd" "cd ${opencv_test_java_bin_dir}\nset PATH=${EXECUTABLE_OUTPUT_PATH}/Release;%PATH%\nant -DjavaLibraryPath=${EXECUTABLE_OUTPUT_PATH}/Release buildAndTest") - #file(WRITE "${CMAKE_BINARY_DIR}/bin/opencv_test_java_D.cmd" "cd ${opencv_test_java_bin_dir}\nset PATH=${EXECUTABLE_OUTPUT_PATH}/Debug;%PATH%\nant -DjavaLibraryPath=${EXECUTABLE_OUTPUT_PATH}/Debug buildAndTest") -#else() - #file(WRITE "${CMAKE_BINARY_DIR}/bin/opencv_test_java.sh" "cd ${opencv_test_java_bin_dir};\nant -DjavaLibraryPath=${LIBRARY_OUTPUT_PATH} buildAndTest;\ncd -") -#endif() - add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/build/jar/opencv-test.jar" COMMAND "${ANT_EXECUTABLE}" build WORKING_DIRECTORY "${opencv_test_java_bin_dir}" @@ -73,8 +68,19 @@ add_custom_command(OUTPUT "${opencv_test_java_bin_dir}/build/jar/opencv-test.jar COMMENT "Build Java tests" ) -add_custom_target(${PROJECT_NAME} ALL SOURCES "${opencv_test_java_bin_dir}/build/jar/opencv-test.jar") -add_dependencies(${PROJECT_NAME} ${the_module}) +# Not add_custom_command because generator expressions aren't supported in +# OUTPUT file names, and we need to generate different files for different +# configurations. +add_custom_target(${PROJECT_NAME}_properties + COMMAND "${CMAKE_COMMAND}" -E echo "opencv.lib.path = $" + > "${opencv_test_java_bin_dir}/ant-$.properties" + VERBATIM + ) + +add_custom_target(${PROJECT_NAME} ALL + DEPENDS ${the_module} ${PROJECT_NAME}_properties + SOURCES "${opencv_test_java_bin_dir}/build/jar/opencv-test.jar" + ) if(ENABLE_SOLUTION_FOLDERS) set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "tests accuracy") diff --git a/modules/java/test/build.xml b/modules/java/test/build.xml index d91118f0a3..d3f826cf00 100644 --- a/modules/java/test/build.xml +++ b/modules/java/test/build.xml @@ -1,4 +1,6 @@ + + @@ -34,8 +36,8 @@ - - + + @@ -61,4 +63,4 @@ - \ No newline at end of file + diff --git a/modules/ts/misc/run.py b/modules/ts/misc/run.py index b09abb6175..ba70678e8c 100755 --- a/modules/ts/misc/run.py +++ b/modules/ts/misc/run.py @@ -759,7 +759,10 @@ class TestSuite(object): return hostlogpath return None elif path == "java": - cmd = [self.ant_executable, "-DjavaLibraryPath=" + self.tests_dir, "buildAndTest"] + cmd = [self.ant_executable, + "-Dopencv.build.type=" + + (self.options.configuration if self.options.configuration else self.build_type), + "buildAndTest"] print >> _stderr, "Run command:", " ".join(cmd) try: