[CXX-2276] Install tries to remove empty directories Created: 03/Jun/21 Updated: 28/Oct/23 Resolved: 10/Sep/21 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | Build |
| Affects Version/s: | None |
| Fix Version/s: | 3.7.0, 3.6.6, 3.7.0-beta1 |
| Type: | Bug | Priority: | Trivial - P5 |
| Reporter: | Ryan Schmidt | Assignee: | Roberto Sanchez |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Installing mongo-cxx-driver 3.6.3 (on macOS) tries to delete empty directories within the install prefix. This is unexpected, especially if the install prefix already contains other unrelated software. When mongo-cxx-driver is installed by MacPorts, at least some directory deletion attempts fail:
Full log here: https://build.macports.org/builders/ports-11_arm64-builder/builds/17498/steps/install-port/logs/stdio MacPorts prevents ports from doing things they should not do, like deleting things that do not belong to them. Users installing mongo-cxx-driver outside of the protection MacPorts provides will just find these directories unexpectedly deleted. An empty directory is not necessarily useless. For example, one may have been created with a particular owner and permissions in order to facilitate files being written there by some process. This problem even caused the build to fail on one of our build machines which uses a slow hard drive and where numerous large unrelated temporary directories within the install prefix had inadvertently not been cleaned up. Traversing the entire install prefix looking for empty directories took longer than one hour, and our build machines cancel a build if no output had been produced by the build for one hour. The problem originates from these lines in your CMakeLists.txt:
I suggest deleting these lines. If your goal was only to delete empty directories that might have been created by the mongo-cxx-driver installation process, then you could confine the deletions to the destination directory that the user (or MacPorts on the user's behalf) specified via the DESTDIR variable when invoking make, e.g. we ran:
and the installation prefix was /opt/local so you should only perform empty directory deletions in /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_mongo-cxx-driver/mongo-cxx-driver/work/destroot/opt/local. However, that won't help if the user didn't specify a DESTDIR. Therefore the safest solution is not to attempt to delete empty directories at all. Or, if you know which directories you created during the build that might still be empty, delete only those by name rather than traversing the filesystem. |
| Comments |
| Comment by Githook User [ 05/Oct/21 ] | ||||||
|
Author: {'name': 'Roberto C. Sánchez', 'email': 'roberto@connexer.com', 'username': 'rcsanchez97'}Message: | ||||||
| Comment by Roberto Sanchez [ 14/Sep/21 ] | ||||||
|
The webhook doesn't seem to comment for commits to the release branch. The commit on releases/v3.6 was: https://github.com/mongodb/mongo-cxx-driver/commit/4a51b556a3ef66f9a53fdbe095a1446a6e2585a9 | ||||||
| Comment by Githook User [ 10/Sep/21 ] | ||||||
|
Author: {'name': 'Roberto C. Sánchez', 'email': 'roberto@connexer.com', 'username': 'rcsanchez97'}Message: | ||||||
| Comment by Roberto Sanchez [ 31/Aug/21 ] | ||||||
|
ryandesign, it seems that the reason for pruning empty directories is because CMake creates them and this is the most effective way of dealing with it. What specifically happens is that we install all public headers with a CMake command like this:
The behavior of this command is to create all of the directories and subdirectories from the entire source tree starting at the directory specified by the DIRECTORY parameter, regardless of whether the FILES_MATCHING filter matches any files, potentially leaving a particular directory empty. We have some directories with private headers (extension .hh rather than .hpp) and if it happens that a directory contains only private headers, then the corresponding directory in the destination tree remains empty. This CMake behavior has been known for some time and is the subject of at least these two issues: 1 2. The combination of this behavior and the fact that the find command does not account for DESTDIR is what has resulted in the buggy behavior reported in this issue. Once I understood the behavior at a more fundamental level and realized that it was only because of the way we install the headers, it was clear that we should only ever expect empty directories under the header directories that we install as part of the C++ driver. There are potential workarounds to this CMake behavior, but they seem to suffer from fragility or other issues that makes them not particularly good choices. Taking all of this together, it seemed that two changes were needed:
This seems like a good way to balance the direct installation of the C++ driver (i.e., outside of some package maintenance framework or distribution packaging setup) where there are no follow-on tasks to handle things like empty directory pruning and to not break for more advanced setups (like the one that triggered the original report). | ||||||
| Comment by Kevin Albertson [ 04/Jun/21 ] | ||||||
|
Thank you for the detailed bug report ryandesign! We will look into this soon. |