Skip to content

Commit

Permalink
Install executables in test tree after building, not during "make ins…
Browse files Browse the repository at this point in the history
…tall"
  • Loading branch information
qris committed Jul 23, 2017
1 parent 61930b3 commit 9560039
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 76 deletions.
4 changes: 3 additions & 1 deletion infrastructure/buildenv-testmain-template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ int main(int argc, char * const * argv)
if(fulltestmode)
{
// banner
BOX_NOTICE("Running test TEST_NAME in " MODE_TEXT " mode...");
std::string box_module = BOX_MODULE;
std::string test_name = box_module.substr(5);
BOX_NOTICE("Running test " << test_name << " in " MODE_TEXT " mode...");

// Count open file descriptors for a very crude "files left open" test
Logging::GetSyslog().Shutdown();
Expand Down
113 changes: 60 additions & 53 deletions infrastructure/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ if(WIN32)
add_definitions(-DWIN32)
endif()

file(READ "${base_dir}/infrastructure/buildenv-testmain-template.cpp" test_template)

# Parsing Makefile.extra files in CMake script is a pain, so the relevant rules for
# code-generating Perl scripts are hard-coded here.

Expand Down Expand Up @@ -176,6 +174,13 @@ foreach(documentation_file ${documentation_files})
set(${module_name}_extra_files ${${module_name}_extra_files} ${output_file})
endforeach()

set(testmain_template_cpp
"${base_dir}/infrastructure/buildenv-testmain-template.cpp"
)
set(release_or_debug_dir
"${base_dir}/$<$<CONFIG:Debug>:debug>$<$<CONFIG:Release>:release>$<$<CONFIG:RelWithDebInfo>:release>"
)

file(STRINGS ${base_dir}/modules.txt module_deps REGEX "^[^#]")
foreach(module_dep ${module_deps})

Expand Down Expand Up @@ -211,19 +216,26 @@ foreach(module_dep ${module_deps})
if(DEBUG)
message(STATUS "add executable '${module_name}': '${module_files}'")
endif()
add_executable(${module_name} ${module_files})

# Unfortunately we have to use install(PROGRAMS) instead of
# install(TARGETS) because TARGETS doesn't allow us to change
# the executable name.
install(PROGRAMS "$<TARGET_FILE:${module_name}>"
CONFIGURATIONS Debug
DESTINATION "${base_dir}/debug/${module_dir}"
RENAME "${bin_name}${CMAKE_EXECUTABLE_SUFFIX}")
install(PROGRAMS "$<TARGET_FILE:${module_name}>"
CONFIGURATIONS Release
DESTINATION "${base_dir}/release/${module_dir}"
RENAME "${bin_name}${CMAKE_EXECUTABLE_SUFFIX}")
add_executable(${module_name} ${module_files})
# Rename the output executable from bin_bbackupd(.exe) to bbackupd(.exe):
set_target_properties(${module_name} PROPERTIES
OUTPUT_NAME "${bin_name}")

# Use a custom post-build command instead of install(...) to install
# binaries ready for running tests, because we don't want "make install" to
# do this too, and absolute-path installations break the CPack generators.
add_custom_command(TARGET ${module_name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"$<TARGET_FILE:${module_name}>"
"${release_or_debug_dir}/${module_dir}/${bin_name}${CMAKE_EXECUTABLE_SUFFIX}"
VERBATIM)

# For "make install" and CPack generators:
install(TARGETS ${module_name} RUNTIME
CONFIGURATIONS Debug;Release
DESTINATION "."
COMPONENT Applications)
elseif(module_name MATCHES "^test_")
string(REGEX MATCH "^test_(.*)" valid_test ${module_name})
set(test_name ${CMAKE_MATCH_1})
Expand All @@ -233,49 +245,37 @@ foreach(module_dep ${module_deps})
message(STATUS "add test '${module_name}': '${module_files}'")
endif()

string(REPLACE "TEST_NAME" ${test_name} test_main "${test_template}")
file(WRITE "${module_path}/_main.cpp.new" "${test_main}")
replace_file_if_different(
"${module_path}/_main.cpp"
"${module_path}/_main.cpp.new")
add_executable(${module_name} ${module_files}
"${module_path}/_main.cpp")
set(module_files ${module_files} "${testmain_template_cpp}")
add_executable(${module_name} ${module_files})

if(WIN32)
install(PROGRAMS "$<TARGET_FILE:${module_name}>"
CONFIGURATIONS Debug
DESTINATION "${base_dir}/debug/${module_dir}")
install(PROGRAMS "$<TARGET_FILE:${module_name}>"
CONFIGURATIONS Release
DESTINATION "${base_dir}/release/${module_dir}")
set(test_executable "$<TARGET_FILE_NAME:${module_name}>")
else()
# Unfortunately we have to use install(PROGRAMS) instead of
# install(TARGETS) because TARGETS doesn't allow us to change
# the executable name.
install(PROGRAMS "$<TARGET_FILE:${module_name}>"
CONFIGURATIONS Debug
DESTINATION "${base_dir}/debug/${module_dir}"
RENAME "_test")
install(PROGRAMS "$<TARGET_FILE:${module_name}>"
CONFIGURATIONS Release
DESTINATION "${base_dir}/release/${module_dir}"
RENAME "_test")
set(test_executable "./_test")
endif()
# Use a custom post-build command instead of install(...) to install
# binaries ready for running tests, because we don't want "make install" to
# do this too, and absolute-path installations break the CPack generators.
add_custom_command(TARGET ${module_name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"$<TARGET_FILE:${module_name}>"
"${release_or_debug_dir}/${module_dir}/${bin_name}${CMAKE_EXECUTABLE_SUFFIX}"
VERBATIM)

if(${APPVEYOR_MODE})
set(appveyor_runtest_pl_switch -a)
else()
set(appveyor_runtest_pl_switch)
endif()

if(WIN32)
set(test_command_internal "$<TARGET_FILE_NAME:${module_name}>")
else()
set(test_command_internal "./$<TARGET_FILE_NAME:${module_name}>")
endif()

target_compile_definitions(${module_name} PRIVATE
-DTEST_EXECUTABLE="${test_executable}")
-DTEST_EXECUTABLE="${test_command_internal}")
add_test(NAME ${test_name}
COMMAND ${PERL_EXECUTABLE} ${base_dir}/runtest.pl
${appveyor_runtest_pl_switch} -c ${test_name}
$<CONFIG> "$<TARGET_FILE:${module_name}>" "${test_executable}"
$<$<CONFIG:Debug>:DEBUG>$<$<CONFIG:Release>:RELEASE>$<$<CONFIG:RelWithDebInfo>:RELEASE>
"$<TARGET_FILE:${module_name}>" "${test_command_internal}"
WORKING_DIRECTORY ${base_dir})

if(${APPVEYOR_MODE})
Expand All @@ -288,7 +288,8 @@ foreach(module_dep ${module_deps})
add_custom_target(${module_name}-prepare
COMMAND ${PERL_EXECUTABLE} ${base_dir}/runtest.pl
-n -c ${test_name}
$<CONFIG> "$<TARGET_FILE:${module_name}>" "${test_executable}"
$<$<CONFIG:Debug>:DEBUG>$<$<CONFIG:Release>:RELEASE>$<$<CONFIG:RelWithDebInfo>:RELEASE>
"$<TARGET_FILE:${module_name}>" "${test_command_internal}"
WORKING_DIRECTORY ${base_dir})
elseif(module_name MATCHES "^(lib_.*|qdbm)$")
if(DEBUG)
Expand Down Expand Up @@ -337,11 +338,12 @@ target_compile_definitions(lib_common PUBLIC $<$<CONFIG:Release>:BOX_RELEASE_BUI
# Detect platform features and write BoxConfig.h.in. Reuse code from
# infrastructure/m4/boxbackup_tests.m4 where possible

include(CheckIncludeFiles)
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckCXXSourceCompiles)
include(CheckSymbolExists)

set(boxconfig_h_file "${CMAKE_BINARY_DIR}/BoxConfig.h.in")
file(REMOVE "${boxconfig_h_file}")
Expand Down Expand Up @@ -553,6 +555,11 @@ endforeach()
check_symbol_exists(dirfd "dirent.h" HAVE_DECL_DIRFD)
file(APPEND "${boxconfig_h_file}" "#cmakedefine01 HAVE_DECL_DIRFD\n")

if(WIN32)
# We emulate this in lib/win32, so we know it's present:
file(APPEND "${boxconfig_h_file}" "#define HAVE_VALID_DIRENT_D_TYPE 1\n")
endif()

# Emulate ax_check_mount_point.m4
# These checks are run by multi-line M4 commands which are harder to parse/fake using
# regexps above, so we hard-code them here:
Expand Down Expand Up @@ -662,7 +669,7 @@ target_compile_definitions(qdbm PUBLIC -DQDBM_STATIC)

# Silence some less-useful warnings
if(MSVC)
add_definitions(/wd4996 /wd4291)
add_definitions(/wd4291 /wd4710 /wd4820 /wd4996)
set_property(TARGET qdbm PROPERTY CMAKE_STATIC_LINKER_FLAGS /IGNORE:LNK4006)
endif(MSVC)

Expand All @@ -675,12 +682,12 @@ target_compile_definitions(test_backupstorefix PRIVATE -DPERL_EXECUTABLE="${perl
# I've set the timeout to 4 times as long as it took to run on a particular run on Appveyor:
# https://ci.appveyor.com/project/qris/boxbackup/build/job/xm10itascygtu93j
set_tests_properties(common PROPERTIES TIMEOUT 20)
set_tests_properties(crypto PROPERTIES TIMEOUT 4)
set_tests_properties(crypto PROPERTIES TIMEOUT 10)
set_tests_properties(compress PROPERTIES TIMEOUT 80)
set_tests_properties(raidfile PROPERTIES TIMEOUT 32)
set_tests_properties(basicserver PROPERTIES TIMEOUT 80)
set_tests_properties(backupstore PROPERTIES TIMEOUT 560)
set_tests_properties(backupstorefix PROPERTIES TIMEOUT 140)
set_tests_properties(backupstore PROPERTIES TIMEOUT 1320)
set_tests_properties(backupstorefix PROPERTIES TIMEOUT 180)
set_tests_properties(backupstorepatch PROPERTIES TIMEOUT 320)
set_tests_properties(backupdiff PROPERTIES TIMEOUT 32)
set_tests_properties(bbackupd PROPERTIES TIMEOUT 1200)
Expand Down
40 changes: 18 additions & 22 deletions infrastructure/makebuildenv.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ print "done\n\n";

# open test mail program template file
my $test_template_file = 'infrastructure/buildenv-testmain-template.cpp';
open FL,$test_template_file or die "Can't open test template file\n";
my $test_template;
read FL,$test_template,-s $test_template_file;
close FL;


# extra platform defines
my $extra_platform_defines = '';
Expand Down Expand Up @@ -525,12 +520,6 @@ for my $mod (@implicit_deps, @modules)
# add additional files for tests
if($type eq 'test')
{
my $testmain = $test_template;
$testmain =~ s/TEST_NAME/$name/g;
open TESTMAIN,">$mod/_main.cpp" or die "Can't open test main file for $mod for writing\n";
print TESTMAIN $testmain;
close TESTMAIN;

# test file...
sub writetestfile
{
Expand Down Expand Up @@ -714,9 +703,15 @@ __E
close MINI_MODULE_MAKEFILE;

opendir DIR, $mod;
my @items = readdir DIR;
my @files = readdir DIR;
closedir DIR;
my @items = map {"$mod/$_"} @files;

if($type eq 'test')
{
push @items, $test_template_file;
}

# add in items from autogen directories, and create output directories
{
my @autogen_items;
Expand Down Expand Up @@ -767,10 +762,11 @@ __E
my @obj_base;
for my $file (@items)
{
my $is_c = $file =~ m/\A(.+)\.c\Z/i;
my $is_cpp = $file =~ m/\A(.+)\.cpp\Z/i;
my $is_rc = $file =~ m/\A(.+)\.rc\Z/i;
my $base = $1;
my $is_c = $file =~ m@(([^/]+)\.c)\Z@i;
my $is_cpp = $file =~ m@(([^/]+)\.cpp)\Z@i;
my $is_rc = $file =~ m@(([^/]+)\.rc)\Z@i;
my $basename = $1;
my $base = $2;

# Don't try to compile .rc files except on Windows:
next if not $is_c and not $is_cpp and not ($is_rc and $target_windows);
Expand All @@ -780,9 +776,9 @@ __E
push @obj_base, $base;

# get the file...
open FL, "$mod/$file";
open FL, $file or die "$file: $!";
my $f;
read FL, $f, -s "$mod/$file";
read FL, $f, -s $file;
close FL;

my %dep;
Expand All @@ -804,19 +800,19 @@ __E
}
keys %dep;

$make .= "$out_name: $mod/$file @dep_paths\n";
$make .= "$out_name: $file @dep_paths\n";

if ($is_c)
{
$make .= "\t\$(_CC) \$(${var_prefix}_CFLAGS) ".
"\$(${type}_${name}_includes) -DBOX_MODULE=\"\\\"$mod\\\"\" " .
"-c $mod/$file -o $out_name\n\n";
"-c $file -o $out_name\n\n";
}
if ($is_cpp)
elsif ($is_cpp)
{
$make .= "\t\$(_CXX) \$(${var_prefix}_CXXFLAGS) ".
"\$(${type}_${name}_includes) -DBOX_MODULE=\"\\\"$mod\\\"\" " .
"-c $mod/$file -o $out_name\n\n";
"-c $file -o $out_name\n\n";
}
elsif ($is_rc)
{
Expand Down

0 comments on commit 9560039

Please sign in to comment.