ExternalProject.cmake and macOS .DS_store
During the extraction phase in _ep_write_extractfile_script, a .DS_Store file is sometimes created in the temporary download directory. Unfortunately, this misleads the logic intended to move the extracted contents to the destination directory and adds another unnecessary (and deal breaking) sub-directory. For example:
Expected result :
- ../ext_target_prefix/src/ext_target/exploded_tarfile_directory_contents.
Actual Result:
- ../ext_target_prefix/src/ext_target/exploded_tarfile_directory/exploded_tarfile_directory_contents.
Because of this state before the move:
- ../ext_target_prefix/src/ext_target1234/.
- ../ext_target_prefix/src/ext_target1234/.DS_Store <---- Offending .DS_Store file.
- ../ext_target_prefix/src/ext_target1234/exploded_tarfile_directory/exploded_tarfile_directory_contents.
The following code within the function moves the contents of the exploded directory or the directory itself depending on a count of files:
# Analyze what came out of the tar file:
#
message(STATUS \"extracting... [analysis]\")
file(GLOB contents \"\${ut_dir}/*\")
list(LENGTH contents n)
if(NOT n EQUAL 1 OR NOT IS_DIRECTORY \"\${contents}\")
set(contents \"\${ut_dir}\")
endif()
# Move \"the one\" directory to the final directory:
#
message(STATUS \"extracting... [rename]\")
file(REMOVE_RECURSE \${directory})
get_filename_component(contents \${contents} ABSOLUTE)
file(RENAME \${contents} \${directory})
In most cases (if not all?) cmake should ignore the .DS_Store Mac specific folder attribute files. I fixed this myself by removing the the .DS_Store entry from the list like so:
# Analyze what came out of the tar file:
#
message(STATUS \"extracting... [analysis]\")
file(GLOB contents \"\${ut_dir}/*\")
list(REMOVE_ITEM contents \"\${ut_dir}/.DS_Store\")
list(LENGTH contents n)
if(NOT n EQUAL 1 OR NOT IS_DIRECTORY \"\${contents}\")
set(contents \"\${ut_dir}\")
endif()
# Move \"the one\" directory to the final directory:
#
message(STATUS \"extracting... [rename]\")
file(REMOVE_RECURSE \${directory})
get_filename_component(contents \${contents} ABSOLUTE)
file(RENAME \${contents} \${directory})
I attempted to control the OS X tar extraction behavior to exclude these pesky annoyances or even some obscure environment variables that Google up, to no avail. Haven't found any consistent documented logic behind when tar creates these or not as I have another source code .tar.gz that explodes just fine. Maybe just me, but in general cmake logic needs to take into account the "possible" existence of these Mac artifacts.