CPack: allow packaging of empty directories

This commit is contained in:
Domen Vrankar 2015-09-28 22:50:15 +02:00
parent ecd71c9c1a
commit 9298f56dce
21 changed files with 79 additions and 5 deletions

View File

@ -0,0 +1,4 @@
cpack-package-empty-dirs
------------------------
* The :module:`CPack` module learned to package empty directories.

View File

@ -78,7 +78,7 @@ int cmCPackArchiveGenerator::addOneComponentToArchive(cmArchiveWrite& archive,
std::string rp = filePrefix + *fileIt; std::string rp = filePrefix + *fileIt;
cmCPackLogger(cmCPackLog::LOG_DEBUG,"Adding file: " cmCPackLogger(cmCPackLog::LOG_DEBUG,"Adding file: "
<< rp << std::endl); << rp << std::endl);
archive.Add(rp); archive.Add(rp, 0, 0, false);
if (!archive) if (!archive)
{ {
cmCPackLogger(cmCPackLog::LOG_ERROR, "ERROR while packaging files: " cmCPackLogger(cmCPackLog::LOG_ERROR, "ERROR while packaging files: "
@ -284,7 +284,7 @@ int cmCPackArchiveGenerator::PackageFiles()
// Get the relative path to the file // Get the relative path to the file
std::string rp = cmSystemTools::RelativePath(toplevel.c_str(), std::string rp = cmSystemTools::RelativePath(toplevel.c_str(),
fileIt->c_str()); fileIt->c_str());
archive.Add(rp); archive.Add(rp, 0, 0, false);
if(!archive) if(!archive)
{ {
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem while adding file< " cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem while adding file< "

View File

@ -367,6 +367,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
cmCPackLogger(cmCPackLog::LOG_OUTPUT, cmCPackLogger(cmCPackLog::LOG_OUTPUT,
"- Install directory: " << top << std::endl); "- Install directory: " << top << std::endl);
gl.RecurseOn(); gl.RecurseOn();
gl.SetRecurseListDirs(true);
if ( !gl.FindFiles(findExpr) ) if ( !gl.FindFiles(findExpr) )
{ {
cmCPackLogger(cmCPackLog::LOG_ERROR, cmCPackLogger(cmCPackLog::LOG_ERROR,
@ -379,7 +380,11 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
for ( gfit = files.begin(); gfit != files.end(); ++ gfit ) for ( gfit = files.begin(); gfit != files.end(); ++ gfit )
{ {
bool skip = false; bool skip = false;
std::string &inFile = *gfit; std::string inFile = *gfit;
if(cmSystemTools::FileIsDirectory(*gfit))
{
inFile += '/';
}
for ( regIt= ignoreFilesRegex.begin(); for ( regIt= ignoreFilesRegex.begin();
regIt!= ignoreFilesRegex.end(); regIt!= ignoreFilesRegex.end();
++ regIt) ++ regIt)
@ -869,6 +874,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
cmsys::Glob glB; cmsys::Glob glB;
findExpr += "/*"; findExpr += "/*";
glB.RecurseOn(); glB.RecurseOn();
glB.SetRecurseListDirs(true);
glB.FindFiles(findExpr); glB.FindFiles(findExpr);
filesBefore = glB.GetFiles(); filesBefore = glB.GetFiles();
std::sort(filesBefore.begin(),filesBefore.end()); std::sort(filesBefore.begin(),filesBefore.end());
@ -908,6 +914,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
{ {
cmsys::Glob glA; cmsys::Glob glA;
glA.RecurseOn(); glA.RecurseOn();
glA.SetRecurseListDirs(true);
glA.FindFiles(findExpr); glA.FindFiles(findExpr);
std::vector<std::string> filesAfter = glA.GetFiles(); std::vector<std::string> filesAfter = glA.GetFiles();
std::sort(filesAfter.begin(),filesAfter.end()); std::sort(filesAfter.begin(),filesAfter.end());
@ -1074,6 +1081,7 @@ int cmCPackGenerator::DoPackage()
std::string findExpr = tempDirectory; std::string findExpr = tempDirectory;
findExpr += "/*"; findExpr += "/*";
gl.RecurseOn(); gl.RecurseOn();
gl.SetRecurseListDirs(true);
gl.SetRecurseThroughSymlinks(false); gl.SetRecurseThroughSymlinks(false);
if ( !gl.FindFiles(findExpr) ) if ( !gl.FindFiles(findExpr) )
{ {

View File

@ -290,7 +290,7 @@ if("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
add_RunCMake_test(CompilerLauncher) add_RunCMake_test(CompilerLauncher)
endif() endif()
add_RunCMake_test_group(CPack "DEB;RPM") add_RunCMake_test_group(CPack "DEB;RPM;TGZ")
# add a test to make sure symbols are exported from a shared library # add a test to make sure symbols are exported from a shared library
# for MSVC compilers CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS property is used # for MSVC compilers CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS property is used
add_RunCMake_test(AutoExportDll) add_RunCMake_test(AutoExportDll)

View File

@ -0,0 +1,5 @@
set(CPACK_COMPONENTS_ALL test)
install(DIRECTORY DESTINATION empty
COMPONENT test)
set(CPACK_PACKAGE_NAME "components_empty_dir")

View File

@ -0,0 +1,5 @@
set(whitespaces_ "[\t\n\r ]*")
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_1 "components_empty_dir*.deb")
set(EXPECTED_FILE_CONTENT_1 "^.*/usr/${whitespaces_}.*/usr/empty/$")

View File

@ -0,0 +1,2 @@
set(CPACK_PACKAGE_CONTACT "someone")
set(CPACK_DEB_COMPONENT_INSTALL "ON")

View File

@ -0,0 +1,5 @@
set(whitespaces_ "[\t\n\r ]*")
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_1 "empty_dir*.deb")
set(EXPECTED_FILE_CONTENT_1 "^.*/usr/${whitespaces_}.*/usr/empty/$")

View File

@ -0,0 +1 @@
set(CPACK_PACKAGE_CONTACT "someone")

View File

@ -0,0 +1,4 @@
install(DIRECTORY DESTINATION empty
COMPONENT test)
set(CPACK_PACKAGE_NAME "empty_dir")

View File

@ -0,0 +1,5 @@
set(whitespaces_ "[\t\n\r ]*")
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_1 "components_empty_dir*.rpm")
set(EXPECTED_FILE_CONTENT_1 "^/usr/empty$")

View File

@ -0,0 +1 @@
^CPackRPM: Will use GENERATED spec file: .*/Tests/RunCMake/RPM/CPack/COMPONENTS_EMPTY_DIR-build/_CPack_Packages/.*/RPM/SPECS/components_empty_dir.spec$

View File

@ -0,0 +1,5 @@
set(whitespaces_ "[\t\n\r ]*")
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_1 "empty_dir*.rpm")
set(EXPECTED_FILE_CONTENT_1 "^/usr/empty$")

View File

@ -0,0 +1 @@
^CPackRPM: Will use GENERATED spec file: .*/Tests/RunCMake/RPM/CPack/EMPTY_DIR-build/_CPack_Packages/.*/RPM/SPECS/empty_dir.spec$

View File

@ -4,7 +4,9 @@ include(RunCMake)
include("${RunCMake_SOURCE_DIR}/CPackTestHelpers.cmake") include("${RunCMake_SOURCE_DIR}/CPackTestHelpers.cmake")
# args: TEST_NAME "GENERATORS" RUN_CMAKE_BUILD_STEP # args: TEST_NAME "GENERATORS" RUN_CMAKE_BUILD_STEP
run_cpack_test(MINIMAL "RPM;DEB" false) run_cpack_test(MINIMAL "RPM;DEB;TGZ" false)
run_cpack_test(PARTIALLY_RELOCATABLE_WARNING "RPM" false) run_cpack_test(PARTIALLY_RELOCATABLE_WARNING "RPM" false)
run_cpack_test(DEB_EXTRA "DEB" false) run_cpack_test(DEB_EXTRA "DEB" false)
run_cpack_test(DEPENDENCIES "RPM;DEB" true) run_cpack_test(DEPENDENCIES "RPM;DEB" true)
run_cpack_test(EMPTY_DIR "RPM;DEB;TGZ" true)
run_cpack_test(COMPONENTS_EMPTY_DIR "RPM;DEB;TGZ" true)

View File

@ -0,0 +1,3 @@
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_1 "components_empty_dir*.tar.gz")
set(EXPECTED_FILE_CONTENT_1 "^[^\n]*empty/$")

View File

@ -0,0 +1 @@
set(CPACK_ARCHIVE_COMPONENT_INSTALL "ON")

View File

@ -0,0 +1,3 @@
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_1 "empty_dir*.tar.gz")
set(EXPECTED_FILE_CONTENT_1 "^[^\n]*empty_dir-0.1.1-[^\n]*/empty/$")

View File

@ -0,0 +1,10 @@
set(ALL_FILES_GLOB "*.tar.gz")
function(getPackageContent FILE RESULT_VAR)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar -ztvf ${FILE}
OUTPUT_VARIABLE package_content_
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
endfunction()

View File

@ -0,0 +1,5 @@
set(whitespaces_ "[\t\n\r ]*")
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_1 "minimal*.tar.gz")
set(EXPECTED_FILE_CONTENT_1 "^[^\n]*minimal-0.1.1-[^\n]*/foo/\n[^\n]*minimal-0.1.1-[^\n]*/foo/CMakeLists.txt$")

View File

@ -0,0 +1,4 @@
function(get_test_prerequirements found_var config_file)
file(WRITE "${config_file}" "")
set(${found_var} true PARENT_SCOPE)
endfunction()