mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
install(DIRECTORY): Revert "Add EXCLUDE_EMPTY_DIRECTORIES option"
Revert commit b70ef48b27
(install(DIRECTORY): Add
EXCLUDE_EMPTY_DIRECTORIES option, 2025-04-20, v4.1.0-rc1~212^2).
The implementation had at least two problems:
* It did not exclude the top-level directory if empty.
* It did not exclude non-empty directories whose contents are
all filtered out.
Revert the feature pending a revised implementation.
Issue: #19189
Closes: #27092
This commit is contained in:
@@ -648,7 +648,6 @@ Signatures
|
||||
[USE_SOURCE_PERMISSIONS] [OPTIONAL] [MESSAGE_NEVER]
|
||||
[CONFIGURATIONS <config>...]
|
||||
[COMPONENT <component>] [EXCLUDE_FROM_ALL]
|
||||
[EXCLUDE_EMPTY_DIRECTORIES]
|
||||
[FILES_MATCHING]
|
||||
[<match-rule> <match-option>...]...
|
||||
)
|
||||
@@ -751,13 +750,6 @@ Signatures
|
||||
|
||||
Disable file installation status output.
|
||||
|
||||
``EXCLUDE_EMPTY_DIRECTORIES``
|
||||
.. versionadded:: 4.1
|
||||
|
||||
Exclude empty directories from installation. A directory is
|
||||
considered empty if it contains no files, no symbolic links,
|
||||
and no non-empty subdirectories.
|
||||
|
||||
``FILES_MATCHING``
|
||||
This option may be given before the first ``<match-rule>`` to
|
||||
disable installation of files (but not directories) not matched
|
||||
|
@@ -71,10 +71,6 @@ Commands
|
||||
``POPULATE`` subcommands for interfacing CMake targets with pkg-config based
|
||||
dependencies.
|
||||
|
||||
* The :command:`install(DIRECTORY)` command gained a new
|
||||
``EXCLUDE_EMPTY_DIRECTORIES`` option to skip installation
|
||||
of empty directories.
|
||||
|
||||
* The :command:`project` command now has experimental support for the
|
||||
``COMPAT_VERSION`` keyword, gated by
|
||||
``CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO``.
|
||||
|
@@ -25,10 +25,6 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include <cm/string_view>
|
||||
#include <cmext/string_view>
|
||||
|
||||
using namespace cmFSPermissions;
|
||||
|
||||
@@ -298,13 +294,6 @@ bool cmFileCopier::CheckKeyword(std::string const& arg)
|
||||
this->Doing = DoingNone;
|
||||
this->MatchlessFiles = false;
|
||||
}
|
||||
} else if (arg == "EXCLUDE_EMPTY_DIRECTORIES") {
|
||||
if (this->CurrentMatchRule) {
|
||||
this->NotAfterMatch(arg);
|
||||
} else {
|
||||
this->Doing = DoingNone;
|
||||
this->ExcludeEmptyDirectories = true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -658,29 +647,6 @@ bool cmFileCopier::InstallFile(std::string const& fromFile,
|
||||
return this->SetPermissions(toFile, permissions);
|
||||
}
|
||||
|
||||
static bool IsEmptyDirectory(std::string const& path,
|
||||
std::unordered_map<std::string, bool>& cache)
|
||||
{
|
||||
auto i = cache.find(path);
|
||||
if (i == cache.end()) {
|
||||
bool isEmpty = (!cmSystemTools::FileIsSymlink(path) &&
|
||||
cmSystemTools::FileIsDirectory(path));
|
||||
if (isEmpty) {
|
||||
cmsys::Directory d;
|
||||
d.Load(path);
|
||||
unsigned long numFiles = d.GetNumberOfFiles();
|
||||
for (unsigned long fi = 0; isEmpty && fi < numFiles; ++fi) {
|
||||
std::string const& name = d.GetFileName(fi);
|
||||
if (name != "."_s && name != ".."_s) {
|
||||
isEmpty = IsEmptyDirectory(d.GetFilePath(fi), cache);
|
||||
}
|
||||
}
|
||||
}
|
||||
i = cache.emplace(path, isEmpty).first;
|
||||
}
|
||||
return i->second;
|
||||
}
|
||||
|
||||
bool cmFileCopier::InstallDirectory(std::string const& source,
|
||||
std::string const& destination,
|
||||
MatchProperties match_properties)
|
||||
@@ -753,11 +719,6 @@ bool cmFileCopier::InstallDirectory(std::string const& source,
|
||||
strcmp(dir.GetFile(fileNum), "..") == 0)) {
|
||||
std::string fromPath = cmStrCat(source, '/', dir.GetFile(fileNum));
|
||||
std::string toPath = cmStrCat(destination, '/', dir.GetFile(fileNum));
|
||||
if (this->ExcludeEmptyDirectories &&
|
||||
IsEmptyDirectory(fromPath, this->DirEmptyCache)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!this->Install(fromPath, toPath)) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "cmsys/RegularExpression.hxx"
|
||||
@@ -31,7 +30,6 @@ protected:
|
||||
char const* Name;
|
||||
bool Always = false;
|
||||
cmFileTimeCache FileTimes;
|
||||
std::unordered_map<std::string, bool> DirEmptyCache;
|
||||
|
||||
// Whether to install a file not matching any expression.
|
||||
bool MatchlessFiles = true;
|
||||
@@ -91,7 +89,6 @@ protected:
|
||||
bool UseGivenPermissionsFile = false;
|
||||
bool UseGivenPermissionsDir = false;
|
||||
bool UseSourcePermissions = true;
|
||||
bool ExcludeEmptyDirectories = false;
|
||||
bool FollowSymlinkChain = false;
|
||||
std::string Destination;
|
||||
std::string FilesFromDir;
|
||||
|
@@ -1787,14 +1787,6 @@ bool HandleDirectoryMode(std::vector<std::string> const& args,
|
||||
}
|
||||
exclude_from_all = true;
|
||||
doing = DoingNone;
|
||||
} else if (args[i] == "EXCLUDE_EMPTY_DIRECTORIES") {
|
||||
if (in_match_mode) {
|
||||
status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
|
||||
"\" after PATTERN or REGEX."));
|
||||
return false;
|
||||
}
|
||||
literal_args += " EXCLUDE_EMPTY_DIRECTORIES";
|
||||
doing = DoingNone;
|
||||
} else if (doing == DoingDirs) {
|
||||
// Convert this directory to a full path.
|
||||
std::string dir = args[i];
|
||||
|
@@ -1,30 +0,0 @@
|
||||
file(REMOVE_RECURSE ${RunCMake_TEST_BINARY_DIR}/prefix)
|
||||
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -P ${RunCMake_TEST_BINARY_DIR}/cmake_install.cmake
|
||||
OUTPUT_VARIABLE out ERROR_VARIABLE err)
|
||||
|
||||
set(f ${RunCMake_TEST_BINARY_DIR}/prefix/dir_to_install/empty.txt)
|
||||
if(NOT EXISTS "${f}")
|
||||
string(APPEND RunCMake_TEST_FAILED
|
||||
"File was not installed:\n ${f}\n")
|
||||
endif()
|
||||
|
||||
set(empty_folder ${RunCMake_TEST_BINARY_DIR}/prefix/dir_to_install/empty_folder)
|
||||
if(EXISTS "${empty_folder}")
|
||||
string(APPEND RunCMake_TEST_FAILED
|
||||
"empty_folder should not have be installed:\n ${empty_folder}\n")
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
set(folder_with_symlink ${RunCMake_TEST_BINARY_DIR}/prefix/dir_to_install/folder_with_symlink)
|
||||
if(NOT EXISTS "${folder_with_symlink}")
|
||||
string(APPEND RunCMake_TEST_FAILED
|
||||
"folder_with_symlink was not installed:\n ${folder_with_symlink}\n")
|
||||
endif()
|
||||
|
||||
set(symlink_to_empty_txt ${RunCMake_TEST_BINARY_DIR}/prefix/dir_to_install/folder_with_symlink/symlink_to_empty.txt)
|
||||
if(NOT EXISTS "${symlink_to_empty_txt}")
|
||||
string(APPEND RunCMake_TEST_FAILED
|
||||
"symlink_to_empty.txt was not installed:\n ${symlink_to_empty_txt}\n")
|
||||
endif()
|
||||
endif()
|
@@ -1,27 +0,0 @@
|
||||
set(CMAKE_INSTALL_MESSAGE "ALWAYS")
|
||||
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/prefix")
|
||||
|
||||
set(DIR_TO_INSTALL "${CMAKE_BINARY_DIR}/dir_to_install")
|
||||
file(MAKE_DIRECTORY ${DIR_TO_INSTALL})
|
||||
|
||||
file(TOUCH ${DIR_TO_INSTALL}/empty.txt)
|
||||
|
||||
# make an empty folder
|
||||
file(MAKE_DIRECTORY ${DIR_TO_INSTALL}/empty_folder)
|
||||
# make empty subfolders under the empty folder
|
||||
file(MAKE_DIRECTORY ${DIR_TO_INSTALL}/empty_folder/empty_subfolder1)
|
||||
file(MAKE_DIRECTORY ${DIR_TO_INSTALL}/empty_folder/empty_subfolder2)
|
||||
|
||||
if(UNIX)
|
||||
# make an folder with a symlink
|
||||
file(MAKE_DIRECTORY ${DIR_TO_INSTALL}/folder_with_symlink)
|
||||
file(CREATE_LINK ${DIR_TO_INSTALL}/empty.txt
|
||||
${DIR_TO_INSTALL}/folder_with_symlink/symlink_to_empty.txt
|
||||
SYMBOLIC
|
||||
)
|
||||
endif()
|
||||
|
||||
install(DIRECTORY ${DIR_TO_INSTALL}
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}
|
||||
EXCLUDE_EMPTY_DIRECTORIES
|
||||
)
|
@@ -1 +0,0 @@
|
||||
1
|
@@ -1,5 +0,0 @@
|
||||
CMake Error at DIRECTORY-PATTERN-EXCLUDE_EMPTY_DIRECTORIES.cmake:[0-9]+ \(install\):
|
||||
install DIRECTORY does not allow "EXCLUDE_EMPTY_DIRECTORIES" after PATTERN
|
||||
or REGEX\.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists\.txt:[0-9]+ \(include\)
|
@@ -1 +0,0 @@
|
||||
install(DIRECTORY src DESTINATION src PATTERN *.txt EXCLUDE_EMPTY_DIRECTORIES)
|
@@ -73,8 +73,6 @@ run_cmake(DIRECTORY-MESSAGE_NEVER)
|
||||
run_cmake(DIRECTORY-PATTERN-MESSAGE_NEVER)
|
||||
run_cmake(DIRECTORY-message)
|
||||
run_cmake(DIRECTORY-message-lazy)
|
||||
run_cmake(DIRECTORY-EXCLUDE_EMPTY_DIRECTORIES)
|
||||
run_cmake(DIRECTORY-PATTERN-EXCLUDE_EMPTY_DIRECTORIES)
|
||||
run_cmake(SkipInstallRulesWarning)
|
||||
run_cmake(SkipInstallRulesNoWarning1)
|
||||
run_cmake(SkipInstallRulesNoWarning2)
|
||||
|
Reference in New Issue
Block a user